1
0
Fork 0

Codechange: Convert some more FIO functions to take std::string.

pull/8443/head
Michael Lutz 2020-12-06 21:11:45 +01:00
parent f3326d34e7
commit 65f65ad2ad
14 changed files with 62 additions and 68 deletions

View File

@ -270,9 +270,9 @@ bool IsValidSearchPath(Searchpath sp)
* @param subdir the subdirectory to look in * @param subdir the subdirectory to look in
* @return true if and only if the file can be opened * @return true if and only if the file can be opened
*/ */
bool FioCheckFileExists(const char *filename, Subdirectory subdir) bool FioCheckFileExists(const std::string &filename, Subdirectory subdir)
{ {
FILE *f = FioFOpenFile(filename, "rb", subdir); FILE *f = FioFOpenFile(filename.c_str(), "rb", subdir);
if (f == nullptr) return false; if (f == nullptr) return false;
FioFCloseFile(f); FioFCloseFile(f);
@ -284,9 +284,9 @@ bool FioCheckFileExists(const char *filename, Subdirectory subdir)
* @param filename the file to test. * @param filename the file to test.
* @return true if and only if the file exists. * @return true if and only if the file exists.
*/ */
bool FileExists(const char *filename) bool FileExists(const std::string &filename)
{ {
return access(OTTD2FS(filename), 0) == 0; return access(OTTD2FS(filename.c_str()), 0) == 0;
} }
/** /**
@ -311,12 +311,12 @@ std::string FioFindFullPath(Subdirectory subdir, const char *filename)
FOR_ALL_SEARCHPATHS(sp) { FOR_ALL_SEARCHPATHS(sp) {
std::string buf = FioGetDirectory(sp, subdir); std::string buf = FioGetDirectory(sp, subdir);
buf += filename; buf += filename;
if (FileExists(buf.c_str())) return buf; if (FileExists(buf)) return buf;
#if !defined(_WIN32) #if !defined(_WIN32)
/* Be, as opening files, aware that sometimes the filename /* Be, as opening files, aware that sometimes the filename
* might be in uppercase when it is in lowercase on the * might be in uppercase when it is in lowercase on the
* disk. Of course Windows doesn't care about casing. */ * disk. Of course Windows doesn't care about casing. */
if (strtolower(buf, _searchpaths[sp].size() - 1) && FileExists(buf.c_str())) return buf; if (strtolower(buf, _searchpaths[sp].size() - 1) && FileExists(buf)) return buf;
#endif #endif
} }
@ -338,7 +338,7 @@ std::string FioFindDirectory(Subdirectory subdir)
/* Find and return the first valid directory */ /* Find and return the first valid directory */
FOR_ALL_SEARCHPATHS(sp) { FOR_ALL_SEARCHPATHS(sp) {
std::string ret = FioGetDirectory(sp, subdir); std::string ret = FioGetDirectory(sp, subdir);
if (FileExists(ret.c_str())) return ret; if (FileExists(ret)) return ret;
} }
/* Could not find the directory, fall back to a base path */ /* Could not find the directory, fall back to a base path */
@ -502,14 +502,12 @@ FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir,
* If the parent directory does not exist, it will try to create that as well. * If the parent directory does not exist, it will try to create that as well.
* @param name the new name of the directory * @param name the new name of the directory
*/ */
void FioCreateDirectory(const char *name) void FioCreateDirectory(const std::string &name)
{ {
char dirname[MAX_PATH]; auto p = name.find_last_of(PATHSEPCHAR);
strecpy(dirname, name, lastof(dirname)); if (p != std::string::npos) {
char *p = strrchr(dirname, PATHSEPCHAR); std::string dirname = name.substr(0, p);
if (p != nullptr) { DIR *dir = ttd_opendir(dirname.c_str());
*p = '\0';
DIR *dir = ttd_opendir(dirname);
if (dir == nullptr) { if (dir == nullptr) {
FioCreateDirectory(dirname); // Try creating the parent directory, if we couldn't open it FioCreateDirectory(dirname); // Try creating the parent directory, if we couldn't open it
} else { } else {
@ -520,11 +518,11 @@ void FioCreateDirectory(const char *name)
/* Ignore directory creation errors; they'll surface later on, and most /* Ignore directory creation errors; they'll surface later on, and most
* of the time they are 'directory already exists' errors anyhow. */ * of the time they are 'directory already exists' errors anyhow. */
#if defined(_WIN32) #if defined(_WIN32)
CreateDirectory(OTTD2FS(name), nullptr); CreateDirectory(OTTD2FS(name.c_str()), nullptr);
#elif defined(OS2) && !defined(__INNOTEK_LIBC__) #elif defined(OS2) && !defined(__INNOTEK_LIBC__)
mkdir(OTTD2FS(name)); mkdir(OTTD2FS(name.c_str()));
#else #else
mkdir(OTTD2FS(name), 0755); mkdir(OTTD2FS(name.c_str()), 0755);
#endif #endif
} }
@ -1198,9 +1196,9 @@ void DeterminePaths(const char *exe)
} }
/* Make the necessary folders */ /* Make the necessary folders */
FioCreateDirectory(config_dir.c_str()); FioCreateDirectory(config_dir);
#if defined(WITH_PERSONAL_DIR) #if defined(WITH_PERSONAL_DIR)
FioCreateDirectory(_personal_dir.c_str()); FioCreateDirectory(_personal_dir);
#endif #endif
DEBUG(misc, 3, "%s found as personal directory", _personal_dir.c_str()); DEBUG(misc, 3, "%s found as personal directory", _personal_dir.c_str());
@ -1210,19 +1208,17 @@ void DeterminePaths(const char *exe)
}; };
for (uint i = 0; i < lengthof(default_subdirs); i++) { for (uint i = 0; i < lengthof(default_subdirs); i++) {
FioCreateDirectory((_personal_dir + _subdirs[default_subdirs[i]]).c_str()); FioCreateDirectory(_personal_dir + _subdirs[default_subdirs[i]]);
} }
/* If we have network we make a directory for the autodownloading of content */ /* If we have network we make a directory for the autodownloading of content */
_searchpaths[SP_AUTODOWNLOAD_DIR] = _personal_dir + "content_download" PATHSEP; _searchpaths[SP_AUTODOWNLOAD_DIR] = _personal_dir + "content_download" PATHSEP;
FioCreateDirectory(_searchpaths[SP_AUTODOWNLOAD_DIR].c_str()); FioCreateDirectory(_searchpaths[SP_AUTODOWNLOAD_DIR]);
/* Create the directory for each of the types of content */ /* Create the directory for each of the types of content */
const Subdirectory dirs[] = { SCENARIO_DIR, HEIGHTMAP_DIR, BASESET_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GAME_DIR, GAME_LIBRARY_DIR }; const Subdirectory dirs[] = { SCENARIO_DIR, HEIGHTMAP_DIR, BASESET_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GAME_DIR, GAME_LIBRARY_DIR };
for (uint i = 0; i < lengthof(dirs); i++) { for (uint i = 0; i < lengthof(dirs); i++) {
char *tmp = str_fmt("%s%s", _searchpaths[SP_AUTODOWNLOAD_DIR].c_str(), _subdirs[dirs[i]]); FioCreateDirectory(FioGetDirectory(SP_AUTODOWNLOAD_DIR, dirs[i]));
FioCreateDirectory(tmp);
free(tmp);
} }
extern std::string _log_file; extern std::string _log_file;

