Compare commits

...

6 Commits

Author SHA1 Message Date
aleos
a808526fdd Properly loop over main and import 2020-07-29 14:23:20 -04:00
aleos89
683e5f01a2 Fixed LGTM Alerts 2019-10-10 11:13:15 -04:00
aleos89
a0461ffc1e Another cleanup 2019-07-23 10:45:11 -04:00
aleos89
fe1966ea7a Minor cleanups 2019-07-23 10:40:33 -04:00
aleos89
1cbd688761 Partial reversion
* Made it so changes are made only to the import map_cache to relieve the main one from merge conflicts.
2019-07-23 10:22:19 -04:00
aleos89
61ffb1ce3d Added support for import map_cache building
* Fixes #4234.
* Added maps defined in the import map_index to be saved into the import map_cache.
* Expanded detail of warning messages.
Thanks to @llchrisll!
2019-07-23 08:50:48 -04:00

View File

@ -149,7 +149,8 @@ int find_map(char *name)
fseek(map_cache_fp, sizeof(struct main_header), SEEK_SET); fseek(map_cache_fp, sizeof(struct main_header), SEEK_SET);
for(i = 0; i < header.map_count; i++) { for(i = 0; i < header.map_count; i++) {
if(fread(&info, sizeof(info), 1, map_cache_fp) != 1) printf("An error as occured in fread while reading map_cache\n"); if(fread(&info, sizeof(info), 1, map_cache_fp) != 1)
printf("An error has occurred in fread while reading map_cache_fp.\n");
if(strcmp(name, info.name) == 0) // Map found if(strcmp(name, info.name) == 0) // Map found
return 1; return 1;
else // Map not found, jump to the beginning of the next map info header else // Map not found, jump to the beginning of the next map info header
@ -194,15 +195,23 @@ void process_args(int argc, char *argv[])
int do_init(int argc, char** argv) int do_init(int argc, char** argv)
{ {
/* setup pre-defined, #define-dependant */
map_cache_file = std::string(db_path) + "/" + std::string(DBPATH) + "map_cache.dat";
// Process the command-line arguments // Process the command-line arguments
process_args(argc, argv); process_args(argc, argv);
ShowStatus("Initializing grfio with %s\n", grf_list_file.c_str()); ShowStatus("Initializing grfio with %s\n", grf_list_file.c_str());
grfio_init(grf_list_file.c_str()); grfio_init(grf_list_file.c_str());
// Open the map list
FILE *list;
std::vector<std::string> directories = { std::string(db_path) + "/", std::string(db_path) + "/" + std::string(DBIMPORT) + "/" };
for (const auto &directory : directories) {
/* setup pre-defined, #define-dependant */
if (directory.find("import") != std::string::npos)
map_cache_file = std::string(db_path) + "/" + std::string(DBIMPORT) + "map_cache.dat";
else
map_cache_file = std::string(db_path) + "/" + std::string(DBPATH) + "/map_cache.dat";
// Attempt to open the map cache file and force rebuild if not found // Attempt to open the map cache file and force rebuild if not found
ShowStatus("Opening map cache: %s\n", map_cache_file.c_str()); ShowStatus("Opening map cache: %s\n", map_cache_file.c_str());
if (!rebuild) { if (!rebuild) {
@ -222,11 +231,6 @@ int do_init(int argc, char** argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
// Open the map list
FILE *list;
std::vector<std::string> directories = { std::string(db_path) + "/", std::string(db_path) + "/" + std::string(DBIMPORT) + "/" };
for (const auto &directory : directories) {
std::string filename = directory + map_list_file; std::string filename = directory + map_list_file;
ShowStatus("Opening map list: %s\n", filename.c_str()); ShowStatus("Opening map list: %s\n", filename.c_str());
@ -241,7 +245,8 @@ int do_init(int argc, char** argv)
header.file_size = sizeof(struct main_header); header.file_size = sizeof(struct main_header);
header.map_count = 0; header.map_count = 0;
} else { } else {
if (fread(&header, sizeof(struct main_header), 1, map_cache_fp) != 1) { printf("An error as occured while reading map_cache_fp \n"); } if (fread(&header, sizeof(struct main_header), 1, map_cache_fp) != 1)
printf("An error has occurred in fread while reading map_cache_fp.\n");
header.file_size = GetULong((unsigned char *)&(header.file_size)); header.file_size = GetULong((unsigned char *)&(header.file_size));
header.map_count = GetUShort((unsigned char *)&(header.map_count)); header.map_count = GetUShort((unsigned char *)&(header.map_count));
} }
@ -277,16 +282,16 @@ int do_init(int argc, char** argv)
} }
ShowStatus("Closing map list: %s\n", filename.c_str());
fclose(list);
}
// Write the main header and close the map cache // Write the main header and close the map cache
ShowStatus("Closing map cache: %s\n", map_cache_file.c_str()); ShowStatus("Closing map cache: %s\n", map_cache_file.c_str());
fseek(map_cache_fp, 0, SEEK_SET); fseek(map_cache_fp, 0, SEEK_SET);
fwrite(&header, sizeof(struct main_header), 1, map_cache_fp); fwrite(&header, sizeof(struct main_header), 1, map_cache_fp);
fclose(map_cache_fp); fclose(map_cache_fp);
ShowStatus("Closing map list: %s\n", filename.c_str());
fclose(list);
}
ShowStatus("Finalizing grfio\n"); ShowStatus("Finalizing grfio\n");
grfio_final(); grfio_final();