static void opengl_purge_shader_cache_type(const char* ext) { SCP_string filter("*."); filter += ext; // Previously the cache files were stored in the mod directory. Since we have a better system now, those files // should be cleaned out. This is only needed if we have a mod directory since otherwise we would delete the actual // cache files if (Cmdline_mod != nullptr && strlen(Cmdline_mod) > 0) { SCP_vector<SCP_string> cache_files; cf_get_file_list(cache_files, CF_TYPE_CACHE, filter.c_str(), CF_SORT_NONE, nullptr, CF_LOCATION_TYPE_PRIMARY_MOD | CF_LOCATION_TYPE_SECONDARY_MODS); for (auto& file : cache_files) { cf_delete((file + "." + ext).c_str(), CF_TYPE_CACHE, CF_LOCATION_TYPE_PRIMARY_MOD | CF_LOCATION_TYPE_SECONDARY_MODS); } } SCP_vector<SCP_string> cache_files; SCP_vector<file_list_info> file_info; cf_get_file_list(cache_files, CF_TYPE_CACHE, filter.c_str(), CF_SORT_NONE, &file_info, CF_LOCATION_ROOT_USER | CF_LOCATION_ROOT_GAME | CF_LOCATION_TYPE_ROOT); Assertion(cache_files.size() == file_info.size(), "cf_get_file_list returned different sizes for file names and file informations!"); const auto TIMEOUT = 2.0 * 30.0 * 24.0 * 60.0 * 60.0; // purge timeout in seconds which is ~2 months const SCP_string PREFIX = "ogl_shader-"; auto now = std::time(nullptr); for (size_t i = 0; i < cache_files.size(); ++i) { auto& name = cache_files[i]; auto write_time = file_info[i].write_time; if (name.compare(0, PREFIX.size(), PREFIX) != 0) { // Not an OpenGL cache file continue; } auto diff = std::difftime(now, write_time); if (diff > TIMEOUT) { auto full_name = name + "." + ext; cf_delete(full_name.c_str(), CF_TYPE_CACHE); } } }
static void opengl_purge_shader_cache_type(const char* ext) { SCP_vector<SCP_string> cache_files; SCP_vector<file_list_info> file_info; SCP_string filter("*."); filter += ext; cf_get_file_list(cache_files, CF_TYPE_CACHE, filter.c_str(), false, &file_info); Assertion(cache_files.size() == file_info.size(), "cf_get_file_list returned different sizes for file names and file informations!"); const auto TIMEOUT = 2.0 * 30.0 * 24.0 * 60.0 * 60.0; // purge timeout in seconds which is ~2 months const SCP_string PREFIX = "ogl_shader-"; auto now = std::time(nullptr); for (size_t i = 0; i < cache_files.size(); ++i) { auto& name = cache_files[i]; auto write_time = file_info[i].write_time; if (name.compare(0, PREFIX.size(), PREFIX) != 0) { // Not an OpenGL cache file continue; } std::cout << std::put_time(localtime(&write_time), "%c %Z") << std::endl; auto diff = std::difftime(now, write_time); if (diff > TIMEOUT) { auto full_name = name + "." + ext; cf_delete(full_name.c_str(), CF_TYPE_CACHE); } } }
int fs2netd_get_valid_missions_do() { if (Local_timeout == -1) { Local_timeout = timer_get_seconds() + 30; } // get the available CRCs from the server if we need to if ( FS2NetD_file_list.empty() ) { int rc = FS2NetD_GetMissionsList(FS2NetD_file_list, do_full_packet); do_full_packet = false; // communications error if (rc < 0) { Local_timeout = -1; return 4; } // no missions if ( rc && FS2NetD_file_list.empty() ) { Local_timeout = -1; return 2; } // if timeout passes then bail on crc failure if ( timer_get_seconds() > Local_timeout ) { Local_timeout = -1; return 1; } } // we should have the CRCs, or there were no missions, so process them else { static char **file_names = NULL; static int idx = 0, count = 0; bool found = false; int file_index = 0; char valid_status = MVALID_STATUS_UNKNOWN; char full_name[MAX_FILENAME_LEN], wild_card[10]; char val_text[MAX_FILENAME_LEN+15]; uint checksum = 0; if (file_names == NULL) { // allocate filename space file_names = (char**) vm_malloc_q( sizeof(char*) * 1024 ); // 1024 files should be safe! if (file_names == NULL) { Local_timeout = -1; return 3; } memset( wild_card, 0, sizeof(wild_card) ); strcpy_s( wild_card, NOX("*") ); strcat_s( wild_card, FS_MISSION_FILE_EXT ); idx = count = cf_get_file_list(1024, file_names, CF_TYPE_MISSIONS, wild_card); } // drop idx first thing idx--; // we should be done validating, or just not have nothing to validate if (idx < 0) { for (idx = 0; idx < count; idx++) { if (file_names[idx] != NULL) { vm_free(file_names[idx]); file_names[idx] = NULL; } } vm_free(file_names); file_names = NULL; idx = count = 0; Local_timeout = -1; return 4; } // verify all filenames that we know about with their CRCs // NOTE: that this is done for one file per frame, since this is inside of a popup memset( full_name, 0, MAX_FILENAME_LEN ); strncpy( full_name, cf_add_ext(file_names[idx], FS_MISSION_FILE_EXT), sizeof(full_name) - 1 ); memset( val_text, 0, sizeof(val_text) ); snprintf( val_text, sizeof(val_text) - 1, "Validating: %s", full_name ); if (Is_standalone) { if ( std_gen_is_active() ) { std_gen_set_text(val_text, 1); } } else { popup_change_text(val_text); } cf_chksum_long(full_name, &checksum); // try and find the file file_index = multi_create_lookup_mission(full_name); found = false; if (file_index >= 0) { for (SCP_vector<file_record>::iterator fr = FS2NetD_file_list.begin(); fr != FS2NetD_file_list.end() && !found; ++fr) { if ( !stricmp(full_name, fr->name) ) { if (fr->crc32 == checksum) { found = true; valid_status = MVALID_STATUS_VALID; } else { valid_status = MVALID_STATUS_INVALID; } Multi_create_mission_list[file_index].valid_status = valid_status; } } if (found) { ml_printf("FS2NetD Mission Validation: %s => Valid!", full_name); } else { ml_printf("FS2NetD Mission Validation: %s => INVALID! -- 0x%08x", full_name, checksum); } } } return 0; }
//Generates a list of available campaigns. Sets active campaign to "freespace2.fc2", or if that is unavailable, the first campaign found void pilot_set_start_campaign(player* p) { char wild_card[10]; int i, j, incr = 0; char *t = NULL; int rc = 0; char *campaign_file_list[MAX_CAMPAIGNS]; memset(wild_card, 0, sizeof(wild_card)); strcpy_s(wild_card, NOX("*")); strcat_s(wild_card, FS_CAMPAIGN_FILE_EXT); // set filter for cf_get_file_list() if there isn't one set already (the simroom has a special one) if (Get_file_list_filter == NULL) Get_file_list_filter = campaign_file_list_filter; // now get the list of all campaign names // NOTE: we don't do sorting here, but we assume CF_SORT_NAME, and do it manually below rc = cf_get_file_list(MAX_CAMPAIGNS, campaign_file_list, CF_TYPE_MISSIONS, wild_card, CF_SORT_NONE); for (i = 0; i < rc; i++) { if (!stricmp(campaign_file_list[i], Default_campaign_file_name)) { strcpy_s(p->current_campaign, campaign_file_list[i]); return; } } // now sort everything incr = local_num_campaigns / 2; while (incr > 0) { for (i = incr; i < local_num_campaigns; i++) { j = i - incr; while (j >= 0) { char *name1 = Campaign_names[j]; char *name2 = Campaign_names[j + incr]; // if we hit this then a coder probably did something dumb (like not needing to sort) if ( (name1 == NULL) || (name2 == NULL) ) { Int3(); break; } if ( !strnicmp(name1, "the ", 4) ) name1 += 4; if ( !strnicmp(name2, "the ", 4) ) name2 += 4; if (stricmp(name1, name2) > 0) { // first, do filenames t = campaign_file_list[j]; campaign_file_list[j] = campaign_file_list[j + incr]; campaign_file_list[j + incr] = t; j -= incr; } else { break; } } } incr /= 2; } if (rc > 0) strcpy_s(p->current_campaign, campaign_file_list[0]); else strcpy_s(p->current_campaign, "<none>"); }
void convert_pilot_files() { size_t idx, j, i; size_t count, inf_count; int max_convert, num_converted = 0; SCP_vector<SCP_string> existing; SCP_vector<SCP_string> old_files; // get list of pilots which already exist (new or converted already) cf_get_file_list(existing, CF_TYPE_PLAYERS, "*.plr"); // get list of old pilots which may need converting, starting with inferno pilots Get_file_list_child = "inferno"; cf_get_file_list(old_files, CF_TYPE_SINGLE_PLAYERS, "*.pl2"); inf_count = old_files.size(); cf_get_file_list(old_files, CF_TYPE_SINGLE_PLAYERS, "*.pl2"); if ( old_files.empty() ) { return; } // rip out all files which already exist i = 0; count = old_files.size(); for (idx = 0; idx < existing.size(); idx++) { const char *fname = existing[idx].c_str(); for (j = 0; j < count; j++) { if ( !stricmp(fname, old_files[j].c_str()) ) { // NOTE: we just clear the name here to avoid the fragmentation // from resizing the vector old_files[j] = ""; ++i; } } } // don't convert enough pilots to exceed the pilot limit max_convert = MAX_PILOTS - (int)existing.size(); // if everything is already converted then bail // also bail if MAX_PILOTS (or more!) already exist if (i == count || max_convert <= 0) { return; } mprintf(("PILOT: Beginning pilot file conversion...\n")); // now proceed to convert all of the old files count = old_files.size(); for (idx = 0; idx < count; idx++) { if ( old_files[idx].empty() ) { continue; } pilotfile_convert *pcon = new pilotfile_convert; bool inferno = (idx < inf_count); if ( pcon->plr_convert(old_files[idx].c_str(), inferno) ) { SCP_vector<SCP_string> savefiles; SCP_string wildcard(old_files[idx]); wildcard.append("*.cs2"); if (inferno) { Get_file_list_child = "inferno"; } cf_get_file_list(savefiles, CF_TYPE_SINGLE_PLAYERS, wildcard.c_str()); for (j = 0; j < savefiles.size(); j++) { pcon->csg_convert(savefiles[j].c_str(), inferno); } ++num_converted; } delete pcon; if (num_converted >= max_convert) { break; } } mprintf(("PILOT: Pilot file conversion complete!\n")); }