From 6c21c93192579efc961981caf318754742e3e4e0 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 8 Oct 2019 00:05:31 +0100 Subject: [PATCH] Add command line switch -Z to write detailed version information --- src/crashlog.cpp | 33 +++++++++++++++++++++++++++++++++ src/crashlog.h | 3 +++ src/openttd.cpp | 6 ++++++ src/os/macosx/crashlog_osx.cpp | 6 ++++++ src/os/unix/crashlog_unix.cpp | 6 ++++++ src/os/windows/crashlog_win.cpp | 6 ++++++ 6 files changed, 60 insertions(+) diff --git a/src/crashlog.cpp b/src/crashlog.cpp index 666ac818a8..9ba40322d7 100644 --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -508,6 +508,26 @@ char *CrashLog::FillDesyncCrashLog(char *buffer, const char *last, const DesyncE return buffer; } +/** + * Fill the version info log buffer. + * @param buffer The begin where to write at. + * @param last The last position in the buffer to write to. + * @return the position of the \c '\0' character after the buffer. + */ +char *CrashLog::FillVersionInfoLog(char *buffer, const char *last) const +{ + buffer += seprintf(buffer, last, "*** OpenTTD Version Info Report ***\n\n"); + + buffer = this->LogOpenTTDVersion(buffer, last); + buffer = this->LogOSVersion(buffer, last); + buffer = this->LogCompiler(buffer, last); + buffer = this->LogOSVersionDetail(buffer, last); + buffer = this->LogLibraries(buffer, last); + + buffer += seprintf(buffer, last, "*** End of OpenTTD Version Info Report ***\n"); + return buffer; +} + /** * Write the crash log to a file. * @note On success the filename will be filled with the full path of the @@ -705,6 +725,19 @@ bool CrashLog::MakeDesyncCrashLog(const std::string *log_in, std::string *log_ou return ret; } +/** + * Makes a version info log, writes it to a file. It uses DEBUG to write + * information like paths to the console. + * @return true when everything is made successfully. + */ +bool CrashLog::MakeVersionInfoLog() const +{ + char buffer[65536]; + this->FillVersionInfoLog(buffer, lastof(buffer)); + printf("%s\n", buffer); + return true; +} + /** * Makes a crash dump and crash savegame. It uses DEBUG to write * information like paths to the console. diff --git a/src/crashlog.h b/src/crashlog.h index 3d9c5c26eb..c1cedb5ac1 100644 --- a/src/crashlog.h +++ b/src/crashlog.h @@ -129,6 +129,7 @@ public: char *FillCrashLog(char *buffer, const char *last) const; char *FillDesyncCrashLog(char *buffer, const char *last, const DesyncExtraInfo &info) const; + char *FillVersionInfoLog(char *buffer, const char *last) const; bool WriteCrashLog(const char *buffer, char *filename, const char *filename_last, const char *name = "crash", FILE **crashlog_file = nullptr) const; /** @@ -146,6 +147,7 @@ public: bool MakeCrashLog() const; bool MakeDesyncCrashLog(const std::string *log_in, std::string *log_out, const DesyncExtraInfo &info) const; + bool MakeVersionInfoLog() const; bool MakeCrashSavegameAndScreenshot() const; /** @@ -156,6 +158,7 @@ public: static void InitialiseCrashLog(); static void DesyncCrashLog(const std::string *log_in, std::string *log_out, const DesyncExtraInfo &info); + static void VersionInfoLog(); static void SetErrorMessage(const char *message); static void AfterCrashLogCleanup(); diff --git a/src/openttd.cpp b/src/openttd.cpp index 0ca216c748..b103f73b5a 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -231,6 +231,7 @@ static void ShowHelp() " -c config_file = Use 'config_file' instead of 'openttd.cfg'\n" " -x = Do not automatically save to config file on exit\n" " -q savegame = Write some information about the savegame and exit\n" + " -Z = Write detailed version information and exit\n" "\n", lastof(buf) ); @@ -649,6 +650,7 @@ static const OptionData _options[] = { GETOPT_SHORT_VALUE('K'), GETOPT_SHORT_NOVAL('h'), GETOPT_SHORT_VALUE('J'), + GETOPT_SHORT_NOVAL('Z'), GETOPT_END() }; @@ -804,6 +806,10 @@ int openttd_main(int argc, char *argv[]) case 'c': free(_config_file); _config_file = stredup(mgo.opt); break; case 'x': scanner->save_config = false; break; case 'J': _quit_after_days = Clamp(atoi(mgo.opt), 0, INT_MAX); break; + case 'Z': { + CrashLog::VersionInfoLog(); + goto exit_noshutdown; + } case 'h': i = -2; // Force printing of help. break; diff --git a/src/os/macosx/crashlog_osx.cpp b/src/os/macosx/crashlog_osx.cpp index 9a420ad16e..688464f882 100644 --- a/src/os/macosx/crashlog_osx.cpp +++ b/src/os/macosx/crashlog_osx.cpp @@ -521,3 +521,9 @@ void CDECL HandleCrash(int signum, siginfo_t *si, void *context) CrashLogOSX log(CrashLogOSX::DesyncTag{}); log.MakeDesyncCrashLog(log_in, log_out, info); } + +/* static */ void CrashLog::VersionInfoLog() +{ + CrashLogOSX log(CrashLogOSX::DesyncTag{}); + log.MakeVersionInfoLog(); +} diff --git a/src/os/unix/crashlog_unix.cpp b/src/os/unix/crashlog_unix.cpp index ca1e5de7d0..e65d0a4fc1 100644 --- a/src/os/unix/crashlog_unix.cpp +++ b/src/os/unix/crashlog_unix.cpp @@ -625,3 +625,9 @@ static void CDECL HandleCrash(int signum) CrashLogUnix log(CrashLogUnix::DesyncTag{}); log.MakeDesyncCrashLog(log_in, log_out, info); } + +/* static */ void CrashLog::VersionInfoLog() +{ + CrashLogUnix log(CrashLogUnix::DesyncTag{}); + log.MakeVersionInfoLog(); +} diff --git a/src/os/windows/crashlog_win.cpp b/src/os/windows/crashlog_win.cpp index 91c79989ce..a0d08e83b6 100644 --- a/src/os/windows/crashlog_win.cpp +++ b/src/os/windows/crashlog_win.cpp @@ -621,6 +621,12 @@ static void CDECL CustomAbort(int signal) log.MakeDesyncCrashLog(log_in, log_out, info); } +/* static */ void CrashLog::VersionInfoLog() +{ + CrashLogWindows log(nullptr); + log.MakeVersionInfoLog(); +} + /* The crash log GUI */ static bool _expanded;