mirror of https://github.com/OpenTTD/OpenTTD
Change: add a timestamp in name of crash files
parent
d9a37c915f
commit
b6c5f49379
|
@ -324,6 +324,25 @@ char *CrashLog::LogRecentNews(char *buffer, const char *last) const
|
||||||
return buffer;
|
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.
|
* Fill the crash log buffer with all data of a crash log.
|
||||||
* @param buffer The begin where to write at.
|
* @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
|
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);
|
FILE *file = FioFOpenFile(filename, "w", NO_DIRECTORY);
|
||||||
if (file == nullptr) return false;
|
if (file == nullptr) return false;
|
||||||
|
@ -401,7 +420,7 @@ bool CrashLog::WriteSavegame(char *filename, const char *filename_last) const
|
||||||
try {
|
try {
|
||||||
GamelogEmergency();
|
GamelogEmergency();
|
||||||
|
|
||||||
seprintf(filename, filename_last, "%scrash.sav", _personal_dir.c_str());
|
this->CreateFileName(filename, filename_last, ".sav");
|
||||||
|
|
||||||
/* Don't do a threaded saveload. */
|
/* Don't do a threaded saveload. */
|
||||||
return SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, NO_DIRECTORY, false) == SL_OK;
|
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 */
|
/* Don't draw when we have invalid screen size */
|
||||||
if (_screen.width < 1 || _screen.height < 1 || _screen.dst_ptr == nullptr) return false;
|
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);
|
if (res) strecpy(filename, _full_screenshot_name, filename_last);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,8 @@ protected:
|
||||||
char *LogGamelog(char *buffer, const char *last) const;
|
char *LogGamelog(char *buffer, const char *last) const;
|
||||||
char *LogRecentNews(char *buffer, const char *list) 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:
|
public:
|
||||||
/** Stub destructor to silence some compilers. */
|
/** Stub destructor to silence some compilers. */
|
||||||
virtual ~CrashLog() {}
|
virtual ~CrashLog() {}
|
||||||
|
|
|
@ -186,7 +186,7 @@ public:
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Writing crash savegame...\n");
|
printf("Writing crash screenshot...\n");
|
||||||
if (!this->WriteScreenshot(filename_screenshot, lastof(filename_screenshot))) {
|
if (!this->WriteScreenshot(filename_screenshot, lastof(filename_screenshot))) {
|
||||||
filename_screenshot[0] = '\0';
|
filename_screenshot[0] = '\0';
|
||||||
ret = false;
|
ret = false;
|
||||||
|
|
|
@ -490,7 +490,7 @@ char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) c
|
||||||
CONST PMINIDUMP_CALLBACK_INFORMATION);
|
CONST PMINIDUMP_CALLBACK_INFORMATION);
|
||||||
MiniDumpWriteDump_t funcMiniDumpWriteDump = dbghelp.GetProcAddress("MiniDumpWriteDump");
|
MiniDumpWriteDump_t funcMiniDumpWriteDump = dbghelp.GetProcAddress("MiniDumpWriteDump");
|
||||||
if (funcMiniDumpWriteDump != nullptr) {
|
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 file = CreateFile(OTTD2FS(filename).c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, 0, 0);
|
||||||
HANDLE proc = GetCurrentProcess();
|
HANDLE proc = GetCurrentProcess();
|
||||||
DWORD procid = GetCurrentProcessId();
|
DWORD procid = GetCurrentProcessId();
|
||||||
|
|
Loading…
Reference in New Issue