From 945fd317353cd5816371b7eb95032603aa1dffea Mon Sep 17 00:00:00 2001 From: shweet Date: Mon, 12 Jan 2026 23:12:04 -0500 Subject: [PATCH] remove windows debug code (for now...) --- src/loader.cpp | 144 ++++++++++--------------------------------------- 1 file changed, 29 insertions(+), 115 deletions(-) diff --git a/src/loader.cpp b/src/loader.cpp index 8b20857..3198a95 100644 --- a/src/loader.cpp +++ b/src/loader.cpp @@ -9,13 +9,6 @@ #include -#ifdef _WIN32 - #include "util/path_.h" - #include - #include - #include -#endif - #include "log.h" #include "sdl.h" @@ -44,117 +37,42 @@ namespace anm2ed constexpr int SOCKET_ERROR_ADDRESS_IN_USE = EADDRINUSE; #endif - namespace + bool socket_paths_send(Socket& socket, const std::vector& paths) { -#ifdef _WIN32 - std::filesystem::path g_minidump_dir{}; - PVOID g_vectored_handler{}; - LONG g_dump_in_progress{}; + uint32_t count = htonl(static_cast(paths.size())); + if (!socket.send(&count, sizeof(count))) return false; - void windows_minidump_write(EXCEPTION_POINTERS* exceptionPointers) + for (const auto& path : paths) { - if (g_minidump_dir.empty()) return; - if (InterlockedExchange(&g_dump_in_progress, 1) != 0) return; - - SYSTEMTIME st{}; - GetLocalTime(&st); - - auto pid = GetCurrentProcessId(); - auto code = exceptionPointers && exceptionPointers->ExceptionRecord - ? exceptionPointers->ExceptionRecord->ExceptionCode - : 0u; - - auto filename = std::format("anm2ed_{:04}{:02}{:02}_{:02}{:02}{:02}_pid{:08x}_code{:08x}.dmp", st.wYear, - st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, pid, code); - auto dumpPath = g_minidump_dir / path::from_utf8(filename); - - auto dumpPathW = dumpPath.wstring(); - HANDLE file = CreateFileW(dumpPathW.c_str(), GENERIC_WRITE, FILE_SHARE_READ, nullptr, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, nullptr); - if (file == INVALID_HANDLE_VALUE) return; - - MINIDUMP_EXCEPTION_INFORMATION mei{}; - mei.ThreadId = GetCurrentThreadId(); - mei.ExceptionPointers = exceptionPointers; - mei.ClientPointers = FALSE; - - const MINIDUMP_TYPE dumpType = - static_cast(MiniDumpNormal | MiniDumpWithIndirectlyReferencedMemory | MiniDumpWithThreadInfo | - MiniDumpWithUnloadedModules); - MiniDumpWriteDump(GetCurrentProcess(), pid, file, dumpType, exceptionPointers ? &mei : nullptr, nullptr, nullptr); - - FlushFileBuffers(file); - CloseHandle(file); + uint32_t length = htonl(static_cast(path.size())); + if (!socket.send(&length, sizeof(length))) return false; + if (!path.empty() && !socket.send(path.data(), path.size())) return false; } - LONG WINAPI windows_unhandled_exception_filter(EXCEPTION_POINTERS* exceptionPointers) + return true; + } + + std::vector socket_paths_receive(Socket& socket) + { + uint32_t count{}; + if (!socket.receive(&count, sizeof(count))) return {}; + count = ntohl(count); + + std::vector paths; + paths.reserve(count); + + for (uint32_t i = 0; i < count; ++i) { - windows_minidump_write(exceptionPointers); - return EXCEPTION_EXECUTE_HANDLER; + uint32_t length{}; + if (!socket.receive(&length, sizeof(length))) return {}; + length = ntohl(length); + + std::string path(length, '\0'); + if (length > 0 && !socket.receive(path.data(), length)) return {}; + paths.emplace_back(std::move(path)); } - LONG CALLBACK windows_vectored_exception_handler(EXCEPTION_POINTERS* exceptionPointers) - { - windows_minidump_write(exceptionPointers); - return EXCEPTION_CONTINUE_SEARCH; - } - - void windows_minidumps_configure() - { - auto prefDir = sdl::preferences_directory_get(); - if (prefDir.empty()) return; - - std::error_code ec{}; - auto dumpDir = prefDir / "crash"; - std::filesystem::create_directories(dumpDir, ec); - if (ec) return; - - g_minidump_dir = dumpDir; - - if (!g_vectored_handler) g_vectored_handler = AddVectoredExceptionHandler(1, windows_vectored_exception_handler); - SetUnhandledExceptionFilter(windows_unhandled_exception_filter); - - logger.info(std::format("MiniDumpWriteDump enabled: {}", path::to_utf8(dumpDir))); - } -#endif - - bool socket_paths_send(Socket& socket, const std::vector& paths) - { - uint32_t count = htonl(static_cast(paths.size())); - if (!socket.send(&count, sizeof(count))) return false; - - for (const auto& path : paths) - { - uint32_t length = htonl(static_cast(path.size())); - if (!socket.send(&length, sizeof(length))) return false; - if (!path.empty() && !socket.send(path.data(), path.size())) return false; - } - - return true; - } - - std::vector socket_paths_receive(Socket& socket) - { - uint32_t count{}; - if (!socket.receive(&count, sizeof(count))) return {}; - count = ntohl(count); - - std::vector paths; - paths.reserve(count); - - for (uint32_t i = 0; i < count; ++i) - { - uint32_t length{}; - if (!socket.receive(&length, sizeof(length))) return {}; - length = ntohl(length); - - std::string path(length, '\0'); - if (length > 0 && !socket.receive(path.data(), length)) return {}; - paths.emplace_back(std::move(path)); - } - - return paths; - } + return paths; } std::filesystem::path Loader::settings_path() { return sdl::preferences_directory_get() / "settings.ini"; } @@ -217,10 +135,6 @@ namespace anm2ed logger.info("Initialized SDL"); -#ifdef _WIN32 - windows_minidumps_configure(); -#endif - auto windowProperties = SDL_CreateProperties(); if (windowProperties == 0) @@ -398,4 +312,4 @@ namespace anm2ed SDL_Quit(); } } -} +} \ No newline at end of file