From 011c8f712363c48605dd34a18ef898345329d532 Mon Sep 17 00:00:00 2001 From: Kolyah35 Date: Sat, 21 Mar 2026 02:35:04 +0300 Subject: [PATCH] fix mingw build --- CMakeLists.txt | 3 +- misc/windows/WinSock2.h | 2 + misc/windows/Ws2tcpip.h | 2 + src/AppPlatform_glfw.h | 2 +- src/client/OptionsFile.cpp | 76 +++++++++++++++++-------------- src/client/player/LocalPlayer.cpp | 1 + src/raknet/GetTime.cpp | 2 + 7 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 misc/windows/WinSock2.h create mode 100644 misc/windows/Ws2tcpip.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f0c0f03..cdf558a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,8 @@ if (${PLATFORM} STREQUAL "Desktop") if (WIN32) add_definitions(-D_CRT_SECURE_NO_WARNINGS) - set(EXTRA_LIBS ws2_32) + include_directories(misc/windows) + set(EXTRA_LIBS ws2_32 winhttp) elseif(UNIX) find_library(pthread NAMES pthread) set(EXTRA_LIBS pthread m) diff --git a/misc/windows/WinSock2.h b/misc/windows/WinSock2.h new file mode 100644 index 0000000..46c802c --- /dev/null +++ b/misc/windows/WinSock2.h @@ -0,0 +1,2 @@ +// For mingw, cuz on linux it case-sensitive +#include \ No newline at end of file diff --git a/misc/windows/Ws2tcpip.h b/misc/windows/Ws2tcpip.h new file mode 100644 index 0000000..feed9e3 --- /dev/null +++ b/misc/windows/Ws2tcpip.h @@ -0,0 +1,2 @@ +// For mingw, cuz on linux it case-sensitive +#include \ No newline at end of file diff --git a/src/AppPlatform_glfw.h b/src/AppPlatform_glfw.h index 4b298c0..0e2e505 100755 --- a/src/AppPlatform_glfw.h +++ b/src/AppPlatform_glfw.h @@ -109,7 +109,7 @@ public: virtual bool supportsTouchscreen() override { return true; } - virtual void hideCursor(bool hide) { + virtual void hideCursor(bool hide) override { int isHide = hide ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN; glfwSetInputMode(window, GLFW_CURSOR, isHide); } diff --git a/src/client/OptionsFile.cpp b/src/client/OptionsFile.cpp index feb2fdf..4601429 100755 --- a/src/client/OptionsFile.cpp +++ b/src/client/OptionsFile.cpp @@ -4,10 +4,11 @@ #include #include -#if !defined(_WIN32) -#include -#include -#include +#if defined(_WIN32) + #include +#else + #include + #include #endif OptionsFile::OptionsFile() { @@ -27,39 +28,44 @@ void OptionsFile::setOptionsPath(const std::string& path) { std::string OptionsFile::getOptionsPath() const { return settingsPath; } - void OptionsFile::save(const StringVector& settings) { - FILE* pFile = fopen(settingsPath.c_str(), "w"); - if(pFile != NULL) { - for(StringVector::const_iterator it = settings.begin(); it != settings.end(); ++it) { - fprintf(pFile, "%s\n", it->c_str()); - } - fclose(pFile); - } else { - if (errno != ENOENT) - LOGI("OptionsFile::save failed to open '%s' for writing: %s", settingsPath.c_str(), strerror(errno)); + FILE* pFile = fopen(settingsPath.c_str(), "w"); - // Ensure parent directory exists for safekeeping if path contains directories - std::string dir = settingsPath; - size_t fpos = dir.find_last_of("/\\"); - if (fpos != std::string::npos) { - dir.resize(fpos); - struct stat st; - if (stat(dir.c_str(), &st) != 0) { - // attempt recursive mkdir - std::string toCreate; - for (size_t i = 0; i <= dir.size(); ++i) { - if (i == dir.size() || dir[i] == '/' || dir[i] == '\\') { - if (!toCreate.empty()) { - mkdir(toCreate.c_str(), 0755); - } - } - if (i < dir.size()) - toCreate.push_back(dir[i]); - } - } - } - } + if (!pFile && errno == ENOENT) { + std::string dir = settingsPath; + size_t fpos = dir.find_last_of("/\\"); + if (fpos != std::string::npos) { + dir.resize(fpos); + + std::string toCreate; + for (size_t i = 0; i <= dir.size(); ++i) { + if (i == dir.size() || dir[i] == '/' || dir[i] == '\\') { + if (!toCreate.empty()) { +#if defined(_WIN32) + _mkdir(toCreate.c_str()); +#else + mkdir(toCreate.c_str(), 0755); +#endif + } + } + if (i < dir.size()) + toCreate.push_back(dir[i]); + } + } + + pFile = fopen(settingsPath.c_str(), "w"); + } + + if (!pFile) { + LOGI("OptionsFile::save failed: %s", strerror(errno)); + return; + } + + for (const auto& s : settings) { + fprintf(pFile, "%s\n", s.c_str()); + } + + fclose(pFile); } diff --git a/src/client/player/LocalPlayer.cpp b/src/client/player/LocalPlayer.cpp index b4d57ef..1113468 100755 --- a/src/client/player/LocalPlayer.cpp +++ b/src/client/player/LocalPlayer.cpp @@ -28,6 +28,7 @@ #if defined(_WIN32) #include +#include #else #include #include diff --git a/src/raknet/GetTime.cpp b/src/raknet/GetTime.cpp index 4f868f8..ce7451c 100755 --- a/src/raknet/GetTime.cpp +++ b/src/raknet/GetTime.cpp @@ -140,7 +140,9 @@ RakNet::TimeUS GetTimeUS_Windows( void ) #if _MSC_VER >= 1400 && defined (_M_X64) GetProcessAffinityMask(mProc, (PDWORD_PTR)&mProcMask, (PDWORD_PTR)&mSysMask); #else +#ifndef __MINGW32__ GetProcessAffinityMask(mProc, &mProcMask, &mSysMask); +#endif #endif mThread = GetCurrentThread();