Codechange: make Subdirectory a scoped enum

This commit is contained in:
Peter Nelson
2026-04-05 19:02:51 +01:00
committed by Peter Nelson
parent 93a6aa77c6
commit 5aae8e2d64
52 changed files with 218 additions and 216 deletions
+1 -1
View File
@@ -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()
+2 -2
View File
@@ -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;
};
+3 -3
View File
@@ -143,7 +143,7 @@ struct BaseSet {
std::optional<std::string> 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<Tbase_set> 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);
}
/**
+2 -2
View File
@@ -157,7 +157,7 @@ bool BaseSet<T>::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<Tbase_set>::AddFile(const std::string &filename, size_t basepath_
auto set = std::make_unique<Tbase_set>();
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) {
+15 -15
View File
@@ -425,7 +425,7 @@ static bool ConSave(std::span<std::string_view> 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<std::string_view> 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<std::string_view> 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<std::string_view> 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) {
+2 -2
View File
@@ -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;
}
+2 -2
View File
@@ -111,14 +111,14 @@ void DumpDebugFacilityNames(std::back_insert_iterator<std::string> &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);
+3 -3
View File
@@ -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);
}
+36 -34
View File
@@ -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<std::array<std::string_view, to_underlying(Subdirectory::End)>, 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<std::string, NUM_SEARCHPATHS> _searchpaths;
std::vector<Searchpath> _valid_searchpaths;
std::array<TarList, NUM_SUBDIRS> _tar_list;
TarFileList _tar_filelist[NUM_SUBDIRS];
/** List of tar files found in each subdirectory. */
EnumClassIndexContainer<std::array<TarList, to_underlying(Subdirectory::End)>, Subdirectory> _tar_list;
/** List of files within tar files found in each subdirectory. */
EnumClassIndexContainer<std::array<TarFileList, to_underlying(Subdirectory::End)>, 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<FileHandle> 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<FileHandle> 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<FileHandle> FioFOpenFileTar(const TarFileListEntry &entry,
std::optional<FileHandle> FioFOpenFile(std::string_view filename, std::string_view mode, Subdirectory subdir, size_t *filesize)
{
std::optional<FileHandle> 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<FileHandle> 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;
+20 -20
View File
@@ -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.
};
/**
+24 -24
View File
@@ -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<FiosType, std::string> 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<std::string> 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<FiosType, std::string> 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<std::string> 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<FiosType, std::string> 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<FiosType, std::string> 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<FiosType, std::string> 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<std::string> 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<FiosType, std::string> 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<std::string> 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<std::string> 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<std::string> _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.
+6 -6
View File
@@ -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 {
+1 -1
View File
@@ -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) */
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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);
}
+2 -2
View File
@@ -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;
};
+4 -4
View File
@@ -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<GameStrings> 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<GameStrings> 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;
+2 -2
View File
@@ -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),
+6 -6
View File
@@ -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::span<const std:
{
uint 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 indexed grf-file '{}'", filename);
@@ -123,7 +123,7 @@ void CheckExternalFiles()
/* Not all files were loaded successfully, see which ones */
fmt::format_to(output_iterator, "Trying to load graphics set '{}', but it is incomplete. The game will probably not run correctly until you properly install this set or select another one. See section 1.4 of README.md.\n\nThe following files are corrupted or missing:\n", used_set->name);
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<GRFConfig> GetDefaultExtraGRFConfig()
{
auto gc = std::make_unique<GRFConfig>("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;
}
+3 -3
View File
@@ -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<uint8_t> map, const BmpInfo &inf
*/
static bool ReadHeightmapBMP(std::string_view filename, uint *x, uint *y, std::vector<uint8_t> *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{};
+12 -12
View File
@@ -54,7 +54,7 @@ static std::optional<std::string> 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);
+1 -1
View File
@@ -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) {
+4 -4
View File
@@ -25,9 +25,9 @@
*/
std::optional<std::string> 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<std::string> GetMusicCatEntryName(const std::string &filename, siz
*/
std::optional<std::vector<uint8_t>> 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;
+6 -6
View File
@@ -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);
+9 -9
View File
@@ -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;
}
}
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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! */
+3 -3
View File
@@ -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);
}
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -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<std::string> GRFConfig::GetTextfile(TextfileType type) const
{
return ::GetTextfile(type, NEWGRF_DIR, this->filename);
return ::GetTextfile(type, Subdirectory::NewGrf, this->filename);
}
+1 -1
View File
@@ -236,7 +236,7 @@ void AppendToGRFConfigList(GRFConfigList &dst, std::unique_ptr<GRFConfig> &&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 */
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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);
+6 -6
View File
@@ -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<std::string_view> 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();
+1 -1
View File
@@ -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));
}
+1 -1
View File
@@ -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);
}
+2 -2
View File
@@ -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;
+5 -5
View File
@@ -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);
}
/**
+1 -1
View File
@@ -179,7 +179,7 @@ std::optional<std::string> 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)
+1 -1
View File
@@ -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);
}
}
};
+4 -4
View File
@@ -647,11 +647,11 @@ SQRESULT Squirrel::LoadFile(HSQUIRRELVM vm, const std::string &filename, SQBool
std::optional<FileHandle> 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();
}
+2 -2
View File
@@ -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<GRFConfig>(*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<GRFConfig>(*s);
}
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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);
+2 -2
View File
@@ -35,7 +35,7 @@ static const std::initializer_list<std::array<uint8_t, 32>> _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<uint8_t, 32> 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;
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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<RandomAccessFile>(filename, BASESET_DIR);
original_sound_file = std::make_unique<RandomAccessFile>(filename, Subdirectory::Baseset);
size_t pos = original_sound_file->GetPos();
uint count = original_sound_file->ReadDword();
+1 -1
View File
@@ -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?)");
+3 -3
View File
@@ -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<std::string, std::string, std::less<>>; ///< Map of tar file to tar directory.
using TarFileList = std::map<std::string, TarFileListEntry, std::less<>> ;
extern std::array<TarList, NUM_SUBDIRS> _tar_list;
extern TarFileList _tar_filelist[NUM_SUBDIRS];
extern EnumClassIndexContainer<std::array<TarList, to_underlying(Subdirectory::End)>, Subdirectory> _tar_list;
extern EnumClassIndexContainer<std::array<TarFileList, to_underlying(Subdirectory::End)>, Subdirectory> _tar_filelist;
#endif /* TAR_TYPE_H */
+3 -3
View File
@@ -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);
+1 -1
View File
@@ -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());
+2 -2
View File
@@ -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);