mirror of https://github.com/OpenTTD/OpenTTD.git
Change: add a timestamp in name of crash files
This commit is contained in:
parent
cce665c07b
commit
8639e222c8
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -85,6 +85,8 @@ protected:
|
|||
char *LogGamelog(char *buffer, const char *last) const;
|
||||
char *LogRecentNews(char *buffer, const char *list) const;
|
||||
|
||||
int CreateFileName(char *filename, const char *filename_last, const char *ext, bool with_dir = true) const;
|
||||
|
||||
public:
|
||||
/** Stub destructor to silence some compilers. */
|
||||
virtual ~CrashLog() {}
|
||||
|
|
|
@ -186,7 +186,7 @@ public:
|
|||
ret = false;
|
||||
}
|
||||
|
||||
printf("Writing crash savegame...\n");
|
||||
printf("Writing crash screenshot...\n");
|
||||
if (!this->WriteScreenshot(filename_screenshot, lastof(filename_screenshot))) {
|
||||
filename_screenshot[0] = '\0';
|
||||
ret = false;
|
||||
|
|
|
@ -490,7 +490,7 @@ char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) c
|
|||
CONST PMINIDUMP_CALLBACK_INFORMATION);
|
||||
MiniDumpWriteDump_t funcMiniDumpWriteDump = dbghelp.GetProcAddress("MiniDumpWriteDump");
|
||||
if (funcMiniDumpWriteDump != nullptr) {
|
||||
seprintf(filename, filename_last, "%scrash.dmp", _personal_dir.c_str());
|
||||
this->CreateFileName(filename, filename_last, ".dmp");
|
||||
HANDLE file = CreateFile(OTTD2FS(filename).c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, 0, 0);
|
||||
HANDLE proc = GetCurrentProcess();
|
||||
DWORD procid = GetCurrentProcessId();
|
||||
|
|
Loading…
Reference in New Issue