View File

@ -38,11 +38,11 @@ bool IsValidSearchPath(Searchpath sp);
void FioFCloseFile(FILE *f); void FioFCloseFile(FILE *f);
FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize = nullptr); FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize = nullptr);
bool FioCheckFileExists(const char *filename, Subdirectory subdir); bool FioCheckFileExists(const std::string &filename, Subdirectory subdir);
std::string FioFindFullPath(Subdirectory subdir, const char *filename); std::string FioFindFullPath(Subdirectory subdir, const char *filename);
std::string FioGetDirectory(Searchpath sp, Subdirectory subdir); std::string FioGetDirectory(Searchpath sp, Subdirectory subdir);
std::string FioFindDirectory(Subdirectory subdir); std::string FioFindDirectory(Subdirectory subdir);
void FioCreateDirectory(const char *name); void FioCreateDirectory(const std::string &name);
const char *FiosGetScreenshotDir(); const char *FiosGetScreenshotDir();
@ -50,7 +50,7 @@ void SanitizeFilename(char *filename);
void AppendPathSeparator(std::string &buf); void AppendPathSeparator(std::string &buf);
void DeterminePaths(const char *exe); void DeterminePaths(const char *exe);
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize); void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
bool FileExists(const char *filename); bool FileExists(const std::string &filename);
bool ExtractTar(const char *tar_filename, Subdirectory subdir); bool ExtractTar(const char *tar_filename, Subdirectory subdir);
extern std::string _personal_dir; ///< custom directory for personal settings, saves, newgrf, etc. extern std::string _personal_dir; ///< custom directory for personal settings, saves, newgrf, etc.

