diff --git a/src/fios.cpp b/src/fios.cpp index 075062c443..1ae20cfcb1 100644 --- a/src/fios.cpp +++ b/src/fios.cpp @@ -38,7 +38,7 @@ extern bool FiosIsHiddenFile(const std::filesystem::path &path); extern void FiosGetDrives(FileList &file_list); /* get the name of an oldstyle savegame */ -extern std::string GetOldSaveGameName(const std::string &file); +extern std::string GetOldSaveGameName(std::string_view file); /** * Compare two FiosItem's. Used with sort when sorting the file list. @@ -240,7 +240,7 @@ bool FiosDelete(std::string_view name) return FioRemove(FiosMakeSavegameName(name)); } -typedef std::tuple FiosGetTypeAndNameProc(SaveLoadOperation fop, const std::string &filename, std::string_view ext); +typedef std::tuple FiosGetTypeAndNameProc(SaveLoadOperation fop, std::string_view filename, std::string_view ext); /** * Scanner to scan for a particular type of FIOS file. @@ -377,9 +377,10 @@ static void FiosGetFileList(SaveLoadOperation fop, bool show_dirs, FiosGetTypeAn * @param subdir the sub directory to search in * @return The file title. */ -static std::string GetFileTitle(const std::string &file, Subdirectory subdir) +static std::string GetFileTitle(std::string_view file, Subdirectory subdir) { - auto f = FioFOpenFile(file + ".title", "r", subdir); + std::string filename = fmt::format("{}.title", file); + auto f = FioFOpenFile(filename, "r", subdir); if (!f.has_value()) return {}; char title[80]; @@ -398,7 +399,7 @@ static std::string GetFileTitle(const std::string &file, Subdirectory subdir) * @see FiosGetFileList * @see FiosGetSavegameList */ -std::tuple FiosGetSavegameListCallback(SaveLoadOperation fop, const std::string &file, std::string_view ext) +std::tuple FiosGetSavegameListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext) { /* Show savegame files * .SAV OpenTTD saved game @@ -447,7 +448,7 @@ void FiosGetSavegameList(SaveLoadOperation fop, bool show_dirs, FileList &file_l * @see FiosGetFileList * @see FiosGetScenarioList */ -std::tuple FiosGetScenarioListCallback(SaveLoadOperation fop, const std::string &file, std::string_view ext) +std::tuple FiosGetScenarioListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext) { /* Show scenario files * .SCN OpenTTD style scenario file @@ -488,7 +489,7 @@ void FiosGetScenarioList(SaveLoadOperation fop, bool show_dirs, FileList &file_l FiosGetFileList(fop, show_dirs, &FiosGetScenarioListCallback, subdir, file_list); } -std::tuple FiosGetHeightmapListCallback(SaveLoadOperation, const std::string &file, std::string_view ext) +std::tuple FiosGetHeightmapListCallback(SaveLoadOperation, std::string_view file, std::string_view ext) { /* Show heightmap files * .PNG PNG Based heightmap files @@ -553,7 +554,7 @@ void FiosGetHeightmapList(SaveLoadOperation fop, bool show_dirs, FileList &file_ * @param file Name of the file to check. * @return a FIOS_TYPE_JSON type of the found file, FIOS_TYPE_INVALID if not a valid JSON file, and the title of the file (if any). */ -static std::tuple FiosGetTownDataListCallback(SaveLoadOperation fop, const std::string &file, std::string_view ext) +static std::tuple FiosGetTownDataListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext) { if (fop == SLO_LOAD) { if (StrEqualsIgnoreCase(ext, ".json")) { @@ -715,7 +716,7 @@ FiosNumberedSaveName::FiosNumberedSaveName(const std::string &prefix) : prefix(p static std::string _prefix; ///< Static as the lambda needs access to it. /* Callback for FiosFileScanner. */ - static FiosGetTypeAndNameProc *proc = [](SaveLoadOperation, const std::string &file, std::string_view ext) { + static FiosGetTypeAndNameProc *proc = [](SaveLoadOperation, std::string_view file, std::string_view ext) { if (StrEqualsIgnoreCase(ext, ".sav") && file.starts_with(_prefix)) return std::tuple(FIOS_TYPE_FILE, std::string{}); return std::tuple(FIOS_TYPE_INVALID, std::string{}); }; diff --git a/src/fios.h b/src/fios.h index 36c825a479..b2ef40183b 100644 --- a/src/fios.h +++ b/src/fios.h @@ -116,9 +116,9 @@ bool FiosDelete(std::string_view name); std::string FiosMakeHeightmapName(std::string_view name); std::string FiosMakeSavegameName(std::string_view name); -std::tuple FiosGetSavegameListCallback(SaveLoadOperation fop, const std::string &file, std::string_view ext); -std::tuple FiosGetScenarioListCallback(SaveLoadOperation fop, const std::string &file, std::string_view ext); -std::tuple FiosGetHeightmapListCallback(SaveLoadOperation fop, const std::string &file, std::string_view ext); +std::tuple FiosGetSavegameListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext); +std::tuple FiosGetScenarioListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext); +std::tuple FiosGetHeightmapListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext); void ScanScenarios(); std::optional FindScenario(const ContentInfo &ci, bool md5sum); diff --git a/src/saveload/oldloader.cpp b/src/saveload/oldloader.cpp index 01c1d600a3..5361a000e1 100644 --- a/src/saveload/oldloader.cpp +++ b/src/saveload/oldloader.cpp @@ -231,7 +231,7 @@ static std::tuple DetermineOldSavegameTypeAndName(Fil typedef bool LoadOldMainProc(LoadgameState &ls); -bool LoadOldSaveGame(const std::string &file) +bool LoadOldSaveGame(std::string_view file) { LoadgameState ls{}; @@ -282,7 +282,7 @@ bool LoadOldSaveGame(const std::string &file) return true; } -std::string GetOldSaveGameName(const std::string &file) +std::string GetOldSaveGameName(std::string_view file) { auto f = FioFOpenFile(file, "rb", NO_DIRECTORY); if (!f.has_value()) return {}; diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index fc5a561ff9..d4938ea35d 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -2889,7 +2889,7 @@ static std::pair GetSavegameFormat(const std::s /* actual loader/saver function */ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings); extern bool AfterLoadGame(); -extern bool LoadOldSaveGame(const std::string &file); +extern bool LoadOldSaveGame(std::string_view file); /** * Reset all settings to their default, so any settings missing in the savegame @@ -3250,7 +3250,7 @@ SaveOrLoadResult LoadWithFilter(std::shared_ptr reader) * @param threaded True when threaded saving is allowed * @return Return the result of the action. #SL_OK, #SL_ERROR, or #SL_REINIT ("unload" the game) */ -SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded) +SaveOrLoadResult SaveOrLoad(std::string_view filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded) { /* An instance of saving is already active, so don't go saving again */ if (_sl.saveinprogress && fop == SLO_SAVE && dft == DFT_GAME_FILE && threaded) { diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 267aa081da..3b9fff52c0 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -439,7 +439,7 @@ std::string GenerateDefaultSaveName(); void SetSaveLoadError(StringID str); EncodedString GetSaveLoadErrorType(); EncodedString GetSaveLoadErrorMessage(); -SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded = true); +SaveOrLoadResult SaveOrLoad(std::string_view filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded = true); void WaitTillSaved(); void ProcessAsyncSaveFinish(); void DoExitSave(); diff --git a/src/tar_type.h b/src/tar_type.h index 69f8f04c4a..992cb04448 100644 --- a/src/tar_type.h +++ b/src/tar_type.h @@ -19,8 +19,8 @@ struct TarFileListEntry { size_t position; }; -typedef std::map TarList; ///< Map of tar file to tar directory. -typedef std::map TarFileList; +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];