From 5aae8e2d646066a548f7fe5d1affdcffe0ac6bc4 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 5 Apr 2026 19:02:51 +0100 Subject: [PATCH] Codechange: make Subdirectory a scoped enum --- src/ai/ai_instance.cpp | 2 +- src/ai/ai_scanner.hpp | 4 +- src/base_media_base.h | 6 +-- src/base_media_func.h | 4 +- src/console_cmds.cpp | 30 ++++++------- src/crashlog.cpp | 4 +- src/debug.cpp | 4 +- src/driver.cpp | 6 +-- src/fileio.cpp | 70 +++++++++++++++-------------- src/fileio_type.h | 40 ++++++++--------- src/fios.cpp | 48 ++++++++++---------- src/fios_gui.cpp | 12 ++--- src/fontcache.cpp | 2 +- src/fontcache/freetypefontcache.cpp | 2 +- src/game/game_instance.cpp | 2 +- src/game/game_scanner.hpp | 4 +- src/game/game_text.cpp | 8 ++-- src/genworld.cpp | 4 +- src/gfxinit.cpp | 12 ++--- src/heightmap.cpp | 6 +-- src/help_gui.cpp | 24 +++++----- src/hotkeys.cpp | 2 +- src/music.cpp | 8 ++-- src/music/midifile.cpp | 12 ++--- src/network/core/tcp_content.cpp | 18 ++++---- src/network/network.cpp | 2 +- src/network/network_client.cpp | 2 +- src/network/network_content.cpp | 6 +-- src/newgrf.cpp | 2 +- src/newgrf_config.cpp | 4 +- src/newgrf_config.h | 2 +- src/newgrf_gui.cpp | 2 +- src/newgrf_profiling.cpp | 2 +- src/openttd.cpp | 12 ++--- src/os/macosx/font_osx.cpp | 2 +- src/os/windows/font_win32.cpp | 2 +- src/saveload/oldloader.cpp | 4 +- src/saveload/saveload.cpp | 10 ++--- src/script/script_config.cpp | 2 +- src/script/script_gui.cpp | 2 +- src/script/squirrel.cpp | 8 ++-- src/settings.cpp | 4 +- src/settings_gui.cpp | 2 +- src/settingsgen/settingsgen.cpp | 2 +- src/signature.cpp | 4 +- src/social_integration.cpp | 2 +- src/sound.cpp | 2 +- src/strings.cpp | 2 +- src/tar_type.h | 6 +-- src/textfile_gui.cpp | 6 +-- src/video/sdl2_v.cpp | 2 +- src/window.cpp | 4 +- 52 files changed, 218 insertions(+), 216 deletions(-) diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp index b22da6b668..8e140ffa6a 100644 --- a/src/ai/ai_instance.cpp +++ b/src/ai/ai_instance.cpp @@ -55,7 +55,7 @@ void AIInstance::RegisterAPI() /* Register all classes */ SQAI_RegisterAll(*this->engine); - if (!this->LoadCompatibilityScripts(AI_DIR, AIInfo::ApiVersions)) this->Died(); + if (!this->LoadCompatibilityScripts(Subdirectory::Ai, AIInfo::ApiVersions)) this->Died(); } void AIInstance::Died() diff --git a/src/ai/ai_scanner.hpp b/src/ai/ai_scanner.hpp index 157a0e0d5e..a2a8f40a4e 100644 --- a/src/ai/ai_scanner.hpp +++ b/src/ai/ai_scanner.hpp @@ -44,7 +44,7 @@ public: protected: std::string GetScriptName(ScriptInfo &info) override; std::string_view GetFileName() const override { return PATHSEP "info.nut"; } - Subdirectory GetDirectory() const override { return AI_DIR; } + Subdirectory GetDirectory() const override { return Subdirectory::Ai; } std::string_view GetScannerName() const override { return "AIs"; } void RegisterAPI(class Squirrel &engine) override; @@ -68,7 +68,7 @@ public: protected: std::string GetScriptName(ScriptInfo &info) override; std::string_view GetFileName() const override { return PATHSEP "library.nut"; } - Subdirectory GetDirectory() const override { return AI_LIBRARY_DIR; } + Subdirectory GetDirectory() const override { return Subdirectory::AiLibrary; } std::string_view GetScannerName() const override { return "AI Libraries"; } void RegisterAPI(class Squirrel &engine) override; }; diff --git a/src/base_media_base.h b/src/base_media_base.h index 30a2bb7695..5b3f9ab66a 100644 --- a/src/base_media_base.h +++ b/src/base_media_base.h @@ -143,7 +143,7 @@ struct BaseSet { std::optional GetTextfile(TextfileType type) const { for (const auto &file : this->files) { - auto textfile = ::GetTextfile(type, BASESET_DIR, file.filename); + auto textfile = ::GetTextfile(type, Subdirectory::Baseset, file.filename); if (textfile.has_value()) { return textfile; } @@ -198,8 +198,8 @@ public: { BaseMedia fs; /* Searching in tars is only done in the old "data" directories basesets. */ - uint num = fs.Scan(GetExtension(), Tbase_set::SEARCH_IN_TARS ? OLD_DATA_DIR : OLD_GM_DIR, Tbase_set::SEARCH_IN_TARS); - return num + fs.Scan(GetExtension(), BASESET_DIR, Tbase_set::SEARCH_IN_TARS); + uint num = fs.Scan(GetExtension(), Tbase_set::SEARCH_IN_TARS ? Subdirectory::OldData : Subdirectory::OldGm, Tbase_set::SEARCH_IN_TARS); + return num + fs.Scan(GetExtension(), Subdirectory::Baseset, Tbase_set::SEARCH_IN_TARS); } /** diff --git a/src/base_media_func.h b/src/base_media_func.h index a292f65256..64288da65e 100644 --- a/src/base_media_func.h +++ b/src/base_media_func.h @@ -157,7 +157,7 @@ bool BaseSet::FillSetDetails(const IniFile &ini, const std::string &path, con file->missing_warning = item->value.value(); } - file->check_result = T::CheckMD5(file, BASESET_DIR); + file->check_result = T::CheckMD5(file, Subdirectory::Baseset); switch (file->check_result) { case MD5File::CR_UNKNOWN: break; @@ -191,7 +191,7 @@ bool BaseMedia::AddFile(const std::string &filename, size_t basepath_ auto set = std::make_unique(); IniFile ini{}; std::string path{ filename, basepath_length }; - ini.LoadFromDisk(path, BASESET_DIR); + ini.LoadFromDisk(path, Subdirectory::Baseset); auto psep = path.rfind(PATHSEPCHAR); if (psep != std::string::npos) { diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 2d2221a9e6..6dccc94cec 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -425,7 +425,7 @@ static bool ConSave(std::span argv) std::string filename = fmt::format("{}.sav", argv[1]); IConsolePrint(CC_DEFAULT, "Saving map..."); - if (SaveOrLoad(filename, SaveLoadOperation::Save, DetailedFileType::GameFile, SAVE_DIR) != SL_OK) { + if (SaveOrLoad(filename, SaveLoadOperation::Save, DetailedFileType::GameFile, Subdirectory::Save) != SL_OK) { IConsolePrint(CC_ERROR, "Saving map failed."); } else { IConsolePrint(CC_INFO, "Map successfully saved to '{}'.", filename); @@ -1207,7 +1207,7 @@ static bool ConExec(std::span argv) if (argv.size() < 2) return false; - auto script_file = FioFOpenFile(argv[1], "r", BASE_DIR); + auto script_file = FioFOpenFile(argv[1], "r", Subdirectory::Base); if (!script_file.has_value()) { if (argv.size() == 2 || argv[2] != "0") IConsolePrint(CC_ERROR, "Script file '{}' not found.", argv[1]); @@ -1254,7 +1254,7 @@ static bool ConSchedule(std::span argv) } /* Check if the file exists. It might still go away later, but helpful to show an error now. */ - if (!FioCheckFileExists(argv[2], BASE_DIR)) { + if (!FioCheckFileExists(argv[2], Subdirectory::Base)) { IConsolePrint(CC_ERROR, "Script file '{}' not found.", argv[2]); return true; } @@ -2551,19 +2551,19 @@ static bool ConListDirs(std::span argv) }; static const SubdirNameMap subdir_name_map[] = { /* Game data directories */ - { "baseset", BASESET_DIR, false }, - { "newgrf", NEWGRF_DIR, false }, - { "ai", AI_DIR, false }, - { "ailib", AI_LIBRARY_DIR, false }, - { "gs", GAME_DIR, false }, - { "gslib", GAME_LIBRARY_DIR, false }, - { "scenario", SCENARIO_DIR, false }, - { "heightmap", HEIGHTMAP_DIR, false }, + { "baseset", Subdirectory::Baseset, false }, + { "newgrf", Subdirectory::NewGrf, false }, + { "ai", Subdirectory::Ai, false }, + { "ailib", Subdirectory::AiLibrary, false }, + { "gs", Subdirectory::Gs, false }, + { "gslib", Subdirectory::GsLibrary, false }, + { "scenario", Subdirectory::Scenario, false }, + { "heightmap", Subdirectory::Heightmap, false }, /* Default save locations for user data */ - { "save", SAVE_DIR, true }, - { "autosave", AUTOSAVE_DIR, true }, - { "screenshot", SCREENSHOT_DIR, true }, - { "social_integration", SOCIAL_INTEGRATION_DIR, true }, + { "save", Subdirectory::Save, true }, + { "autosave", Subdirectory::Autosave, true }, + { "screenshot", Subdirectory::Screenshot, true }, + { "social_integration", Subdirectory::SocialIntegration, true }, }; if (argv.size() != 2) { diff --git a/src/crashlog.cpp b/src/crashlog.cpp index d3d4d547e5..f13ec794cf 100644 --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -192,7 +192,7 @@ bool CrashLog::WriteCrashLog() { this->crashlog_filename = this->CreateFileName(".json.log"); - auto file = FioFOpenFile(this->crashlog_filename, "w", NO_DIRECTORY); + auto file = FioFOpenFile(this->crashlog_filename, "w", Subdirectory::None); if (!file.has_value()) return false; std::string survey_json = this->survey.dump(4); @@ -232,7 +232,7 @@ bool CrashLog::WriteSavegame() this->savegame_filename = this->CreateFileName(".sav"); /* Don't do a threaded saveload. */ - return SaveOrLoad(this->savegame_filename, SaveLoadOperation::Save, DetailedFileType::GameFile, NO_DIRECTORY, false) == SL_OK; + return SaveOrLoad(this->savegame_filename, SaveLoadOperation::Save, DetailedFileType::GameFile, Subdirectory::None, false) == SL_OK; } catch (...) { return false; } diff --git a/src/debug.cpp b/src/debug.cpp index da6f1bea7f..7e2fbf7c4e 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -111,14 +111,14 @@ void DumpDebugFacilityNames(std::back_insert_iterator &output_itera void DebugPrint(std::string_view category, int level, std::string &&message) { if (category == "desync" && level != 0) { - static auto f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR); + static auto f = FioFOpenFile("commands-out.log", "wb", Subdirectory::Autosave); if (!f.has_value()) return; fmt::print(*f, "{}{}\n", GetLogPrefix(true), message); fflush(*f); #ifdef RANDOM_DEBUG } else if (category == "random") { - static auto f = FioFOpenFile("random-out.log", "wb", AUTOSAVE_DIR); + static auto f = FioFOpenFile("random-out.log", "wb", Subdirectory::Autosave); if (!f.has_value()) return; fmt::print(*f, "{}\n", message); diff --git a/src/driver.cpp b/src/driver.cpp index f8a948a79b..631bf064b3 100644 --- a/src/driver.cpp +++ b/src/driver.cpp @@ -127,7 +127,7 @@ bool DriverFactoryBase::SelectDriverImpl(const std::string &name, Driver::Type t /* Check if we have already tried this driver in last run. * If it is here, it most likely means we crashed. So skip * hardware acceleration. */ - auto filename = FioFindFullPath(BASE_DIR, HWACCELERATION_TEST_FILE); + auto filename = FioFindFullPath(Subdirectory::Base, HWACCELERATION_TEST_FILE); if (!filename.empty()) { FioRemove(filename); @@ -140,7 +140,7 @@ bool DriverFactoryBase::SelectDriverImpl(const std::string &name, Driver::Type t } /* Write empty file to note we are attempting hardware acceleration. */ - FioFOpenFile(HWACCELERATION_TEST_FILE, "w", BASE_DIR); + FioFOpenFile(HWACCELERATION_TEST_FILE, "w", Subdirectory::Base); } /* Keep old driver in case we need to switch back, or may still need to process an OS callback. */ @@ -210,7 +210,7 @@ void DriverFactoryBase::MarkVideoDriverOperational() /* As part of the detection whether the GPU driver crashes the game, * and as we are operational now, remove the hardware acceleration * test-file. */ - auto filename = FioFindFullPath(BASE_DIR, HWACCELERATION_TEST_FILE); + auto filename = FioFindFullPath(Subdirectory::Base, HWACCELERATION_TEST_FILE); if (!filename.empty()) FioRemove(filename); } diff --git a/src/fileio.cpp b/src/fileio.cpp index bb767376ea..daca71e6b3 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -35,7 +35,8 @@ static bool _do_scan_working_directory = true; extern std::string _config_file; extern std::string _highscore_file; -static const std::string_view _subdirs[] = { +/** Subdirectory names. */ +static const EnumClassIndexContainer, Subdirectory> _subdirs = { "", "save" PATHSEP, "save" PATHSEP "autosave" PATHSEP, @@ -54,7 +55,6 @@ static const std::string_view _subdirs[] = { "social_integration" PATHSEP, "docs" PATHSEP, }; -static_assert(lengthof(_subdirs) == NUM_SUBDIRS); /** * The search paths OpenTTD could search through. @@ -64,8 +64,10 @@ static_assert(lengthof(_subdirs) == NUM_SUBDIRS); */ std::array _searchpaths; std::vector _valid_searchpaths; -std::array _tar_list; -TarFileList _tar_filelist[NUM_SUBDIRS]; +/** List of tar files found in each subdirectory. */ +EnumClassIndexContainer, Subdirectory> _tar_list; +/** List of files within tar files found in each subdirectory. */ +EnumClassIndexContainer, Subdirectory> _tar_filelist; /** * Checks whether the given search path is a valid search path @@ -143,7 +145,7 @@ bool FileExists(std::string_view filename) */ std::string FioFindFullPath(Subdirectory subdir, std::string_view filename) { - assert(subdir < NUM_SUBDIRS); + assert(subdir < Subdirectory::End); for (Searchpath sp : _valid_searchpaths) { std::string buf = FioGetDirectory(sp, subdir); @@ -162,7 +164,7 @@ std::string FioFindFullPath(Subdirectory subdir, std::string_view filename) std::string FioGetDirectory(Searchpath sp, Subdirectory subdir) { - assert(subdir < NUM_SUBDIRS); + assert(subdir < Subdirectory::End); assert(sp < NUM_SEARCHPATHS); return fmt::format("{}{}", _searchpaths[sp], _subdirs[subdir]); @@ -192,7 +194,7 @@ static std::optional FioFOpenFileSp(std::string_view filename, std:: #endif std::string buf; - if (subdir == NO_DIRECTORY) { + if (subdir == Subdirectory::None) { buf = filename; } else { buf = fmt::format("{}{}{}", _searchpaths[sp], _subdirs[subdir], filename); @@ -200,7 +202,7 @@ static std::optional FioFOpenFileSp(std::string_view filename, std:: auto f = FileHandle::Open(buf, mode); #if !defined(_WIN32) - if (!f.has_value() && strtolower(buf, subdir == NO_DIRECTORY ? 0 : _searchpaths[sp].size() - 1) ) { + if (!f.has_value() && strtolower(buf, subdir == Subdirectory::None ? 0 : _searchpaths[sp].size() - 1) ) { f = FileHandle::Open(buf, mode); } #endif @@ -244,15 +246,15 @@ static std::optional FioFOpenFileTar(const TarFileListEntry &entry, std::optional FioFOpenFile(std::string_view filename, std::string_view mode, Subdirectory subdir, size_t *filesize) { std::optional f = std::nullopt; - assert(subdir < NUM_SUBDIRS || subdir == NO_DIRECTORY); + assert(subdir < Subdirectory::End || subdir == Subdirectory::None); for (Searchpath sp : _valid_searchpaths) { f = FioFOpenFileSp(filename, mode, sp, subdir, filesize); - if (f.has_value() || subdir == NO_DIRECTORY) break; + if (f.has_value() || subdir == Subdirectory::None) break; } /* We can only use .tar in case of data-dir, and read-mode */ - if (!f.has_value() && mode[0] == 'r' && subdir != NO_DIRECTORY) { + if (!f.has_value() && mode[0] == 'r' && subdir != Subdirectory::None) { /* Filenames in tars are always forced to be lowercase */ std::string resolved_name{filename}; strtolower(resolved_name); @@ -290,18 +292,18 @@ std::optional FioFOpenFile(std::string_view filename, std::string_vi /* Sometimes a full path is given. To support * the 'subdirectory' must be 'removed'. */ - if (!f.has_value() && subdir != NO_DIRECTORY) { + if (!f.has_value() && subdir != Subdirectory::None) { switch (subdir) { - case BASESET_DIR: - f = FioFOpenFile(filename, mode, OLD_GM_DIR, filesize); + case Subdirectory::Baseset: + f = FioFOpenFile(filename, mode, Subdirectory::OldGm, filesize); if (f.has_value()) break; [[fallthrough]]; - case NEWGRF_DIR: - f = FioFOpenFile(filename, mode, OLD_DATA_DIR, filesize); + case Subdirectory::NewGrf: + f = FioFOpenFile(filename, mode, Subdirectory::OldData, filesize); break; default: - f = FioFOpenFile(filename, mode, NO_DIRECTORY, filesize); + f = FioFOpenFile(filename, mode, Subdirectory::None, filesize); break; } } @@ -380,7 +382,7 @@ uint TarScanner::DoScan(Subdirectory sd) _tar_filelist[sd].clear(); _tar_list[sd].clear(); uint num = this->Scan(".tar", sd, false); - if (sd == BASESET_DIR || sd == NEWGRF_DIR) num += this->Scan(".tar", OLD_DATA_DIR, false); + if (sd == Subdirectory::Baseset || sd == Subdirectory::NewGrf) num += this->Scan(".tar", Subdirectory::OldData, false); return num; } @@ -395,22 +397,22 @@ uint TarScanner::DoScan(Subdirectory sd) TarScanner fs; uint num = 0; if (modes.Test(TarScanner::Mode::Baseset)) { - num += fs.DoScan(BASESET_DIR); + num += fs.DoScan(Subdirectory::Baseset); } if (modes.Test(TarScanner::Mode::NewGRF)) { - num += fs.DoScan(NEWGRF_DIR); + num += fs.DoScan(Subdirectory::NewGrf); } if (modes.Test(TarScanner::Mode::AI)) { - num += fs.DoScan(AI_DIR); - num += fs.DoScan(AI_LIBRARY_DIR); + num += fs.DoScan(Subdirectory::Ai); + num += fs.DoScan(Subdirectory::AiLibrary); } if (modes.Test(TarScanner::Mode::Game)) { - num += fs.DoScan(GAME_DIR); - num += fs.DoScan(GAME_LIBRARY_DIR); + num += fs.DoScan(Subdirectory::Gs); + num += fs.DoScan(Subdirectory::GsLibrary); } if (modes.Test(TarScanner::Mode::Scenario)) { - num += fs.DoScan(SCENARIO_DIR); - num += fs.DoScan(HEIGHTMAP_DIR); + num += fs.DoScan(Subdirectory::Scenario); + num += fs.DoScan(Subdirectory::Heightmap); } Debug(misc, 2, "Scan complete, found {} files", num); return num; @@ -914,7 +916,7 @@ void DeterminePaths(std::string_view exe, bool only_local_path) if (!_config_file.empty()) { config_dir = _searchpaths[SP_WORKING_DIR]; } else { - std::string personal_dir = FioFindFullPath(BASE_DIR, "openttd.cfg"); + std::string personal_dir = FioFindFullPath(Subdirectory::Base, "openttd.cfg"); if (!personal_dir.empty()) { auto end = personal_dir.find_last_of(PATHSEPCHAR); if (end != std::string::npos) personal_dir.erase(end + 1); @@ -981,7 +983,7 @@ void DeterminePaths(std::string_view exe, bool only_local_path) Debug(misc, 1, "{} found as personal directory", _personal_dir); static const Subdirectory default_subdirs[] = { - SAVE_DIR, AUTOSAVE_DIR, SCENARIO_DIR, HEIGHTMAP_DIR, BASESET_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GAME_DIR, GAME_LIBRARY_DIR, SCREENSHOT_DIR, SOCIAL_INTEGRATION_DIR + Subdirectory::Save, Subdirectory::Autosave, Subdirectory::Scenario, Subdirectory::Heightmap, Subdirectory::Baseset, Subdirectory::NewGrf, Subdirectory::Ai, Subdirectory::AiLibrary, Subdirectory::Gs, Subdirectory::GsLibrary, Subdirectory::Screenshot, Subdirectory::SocialIntegration }; for (const auto &default_subdir : default_subdirs) { @@ -995,7 +997,7 @@ void DeterminePaths(std::string_view exe, bool only_local_path) FillValidSearchPaths(only_local_path); /* Create the directory for each of the types of content */ - const Subdirectory subdirs[] = { SCENARIO_DIR, HEIGHTMAP_DIR, BASESET_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GAME_DIR, GAME_LIBRARY_DIR, SOCIAL_INTEGRATION_DIR }; + const Subdirectory subdirs[] = { Subdirectory::Scenario, Subdirectory::Heightmap, Subdirectory::Baseset, Subdirectory::NewGrf, Subdirectory::Ai, Subdirectory::AiLibrary, Subdirectory::Gs, Subdirectory::GsLibrary, Subdirectory::SocialIntegration }; for (const auto &subdir : subdirs) { FioCreateDirectory(FioGetDirectory(SP_AUTODOWNLOAD_DIR, subdir)); } @@ -1135,18 +1137,18 @@ uint FileScanner::Scan(std::string_view extension, Subdirectory sd, bool tars, b num += ScanPath(this, extension, OTTD2FS(path), path.size(), recursive); } - if (tars && sd != NO_DIRECTORY) { + if (tars && sd != Subdirectory::None) { for (const auto &tar : _tar_filelist[sd]) { num += ScanTar(this, extension, tar); } } switch (sd) { - case BASESET_DIR: - num += this->Scan(extension, OLD_GM_DIR, tars, recursive); + case Subdirectory::Baseset: + num += this->Scan(extension, Subdirectory::OldGm, tars, recursive); [[fallthrough]]; - case NEWGRF_DIR: - num += this->Scan(extension, OLD_DATA_DIR, tars, recursive); + case Subdirectory::NewGrf: + num += this->Scan(extension, Subdirectory::OldData, tars, recursive); break; default: break; diff --git a/src/fileio_type.h b/src/fileio_type.h index e542e2ee00..a46d4c1035 100644 --- a/src/fileio_type.h +++ b/src/fileio_type.h @@ -85,26 +85,26 @@ constexpr FiosType FIOS_TYPE_INVALID{AbstractFileType::Invalid, DetailedFileType /** * The different kinds of subdirectories OpenTTD uses */ -enum Subdirectory : uint8_t { - BASE_DIR, ///< Base directory for all subdirectories - SAVE_DIR, ///< Base directory for all savegames - AUTOSAVE_DIR, ///< Subdirectory of save for autosaves - SCENARIO_DIR, ///< Base directory for all scenarios - HEIGHTMAP_DIR, ///< Subdirectory of scenario for heightmaps - OLD_GM_DIR, ///< Old subdirectory for the music - OLD_DATA_DIR, ///< Old subdirectory for the data. - BASESET_DIR, ///< Subdirectory for all base data (base sets, intro game) - NEWGRF_DIR, ///< Subdirectory for all NewGRFs - LANG_DIR, ///< Subdirectory for all translation files - AI_DIR, ///< Subdirectory for all %AI files - AI_LIBRARY_DIR,///< Subdirectory for all %AI libraries - GAME_DIR, ///< Subdirectory for all game scripts - GAME_LIBRARY_DIR, ///< Subdirectory for all GS libraries - SCREENSHOT_DIR, ///< Subdirectory for all screenshots - SOCIAL_INTEGRATION_DIR, ///< Subdirectory for all social integration plugins - DOCS_DIR, ///< Subdirectory for documentation - NUM_SUBDIRS, ///< Number of subdirectories - NO_DIRECTORY, ///< A path without any base directory +enum class Subdirectory : uint8_t { + Base, ///< Base directory for all subdirectories. + Save, ///< Base directory for all savegames. + Autosave, ///< Subdirectory of save for autosaves. + Scenario, ///< Base directory for all scenarios. + Heightmap, ///< Subdirectory of scenario for heightmaps. + OldGm, ///< Old subdirectory for the music. + OldData, ///< Old subdirectory for the data. + Baseset, ///< Subdirectory for all base data (base sets, intro game). + NewGrf, ///< Subdirectory for all NewGRFs. + Lang, ///< Subdirectory for all translation files. + Ai, ///< Subdirectory for all %AI files. + AiLibrary, ///< Subdirectory for all %AI libraries. + Gs, ///< Subdirectory for all game scripts. + GsLibrary, ///< Subdirectory for all GS libraries. + Screenshot, ///< Subdirectory for all screenshots. + SocialIntegration, ///< Subdirectory for all social integration plugins. + Docs, ///< Subdirectory for documentation. + End, ///< End marker. + None, ///< A path without any base directory. }; /** diff --git a/src/fios.cpp b/src/fios.cpp index 812f674669..edb85e9e00 100644 --- a/src/fios.cpp +++ b/src/fios.cpp @@ -336,7 +336,7 @@ static void FiosGetFileList(SaveLoadOperation fop, bool show_dirs, FiosGetTypeAn /* Show files */ FiosFileScanner scanner(fop, callback_proc, file_list); - if (subdir == NO_DIRECTORY) { + if (subdir == Subdirectory::None) { scanner.Scan({}, *_fios_path, false); } else { scanner.Scan({}, subdir, true, true); @@ -386,7 +386,7 @@ std::tuple FiosGetSavegameListCallback(SaveLoadOperation * .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game */ if (StrEqualsIgnoreCase(ext, ".sav")) { - return { FIOS_TYPE_FILE, GetFileTitle(file, SAVE_DIR) }; + return { FIOS_TYPE_FILE, GetFileTitle(file, Subdirectory::Save) }; } if (fop == SaveLoadOperation::Load) { @@ -410,11 +410,11 @@ void FiosGetSavegameList(SaveLoadOperation fop, bool show_dirs, FileList &file_l { static std::optional fios_save_path; - if (!fios_save_path) fios_save_path = FioFindDirectory(SAVE_DIR); + if (!fios_save_path) fios_save_path = FioFindDirectory(Subdirectory::Save); _fios_path = &(*fios_save_path); - FiosGetFileList(fop, show_dirs, &FiosGetSavegameListCallback, NO_DIRECTORY, file_list); + FiosGetFileList(fop, show_dirs, &FiosGetSavegameListCallback, Subdirectory::None, file_list); } /** @@ -433,7 +433,7 @@ std::tuple FiosGetScenarioListCallback(SaveLoadOperation * .SV0 Transport Tycoon Deluxe (Patch) scenario * .SS0 Transport Tycoon Deluxe preset scenario */ if (StrEqualsIgnoreCase(ext, ".scn")) { - return { FIOS_TYPE_SCENARIO, GetFileTitle(file, SCENARIO_DIR) }; + return { FIOS_TYPE_SCENARIO, GetFileTitle(file, Subdirectory::Scenario) }; } @@ -458,12 +458,12 @@ void FiosGetScenarioList(SaveLoadOperation fop, bool show_dirs, FileList &file_l static std::optional fios_scn_path; /* Copy the default path on first run or on 'New Game' */ - if (!fios_scn_path) fios_scn_path = FioFindDirectory(SCENARIO_DIR); + if (!fios_scn_path) fios_scn_path = FioFindDirectory(Subdirectory::Scenario); _fios_path = &(*fios_scn_path); - std::string base_path = FioFindDirectory(SCENARIO_DIR); - Subdirectory subdir = (fop == SaveLoadOperation::Load && base_path == *_fios_path) ? SCENARIO_DIR : NO_DIRECTORY; + std::string base_path = FioFindDirectory(Subdirectory::Scenario); + Subdirectory subdir = (fop == SaveLoadOperation::Load && base_path == *_fios_path) ? Subdirectory::Scenario : Subdirectory::None; FiosGetFileList(fop, show_dirs, &FiosGetScenarioListCallback, subdir, file_list); } @@ -484,8 +484,8 @@ std::tuple FiosGetHeightmapListCallback(SaveLoadOperation if (type == FIOS_TYPE_INVALID) return { FIOS_TYPE_INVALID, {} }; - TarFileList::iterator it = _tar_filelist[SCENARIO_DIR].find(file); - if (it != _tar_filelist[SCENARIO_DIR].end()) { + TarFileList::iterator it = _tar_filelist[Subdirectory::Scenario].find(file); + if (it != _tar_filelist[Subdirectory::Scenario].end()) { /* If the file is in a tar and that tar is not in a heightmap * directory we are for sure not supposed to see it. * Examples of this are pngs part of documentation within @@ -493,7 +493,7 @@ std::tuple FiosGetHeightmapListCallback(SaveLoadOperation */ bool match = false; for (Searchpath sp : _valid_searchpaths) { - std::string buf = FioGetDirectory(sp, HEIGHTMAP_DIR); + std::string buf = FioGetDirectory(sp, Subdirectory::Heightmap); if (it->second.tar_filename.starts_with(buf)) { match = true; @@ -504,7 +504,7 @@ std::tuple FiosGetHeightmapListCallback(SaveLoadOperation if (!match) return { FIOS_TYPE_INVALID, {} }; } - return { type, GetFileTitle(file, HEIGHTMAP_DIR) }; + return { type, GetFileTitle(file, Subdirectory::Heightmap) }; } /** @@ -517,12 +517,12 @@ void FiosGetHeightmapList(SaveLoadOperation fop, bool show_dirs, FileList &file_ { static std::optional fios_hmap_path; - if (!fios_hmap_path) fios_hmap_path = FioFindDirectory(HEIGHTMAP_DIR); + if (!fios_hmap_path) fios_hmap_path = FioFindDirectory(Subdirectory::Heightmap); _fios_path = &(*fios_hmap_path); - std::string base_path = FioFindDirectory(HEIGHTMAP_DIR); - Subdirectory subdir = base_path == *_fios_path ? HEIGHTMAP_DIR : NO_DIRECTORY; + std::string base_path = FioFindDirectory(Subdirectory::Heightmap); + Subdirectory subdir = base_path == *_fios_path ? Subdirectory::Heightmap : Subdirectory::None; FiosGetFileList(fop, show_dirs, &FiosGetHeightmapListCallback, subdir, file_list); } @@ -537,7 +537,7 @@ static std::tuple FiosGetTownDataListCallback(SaveLoadOpe { if (fop == SaveLoadOperation::Load) { if (StrEqualsIgnoreCase(ext, ".json")) { - return { FIOS_TYPE_JSON, GetFileTitle(file, SAVE_DIR) }; + return { FIOS_TYPE_JSON, GetFileTitle(file, Subdirectory::Save) }; } } @@ -554,12 +554,12 @@ void FiosGetTownDataList(SaveLoadOperation fop, bool show_dirs, FileList &file_l { static std::optional fios_town_data_path; - if (!fios_town_data_path) fios_town_data_path = FioFindDirectory(HEIGHTMAP_DIR); + if (!fios_town_data_path) fios_town_data_path = FioFindDirectory(Subdirectory::Heightmap); _fios_path = &(*fios_town_data_path); - std::string base_path = FioFindDirectory(HEIGHTMAP_DIR); - Subdirectory subdir = base_path == *_fios_path ? HEIGHTMAP_DIR : NO_DIRECTORY; + std::string base_path = FioFindDirectory(Subdirectory::Heightmap); + Subdirectory subdir = base_path == *_fios_path ? Subdirectory::Heightmap : Subdirectory::None; FiosGetFileList(fop, show_dirs, &FiosGetTownDataListCallback, subdir, file_list); } @@ -571,7 +571,7 @@ std::string_view FiosGetScreenshotDir() { static std::optional fios_screenshot_path; - if (!fios_screenshot_path) fios_screenshot_path = FioFindDirectory(SCREENSHOT_DIR); + if (!fios_screenshot_path) fios_screenshot_path = FioFindDirectory(Subdirectory::Screenshot); return *fios_screenshot_path; } @@ -605,13 +605,13 @@ public: { if (this->scanned && !rescan) return; - this->FileScanner::Scan(".id", SCENARIO_DIR, true, true); + this->FileScanner::Scan(".id", Subdirectory::Scenario, true, true); this->scanned = true; } bool AddFile(const std::string &filename, size_t, const std::string &) override { - auto f = FioFOpenFile(filename, "r", SCENARIO_DIR); + auto f = FioFOpenFile(filename, "r", Subdirectory::Scenario); if (!f.has_value()) return false; ScenarioIdentifier id; @@ -626,7 +626,7 @@ public: /* open the scenario file, but first get the name. * This is safe as we check on extension which * must always exist. */ - f = FioFOpenFile(filename.substr(0, filename.rfind('.')), "rb", SCENARIO_DIR, &size); + f = FioFOpenFile(filename.substr(0, filename.rfind('.')), "rb", Subdirectory::Scenario, &size); if (!f.has_value()) return false; /* calculate md5sum */ @@ -690,7 +690,7 @@ void ScanScenarios() FiosNumberedSaveName::FiosNumberedSaveName(const std::string &prefix) : prefix(prefix), number(-1) { static std::optional _autosave_path; - if (!_autosave_path) _autosave_path = FioFindDirectory(AUTOSAVE_DIR); + if (!_autosave_path) _autosave_path = FioFindDirectory(Subdirectory::Autosave); static std::string _prefix; ///< Static as the lambda needs access to it. diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 9c5e24aa0d..65a725e91c 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -470,16 +470,16 @@ public: o_dir.type = FIOS_TYPE_DIRECT; switch (this->abstract_filetype) { case AbstractFileType::Savegame: - o_dir.name = FioFindDirectory(SAVE_DIR); + o_dir.name = FioFindDirectory(Subdirectory::Save); break; case AbstractFileType::Scenario: - o_dir.name = FioFindDirectory(SCENARIO_DIR); + o_dir.name = FioFindDirectory(Subdirectory::Scenario); break; case AbstractFileType::Heightmap: case AbstractFileType::TownData: - o_dir.name = FioFindDirectory(HEIGHTMAP_DIR); + o_dir.name = FioFindDirectory(Subdirectory::Heightmap); break; default: @@ -759,7 +759,7 @@ public: if (file->type.detailed == DetailedFileType::GameFile) { /* Other detailed file types cannot be checked before. */ - SaveOrLoad(file->name, SaveLoadOperation::Check, DetailedFileType::GameFile, NO_DIRECTORY, false); + SaveOrLoad(file->name, SaveLoadOperation::Check, DetailedFileType::GameFile, Subdirectory::None, false); } this->InvalidateData(SLIWD_SELECTION_CHANGES); @@ -849,7 +849,7 @@ public: } else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked if (this->abstract_filetype == AbstractFileType::Savegame || this->abstract_filetype == AbstractFileType::Scenario) { _file_to_saveload.name = FiosMakeSavegameName(this->filename_editbox.text.GetText()); - if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) { + if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::Save)) { ShowQuery(GetEncodedString(STR_SAVELOAD_OVERWRITE_TITLE), GetEncodedString(STR_SAVELOAD_OVERWRITE_WARNING), this, SaveLoadWindow::SaveGameConfirmationCallback); } else { @@ -857,7 +857,7 @@ public: } } else { _file_to_saveload.name = FiosMakeHeightmapName(this->filename_editbox.text.GetText()); - if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) { + if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::Save)) { ShowQuery(GetEncodedString(STR_SAVELOAD_OVERWRITE_TITLE), GetEncodedString(STR_SAVELOAD_OVERWRITE_WARNING), this, SaveLoadWindow::SaveHeightmapConfirmationCallback); } else { diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 0eb4c16fcb..a227552dfd 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -199,7 +199,7 @@ static std::string GetDefaultTruetypeFontFile([[maybe_unused]] FontSize fs) { #if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA) /* Find font file. */ - return FioFindFullPath(BASESET_DIR, GetDefaultTruetypeFont(fs)); + return FioFindFullPath(Subdirectory::Baseset, GetDefaultTruetypeFont(fs)); #else return {}; #endif /* defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA) */ diff --git a/src/fontcache/freetypefontcache.cpp b/src/fontcache/freetypefontcache.cpp index 6e6019ac1f..6008b4ed9f 100644 --- a/src/fontcache/freetypefontcache.cpp +++ b/src/fontcache/freetypefontcache.cpp @@ -244,7 +244,7 @@ public: if (error != FT_Err_Ok) { /* Check if font is a relative filename in one of our search-paths. */ - std::string full_font = FioFindFullPath(BASE_DIR, font_name); + std::string full_font = FioFindFullPath(Subdirectory::Base, font_name); if (!full_font.empty()) { error = FT_New_Face(_ft_library, full_font.c_str(), 0, &face); } diff --git a/src/game/game_instance.cpp b/src/game/game_instance.cpp index c857e432bc..23b694c75f 100644 --- a/src/game/game_instance.cpp +++ b/src/game/game_instance.cpp @@ -50,7 +50,7 @@ void GameInstance::RegisterAPI() /* Register all classes */ SQGS_RegisterAll(*this->engine); - if (!this->LoadCompatibilityScripts(GAME_DIR, GameInfo::ApiVersions)) this->Died(); + if (!this->LoadCompatibilityScripts(Subdirectory::Gs, GameInfo::ApiVersions)) this->Died(); if (this->IsAlive()) RegisterGameTranslation(*this->engine); } diff --git a/src/game/game_scanner.hpp b/src/game/game_scanner.hpp index b0353c67d4..629721858d 100644 --- a/src/game/game_scanner.hpp +++ b/src/game/game_scanner.hpp @@ -29,7 +29,7 @@ public: protected: std::string GetScriptName(ScriptInfo &info) override; std::string_view GetFileName() const override { return PATHSEP "info.nut"; } - Subdirectory GetDirectory() const override { return GAME_DIR; } + Subdirectory GetDirectory() const override { return Subdirectory::Gs; } std::string_view GetScannerName() const override { return "Game Scripts"; } void RegisterAPI(class Squirrel &engine) override; }; @@ -51,7 +51,7 @@ public: protected: std::string GetScriptName(ScriptInfo &info) override; std::string_view GetFileName() const override { return PATHSEP "library.nut"; } - Subdirectory GetDirectory() const override { return GAME_LIBRARY_DIR; } + Subdirectory GetDirectory() const override { return Subdirectory::GsLibrary; } std::string_view GetScannerName() const override { return "GS Libraries"; } void RegisterAPI(class Squirrel &engine) override; }; diff --git a/src/game/game_text.cpp b/src/game/game_text.cpp index d3e16a876a..816446a2cf 100644 --- a/src/game/game_text.cpp +++ b/src/game/game_text.cpp @@ -49,7 +49,7 @@ void CDECL StrgenFatalI(const std::string &msg) LanguageStrings ReadRawLanguageStrings(const std::string &file) { size_t to_read; - auto fh = FioFOpenFile(file, "rb", GAME_DIR, &to_read); + auto fh = FioFOpenFile(file, "rb", Subdirectory::Gs, &to_read); if (!fh.has_value()) return LanguageStrings(); auto pos = file.rfind(PATHSEPCHAR); @@ -212,7 +212,7 @@ static std::shared_ptr LoadTranslations() basename.erase(e + 1); std::string filename = basename + "lang" PATHSEP "english.txt"; - if (!FioCheckFileExists(filename, GAME_DIR)) return nullptr; + if (!FioCheckFileExists(filename, Subdirectory::Gs)) return nullptr; auto ls = ReadRawLanguageStrings(filename); if (!ls.IsValid()) return nullptr; @@ -227,10 +227,10 @@ static std::shared_ptr LoadTranslations() const std::string tar_filename = info->GetTarFile(); TarList::iterator iter; - if (!tar_filename.empty() && (iter = _tar_list[GAME_DIR].find(tar_filename)) != _tar_list[GAME_DIR].end()) { + if (!tar_filename.empty() && (iter = _tar_list[Subdirectory::Gs].find(tar_filename)) != _tar_list[Subdirectory::Gs].end()) { /* The main script is in a tar file, so find all files that * are in the same tar and add them to the langfile scanner. */ - for (const auto &[name, entry] : _tar_filelist[GAME_DIR]) { + for (const auto &[name, entry] : _tar_filelist[Subdirectory::Gs]) { /* Not in the same tar. */ if (entry.tar_filename != iter->first) continue; diff --git a/src/genworld.cpp b/src/genworld.cpp index 3c4c1abfda..0f51bff595 100644 --- a/src/genworld.cpp +++ b/src/genworld.cpp @@ -217,7 +217,7 @@ static void _GenerateWorld() if (_debug_desync_level > 0) { std::string name = fmt::format("dmp_cmds_{:08x}_{:08x}.sav", _settings_game.game_creation.generation_seed, TimerGameEconomy::date); - SaveOrLoad(name, SaveLoadOperation::Save, DetailedFileType::GameFile, AUTOSAVE_DIR, false); + SaveOrLoad(name, SaveLoadOperation::Save, DetailedFileType::GameFile, Subdirectory::Autosave, false); } } catch (AbortGenerateWorldSignal&) { CleanupGeneration(); @@ -360,7 +360,7 @@ void LoadTownData() { /* Load the JSON file as a string initially. We'll parse it soon. */ size_t filesize; - auto f = FioFOpenFile(_file_to_saveload.name, "rb", HEIGHTMAP_DIR, &filesize); + auto f = FioFOpenFile(_file_to_saveload.name, "rb", Subdirectory::Heightmap, &filesize); if (!f.has_value()) { ShowErrorMessage(GetEncodedString(STR_TOWN_DATA_ERROR_LOAD_FAILED), diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index 0772e8cdec..45686ffafd 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -47,7 +47,7 @@ static uint LoadGrfFile(const std::string &filename, SpriteID load_index, bool n SpriteID load_index_org = load_index; SpriteID sprite_id = 0; - SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap); + SpriteFile &file = OpenCachedSpriteFile(filename, Subdirectory::Baseset, needs_palette_remap); Debug(sprite, 2, "Reading grf-file '{}'", filename); @@ -82,7 +82,7 @@ static void LoadGrfFileIndexed(const std::string &filename, std::spanname); for (const auto &file : used_set->files) { - MD5File::ChecksumResult res = GraphicsSet::CheckMD5(&file, BASESET_DIR); + MD5File::ChecksumResult res = GraphicsSet::CheckMD5(&file, Subdirectory::Baseset); if (res != MD5File::CR_MATCH) fmt::format_to(output_iterator, "\t{} is {} ({})\n", file.filename, res == MD5File::CR_MISMATCH ? "corrupt" : "missing", file.missing_warning); } fmt::format_to(output_iterator, "\n"); @@ -136,7 +136,7 @@ void CheckExternalFiles() static_assert(SoundsSet::NUM_FILES == 1); /* No need to loop each file, as long as there is only a single * sound file. */ - fmt::format_to(output_iterator, "\t{} is {} ({})\n", sounds_set->files[0].filename, SoundsSet::CheckMD5(&sounds_set->files[0], BASESET_DIR) == MD5File::CR_MISMATCH ? "corrupt" : "missing", sounds_set->files[0].missing_warning); + fmt::format_to(output_iterator, "\t{} is {} ({})\n", sounds_set->files[0].filename, SoundsSet::CheckMD5(&sounds_set->files[0], Subdirectory::Baseset) == MD5File::CR_MISMATCH ? "corrupt" : "missing", sounds_set->files[0].missing_warning); } if (!error_msg.empty()) ShowInfoI(error_msg); @@ -150,7 +150,7 @@ static std::unique_ptr GetDefaultExtraGRFConfig() { auto gc = std::make_unique("OPENTTD.GRF"); gc->palette |= GRFP_GRF_DOS; - FillGRFDetails(*gc, false, BASESET_DIR); + FillGRFDetails(*gc, false, Subdirectory::Baseset); gc->flags.Reset(GRFConfigFlag::InitOnly); return gc; } @@ -388,7 +388,7 @@ GRFConfig &GraphicsSet::GetOrCreateExtraConfig() const case PAL_WINDOWS: this->extra_cfg->palette |= GRFP_GRF_WINDOWS; break; default: break; } - FillGRFDetails(*this->extra_cfg, false, BASESET_DIR); + FillGRFDetails(*this->extra_cfg, false, Subdirectory::Baseset); } return *this->extra_cfg; } diff --git a/src/heightmap.cpp b/src/heightmap.cpp index 1c4c141df4..afa997f897 100644 --- a/src/heightmap.cpp +++ b/src/heightmap.cpp @@ -155,7 +155,7 @@ static bool ReadHeightmapPNG(std::string_view filename, uint *x, uint *y, std::v png_structp png_ptr = nullptr; png_infop info_ptr = nullptr; - auto fp = FioFOpenFile(filename, "rb", HEIGHTMAP_DIR); + auto fp = FioFOpenFile(filename, "rb", Subdirectory::Heightmap); if (!fp.has_value()) { ShowErrorMessage(GetEncodedString(STR_ERROR_PNGMAP), GetEncodedString(STR_ERROR_PNGMAP_FILE_NOT_FOUND), WL_ERROR); return false; @@ -281,13 +281,13 @@ static void ReadHeightmapBMPImageData(std::span map, const BmpInfo &inf */ static bool ReadHeightmapBMP(std::string_view filename, uint *x, uint *y, std::vector *map) { - auto f = FioFOpenFile(filename, "rb", HEIGHTMAP_DIR); + auto f = FioFOpenFile(filename, "rb", Subdirectory::Heightmap); if (!f.has_value()) { ShowErrorMessage(GetEncodedString(STR_ERROR_BMPMAP), GetEncodedString(STR_ERROR_PNGMAP_FILE_NOT_FOUND), WL_ERROR); return false; } - RandomAccessFile file(filename, HEIGHTMAP_DIR); + RandomAccessFile file(filename, Subdirectory::Heightmap); BmpInfo info{}; BmpData data{}; diff --git a/src/help_gui.cpp b/src/help_gui.cpp index 65f1ec3db1..94d973c74a 100644 --- a/src/help_gui.cpp +++ b/src/help_gui.cpp @@ -54,7 +54,7 @@ static std::optional FindGameManualFilePath(std::string_view filena for (Searchpath sp : searchpaths) { std::string file_path = FioGetDirectory(sp, subdir); file_path.append(filename); - if (FioCheckFileExists(file_path, NO_DIRECTORY)) return file_path; + if (FioCheckFileExists(file_path, Subdirectory::None)) return file_path; } return {}; @@ -76,7 +76,7 @@ struct GameManualTextfileWindow : public TextfileWindow { } this->filepath = filepath.value(); - this->LoadTextfile(this->filepath, NO_DIRECTORY); + this->LoadTextfile(this->filepath, Subdirectory::None); this->OnClick({ 0, 0 }, WID_TF_WRAPTEXT, 1); } @@ -129,30 +129,30 @@ struct HelpWindow : public Window { { this->InitNested(number); - this->EnableTextfileButton(README_FILENAME, BASE_DIR, WID_HW_README); - this->EnableTextfileButton(CHANGELOG_FILENAME, BASE_DIR, WID_HW_CHANGELOG); - this->EnableTextfileButton(KNOWN_BUGS_FILENAME, BASE_DIR, WID_HW_KNOWN_BUGS); - this->EnableTextfileButton(LICENSE_FILENAME, BASE_DIR, WID_HW_LICENSE); - this->EnableTextfileButton(FONTS_FILENAME, DOCS_DIR, WID_HW_FONTS); + this->EnableTextfileButton(README_FILENAME, Subdirectory::Base, WID_HW_README); + this->EnableTextfileButton(CHANGELOG_FILENAME, Subdirectory::Base, WID_HW_CHANGELOG); + this->EnableTextfileButton(KNOWN_BUGS_FILENAME, Subdirectory::Base, WID_HW_KNOWN_BUGS); + this->EnableTextfileButton(LICENSE_FILENAME, Subdirectory::Base, WID_HW_LICENSE); + this->EnableTextfileButton(FONTS_FILENAME, Subdirectory::Docs, WID_HW_FONTS); } void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override { switch (widget) { case WID_HW_README: - new GameManualTextfileWindow(README_FILENAME, BASE_DIR); + new GameManualTextfileWindow(README_FILENAME, Subdirectory::Base); break; case WID_HW_CHANGELOG: - new GameManualTextfileWindow(CHANGELOG_FILENAME, BASE_DIR); + new GameManualTextfileWindow(CHANGELOG_FILENAME, Subdirectory::Base); break; case WID_HW_KNOWN_BUGS: - new GameManualTextfileWindow(KNOWN_BUGS_FILENAME, BASE_DIR); + new GameManualTextfileWindow(KNOWN_BUGS_FILENAME, Subdirectory::Base); break; case WID_HW_LICENSE: - new GameManualTextfileWindow(LICENSE_FILENAME, BASE_DIR); + new GameManualTextfileWindow(LICENSE_FILENAME, Subdirectory::Base); break; case WID_HW_FONTS: - new GameManualTextfileWindow(FONTS_FILENAME, DOCS_DIR); + new GameManualTextfileWindow(FONTS_FILENAME, Subdirectory::Docs); break; case WID_HW_WEBSITE: OpenBrowser(WEBSITE_LINK); diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp index efc2d26c8a..1d9f019dcd 100644 --- a/src/hotkeys.cpp +++ b/src/hotkeys.cpp @@ -315,7 +315,7 @@ int HotkeyList::CheckMatch(uint16_t keycode, bool global_only) const static void SaveLoadHotkeys(bool save) { IniFile ini{}; - ini.LoadFromDisk(_hotkeys_file, NO_DIRECTORY); + ini.LoadFromDisk(_hotkeys_file, Subdirectory::None); for (HotkeyList *list : *_hotkey_lists) { if (save) { diff --git a/src/music.cpp b/src/music.cpp index 165728bac8..175f2ee4fb 100644 --- a/src/music.cpp +++ b/src/music.cpp @@ -25,9 +25,9 @@ */ std::optional GetMusicCatEntryName(const std::string &filename, size_t entrynum) { - if (!FioCheckFileExists(filename, BASESET_DIR)) return std::nullopt; + if (!FioCheckFileExists(filename, Subdirectory::Baseset)) return std::nullopt; - RandomAccessFile file(filename, BASESET_DIR); + RandomAccessFile file(filename, Subdirectory::Baseset); uint32_t ofs = file.ReadDword(); size_t entry_count = ofs / 8; if (entrynum >= entry_count) return std::nullopt; @@ -49,9 +49,9 @@ std::optional GetMusicCatEntryName(const std::string &filename, siz */ std::optional> GetMusicCatEntryData(const std::string &filename, size_t entrynum) { - if (!FioCheckFileExists(filename, BASESET_DIR)) return std::nullopt; + if (!FioCheckFileExists(filename, Subdirectory::Baseset)) return std::nullopt; - RandomAccessFile file(filename, BASESET_DIR); + RandomAccessFile file(filename, Subdirectory::Baseset); uint32_t ofs = file.ReadDword(); size_t entry_count = ofs / 8; if (entrynum >= entry_count) return std::nullopt; diff --git a/src/music/midifile.cpp b/src/music/midifile.cpp index 97c284b3cb..9f5f247c46 100644 --- a/src/music/midifile.cpp +++ b/src/music/midifile.cpp @@ -410,7 +410,7 @@ static bool FixupMidiData(MidiFile &target) */ bool MidiFile::ReadSMFHeader(const std::string &filename, SMFHeader &header) { - auto file = FioFOpenFile(filename, "rb", Subdirectory::BASESET_DIR); + auto file = FioFOpenFile(filename, "rb", Subdirectory::Baseset); if (!file.has_value()) return false; bool result = ReadSMFHeader(*file, header); return result; @@ -457,7 +457,7 @@ bool MidiFile::LoadFile(const std::string &filename) this->tempos.clear(); this->tickdiv = 0; - auto file = FioFOpenFile(filename, "rb", Subdirectory::BASESET_DIR); + auto file = FioFOpenFile(filename, "rb", Subdirectory::Baseset); if (!file.has_value()) return false; SMFHeader header; @@ -911,7 +911,7 @@ static void WriteVariableLen(FileHandle &f, uint32_t value) */ bool MidiFile::WriteSMF(const std::string &filename) { - auto of = FioFOpenFile(filename, "wb", Subdirectory::NO_DIRECTORY); + auto of = FioFOpenFile(filename, "wb", Subdirectory::None); if (!of.has_value()) return false; auto &f = *of; @@ -1039,9 +1039,9 @@ bool MidiFile::WriteSMF(const std::string &filename) std::string MidiFile::GetSMFFile(const MusicSongInfo &song) { if (song.filetype == MTT_STANDARDMIDI) { - std::string filename = FioFindFullPath(Subdirectory::BASESET_DIR, song.filename); + std::string filename = FioFindFullPath(Subdirectory::Baseset, song.filename); if (!filename.empty()) return filename; - filename = FioFindFullPath(Subdirectory::OLD_GM_DIR, song.filename); + filename = FioFindFullPath(Subdirectory::OldGm, song.filename); if (!filename.empty()) return filename; return std::string(); @@ -1049,7 +1049,7 @@ std::string MidiFile::GetSMFFile(const MusicSongInfo &song) if (song.filetype != MTT_MPSMIDI) return std::string(); - std::string tempdirname = FioGetDirectory(Searchpath::SP_AUTODOWNLOAD_DIR, Subdirectory::BASESET_DIR); + std::string tempdirname = FioGetDirectory(Searchpath::SP_AUTODOWNLOAD_DIR, Subdirectory::Baseset); { std::string_view basename{song.filename}; auto fnstart = basename.rfind(PATHSEPCHAR); diff --git a/src/network/core/tcp_content.cpp b/src/network/core/tcp_content.cpp index 8f17c7ec81..ae99cb7b01 100644 --- a/src/network/core/tcp_content.cpp +++ b/src/network/core/tcp_content.cpp @@ -184,19 +184,19 @@ bool NetworkContentSocketHandler::ReceiveServerContent(Packet &) { return this-> Subdirectory GetContentInfoSubDir(ContentType type) { switch (type) { - default: return NO_DIRECTORY; - case CONTENT_TYPE_AI: return AI_DIR; - case CONTENT_TYPE_AI_LIBRARY: return AI_LIBRARY_DIR; - case CONTENT_TYPE_GAME: return GAME_DIR; - case CONTENT_TYPE_GAME_LIBRARY: return GAME_LIBRARY_DIR; - case CONTENT_TYPE_NEWGRF: return NEWGRF_DIR; + default: return Subdirectory::None; + case CONTENT_TYPE_AI: return Subdirectory::Ai; + case CONTENT_TYPE_AI_LIBRARY: return Subdirectory::AiLibrary; + case CONTENT_TYPE_GAME: return Subdirectory::Gs; + case CONTENT_TYPE_GAME_LIBRARY: return Subdirectory::GsLibrary; + case CONTENT_TYPE_NEWGRF: return Subdirectory::NewGrf; case CONTENT_TYPE_BASE_GRAPHICS: case CONTENT_TYPE_BASE_SOUNDS: case CONTENT_TYPE_BASE_MUSIC: - return BASESET_DIR; + return Subdirectory::Baseset; - case CONTENT_TYPE_SCENARIO: return SCENARIO_DIR; - case CONTENT_TYPE_HEIGHTMAP: return HEIGHTMAP_DIR; + case CONTENT_TYPE_SCENARIO: return Subdirectory::Scenario; + case CONTENT_TYPE_HEIGHTMAP: return Subdirectory::Heightmap; } } diff --git a/src/network/network.cpp b/src/network/network.cpp index 95de021628..3635d08359 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -1148,7 +1148,7 @@ void NetworkGameLoop() #ifdef DEBUG_DUMP_COMMANDS /* Loading of the debug commands from -ddesync>=1 */ - static auto f = FioFOpenFile("commands.log", "rb", SAVE_DIR); + static auto f = FioFOpenFile("commands.log", "rb", Subdirectory::Save); static TimerGameEconomy::Date next_date(0); static uint32_t next_date_fract; static CommandPacket *cp = nullptr; diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 78e9290601..f5d493b7ce 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -863,7 +863,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet /* Set the abstract filetype. This is read during savegame load. */ _file_to_saveload.SetMode(FIOS_TYPE_FILE, SaveLoadOperation::Load); - bool load_success = SafeLoad({}, SaveLoadOperation::Load, DetailedFileType::GameFile, GM_NORMAL, NO_DIRECTORY, this->savegame); + bool load_success = SafeLoad({}, SaveLoadOperation::Load, DetailedFileType::GameFile, GM_NORMAL, Subdirectory::None, this->savegame); this->savegame = nullptr; /* Long savegame loads shouldn't affect the lag calculation! */ diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp index 34413e8574..46dc31bb0e 100644 --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -370,7 +370,7 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(const Co static std::string GetFullFilename(const ContentInfo &ci, bool compressed) { Subdirectory dir = GetContentInfoSubDir(ci.type); - if (dir == NO_DIRECTORY) return {}; + if (dir == Subdirectory::None) return {}; std::string buf = FioGetDirectory(SP_AUTODOWNLOAD_DIR, dir); buf += ci.filename; @@ -527,7 +527,7 @@ void ClientNetworkContentSocketHandler::AfterDownload() FioRemove(GetFullFilename(*this->cur_info, true)); Subdirectory sd = GetContentInfoSubDir(this->cur_info->type); - if (sd == NO_DIRECTORY) NOT_REACHED(); + if (sd == Subdirectory::None) NOT_REACHED(); TarScanner ts; std::string fname = GetFullFilename(*this->cur_info, false); @@ -535,7 +535,7 @@ void ClientNetworkContentSocketHandler::AfterDownload() if (this->cur_info->type == CONTENT_TYPE_BASE_MUSIC) { /* Music can't be in a tar. So extract the tar! */ - ExtractTar(fname, BASESET_DIR); + ExtractTar(fname, Subdirectory::Baseset); FioRemove(fname); } diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 1edcdc2172..1c65768d0d 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -1836,7 +1836,7 @@ void LoadNewGRF(SpriteID load_index, uint num_baseset) if (c->status == GRFStatus::Disabled || c->status == GRFStatus::NotFound) continue; if (stage > GrfLoadingStage::Init && c->flags.Test(GRFConfigFlag::InitOnly)) continue; - Subdirectory subdir = num_grfs < num_baseset ? BASESET_DIR : NEWGRF_DIR; + Subdirectory subdir = num_grfs < num_baseset ? Subdirectory::Baseset : Subdirectory::NewGrf; if (!FioCheckFileExists(c->filename, subdir)) { Debug(grf, 0, "NewGRF file is missing '{}'; disabling", c->filename); c->status = GRFStatus::NotFound; diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index 982bc0b696..47eb866cff 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -510,7 +510,7 @@ public: } GRFFileScanner fs; - int ret = fs.Scan(".grf", NEWGRF_DIR); + int ret = fs.Scan(".grf", Subdirectory::NewGrf); /* The number scanned and the number returned may not be the same; * duplicate NewGRFs and base sets are ignored in the return value. */ _settings_client.gui.last_newgrf_count = fs.num_scanned; @@ -654,5 +654,5 @@ std::string GRFBuildParamList(const GRFConfig &c) */ std::optional GRFConfig::GetTextfile(TextfileType type) const { - return ::GetTextfile(type, NEWGRF_DIR, this->filename); + return ::GetTextfile(type, Subdirectory::NewGrf, this->filename); } diff --git a/src/newgrf_config.h b/src/newgrf_config.h index 0bb5f27c9b..40a8e6555e 100644 --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -236,7 +236,7 @@ void AppendToGRFConfigList(GRFConfigList &dst, std::unique_ptr &&el); void ClearGRFConfigList(GRFConfigList &config); void ResetGRFConfig(bool defaults); GRFListCompatibility IsGoodGRFConfigList(GRFConfigList &grfconfig); -bool FillGRFDetails(GRFConfig &config, bool is_static, Subdirectory subdir = NEWGRF_DIR); +bool FillGRFDetails(GRFConfig &config, bool is_static, Subdirectory subdir = Subdirectory::NewGrf); std::string GRFBuildParamList(const GRFConfig &c); /* In newgrf_gui.cpp */ diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index a299288fe5..9f0576c7ba 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -554,7 +554,7 @@ struct NewGRFTextfileWindow : public TextfileWindow { this->ConstructWindow(); auto textfile = this->grf_config->GetTextfile(file_type); - this->LoadTextfile(textfile.value(), NEWGRF_DIR); + this->LoadTextfile(textfile.value(), Subdirectory::NewGrf); } std::string GetWidgetString(WidgetID widget, StringID stringid) const override diff --git a/src/newgrf_profiling.cpp b/src/newgrf_profiling.cpp index 80a852a05d..b977e83f5b 100644 --- a/src/newgrf_profiling.cpp +++ b/src/newgrf_profiling.cpp @@ -123,7 +123,7 @@ uint32_t NewGRFProfiler::Finish() uint32_t total_microseconds = 0; - auto f = FioFOpenFile(filename, "wt", Subdirectory::NO_DIRECTORY); + auto f = FioFOpenFile(filename, "wt", Subdirectory::None); if (!f.has_value()) { IConsolePrint(CC_ERROR, "Failed to open '{}' for writing.", filename); diff --git a/src/openttd.cpp b/src/openttd.cpp index 7f03b9a6a4..751f8247bb 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -329,7 +329,7 @@ static void LoadIntroGame(bool load_newgrfs = true) SetupColoursAndInitialWindow(); /* Load the default opening screen savegame */ - if (SaveOrLoad("opntitle.dat", SaveLoadOperation::Load, DetailedFileType::GameFile, BASESET_DIR) != SL_OK) { + if (SaveOrLoad("opntitle.dat", SaveLoadOperation::Load, DetailedFileType::GameFile, Subdirectory::Baseset) != SL_OK) { GenerateWorld(GWM_EMPTY, 64, 64); // if failed loading, make empty world. SetLocalCompany(COMPANY_SPECTATOR); } else { @@ -612,7 +612,7 @@ int openttd_main(std::span arguments) auto [_, title] = FiosGetSavegameListCallback(SaveLoadOperation::Load, mgo.opt, extension); _load_check_data.Clear(); - SaveOrLoadResult res = SaveOrLoad(mgo.opt, SaveLoadOperation::Check, DetailedFileType::GameFile, SAVE_DIR, false); + SaveOrLoadResult res = SaveOrLoad(mgo.opt, SaveLoadOperation::Check, DetailedFileType::GameFile, Subdirectory::Save, false); if (res != SL_OK || _load_check_data.HasErrors()) { fmt::print(stderr, "Failed to open savegame\n"); if (_load_check_data.HasErrors()) { @@ -1098,7 +1098,7 @@ void SwitchToMode(SwitchMode new_mode) ResetGRFConfig(true); ResetWindowSystem(); - if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.ftype.detailed, GM_NORMAL, NO_DIRECTORY)) { + if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.ftype.detailed, GM_NORMAL, Subdirectory::None)) { ShowErrorMessage(GetSaveLoadErrorType(), GetSaveLoadErrorMessage(), WL_CRITICAL); } else { if (_file_to_saveload.ftype.abstract == AbstractFileType::Scenario) { @@ -1134,7 +1134,7 @@ void SwitchToMode(SwitchMode new_mode) break; case SM_LOAD_SCENARIO: { // Load scenario from scenario editor - if (SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.ftype.detailed, GM_EDITOR, NO_DIRECTORY)) { + if (SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.ftype.detailed, GM_EDITOR, Subdirectory::None)) { SetLocalCompany(OWNER_NONE); GenerateSavegameId(); _settings_newgame.game_creation.starting_year = TimerGameCalendar::year; @@ -1175,7 +1175,7 @@ void SwitchToMode(SwitchMode new_mode) case SM_SAVE_GAME: // Save game. /* Make network saved games on pause compatible to singleplayer mode */ - if (SaveOrLoad(_file_to_saveload.name, SaveLoadOperation::Save, DetailedFileType::GameFile, NO_DIRECTORY) != SL_OK) { + if (SaveOrLoad(_file_to_saveload.name, SaveLoadOperation::Save, DetailedFileType::GameFile, Subdirectory::None) != SL_OK) { ShowErrorMessage(GetSaveLoadErrorType(), GetSaveLoadErrorMessage(), WL_ERROR); } else { CloseWindowById(WC_SAVELOAD, 0); @@ -1245,7 +1245,7 @@ void StateGameLoop() if (_debug_desync_level > 2 && TimerGameEconomy::date_fract == 0 && (TimerGameEconomy::date.base() & 0x1F) == 0) { /* Save the desync savegame if needed. */ std::string name = fmt::format("dmp_cmds_{:08x}_{:08x}.sav", _settings_game.game_creation.generation_seed, TimerGameEconomy::date); - SaveOrLoad(name, SaveLoadOperation::Save, DetailedFileType::GameFile, AUTOSAVE_DIR, false); + SaveOrLoad(name, SaveLoadOperation::Save, DetailedFileType::GameFile, Subdirectory::Autosave, false); } CheckCaches(); diff --git a/src/os/macosx/font_osx.cpp b/src/os/macosx/font_osx.cpp index b389c4effa..a8caeaa635 100644 --- a/src/os/macosx/font_osx.cpp +++ b/src/os/macosx/font_osx.cpp @@ -331,7 +331,7 @@ private: path.reset(CFStringCreateWithCString(kCFAllocatorDefault, font_name.c_str(), kCFStringEncodingUTF8)); } else { /* Scan the search-paths to see if it can be found. */ - std::string full_font = FioFindFullPath(BASE_DIR, font_name); + std::string full_font = FioFindFullPath(Subdirectory::Base, font_name); if (!full_font.empty()) { path.reset(CFStringCreateWithCString(kCFAllocatorDefault, full_font.c_str(), kCFStringEncodingUTF8)); } diff --git a/src/os/windows/font_win32.cpp b/src/os/windows/font_win32.cpp index c36c34beac..92c8b0b6ee 100644 --- a/src/os/windows/font_win32.cpp +++ b/src/os/windows/font_win32.cpp @@ -352,7 +352,7 @@ private: convert_to_fs(font_name, fontPath); } else { /* Scan the search-paths to see if it can be found. */ - std::string full_font = FioFindFullPath(BASE_DIR, font_name); + std::string full_font = FioFindFullPath(Subdirectory::Base, font_name); if (!full_font.empty()) { convert_to_fs(font_name, fontPath); } diff --git a/src/saveload/oldloader.cpp b/src/saveload/oldloader.cpp index 04dda298bd..154fa56a84 100644 --- a/src/saveload/oldloader.cpp +++ b/src/saveload/oldloader.cpp @@ -243,7 +243,7 @@ bool LoadOldSaveGame(std::string_view file) _settings_game.construction.freeform_edges = false; // disable so we can convert map array (SetTileType is still used) /* Open file */ - ls.file = FioFOpenFile(file, "rb", NO_DIRECTORY); + ls.file = FioFOpenFile(file, "rb", Subdirectory::None); if (!ls.file.has_value()) { Debug(oldloader, 0, "Cannot open file '{}'", file); @@ -286,7 +286,7 @@ bool LoadOldSaveGame(std::string_view file) std::string GetOldSaveGameName(std::string_view file) { - auto f = FioFOpenFile(file, "rb", NO_DIRECTORY); + auto f = FioFOpenFile(file, "rb", Subdirectory::None); if (!f.has_value()) return {}; std::string name; diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index e4c8dd63b4..4ae50257a5 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -3345,9 +3345,9 @@ SaveOrLoadResult SaveOrLoad(std::string_view filename, SaveLoadOperation fop, De auto fh = (fop == SaveLoadOperation::Save) ? FioFOpenFile(filename, "wb", sb) : FioFOpenFile(filename, "rb", sb); /* Make it a little easier to load savegames from the console */ - if (!fh.has_value() && fop != SaveLoadOperation::Save) fh = FioFOpenFile(filename, "rb", SAVE_DIR); - if (!fh.has_value() && fop != SaveLoadOperation::Save) fh = FioFOpenFile(filename, "rb", BASE_DIR); - if (!fh.has_value() && fop != SaveLoadOperation::Save) fh = FioFOpenFile(filename, "rb", SCENARIO_DIR); + if (!fh.has_value() && fop != SaveLoadOperation::Save) fh = FioFOpenFile(filename, "rb", Subdirectory::Save); + if (!fh.has_value() && fop != SaveLoadOperation::Save) fh = FioFOpenFile(filename, "rb", Subdirectory::Base); + if (!fh.has_value() && fop != SaveLoadOperation::Save) fh = FioFOpenFile(filename, "rb", Subdirectory::Scenario); if (!fh.has_value()) { SlError(fop == SaveLoadOperation::Save ? STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE : STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE); @@ -3391,7 +3391,7 @@ void DoAutoOrNetsave(FiosNumberedSaveName &counter) } Debug(sl, 2, "Autosaving to '{}'", filename); - if (SaveOrLoad(filename, SaveLoadOperation::Save, DetailedFileType::GameFile, AUTOSAVE_DIR) != SL_OK) { + if (SaveOrLoad(filename, SaveLoadOperation::Save, DetailedFileType::GameFile, Subdirectory::Autosave) != SL_OK) { ShowErrorMessage(GetEncodedString(STR_ERROR_AUTOSAVE_FAILED), {}, WL_ERROR); } } @@ -3400,7 +3400,7 @@ void DoAutoOrNetsave(FiosNumberedSaveName &counter) /** Do a save when exiting the game (_settings_client.gui.autosave_on_exit) */ void DoExitSave() { - SaveOrLoad("exit.sav", SaveLoadOperation::Save, DetailedFileType::GameFile, AUTOSAVE_DIR); + SaveOrLoad("exit.sav", SaveLoadOperation::Save, DetailedFileType::GameFile, Subdirectory::Autosave); } /** diff --git a/src/script/script_config.cpp b/src/script/script_config.cpp index fcb9e75574..0b3cc75567 100644 --- a/src/script/script_config.cpp +++ b/src/script/script_config.cpp @@ -179,7 +179,7 @@ std::optional ScriptConfig::GetTextfile(TextfileType type, CompanyI { if (slot == CompanyID::Invalid() || this->GetInfo() == nullptr) return std::nullopt; - return ::GetTextfile(type, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR, this->GetInfo()->GetMainScript()); + return ::GetTextfile(type, (slot == OWNER_DEITY) ? Subdirectory::Gs : Subdirectory::Ai, this->GetInfo()->GetMainScript()); } void ScriptConfig::SetToLoadData(ScriptInstance::ScriptData *data) diff --git a/src/script/script_gui.cpp b/src/script/script_gui.cpp index 4fc9630f81..a5e3964267 100644 --- a/src/script/script_gui.cpp +++ b/src/script/script_gui.cpp @@ -618,7 +618,7 @@ struct ScriptTextfileWindow : public TextfileWindow { if (!textfile.has_value()) { this->Close(); } else { - this->LoadTextfile(textfile.value(), (this->slot == OWNER_DEITY) ? GAME_DIR : AI_DIR); + this->LoadTextfile(textfile.value(), (this->slot == OWNER_DEITY) ? Subdirectory::Gs : Subdirectory::Ai); } } }; diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp index 97ee44188b..ef04a2700c 100644 --- a/src/script/squirrel.cpp +++ b/src/script/squirrel.cpp @@ -647,11 +647,11 @@ SQRESULT Squirrel::LoadFile(HSQUIRRELVM vm, const std::string &filename, SQBool std::optional file = std::nullopt; size_t size; if (this->GetAPIName().starts_with("AI")) { - file = FioFOpenFile(filename, "rb", AI_DIR, &size); - if (!file.has_value()) file = FioFOpenFile(filename, "rb", AI_LIBRARY_DIR, &size); + file = FioFOpenFile(filename, "rb", Subdirectory::Ai, &size); + if (!file.has_value()) file = FioFOpenFile(filename, "rb", Subdirectory::AiLibrary, &size); } else if (this->GetAPIName().starts_with("GS")) { - file = FioFOpenFile(filename, "rb", GAME_DIR, &size); - if (!file.has_value()) file = FioFOpenFile(filename, "rb", GAME_LIBRARY_DIR, &size); + file = FioFOpenFile(filename, "rb", Subdirectory::Gs, &size); + if (!file.has_value()) file = FioFOpenFile(filename, "rb", Subdirectory::GsLibrary, &size); } else { NOT_REACHED(); } diff --git a/src/settings.cpp b/src/settings.cpp index 2ee51b6309..fa9a27c116 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -155,7 +155,7 @@ private: public: ConfigIniFile(const std::string &filename) : IniFile(list_group_names) { - this->LoadFromDisk(filename, NO_DIRECTORY); + this->LoadFromDisk(filename, Subdirectory::None); } }; @@ -1096,7 +1096,7 @@ static GRFConfigList GRFLoadConfig(const IniFile &ini, std::string_view grpname, const GRFConfig *s = FindGRFConfig(grfid, FGCM_EXACT, &md5sum); if (s != nullptr) c = std::make_unique(*s); } - if (c == nullptr && !FioCheckFileExists(std::string(item_name), NEWGRF_DIR)) { + if (c == nullptr && !FioCheckFileExists(std::string(item_name), Subdirectory::NewGrf)) { const GRFConfig *s = FindGRFConfig(grfid, FGCM_NEWEST_VALID); if (s != nullptr) c = std::make_unique(*s); } diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index cc6f928404..b9ad0bd765 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -104,7 +104,7 @@ struct BaseSetTextfileWindow : public TextfileWindow { BaseSetTextfileWindow(Window *parent, TextfileType file_type, const std::string &name, const std::string &textfile, StringID content_type) : TextfileWindow(parent, file_type), name(name), content_type(content_type) { this->ConstructWindow(); - this->LoadTextfile(textfile, BASESET_DIR); + this->LoadTextfile(textfile, Subdirectory::Baseset); } std::string GetWidgetString(WidgetID widget, StringID stringid) const override diff --git a/src/settingsgen/settingsgen.cpp b/src/settingsgen/settingsgen.cpp index e82867545b..c21571b1d7 100644 --- a/src/settingsgen/settingsgen.cpp +++ b/src/settingsgen/settingsgen.cpp @@ -369,7 +369,7 @@ static void ProcessIniFile(std::string_view fname) static const IniLoadFile::IniGroupNameList seq_groups = {PREAMBLE_GROUP_NAME, POSTAMBLE_GROUP_NAME}; SettingsIniFile ini{{}, seq_groups}; - ini.LoadFromDisk(fname, NO_DIRECTORY); + ini.LoadFromDisk(fname, Subdirectory::None); DumpGroup(ini, PREAMBLE_GROUP_NAME); DumpSections(ini); diff --git a/src/signature.cpp b/src/signature.cpp index 87e931a5ca..28425a163d 100644 --- a/src/signature.cpp +++ b/src/signature.cpp @@ -35,7 +35,7 @@ static const std::initializer_list> _public_keys_v1 = { */ static std::string CalculateHashV1(const std::string &filename) { - auto f = FioFOpenFile(filename, "rb", NO_DIRECTORY); + auto f = FioFOpenFile(filename, "rb", Subdirectory::None); if (!f.has_value()) return {}; std::array digest; @@ -195,7 +195,7 @@ static bool ValidateSchema(const nlohmann::json &signatures, const std::string & static bool _ValidateSignatureFile(const std::string &filename) { size_t filesize; - auto f = FioFOpenFile(filename, "rb", NO_DIRECTORY, &filesize); + auto f = FioFOpenFile(filename, "rb", Subdirectory::None, &filesize); if (!f.has_value()) { Debug(misc, 0, "Failed to validate signature: file not found: {}", filename); return false; diff --git a/src/social_integration.cpp b/src/social_integration.cpp index d19d579471..ab1da89b61 100644 --- a/src/social_integration.cpp +++ b/src/social_integration.cpp @@ -63,7 +63,7 @@ public: std::string extension = "-social.so"; #endif - this->FileScanner::Scan(extension, SOCIAL_INTEGRATION_DIR, false); + this->FileScanner::Scan(extension, Subdirectory::SocialIntegration, false); } bool AddFile(const std::string &filename, size_t basepath_length, const std::string &) override diff --git a/src/sound.cpp b/src/sound.cpp index 0670ad136e..b2804ecd70 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -37,7 +37,7 @@ static void OpenBankFile(const std::string &filename) /* If there is no sound file (nosound set), don't load anything */ if (filename.empty()) return; - original_sound_file = std::make_unique(filename, BASESET_DIR); + original_sound_file = std::make_unique(filename, Subdirectory::Baseset); size_t pos = original_sound_file->GetPos(); uint count = original_sound_file->ReadDword(); diff --git a/src/strings.cpp b/src/strings.cpp index c24067cdaf..cb4a3e932f 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -2256,7 +2256,7 @@ static void FillLanguageList(const std::string &path) void InitializeLanguagePacks() { for (Searchpath sp : _valid_searchpaths) { - FillLanguageList(FioGetDirectory(sp, LANG_DIR)); + FillLanguageList(FioGetDirectory(sp, Subdirectory::Lang)); } if (_languages.empty()) UserError("No available language packs (invalid versions?)"); diff --git a/src/tar_type.h b/src/tar_type.h index 534ca68889..ae87c504bd 100644 --- a/src/tar_type.h +++ b/src/tar_type.h @@ -10,9 +10,9 @@ #ifndef TAR_TYPE_H #define TAR_TYPE_H +#include "core/enum_type.hpp" #include "fileio_type.h" - struct TarFileListEntry { std::string tar_filename; size_t size; @@ -21,7 +21,7 @@ struct TarFileListEntry { using TarList = std::map>; ///< Map of tar file to tar directory. using TarFileList = std::map> ; -extern std::array _tar_list; -extern TarFileList _tar_filelist[NUM_SUBDIRS]; +extern EnumClassIndexContainer, Subdirectory> _tar_list; +extern EnumClassIndexContainer, Subdirectory> _tar_filelist; #endif /* TAR_TYPE_H */ diff --git a/src/textfile_gui.cpp b/src/textfile_gui.cpp index 854f21c5fb..d483ca8c4a 100644 --- a/src/textfile_gui.cpp +++ b/src/textfile_gui.cpp @@ -366,7 +366,7 @@ void TextfileWindow::NavigateHistory(int delta) if (this->history[this->history_pos].filepath != this->filepath) { this->filepath = this->history[this->history_pos].filepath; this->filename = this->filepath.substr(this->filepath.find_last_of(PATHSEP) + 1); - this->LoadTextfile(this->filepath, NO_DIRECTORY); + this->LoadTextfile(this->filepath, Subdirectory::None); } this->SetWidgetDisabledState(WID_TF_NAVFORWARD, this->history_pos + 1 >= this->history.size()); @@ -445,7 +445,7 @@ void TextfileWindow::NavigateToFile(std::string newfile, size_t line) /* Paste the two together and check file exists. */ newpath = newpath + newfile; - if (!FioCheckFileExists(newpath, NO_DIRECTORY)) return; + if (!FioCheckFileExists(newpath, Subdirectory::None)) return; /* Update history. */ this->AppendHistory(newpath); @@ -454,7 +454,7 @@ void TextfileWindow::NavigateToFile(std::string newfile, size_t line) this->filepath = newpath; this->filename = newpath.substr(newpath.find_last_of(PATHSEP) + 1); - this->LoadTextfile(this->filepath, NO_DIRECTORY); + this->LoadTextfile(this->filepath, Subdirectory::None); this->GetScrollbar(WID_TF_HSCROLLBAR)->SetPosition(0); this->GetScrollbar(WID_TF_VSCROLLBAR)->SetPosition(0); diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index 8c1c010acd..11f35bb86c 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -167,7 +167,7 @@ bool VideoDriver_SDL_Base::CreateMainWindow(uint w, uint h, uint flags) return false; } - std::string icon_path = FioFindFullPath(BASESET_DIR, "openttd.32.bmp"); + std::string icon_path = FioFindFullPath(Subdirectory::Baseset, "openttd.32.bmp"); if (!icon_path.empty()) { /* Give the application an icon */ SDL_Surface *icon = SDL_LoadBMP(icon_path.c_str()); diff --git a/src/window.cpp b/src/window.cpp index d80161c385..ea5a0e5818 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -168,7 +168,7 @@ int16_t WindowDesc::GetDefaultHeight() const void WindowDesc::LoadFromConfig() { IniFile ini; - ini.LoadFromDisk(_windows_file, NO_DIRECTORY); + ini.LoadFromDisk(_windows_file, Subdirectory::None); for (WindowDesc *wd : *_window_descs) { if (wd->ini_key.empty()) continue; IniLoadWindowSettings(ini, wd->ini_key, wd); @@ -190,7 +190,7 @@ void WindowDesc::SaveToConfig() std::sort(_window_descs->begin(), _window_descs->end(), DescSorter); IniFile ini; - ini.LoadFromDisk(_windows_file, NO_DIRECTORY); + ini.LoadFromDisk(_windows_file, Subdirectory::None); for (WindowDesc *wd : *_window_descs) { if (wd->ini_key.empty()) continue; IniSaveWindowSettings(ini, wd->ini_key, wd);