View File

@ -200,26 +200,26 @@ const char *FiosBrowseTo(const FiosItem *item)
/** /**
* Construct a filename from its components in destination buffer \a buf. * Construct a filename from its components in destination buffer \a buf.
* @param buf Destination buffer.
* @param path Directory path, may be \c nullptr. * @param path Directory path, may be \c nullptr.
* @param name Filename. * @param name Filename.
* @param ext Filename extension (use \c "" for no extension). * @param ext Filename extension (use \c "" for no extension).
* @param last Last element of buffer \a buf. * @return The completed filename.
*/ */
static void FiosMakeFilename(char *buf, const char *path, const char *name, const char *ext, const char *last) static std::string FiosMakeFilename(const std::string *path, const char *name, const char *ext)
{ {
std::string buf;
if (path != nullptr) { if (path != nullptr) {
const char *buf_start = buf; buf = *path;
buf = strecpy(buf, path, last);
/* Remove trailing path separator, if present */ /* Remove trailing path separator, if present */
if (buf > buf_start && buf[-1] == PATHSEPCHAR) buf--; if (!buf.empty() && buf.back() == PATHSEPCHAR) buf.pop_back();
} }
/* Don't append the extension if it is already there */ /* Don't append the extension if it is already there */
const char *period = strrchr(name, '.'); const char *period = strrchr(name, '.');
if (period != nullptr && strcasecmp(period, ext) == 0) ext = ""; if (period != nullptr && strcasecmp(period, ext) == 0) ext = "";
seprintf(buf, last, PATHSEP "%s%s", name, ext); return buf + name + ext;
} }
/** /**
@ -227,27 +227,26 @@ static void FiosMakeFilename(char *buf, const char *path, const char *name, cons
* @param buf Destination buffer for saving the filename. * @param buf Destination buffer for saving the filename.
* @param name Name of the file. * @param name Name of the file.
* @param last Last element of buffer \a buf. * @param last Last element of buffer \a buf.
* @return The completed filename.
*/ */
void FiosMakeSavegameName(char *buf, const char *name, const char *last) std::string FiosMakeSavegameName(const char *name)
{ {
const char *extension = (_game_mode == GM_EDITOR) ? ".scn" : ".sav"; const char *extension = (_game_mode == GM_EDITOR) ? ".scn" : ".sav";
FiosMakeFilename(buf, _fios_path->c_str(), name, extension, last); return FiosMakeFilename(_fios_path, name, extension);
} }
/** /**
* Construct a filename for a height map. * Construct a filename for a height map.
* @param buf Destination buffer.
* @param name Filename. * @param name Filename.
* @param last Last element of buffer \a buf. * @return The completed filename.
*/ */
void FiosMakeHeightmapName(char *buf, const char *name, const char *last) std::string FiosMakeHeightmapName(const char *name)
{ {
char ext[5]; std::string ext(".");
ext[0] = '.'; ext += GetCurrentScreenshotExtension();
strecpy(ext + 1, GetCurrentScreenshotExtension(), lastof(ext));
FiosMakeFilename(buf, _fios_path->c_str(), name, ext, last); return FiosMakeFilename(_fios_path, name, ext.c_str());
} }
/** /**
@ -257,10 +256,8 @@ void FiosMakeHeightmapName(char *buf, const char *name, const char *last)
*/ */
bool FiosDelete(const char *name) bool FiosDelete(const char *name)
{ {
char filename[512]; std::string filename = FiosMakeSavegameName(name);
return unlink(filename.c_str()) == 0;
FiosMakeSavegameName(filename, name, lastof(filename));
return unlink(filename) == 0;
} }
typedef FiosType fios_getlist_callback_proc(SaveLoadOperation fop, const char *filename, const char *ext, char *title, const char *last); typedef FiosType fios_getlist_callback_proc(SaveLoadOperation fop, const char *filename, const char *ext, char *title, const char *last);

