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)
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)

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 void hideCursor(bool hide) {
virtual void hideCursor(bool hide) override {
int isHide = hide ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN;
glfwSetInputMode(window, GLFW_CURSOR, isHide);
}

View File

@@ -4,10 +4,11 @@
#include <errno.h>
#include <platform/log.h>
#if !defined(_WIN32)
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#if defined(_WIN32)
#include <direct.h>
#else
#include <sys/stat.h>
#include <sys/types.h>
#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));
// Ensure parent directory exists for safekeeping if path contains directories
if (!pFile && errno == ENOENT) {
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()) {
#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);
}

View File

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

View File

@@ -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();