Changeset - r26170:40e0ba47161b
[Not reviewed]
master
0 4 0
glx22 - 3 years ago 2021-12-22 18:26:49
glx@openttd.org
Change: add a timestamp in name of crash files
4 files changed with 28 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/crashlog.cpp
Show inline comments
 
@@ -325,6 +325,25 @@ char *CrashLog::LogRecentNews(char *buff
 
}
 

	
 
/**
 
 * 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.
 
 * @param last   The last position in the buffer to write to.
 
@@ -366,7 +385,7 @@ char *CrashLog::FillCrashLog(char *buffe
 
 */
 
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 *filen
 
	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 *fil
 
	/* 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;
 
}
src/crashlog.h
Show inline comments
 
@@ -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() {}
src/os/macosx/crashlog_osx.cpp
Show inline comments
 
@@ -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;
src/os/windows/crashlog_win.cpp
Show inline comments
 
@@ -490,7 +490,7 @@ char *CrashLogWindows::AppendDecodedStac
 
				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();
0 comments (0 inline, 0 general)