/* * Add archives to the game. * 1) archives from Sharepath/Data to extend/replace builtin game content * 2) archived demos */ void PHYSFSX_addArchiveContent() { char **list = NULL; static const char *const archive_exts[] = { ".zip", ".7z", NULL }; char *file[2]; int i = 0, content_updated = 0; con_printf(CON_DEBUG, "PHYSFS: Adding archives to the game.\n"); // find files in Searchpath ... list = PHYSFSX_findFiles("", archive_exts); // if found, add them... for (i = 0; list[i] != NULL; i++) { MALLOC(file[0], char, PATH_MAX); MALLOC(file[1], char, PATH_MAX); snprintf(file[0], sizeof(char)*PATH_MAX, "%s", list[i]); PHYSFSX_getRealPath(file[0],file[1]); if (PHYSFS_addToSearchPath(file[1], 0)) { con_printf(CON_DEBUG, "PHYSFS: Added %s to Search Path\n",file[1]); content_updated = 1; } d_free(file[0]); d_free(file[1]); } PHYSFS_freeList(list); list = NULL; #if PHYSFS_VER_MAJOR >= 2 // find files in DEMO_DIR ... list = PHYSFSX_findFiles(DEMO_DIR, archive_exts); // if found, add them... for (i = 0; list[i] != NULL; i++) { MALLOC(file[0], char, PATH_MAX); MALLOC(file[1], char, PATH_MAX); snprintf(file[0], sizeof(char)*PATH_MAX, "%s%s", DEMO_DIR, list[i]); PHYSFSX_getRealPath(file[0],file[1]); if (PHYSFS_mount(file[1], DEMO_DIR, 0)) { con_printf(CON_DEBUG, "PHYSFS: Added %s to %s\n",file[1], DEMO_DIR); content_updated = 1; } d_free(file[0]); d_free(file[1]); } PHYSFS_freeList(list); list = NULL; #endif if (content_updated) { con_printf(CON_DEBUG, "Game content updated!\n"); PHYSFSX_listSearchPathContent(); } }
// Removes content added above when quitting game void PHYSFSX_removeArchiveContent() { char **list = NULL; static const char *const archive_exts[] = { ".zip", ".7z", NULL }; char *file[2]; int i = 0; // find files in Searchpath ... list = PHYSFSX_findFiles("", archive_exts); // if found, remove them... for (i = 0; list[i] != NULL; i++) { MALLOC(file[0], char, PATH_MAX); MALLOC(file[1], char, PATH_MAX); snprintf(file[0], sizeof(char)*PATH_MAX, "%s", list[i]); PHYSFSX_getRealPath(file[0],file[1]); PHYSFS_removeFromSearchPath(file[1]); d_free(file[0]); d_free(file[1]); } PHYSFS_freeList(list); list = NULL; // find files in DEMO_DIR ... list = PHYSFSX_findFiles(DEMO_DIR, archive_exts); // if found, remove them... for (i = 0; list[i] != NULL; i++) { MALLOC(file[0], char, PATH_MAX); MALLOC(file[1], char, PATH_MAX); snprintf(file[0], sizeof(char)*PATH_MAX, "%s%s", DEMO_DIR, list[i]); PHYSFSX_getRealPath(file[0],file[1]); PHYSFS_removeFromSearchPath(file[1]); d_free(file[0]); d_free(file[1]); } PHYSFS_freeList(list); list = NULL; }
/* Loads music file names from a given directory or M3U playlist */ void jukebox_load() { jukebox_unload(); // Check if it's an M3U file auto &cfgpath = CGameCfg.CMLevelMusicPath; size_t musiclen = strlen(cfgpath.data()); if (musiclen > 4 && !d_stricmp(&cfgpath[musiclen - 4], ".m3u")) read_m3u(); else // a directory { class PHYSFS_path_deleter { public: void operator()(const char *const p) const noexcept { PHYSFS_removeFromSearchPath(p); } }; std::unique_ptr<const char, PHYSFS_path_deleter> new_path; const char *sep = PHYSFS_getDirSeparator(); size_t seplen = strlen(sep); // stick a separator on the end if necessary. if (musiclen >= seplen) { auto p = &cfgpath[musiclen - seplen]; if (strcmp(p, sep)) cfgpath.copy_if(musiclen, sep, seplen); } const auto p = cfgpath.data(); // Read directory using PhysicsFS if (PHYSFS_isDirectory(p)) // find files in relative directory JukeboxSongs.list.reset(PHYSFSX_findFiles(p, jukebox_exts)); else { if (PHYSFSX_isNewPath(p)) new_path.reset(p); PHYSFS_addToSearchPath(p, 0); // as mountpoints are no option (yet), make sure only files originating from GameCfg.CMLevelMusicPath are aded to the list. JukeboxSongs.list.reset(PHYSFSX_findabsoluteFiles("", p, jukebox_exts)); } if (!JukeboxSongs.list) { return; } JukeboxSongs.num_songs = std::distance(JukeboxSongs.list.begin(), JukeboxSongs.list.end()); } if (JukeboxSongs.num_songs) { con_printf(CON_DEBUG,"Jukebox: %d music file(s) found in %s", JukeboxSongs.num_songs, cfgpath.data()); if (CGameCfg.CMLevelMusicTrack[1] != JukeboxSongs.num_songs) { CGameCfg.CMLevelMusicTrack[1] = JukeboxSongs.num_songs; CGameCfg.CMLevelMusicTrack[0] = 0; // number of songs changed so start from beginning. } } else { CGameCfg.CMLevelMusicTrack[0] = -1; CGameCfg.CMLevelMusicTrack[1] = -1; con_puts(CON_DEBUG,"Jukebox music could not be found!"); } }