fix mingw build

This commit is contained in:
2026-03-21 02:35:04 +03:00
parent f69c009da9
commit 011c8f7123
7 changed files with 51 additions and 37 deletions

View File

@@ -28,7 +28,8 @@ if (${PLATFORM} STREQUAL "Desktop")
if (WIN32) if (WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_WARNINGS)
set(EXTRA_LIBS ws2_32) include_directories(misc/windows)
set(EXTRA_LIBS ws2_32 winhttp)
elseif(UNIX) elseif(UNIX)
find_library(pthread NAMES pthread) find_library(pthread NAMES pthread)
set(EXTRA_LIBS pthread m) set(EXTRA_LIBS pthread m)

2
misc/windows/WinSock2.h Normal file
View File

@@ -0,0 +1,2 @@
// For mingw, cuz on linux it case-sensitive
#include <winsock2.h>

2
misc/windows/Ws2tcpip.h Normal file
View File

@@ -0,0 +1,2 @@
// For mingw, cuz on linux it case-sensitive
#include <ws2tcpip.h>

View File

@@ -109,7 +109,7 @@ public:
virtual bool supportsTouchscreen() override { return true; } 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; int isHide = hide ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN;
glfwSetInputMode(window, GLFW_CURSOR, isHide); glfwSetInputMode(window, GLFW_CURSOR, isHide);
} }

View File

@@ -4,10 +4,11 @@
#include <errno.h> #include <errno.h>
#include <platform/log.h> #include <platform/log.h>
#if !defined(_WIN32) #if defined(_WIN32)
#include <sys/stat.h> #include <direct.h>
#include <sys/types.h> #else
#include <unistd.h> #include <sys/stat.h>
#include <sys/types.h>
#endif #endif
OptionsFile::OptionsFile() { OptionsFile::OptionsFile() {
@@ -27,39 +28,44 @@ void OptionsFile::setOptionsPath(const std::string& path) {
std::string OptionsFile::getOptionsPath() const { std::string OptionsFile::getOptionsPath() const {
return settingsPath; return settingsPath;
} }
void OptionsFile::save(const StringVector& settings) { void OptionsFile::save(const StringVector& settings) {
FILE* pFile = fopen(settingsPath.c_str(), "w"); 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));
// Ensure parent directory exists for safekeeping if path contains directories if (!pFile && errno == ENOENT) {
std::string dir = settingsPath; std::string dir = settingsPath;
size_t fpos = dir.find_last_of("/\\"); size_t fpos = dir.find_last_of("/\\");
if (fpos != std::string::npos) { if (fpos != std::string::npos) {
dir.resize(fpos); dir.resize(fpos);
struct stat st;
if (stat(dir.c_str(), &st) != 0) { std::string toCreate;
// attempt recursive mkdir for (size_t i = 0; i <= dir.size(); ++i) {
std::string toCreate; if (i == dir.size() || dir[i] == '/' || dir[i] == '\\') {
for (size_t i = 0; i <= dir.size(); ++i) { if (!toCreate.empty()) {
if (i == dir.size() || dir[i] == '/' || dir[i] == '\\') { #if defined(_WIN32)
if (!toCreate.empty()) { _mkdir(toCreate.c_str());
mkdir(toCreate.c_str(), 0755); #else
} mkdir(toCreate.c_str(), 0755);
} #endif
if (i < dir.size()) }
toCreate.push_back(dir[i]); }
} 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);
} }

View File

@@ -28,6 +28,7 @@
#if defined(_WIN32) #if defined(_WIN32)
#include <direct.h> #include <direct.h>
#include <sys/stat.h>
#else #else
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>

View File

@@ -140,7 +140,9 @@ RakNet::TimeUS GetTimeUS_Windows( void )
#if _MSC_VER >= 1400 && defined (_M_X64) #if _MSC_VER >= 1400 && defined (_M_X64)
GetProcessAffinityMask(mProc, (PDWORD_PTR)&mProcMask, (PDWORD_PTR)&mSysMask); GetProcessAffinityMask(mProc, (PDWORD_PTR)&mProcMask, (PDWORD_PTR)&mSysMask);
#else #else
#ifndef __MINGW32__
GetProcessAffinityMask(mProc, &mProcMask, &mSysMask); GetProcessAffinityMask(mProc, &mProcMask, &mSysMask);
#endif
#endif #endif
mThread = GetCurrentThread(); mThread = GetCurrentThread();