View File

@ -220,8 +220,8 @@ const char *FiosBrowseTo(const FiosItem *item);
StringID FiosGetDescText(const char **path, uint64 *total_free); StringID FiosGetDescText(const char **path, uint64 *total_free);
bool FiosDelete(const char *name); bool FiosDelete(const char *name);
void FiosMakeHeightmapName(char *buf, const char *name, const char *last); std::string FiosMakeHeightmapName(const char *name);
void FiosMakeSavegameName(char *buf, const char *name, const char *last); std::string FiosMakeSavegameName(const char *name);
FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last); FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last);

View File

@ -771,14 +771,14 @@ public:
} }
} else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked } else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked
if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) { if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) {
FiosMakeSavegameName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name)); _file_to_saveload.name = FiosMakeSavegameName(this->filename_editbox.text.buf);
if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) { if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) {
ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING, this, SaveLoadWindow::SaveGameConfirmationCallback); ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING, this, SaveLoadWindow::SaveGameConfirmationCallback);
} else { } else {
_switch_mode = SM_SAVE_GAME; _switch_mode = SM_SAVE_GAME;
} }
} else { } else {
FiosMakeHeightmapName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name)); _file_to_saveload.name = FiosMakeHeightmapName(this->filename_editbox.text.buf);
if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) { if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) {
ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING, this, SaveLoadWindow::SaveHeightmapConfirmationCallback); ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING, this, SaveLoadWindow::SaveHeightmapConfirmationCallback);
} else { } else {

View File

@ -831,7 +831,7 @@ static void _ShowGenerateLandscape(GenerateLandscapeWindowMode mode)
if (mode == GLWM_HEIGHTMAP) { if (mode == GLWM_HEIGHTMAP) {
/* If the function returns negative, it means there was a problem loading the heightmap */ /* If the function returns negative, it means there was a problem loading the heightmap */
if (!GetHeightmapDimensions(_file_to_saveload.detail_ftype, _file_to_saveload.name, &x, &y)) return; if (!GetHeightmapDimensions(_file_to_saveload.detail_ftype, _file_to_saveload.name.c_str(), &x, &y)) return;
} }
WindowDesc *desc = (mode == GLWM_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc; WindowDesc *desc = (mode == GLWM_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc;

View File

@ -1305,7 +1305,7 @@ void GenerateLandscape(byte mode)
if (mode == GWM_HEIGHTMAP) { if (mode == GWM_HEIGHTMAP) {
SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_HEIGHTMAP); SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_HEIGHTMAP);
LoadHeightmap(_file_to_saveload.detail_ftype, _file_to_saveload.name); LoadHeightmap(_file_to_saveload.detail_ftype, _file_to_saveload.name.c_str());
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE); IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
} else if (_settings_game.game_creation.land_generator == LG_TERRAGENESIS) { } else if (_settings_game.game_creation.land_generator == LG_TERRAGENESIS) {
SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_TERRAGENESIS); SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_TERRAGENESIS);

View File

