mirror of
https://github.com/alexbatalov/fallout1-ce.git
synced 2024-10-04 13:49:51 +00:00
parent
1fa0c5327a
commit
ba06955de0
@ -12,6 +12,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#else
|
#else
|
||||||
|
#include <dirent.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
@ -219,6 +220,7 @@ int compat_mkdir(const char* path)
|
|||||||
char nativePath[COMPAT_MAX_PATH];
|
char nativePath[COMPAT_MAX_PATH];
|
||||||
strcpy(nativePath, path);
|
strcpy(nativePath, path);
|
||||||
compat_windows_path_to_native(nativePath);
|
compat_windows_path_to_native(nativePath);
|
||||||
|
compat_resolve_path(nativePath);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return mkdir(nativePath);
|
return mkdir(nativePath);
|
||||||
@ -243,6 +245,7 @@ FILE* compat_fopen(const char* path, const char* mode)
|
|||||||
char nativePath[COMPAT_MAX_PATH];
|
char nativePath[COMPAT_MAX_PATH];
|
||||||
strcpy(nativePath, path);
|
strcpy(nativePath, path);
|
||||||
compat_windows_path_to_native(nativePath);
|
compat_windows_path_to_native(nativePath);
|
||||||
|
compat_resolve_path(nativePath);
|
||||||
return fopen(nativePath, mode);
|
return fopen(nativePath, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,6 +254,7 @@ int compat_remove(const char* path)
|
|||||||
char nativePath[COMPAT_MAX_PATH];
|
char nativePath[COMPAT_MAX_PATH];
|
||||||
strcpy(nativePath, path);
|
strcpy(nativePath, path);
|
||||||
compat_windows_path_to_native(nativePath);
|
compat_windows_path_to_native(nativePath);
|
||||||
|
compat_resolve_path(nativePath);
|
||||||
return remove(nativePath);
|
return remove(nativePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,10 +263,12 @@ int compat_rename(const char* oldFileName, const char* newFileName)
|
|||||||
char nativeOldFileName[COMPAT_MAX_PATH];
|
char nativeOldFileName[COMPAT_MAX_PATH];
|
||||||
strcpy(nativeOldFileName, oldFileName);
|
strcpy(nativeOldFileName, oldFileName);
|
||||||
compat_windows_path_to_native(nativeOldFileName);
|
compat_windows_path_to_native(nativeOldFileName);
|
||||||
|
compat_resolve_path(nativeOldFileName);
|
||||||
|
|
||||||
char nativeNewFileName[COMPAT_MAX_PATH];
|
char nativeNewFileName[COMPAT_MAX_PATH];
|
||||||
strcpy(nativeNewFileName, newFileName);
|
strcpy(nativeNewFileName, newFileName);
|
||||||
compat_windows_path_to_native(nativeNewFileName);
|
compat_windows_path_to_native(nativeNewFileName);
|
||||||
|
compat_resolve_path(nativeNewFileName);
|
||||||
|
|
||||||
return rename(nativeOldFileName, nativeNewFileName);
|
return rename(nativeOldFileName, nativeNewFileName);
|
||||||
}
|
}
|
||||||
@ -280,6 +286,60 @@ void compat_windows_path_to_native(char* path)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void compat_resolve_path(char* path)
|
||||||
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
|
char* pch = path;
|
||||||
|
|
||||||
|
DIR *dir;
|
||||||
|
if (pch[0] == '/') {
|
||||||
|
dir = opendir("/");
|
||||||
|
pch++;
|
||||||
|
} else {
|
||||||
|
dir = opendir(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
while (dir != NULL) {
|
||||||
|
char* sep = strchr(pch, '/');
|
||||||
|
size_t length;
|
||||||
|
if (sep != NULL) {
|
||||||
|
length = sep - pch;
|
||||||
|
} else {
|
||||||
|
length = strlen(pch);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
struct dirent* entry = readdir(dir);
|
||||||
|
while (entry != NULL) {
|
||||||
|
if (strlen(entry->d_name) == length && compat_strnicmp(pch, entry->d_name, length) == 0) {
|
||||||
|
strncpy(pch, entry->d_name, length);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
entry = readdir(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
dir = NULL;
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sep == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
*sep = '\0';
|
||||||
|
dir = opendir(path);
|
||||||
|
*sep = '/';
|
||||||
|
|
||||||
|
pch = sep + 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
char* compat_strdup(const char* string)
|
char* compat_strdup(const char* string)
|
||||||
{
|
{
|
||||||
return SDL_strdup(string);
|
return SDL_strdup(string);
|
||||||
|
@ -38,6 +38,7 @@ FILE* compat_fopen(const char* path, const char* mode);
|
|||||||
int compat_remove(const char* path);
|
int compat_remove(const char* path);
|
||||||
int compat_rename(const char* oldFileName, const char* newFileName);
|
int compat_rename(const char* oldFileName, const char* newFileName);
|
||||||
void compat_windows_path_to_native(char* path);
|
void compat_windows_path_to_native(char* path);
|
||||||
|
void compat_resolve_path(char* path);
|
||||||
char* compat_strdup(const char* string);
|
char* compat_strdup(const char* string);
|
||||||
long getFileSize(FILE* stream);
|
long getFileSize(FILE* stream);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user