From 9fe4cea07ec4fdb7f453567cb8b397c28907d92f Mon Sep 17 00:00:00 2001 From: Ted John Date: Fri, 2 Apr 2021 21:09:34 +0100 Subject: [PATCH] Save .park in crash code --- src/openrct2/ParkFile.cpp | 10 ++++++++++ src/openrct2/ParkFile.h | 14 ++++++++++++++ src/openrct2/libopenrct2.vcxproj | 3 ++- src/openrct2/platform/Crash.cpp | 28 ++++++---------------------- 4 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 src/openrct2/ParkFile.h diff --git a/src/openrct2/ParkFile.cpp b/src/openrct2/ParkFile.cpp index 56d5d9d95a..8591274155 100644 --- a/src/openrct2/ParkFile.cpp +++ b/src/openrct2/ParkFile.cpp @@ -7,6 +7,8 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "ParkFile.h" + #include "Cheats.h" #include "Context.h" #include "GameState.h" @@ -1245,6 +1247,14 @@ namespace OpenRCT2 } } // namespace OpenRCT2 +void ParkFileExporter::Export(std::string_view path) +{ + map_reorganise_elements(); + + auto parkFile = std::make_unique(); + parkFile->Save(path); +} + enum : uint32_t { S6_SAVE_FLAG_EXPORT = 1 << 0, diff --git a/src/openrct2/ParkFile.h b/src/openrct2/ParkFile.h new file mode 100644 index 0000000000..a0de419102 --- /dev/null +++ b/src/openrct2/ParkFile.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +struct ObjectRepositoryItem; + +class ParkFileExporter +{ +public: + std::vector ExportObjectsList; + + void Export(std::string_view path); +}; diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 609a18cf54..e8d41e848b 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -280,6 +280,7 @@ + @@ -876,4 +877,4 @@ - + \ No newline at end of file diff --git a/src/openrct2/platform/Crash.cpp b/src/openrct2/platform/Crash.cpp index 90a92a7855..9410d1b509 100644 --- a/src/openrct2/platform/Crash.cpp +++ b/src/openrct2/platform/Crash.cpp @@ -27,6 +27,7 @@ # include "../Context.h" # include "../Game.h" # include "../OpenRCT2.h" +# include "../ParkFile.h" # include "../Version.h" # include "../config/Config.h" # include "../core/Console.hpp" @@ -35,7 +36,6 @@ # include "../interface/Screenshot.h" # include "../localisation/Language.h" # include "../object/ObjectManager.h" -# include "../rct2/S6Exporter.h" # include "../scenario/Scenario.h" # include "../util/SawyerCoding.h" # include "../util/Util.h" @@ -114,12 +114,10 @@ static bool OnCrash( wchar_t dumpFilePath[MAX_PATH]; wchar_t saveFilePath[MAX_PATH]; wchar_t configFilePath[MAX_PATH]; - wchar_t saveFilePathGZIP[MAX_PATH]; wchar_t recordFilePathNew[MAX_PATH]; swprintf_s(dumpFilePath, std::size(dumpFilePath), L"%s\\%s.dmp", dumpPath, miniDumpId); - swprintf_s(saveFilePath, std::size(saveFilePath), L"%s\\%s.sv6", dumpPath, miniDumpId); + swprintf_s(saveFilePath, std::size(saveFilePath), L"%s\\%s.park", dumpPath, miniDumpId); swprintf_s(configFilePath, std::size(configFilePath), L"%s\\%s.ini", dumpPath, miniDumpId); - swprintf_s(saveFilePathGZIP, std::size(saveFilePathGZIP), L"%s\\%s.sv6.gz", dumpPath, miniDumpId); swprintf_s(recordFilePathNew, std::size(recordFilePathNew), L"%s\\%s.sv6r", dumpPath, miniDumpId); wchar_t dumpFilePathNew[MAX_PATH]; @@ -172,7 +170,7 @@ static bool OnCrash( auto saveFilePathUTF8 = String::ToUtf8(saveFilePath); try { - auto exporter = std::make_unique(); + auto exporter = std::make_unique(); // Make sure the save is using the current viewport settings. viewport_set_saved_view(); @@ -185,8 +183,7 @@ static bool OnCrash( auto& objManager = ctx->GetObjectManager(); exporter->ExportObjectsList = objManager.GetPackableObjects(); - exporter->Export(); - exporter->SaveGame(saveFilePathUTF8.c_str()); + exporter->Export(saveFilePathUTF8.c_str()); savedGameDumped = true; } catch (const std::exception&) @@ -196,19 +193,7 @@ static bool OnCrash( // Compress the save if (savedGameDumped) { - FILE* input = _wfopen(saveFilePath, L"rb"); - FILE* dest = _wfopen(saveFilePathGZIP, L"wb"); - - if (util_gzip_compress(input, dest)) - { - uploadFiles[L"attachment_park.sv6.gz"] = saveFilePathGZIP; - } - else - { - uploadFiles[L"attachment_park.sv6"] = saveFilePath; - } - fclose(input); - fclose(dest); + uploadFiles[L"attachment_park.park"] = saveFilePath; } auto configFilePathUTF8 = String::ToUtf8(configFilePath); @@ -294,7 +279,6 @@ static bool OnCrash( if (savedGameDumped) { files[numFiles++] = ILCreateFromPathW(saveFilePath); - files[numFiles++] = ILCreateFromPathW(saveFilePathGZIP); } if (with_record) { @@ -336,7 +320,7 @@ CExceptionHandler crash_init() auto exHandler = new google_breakpad::ExceptionHandler( GetDumpDirectory(), 0, OnCrash, 0, google_breakpad::ExceptionHandler::HANDLER_ALL, MiniDumpWithDataSegs, PipeName, 0); return reinterpret_cast(exHandler); -#else // USE_BREAKPAD +#else // USE_BREAKPAD return nullptr; #endif // USE_BREAKPAD }