@ -1078,11 +1078,11 @@ std::string MidiFile::GetSMFFile(const MusicSongInfo &song)
std::string tempdirname = FioGetDirectory(Searchpath::SP_AUTODOWNLOAD_DIR, Subdirectory::BASESET_DIR); std::string tempdirname = FioGetDirectory(Searchpath::SP_AUTODOWNLOAD_DIR, Subdirectory::BASESET_DIR);
tempdirname += basename; tempdirname += basename;
AppendPathSeparator(tempdirname); AppendPathSeparator(tempdirname);
FioCreateDirectory(tempdirname.c_str()); FioCreateDirectory(tempdirname);
std::string output_filename = tempdirname + std::to_string(song.cat_index) + ".mid"; std::string output_filename = tempdirname + std::to_string(song.cat_index) + ".mid";
if (FileExists(output_filename.c_str())) { if (FileExists(output_filename)) {
/* If the file already exists, assume it's the correct decoded data */ /* If the file already exists, assume it's the correct decoded data */
return output_filename; return output_filename;
} }

View File

@ -541,7 +541,7 @@ bool ClientNetworkGameSocketHandler::IsConnected()
* DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p * DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p
************/ ************/
extern bool SafeLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = nullptr); extern bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = nullptr);
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p) NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p)
{ {
@ -867,7 +867,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
/* The map is done downloading, load it */ /* The map is done downloading, load it */
ClearErrorMessages(); ClearErrorMessages();
bool load_success = SafeLoad(nullptr, SLO_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, lf); bool load_success = SafeLoad({}, SLO_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, lf);
/* Long savegame loads shouldn't affect the lag calculation! */ /* Long savegame loads shouldn't affect the lag calculation! */
this->last_packet = _realtime_tick; this->last_packet = _realtime_tick;

View File

@ -626,9 +626,9 @@ int openttd_main(int argc, char *argv[])
_file_to_saveload.SetMode(SLO_LOAD, is_scenario ? FT_SCENARIO : FT_SAVEGAME, DFT_GAME_FILE); _file_to_saveload.SetMode(SLO_LOAD, is_scenario ? FT_SCENARIO : FT_SAVEGAME, DFT_GAME_FILE);
/* if the file doesn't exist or it is not a valid savegame, let the saveload code show an error */ /* if the file doesn't exist or it is not a valid savegame, let the saveload code show an error */
const char *t = strrchr(_file_to_saveload.name, '.'); auto t = _file_to_saveload.name.find_last_of('.');
if (t != nullptr) { if (t != std::string::npos) {
FiosType ft = FiosGetSavegameListCallback(SLO_LOAD, _file_to_saveload.name, t, nullptr, nullptr); FiosType ft = FiosGetSavegameListCallback(SLO_LOAD, _file_to_saveload.name.c_str(), _file_to_saveload.name.substr(t).c_str(), nullptr, nullptr);
if (ft != FIOS_TYPE_INVALID) _file_to_saveload.SetMode(ft); if (ft != FIOS_TYPE_INVALID) _file_to_saveload.SetMode(ft);
} }
@ -960,7 +960,7 @@ static void MakeNewEditorWorld()
* @param subdir default directory to look for filename, set to 0 if not needed * @param subdir default directory to look for filename, set to 0 if not needed
* @param lf Load filter to use, if nullptr: use filename + subdir. * @param lf Load filter to use, if nullptr: use filename + subdir.
*/ */
bool SafeLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = nullptr) bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = nullptr)
{ {
assert(fop == SLO_LOAD); assert(fop == SLO_LOAD);
assert(dft == DFT_GAME_FILE || (lf == nullptr && dft == DFT_OLD_GAME_FILE)); assert(dft == DFT_GAME_FILE || (lf == nullptr && dft == DFT_OLD_GAME_FILE));
@ -968,7 +968,7 @@ bool SafeLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft,
_game_mode = newgm; _game_mode = newgm;
switch (lf == nullptr ? SaveOrLoad(filename, fop, dft, subdir) : LoadWithFilter(lf)) { switch (lf == nullptr ? SaveOrLoad(filename.c_str(), fop, dft, subdir) : LoadWithFilter(lf)) {
case SL_OK: return true; case SL_OK: return true;
case SL_REINIT: case SL_REINIT:
@ -1127,7 +1127,7 @@ void SwitchToMode(SwitchMode new_mode)
case SM_SAVE_GAME: // Save game. case SM_SAVE_GAME: // Save game.
/* Make network saved games on pause compatible to singleplayer */ /* Make network saved games on pause compatible to singleplayer */
if (SaveOrLoad(_file_to_saveload.name, SLO_SAVE, DFT_GAME_FILE, NO_DIRECTORY) != SL_OK) { if (SaveOrLoad(_file_to_saveload.name.c_str(), SLO_SAVE, DFT_GAME_FILE, NO_DIRECTORY) != SL_OK) {
SetDParamStr(0, GetSaveLoadErrorString()); SetDParamStr(0, GetSaveLoadErrorString());
ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR); ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
} else { } else {
@ -1136,7 +1136,7 @@ void SwitchToMode(SwitchMode new_mode)
break; break;
case SM_SAVE_HEIGHTMAP: // Save heightmap. case SM_SAVE_HEIGHTMAP: // Save heightmap.
MakeHeightmapScreenshot(_file_to_saveload.name); MakeHeightmapScreenshot(_file_to_saveload.name.c_str());
DeleteWindowById(WC_SAVELOAD, 0); DeleteWindowById(WC_SAVELOAD, 0);
break; break;

View File

@ -2930,7 +2930,7 @@ void FileToSaveLoad::SetMode(SaveLoadOperation fop, AbstractFileType aft, Detail
*/ */
void FileToSaveLoad::SetName(const char *name) void FileToSaveLoad::SetName(const char *name)
{ {
strecpy(this->name, name, lastof(this->name)); this->name = name;
} }
/** /**

View File

@ -12,6 +12,7 @@
#include "../fileio_type.h" #include "../fileio_type.h"
#include "../strings_type.h" #include "../strings_type.h"
#include <string>
/** SaveLoad versions /** SaveLoad versions
* Previous savegame versions, the trunk revision where they were * Previous savegame versions, the trunk revision where they were
@ -337,7 +338,7 @@ struct FileToSaveLoad {
SaveLoadOperation file_op; ///< File operation to perform. SaveLoadOperation file_op; ///< File operation to perform.
DetailedFileType detail_ftype; ///< Concrete file type (PNG, BMP, old save, etc). DetailedFileType detail_ftype; ///< Concrete file type (PNG, BMP, old save, etc).
AbstractFileType abstract_ftype; ///< Abstract type of file (scenario, heightmap, etc). AbstractFileType abstract_ftype; ///< Abstract type of file (scenario, heightmap, etc).
char name[MAX_PATH]; ///< Name of the file. std::string name; ///< Name of the file.
char title[255]; ///< Internal name of the game. char title[255]; ///< Internal name of the game.
void SetMode(FiosType ft); void SetMode(FiosType ft);

View File

@ -120,7 +120,7 @@ bool ScriptInstance::LoadCompatibilityScripts(const char *api_version, Subdirect
FOR_ALL_SEARCHPATHS(sp) { FOR_ALL_SEARCHPATHS(sp) {
std::string buf = FioGetDirectory(sp, dir); std::string buf = FioGetDirectory(sp, dir);
buf += script_name; buf += script_name;
if (!FileExists(buf.c_str())) continue; if (!FileExists(buf)) continue;
if (this->engine->LoadScript(buf.c_str())) return true; if (this->engine->LoadScript(buf.c_str())) return true;

View File

@ -128,7 +128,7 @@ static void *_dedicated_video_mem;
/* Whether a fork has been done. */ /* Whether a fork has been done. */
bool _dedicated_forks; bool _dedicated_forks;
extern bool SafeLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = nullptr); extern bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = nullptr);
static FVideoDriver_Dedicated iFVideoDriver_Dedicated; static FVideoDriver_Dedicated iFVideoDriver_Dedicated;