Change: add a timestamp in name of crash files
This commit is contained in:
@@ -324,6 +324,25 @@ char *CrashLog::LogRecentNews(char *buffer, const char *last) const
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a timestamped filename.
|
||||
* @param filename The begin where to write at.
|
||||
* @param filename_last The last position in the buffer to write to.
|
||||
* @param ext The extension for the filename.
|
||||
* @param with_dir Whether to prepend the filename with the personal directory.
|
||||
* @return the number of added characters.
|
||||
*/
|
||||
int CrashLog::CreateFileName(char *filename, const char *filename_last, const char *ext, bool with_dir) const
|
||||
{
|
||||
static std::string crashname;
|
||||
|
||||
if (crashname.empty()) {
|
||||
UTCTime::Format(filename, filename_last, "crash%Y%m%d%H%M%S");
|
||||
crashname = filename;
|
||||
}
|
||||
return seprintf(filename, filename_last, "%s%s%s", with_dir ? _personal_dir.c_str() : "", crashname.c_str(), ext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the crash log buffer with all data of a crash log.
|
||||
* @param buffer The begin where to write at.
|
||||
@@ -366,7 +385,7 @@ char *CrashLog::FillCrashLog(char *buffer, const char *last) const
|
||||
*/
|
||||
bool CrashLog::WriteCrashLog(const char *buffer, char *filename, const char *filename_last) const
|
||||
{
|
||||
seprintf(filename, filename_last, "%scrash.log", _personal_dir.c_str());
|
||||
this->CreateFileName(filename, filename_last, ".log");
|
||||
|
||||
FILE *file = FioFOpenFile(filename, "w", NO_DIRECTORY);
|
||||
if (file == nullptr) return false;
|
||||
@@ -401,7 +420,7 @@ bool CrashLog::WriteSavegame(char *filename, const char *filename_last) const
|
||||
try {
|
||||
GamelogEmergency();
|
||||
|
||||
seprintf(filename, filename_last, "%scrash.sav", _personal_dir.c_str());
|
||||
this->CreateFileName(filename, filename_last, ".sav");
|
||||
|
||||
/* Don't do a threaded saveload. */
|
||||
return SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, NO_DIRECTORY, false) == SL_OK;
|
||||
@@ -423,7 +442,9 @@ bool CrashLog::WriteScreenshot(char *filename, const char *filename_last) const
|
||||
/* Don't draw when we have invalid screen size */
|
||||
if (_screen.width < 1 || _screen.height < 1 || _screen.dst_ptr == nullptr) return false;
|
||||
|
||||
bool res = MakeScreenshot(SC_CRASHLOG, "crash");
|
||||
this->CreateFileName(filename, filename_last, "", false);
|
||||
bool res = MakeScreenshot(SC_CRASHLOG, filename);
|
||||
filename[0] = '\0';
|
||||
if (res) strecpy(filename, _full_screenshot_name, filename_last);
|
||||
return res;
|
||||
}
|
||||
|
Reference in New Issue
Block a user