mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-13 02:52:37 +00:00
Codechange: let GenerateDefaultSaveName return std::string
This commit is contained in:
parent
ac1d042550
commit
993f90b6a0
@ -1061,17 +1061,17 @@ void DeterminePaths(const char *exe, bool only_local_path)
|
||||
|
||||
/**
|
||||
* Sanitizes a filename, i.e. removes all illegal characters from it.
|
||||
* @param filename the "\0" terminated filename
|
||||
* @param filename the filename
|
||||
*/
|
||||
void SanitizeFilename(char *filename)
|
||||
void SanitizeFilename(std::string &filename)
|
||||
{
|
||||
for (; *filename != '\0'; filename++) {
|
||||
switch (*filename) {
|
||||
for (auto &c : filename) {
|
||||
switch (c) {
|
||||
/* The following characters are not allowed in filenames
|
||||
* on at least one of the supported operating systems: */
|
||||
case ':': case '\\': case '*': case '?': case '/':
|
||||
case '<': case '>': case '|': case '"':
|
||||
*filename = '_';
|
||||
c = '_';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ void FioCreateDirectory(const std::string &name);
|
||||
|
||||
const char *FiosGetScreenshotDir();
|
||||
|
||||
void SanitizeFilename(char *filename);
|
||||
void SanitizeFilename(std::string &filename);
|
||||
void AppendPathSeparator(std::string &buf);
|
||||
void DeterminePaths(const char *exe, bool only_local_path);
|
||||
std::unique_ptr<char[]> ReadFileToMem(const std::string &filename, size_t &lenp, size_t maxsize);
|
||||
|
@ -299,8 +299,7 @@ public:
|
||||
/** Generate a default save filename. */
|
||||
void GenerateFileName()
|
||||
{
|
||||
GenerateDefaultSaveName(this->filename_editbox.text.buf, &this->filename_editbox.text.buf[this->filename_editbox.text.max_bytes - 1]);
|
||||
this->filename_editbox.text.UpdateSize();
|
||||
this->filename_editbox.text.Assign(GenerateDefaultSaveName());
|
||||
}
|
||||
|
||||
SaveLoadWindow(WindowDesc *desc, AbstractFileType abstract_filetype, SaveLoadOperation fop)
|
||||
|
@ -3170,17 +3170,16 @@ SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop,
|
||||
*/
|
||||
void DoAutoOrNetsave(FiosNumberedSaveName &counter)
|
||||
{
|
||||
char buf[MAX_PATH];
|
||||
std::string filename;
|
||||
|
||||
if (_settings_client.gui.keep_all_autosave) {
|
||||
GenerateDefaultSaveName(buf, lastof(buf));
|
||||
strecat(buf, counter.Extension().c_str(), lastof(buf));
|
||||
filename = GenerateDefaultSaveName() + counter.Extension();
|
||||
} else {
|
||||
strecpy(buf, counter.Filename().c_str(), lastof(buf));
|
||||
filename = counter.Filename();
|
||||
}
|
||||
|
||||
Debug(sl, 2, "Autosaving to '{}'", buf);
|
||||
if (SaveOrLoad(buf, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR) != SL_OK) {
|
||||
Debug(sl, 2, "Autosaving to '{}'", filename);
|
||||
if (SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR) != SL_OK) {
|
||||
ShowErrorMessage(STR_ERROR_AUTOSAVE_FAILED, INVALID_STRING_ID, WL_ERROR);
|
||||
}
|
||||
}
|
||||
@ -3193,11 +3192,9 @@ void DoExitSave()
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the buffer with the default name for a savegame *or* screenshot.
|
||||
* @param buf the buffer to write to.
|
||||
* @param last the last element in the buffer.
|
||||
* Get the default name for a savegame *or* screenshot.
|
||||
*/
|
||||
void GenerateDefaultSaveName(char *buf, const char *last)
|
||||
std::string GenerateDefaultSaveName()
|
||||
{
|
||||
/* Check if we have a name for this map, which is the name of the first
|
||||
* available company. When there's no company available we'll use
|
||||
@ -3222,8 +3219,9 @@ void GenerateDefaultSaveName(char *buf, const char *last)
|
||||
SetDParam(2, TimerGameCalendar::date);
|
||||
|
||||
/* Get the correct string (special string for when there's not company) */
|
||||
GetString(buf, !Company::IsValidID(cid) ? STR_SAVEGAME_NAME_SPECTATOR : STR_SAVEGAME_NAME_DEFAULT, last);
|
||||
SanitizeFilename(buf);
|
||||
std::string filename = GetString(!Company::IsValidID(cid) ? STR_SAVEGAME_NAME_SPECTATOR : STR_SAVEGAME_NAME_DEFAULT);
|
||||
SanitizeFilename(filename);
|
||||
return filename;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -393,7 +393,7 @@ enum SavegameType {
|
||||
|
||||
extern FileToSaveLoad _file_to_saveload;
|
||||
|
||||
void GenerateDefaultSaveName(char *buf, const char *last);
|
||||
std::string GenerateDefaultSaveName();
|
||||
void SetSaveLoadError(StringID str);
|
||||
const char *GetSaveLoadErrorString();
|
||||
SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded = true);
|
||||
|
@ -674,7 +674,7 @@ static const char *MakeScreenshotName(const char *default_fn, const char *ext, b
|
||||
if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
|
||||
strecpy(_screenshot_name, default_fn, lastof(_screenshot_name));
|
||||
} else {
|
||||
GenerateDefaultSaveName(_screenshot_name, lastof(_screenshot_name));
|
||||
strecpy(_screenshot_name, GenerateDefaultSaveName().c_str(), lastof(_screenshot_name));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user