| 13 | static AppInfo _appInfo; |
| 14 | |
| 15 | [[maybe_unused]] static bool onCrash( |
| 16 | const wchar_t* dumpPath, const wchar_t* miniDumpId, |
| 17 | [[maybe_unused]] void* context, |
| 18 | [[maybe_unused]] EXCEPTION_POINTERS* exinfo, |
| 19 | [[maybe_unused]] MDRawAssertionInfo* assertion, |
| 20 | bool succeeded) |
| 21 | { |
| 22 | if (!succeeded) |
| 23 | { |
| 24 | constexpr const char* dumpFailedMessage = "Failed to create the dump. Please file an issue with OpenLoco on GitHub and " |
| 25 | "provide latest save, and provide " |
| 26 | "information about what you did before the crash occurred."; |
| 27 | printf("%s\n", dumpFailedMessage); |
| 28 | MessageBoxA(nullptr, dumpFailedMessage, "OpenLoco", MB_OK | MB_ICONERROR); |
| 29 | return succeeded; |
| 30 | } |
| 31 | wchar_t dumpFilePath[MAX_PATH]; |
| 32 | swprintf_s(dumpFilePath, std::size(dumpFilePath), L"%s\\%s.dmp", dumpPath, miniDumpId); |
| 33 | |
| 34 | std::wstring version = Utility::toUtf16(_appInfo.version); |
| 35 | |
| 36 | wchar_t dumpFilePathNew[MAX_PATH]; |
| 37 | swprintf_s( |
| 38 | dumpFilePathNew, std::size(dumpFilePathNew), L"%s\\%s(%s).dmp", dumpPath, miniDumpId, version.c_str()); |
| 39 | |
| 40 | // Try to rename the files |
| 41 | if (_wrename(dumpFilePath, dumpFilePathNew) == 0) |
| 42 | { |
| 43 | wcscpy_s(dumpFilePath, dumpFilePathNew); |
| 44 | } |
| 45 | |
| 46 | // Log information to output |
| 47 | wprintf(L"Dump Path: %s\n", dumpPath); |
| 48 | wprintf(L"Dump File Path: %s\n", dumpFilePath); |
| 49 | wprintf(L"Dump Id: %s\n", miniDumpId); |
| 50 | wprintf(L"Version: %s\n", version.c_str()); |
| 51 | |
| 52 | constexpr const wchar_t* MessageFormat = L"A crash has occurred and a dump was created at\n%s.\n\nPlease file an issue " |
| 53 | L"with %S on GitHub and provide " |
| 54 | L"the dump and most recently saved game there.\n\n\nVersion: %s\n\n"; |
| 55 | wchar_t message[MAX_PATH * 2]; |
| 56 | swprintf_s(message, MessageFormat, dumpFilePath, _appInfo.name.c_str(), version.c_str()); |
| 57 | MessageBoxW(nullptr, message, L"OpenLoco", MB_OK | MB_ICONERROR); |
| 58 | |
| 59 | HRESULT coInitializeResult = CoInitialize(nullptr); |
| 60 | if (SUCCEEDED(coInitializeResult)) |
| 61 | { |
| 62 | LPITEMIDLIST pidl = ILCreateFromPathW(dumpPath); |
| 63 | LPITEMIDLIST files[6]; |
| 64 | uint32_t numFiles = 0; |
| 65 | |
| 66 | files[numFiles++] = ILCreateFromPathW(dumpFilePath); |
| 67 | if (pidl != nullptr) |
| 68 | { |
| 69 | SHOpenFolderAndSelectItems(pidl, numFiles, (LPCITEMIDLIST*)files, 0); |
| 70 | ILFree(pidl); |
| 71 | for (uint32_t i = 0; i < numFiles; i++) |
| 72 | { |