mirror of
https://github.com/fallout2-ce/fallout2-ce.git
synced 2026-07-27 16:47:11 -07:00
Compare commits
19
Commits
main
...
platform_compat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a4469cc57 | ||
|
|
8bf7064a08 | ||
|
|
dfea73105c | ||
|
|
dd604b22b6 | ||
|
|
e1426a40c6 | ||
|
|
ae6c7aba6e | ||
|
|
e5387bef63 | ||
|
|
76080a4878 | ||
|
|
12314cd5d7 | ||
|
|
a0e1b73116 | ||
|
|
23c38f60f1 | ||
|
|
0c1ecfc3ac | ||
|
|
45676bcc05 | ||
|
|
46152f7e86 | ||
|
|
b6d1a29411 | ||
|
|
6bbd1a48cc | ||
|
|
3b7e1d8916 | ||
|
|
1f05d0b690 | ||
|
|
444565e8a1 |
@@ -142,7 +142,7 @@ jobs:
|
||||
ios:
|
||||
name: iOS
|
||||
|
||||
runs-on: macos-14
|
||||
runs-on: macos-15
|
||||
needs: [ce-dat]
|
||||
|
||||
steps:
|
||||
@@ -328,7 +328,7 @@ jobs:
|
||||
macos:
|
||||
name: macOS
|
||||
|
||||
runs-on: macos-14
|
||||
runs-on: macos-15
|
||||
|
||||
steps:
|
||||
- name: Clone
|
||||
|
||||
+2
-2
@@ -6,10 +6,10 @@ set(EXECUTABLE_NAME fallout2-ce)
|
||||
|
||||
if(APPLE)
|
||||
if(IOS)
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "12" CACHE STRING "")
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "13" CACHE STRING "")
|
||||
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "")
|
||||
else()
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "")
|
||||
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -89,6 +89,7 @@ def assertSdlJavaBindingsMatch = { String variantName ->
|
||||
|
||||
android {
|
||||
compileSdk 32
|
||||
ndkVersion "27.3.13750724"
|
||||
|
||||
defaultConfig {
|
||||
applicationId 'com.alexbatalov.fallout2ce'
|
||||
|
||||
+40
-189
@@ -1,6 +1,5 @@
|
||||
#include "platform_compat.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <filesystem>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
@@ -14,17 +13,6 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#ifdef _WIN64
|
||||
#include <timeapi.h>
|
||||
#else
|
||||
#include <mmsystem.h>
|
||||
#endif
|
||||
#else
|
||||
#include <chrono>
|
||||
#endif
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
namespace fallout {
|
||||
@@ -69,138 +57,46 @@ char* compat_itoa(int value, char* buffer, int radix)
|
||||
|
||||
void compat_splitpath(const char* path, char* drive, char* dir, char* fname, char* ext)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
_splitpath(path, drive, dir, fname, ext);
|
||||
#else
|
||||
const char* driveStart = path;
|
||||
const char* pathAfterDrive = path;
|
||||
if (pathAfterDrive[0] != '\0'
|
||||
&& pathAfterDrive[1] != '\0'
|
||||
&& compatIsPathSeparator(pathAfterDrive[0])
|
||||
&& compatIsPathSeparator(pathAfterDrive[1])) {
|
||||
pathAfterDrive += 2;
|
||||
while (*pathAfterDrive != '\0' && !compatIsPathSeparator(*pathAfterDrive) && *pathAfterDrive != '.') {
|
||||
pathAfterDrive++;
|
||||
}
|
||||
}
|
||||
std::filesystem::path fsPath(path);
|
||||
|
||||
if (drive != nullptr) {
|
||||
size_t driveSize = pathAfterDrive - driveStart;
|
||||
if (driveSize > COMPAT_MAX_DRIVE - 1) {
|
||||
driveSize = COMPAT_MAX_DRIVE - 1;
|
||||
}
|
||||
strncpy(drive, driveStart, driveSize);
|
||||
drive[driveSize] = '\0';
|
||||
}
|
||||
|
||||
const char* fnameStart = pathAfterDrive;
|
||||
for (const char* pch = pathAfterDrive; *pch != '\0'; pch++) {
|
||||
if (compatIsPathSeparator(*pch)) {
|
||||
fnameStart = pch + 1;
|
||||
}
|
||||
}
|
||||
|
||||
const char* end = pathAfterDrive + strlen(pathAfterDrive);
|
||||
const char* extStart = end;
|
||||
for (const char* pch = end; pch != fnameStart; pch--) {
|
||||
if (pch[-1] == '.') {
|
||||
extStart = pch - 1;
|
||||
break;
|
||||
}
|
||||
strncpy(drive, fsPath.root_name().string().c_str(), COMPAT_MAX_DRIVE - 1);
|
||||
}
|
||||
|
||||
if (dir != nullptr) {
|
||||
size_t dirSize = fnameStart - pathAfterDrive;
|
||||
if (dirSize > COMPAT_MAX_DIR - 1) {
|
||||
dirSize = COMPAT_MAX_DIR - 1;
|
||||
}
|
||||
strncpy(dir, pathAfterDrive, dirSize);
|
||||
dir[dirSize] = '\0';
|
||||
strncpy(dir, fsPath.parent_path().string().c_str(), COMPAT_MAX_DIR - 1);
|
||||
}
|
||||
|
||||
if (fname != nullptr) {
|
||||
size_t fileNameSize = extStart - fnameStart;
|
||||
if (fileNameSize > COMPAT_MAX_FNAME - 1) {
|
||||
fileNameSize = COMPAT_MAX_FNAME - 1;
|
||||
}
|
||||
strncpy(fname, fnameStart, fileNameSize);
|
||||
fname[fileNameSize] = '\0';
|
||||
strncpy(fname, fsPath.stem().string().c_str(), COMPAT_MAX_FNAME - 1);
|
||||
}
|
||||
|
||||
if (ext != nullptr) {
|
||||
size_t extSize = end - extStart;
|
||||
if (extSize > COMPAT_MAX_EXT - 1) {
|
||||
extSize = COMPAT_MAX_EXT - 1;
|
||||
}
|
||||
strncpy(ext, extStart, extSize);
|
||||
ext[extSize] = '\0';
|
||||
strncpy(ext, fsPath.extension().string().c_str(), COMPAT_MAX_EXT - 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void compat_makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
_makepath(path, drive, dir, fname, ext);
|
||||
#else
|
||||
path[0] = '\0';
|
||||
std::filesystem::path fsPath;
|
||||
|
||||
if (drive != nullptr) {
|
||||
if (*drive != '\0') {
|
||||
strcpy(path, drive);
|
||||
path = strchr(path, '\0');
|
||||
|
||||
if (compatIsPathSeparator(path[-1])) {
|
||||
path--;
|
||||
} else {
|
||||
*path = '/';
|
||||
}
|
||||
}
|
||||
if (drive != nullptr && *drive != '\0') {
|
||||
fsPath /= drive;
|
||||
}
|
||||
|
||||
if (dir != nullptr) {
|
||||
if (*dir != '\0') {
|
||||
if (!compatIsPathSeparator(*dir) && compatIsPathSeparator(*path)) {
|
||||
path++;
|
||||
}
|
||||
|
||||
strcpy(path, dir);
|
||||
path = strchr(path, '\0');
|
||||
|
||||
if (compatIsPathSeparator(path[-1])) {
|
||||
path--;
|
||||
} else {
|
||||
*path = '/';
|
||||
}
|
||||
}
|
||||
if (dir != nullptr && *dir != '\0') {
|
||||
fsPath /= dir;
|
||||
}
|
||||
|
||||
if (fname != nullptr && *fname != '\0') {
|
||||
if (!compatIsPathSeparator(*fname) && compatIsPathSeparator(*path)) {
|
||||
path++;
|
||||
}
|
||||
|
||||
strcpy(path, fname);
|
||||
path = strchr(path, '\0');
|
||||
} else {
|
||||
if (compatIsPathSeparator(*path)) {
|
||||
path++;
|
||||
}
|
||||
fsPath /= fname;
|
||||
}
|
||||
|
||||
if (ext != nullptr) {
|
||||
if (*ext != '\0') {
|
||||
if (*ext != '.') {
|
||||
*path++ = '.';
|
||||
}
|
||||
|
||||
strcpy(path, ext);
|
||||
path = strchr(path, '\0');
|
||||
}
|
||||
if (ext != nullptr && *ext != '\0') {
|
||||
fsPath += ext;
|
||||
}
|
||||
|
||||
*path = '\0';
|
||||
#endif
|
||||
strncpy(path, fsPath.string().c_str(), COMPAT_MAX_PATH - 1);
|
||||
}
|
||||
|
||||
long compat_tell(int fd)
|
||||
@@ -208,100 +104,48 @@ long compat_tell(int fd)
|
||||
return lseek(fd, 0, SEEK_CUR);
|
||||
}
|
||||
|
||||
long compat_filelength(int fd)
|
||||
long compat_filelength(const char* path)
|
||||
{
|
||||
long originalOffset = lseek(fd, 0, SEEK_CUR);
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
long filesize = lseek(fd, 0, SEEK_END);
|
||||
lseek(fd, originalOffset, SEEK_SET);
|
||||
return filesize;
|
||||
char nativePath[COMPAT_MAX_PATH];
|
||||
compat_prepare_native_path(nativePath, path);
|
||||
return std::filesystem::file_size(nativePath);
|
||||
}
|
||||
|
||||
int compat_mkdir(const char* path)
|
||||
{
|
||||
std::error_code ec;
|
||||
char nativePath[COMPAT_MAX_PATH];
|
||||
compat_prepare_native_path(nativePath, path);
|
||||
|
||||
#ifdef _WIN32
|
||||
return mkdir(nativePath);
|
||||
#else
|
||||
return mkdir(nativePath, 0755);
|
||||
#endif
|
||||
std::filesystem::create_directory(nativePath, ec);
|
||||
return ec.value();
|
||||
}
|
||||
|
||||
int compat_mkdir_recursive(const char* path)
|
||||
{
|
||||
char drive[COMPAT_MAX_DRIVE];
|
||||
compat_splitpath(path, drive, nullptr, nullptr, nullptr);
|
||||
|
||||
char pathCopy[COMPAT_MAX_PATH];
|
||||
strcpy(pathCopy, path);
|
||||
|
||||
// Skip drive root (e.g. "C:\\" or leading "/") to avoid mkdir("") or mkdir("C:").
|
||||
char* sep = pathCopy + strlen(drive);
|
||||
if (*sep == '\\' || *sep == '/') sep++;
|
||||
for (; *sep != '\0'; sep++) {
|
||||
if (*sep == '\\' || *sep == '/') {
|
||||
char saved = *sep;
|
||||
*sep = '\0';
|
||||
if (compat_mkdir(pathCopy) < 0) {
|
||||
break;
|
||||
}
|
||||
*sep = saved;
|
||||
}
|
||||
}
|
||||
return compat_mkdir(path);
|
||||
std::error_code ec;
|
||||
char nativePath[COMPAT_MAX_PATH];
|
||||
compat_prepare_native_path(nativePath, path);
|
||||
std::filesystem::create_directories(nativePath, ec);
|
||||
return ec.value();
|
||||
}
|
||||
|
||||
bool compat_is_dir(const char* path)
|
||||
{
|
||||
char nativePath[COMPAT_MAX_PATH];
|
||||
compat_prepare_native_path(nativePath, path);
|
||||
|
||||
#ifdef _WIN32
|
||||
struct _stat info;
|
||||
if (_stat(nativePath, &info) != 0) {
|
||||
return false;
|
||||
}
|
||||
return (info.st_mode & _S_IFDIR) != 0;
|
||||
#else
|
||||
struct stat info;
|
||||
if (stat(nativePath, &info) != 0) {
|
||||
return false;
|
||||
}
|
||||
return S_ISDIR(info.st_mode);
|
||||
#endif
|
||||
return std::filesystem::is_directory(nativePath);
|
||||
}
|
||||
|
||||
bool compat_file_exists(const char* filePath)
|
||||
{
|
||||
char nativePath[COMPAT_MAX_PATH];
|
||||
compat_prepare_native_path(nativePath, filePath);
|
||||
|
||||
#ifdef _WIN32
|
||||
struct _stat info;
|
||||
if (_stat(nativePath, &info) != 0) {
|
||||
return false;
|
||||
}
|
||||
return (info.st_mode & _S_IFDIR) == 0;
|
||||
#else
|
||||
struct stat info;
|
||||
if (stat(nativePath, &info) != 0) {
|
||||
return false;
|
||||
}
|
||||
return !S_ISDIR(info.st_mode);
|
||||
#endif
|
||||
return std::filesystem::exists(nativePath);
|
||||
}
|
||||
|
||||
unsigned int compat_timeGetTime()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return timeGetTime();
|
||||
#else
|
||||
static auto start = std::chrono::steady_clock::now();
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
return static_cast<unsigned int>(std::chrono::duration_cast<std::chrono::milliseconds>(now - start).count());
|
||||
#endif
|
||||
return SDL_GetTicks64();
|
||||
}
|
||||
|
||||
FILE* compat_fopen(const char* path, const char* mode)
|
||||
@@ -350,20 +194,25 @@ char* compat_gzgets(gzFile stream, char* buffer, int maxCount)
|
||||
|
||||
int compat_remove(const char* path)
|
||||
{
|
||||
std::error_code err;
|
||||
char nativePath[COMPAT_MAX_PATH];
|
||||
compat_prepare_native_path(nativePath, path);
|
||||
return remove(nativePath);
|
||||
std::filesystem::remove(nativePath, err);
|
||||
return err.value();
|
||||
}
|
||||
|
||||
int compat_rename(const char* oldFileName, const char* newFileName)
|
||||
{
|
||||
std::error_code err;
|
||||
|
||||
char nativeOldFileName[COMPAT_MAX_PATH];
|
||||
compat_prepare_native_path(nativeOldFileName, oldFileName);
|
||||
|
||||
char nativeNewFileName[COMPAT_MAX_PATH];
|
||||
compat_prepare_native_path(nativeNewFileName, newFileName);
|
||||
|
||||
return rename(nativeOldFileName, nativeNewFileName);
|
||||
std::filesystem::rename(nativeOldFileName, nativeNewFileName, err);
|
||||
return err.value();
|
||||
}
|
||||
|
||||
void compat_windows_path_to_native(char* path)
|
||||
@@ -446,7 +295,9 @@ int compat_access(const char* path, int mode)
|
||||
{
|
||||
char nativePath[COMPAT_MAX_PATH];
|
||||
compat_prepare_native_path(nativePath, path);
|
||||
return access(nativePath, mode);
|
||||
std::filesystem::perms targetPrms = static_cast<std::filesystem::perms>(mode);
|
||||
std::filesystem::perms fsPrms = std::filesystem::status(nativePath).permissions();
|
||||
return targetPrms == fsPrms;
|
||||
}
|
||||
|
||||
char* compat_strdup(const char* string)
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#ifndef PLATFORM_COMPAT_H
|
||||
#define PLATFORM_COMPAT_H
|
||||
|
||||
#include <errno.h>
|
||||
#include <filesystem>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
@@ -30,7 +33,7 @@ char* compat_itoa(int value, char* buffer, int radix);
|
||||
void compat_splitpath(const char* path, char* drive, char* dir, char* fname, char* ext);
|
||||
void compat_makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext);
|
||||
long compat_tell(int fileHandle);
|
||||
long compat_filelength(int fd);
|
||||
long compat_filelength(const char* path);
|
||||
int compat_mkdir(const char* path);
|
||||
int compat_mkdir_recursive(const char* path);
|
||||
bool compat_is_dir(const char* path);
|
||||
|
||||
Reference in New Issue
Block a user