1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-09 22:56:53 +02:00

Linux case-insensitive for file names

This commit is contained in:
XProger
2023-03-01 06:18:26 +03:00
parent 6033a1ffe1
commit 329b459137
3 changed files with 169 additions and 93 deletions

View File

@@ -1081,21 +1081,8 @@ namespace TR {
break;
case VER_TR1_PSX : sprintf(dst, "PSXDATA/%s.PSX", LEVEL_INFO[id].name); break;
case VER_TR1_SAT : sprintf(dst, "DATA/%s.SAT", LEVEL_INFO[id].name); break;
case VER_TR2_PC : { // oh FFFFUUUUUUCKing CaTaComB.Tr2!
if (id == LVL_TR2_VENICE || id == LVL_TR2_CUT_2 || id == LVL_TR2_PLATFORM || id == LVL_TR2_CUT_3 || id == LVL_TR2_UNWATER ||
id == LVL_TR2_KEEL || id == LVL_TR2_LIVING || id == LVL_TR2_DECK || id == LVL_TR2_CATACOMB || id == LVL_TR2_ICECAVE ||
id == LVL_TR2_CUT_4 || id == LVL_TR2_XIAN || id == LVL_TR2_HOUSE) {
char buf[64];
strcpy(buf, LEVEL_INFO[id].name);
StrUtils::toLower(buf);
sprintf(dst, "DATA/%s.TR2", buf);
} else if (id == LVL_TR2_TITLE) {
sprintf(dst, "DATA/%s.tr2", LEVEL_INFO[id].name);
} else if (id == LVL_TR2_EMPRTOMB) {
strcpy(dst, "DATA/Emprtomb.tr2");
} else {
case VER_TR2_PC : {
sprintf(dst, "DATA/%s.TR2", LEVEL_INFO[id].name);
}
if (Stream::existsContent(dst)) break;
strcpy(dst, LEVEL_INFO[id].name);
StrUtils::toLower(dst);

View File

@@ -320,6 +320,76 @@ void joyUpdate() {
}
}
// filesystem
#define MAX_FILES 4096
char* gFiles[MAX_FILES];
int32 gFilesCount;
void addDir(char* path)
{
char* fileName;
struct dirent* e;
DIR* dir = opendir(path);
int32 pathLen = strlen(path);
path[pathLen] = '/';
while ((e = readdir(dir)))
{
if (e->d_type == DT_DIR)
{
if (e->d_name[0] != '.')
{
strcpy(path + 1 + pathLen, e->d_name);
addDir(path);
}
}
else
{
ASSERT(gFilesCount < MAX_FILES);
if (gFilesCount < MAX_FILES)
{
strcpy(path + 1 + pathLen, e->d_name);
fileName = (char*)malloc(strlen(path) + 1 - 2);
gFiles[gFilesCount++] = strcpy(fileName, path + 2);
}
}
}
path[pathLen] = '\0';
}
void fsInit()
{
char path[1024];
strcpy(path, ".");
addDir(path);
LOG("scan %d files\n", gFilesCount);
}
void fsFree()
{
int32 i;
for (i = 0; i < gFilesCount; i++)
{
free(gFiles[i]);
}
}
const char* osFixFileName(const char* fileName)
{
int32 i;
for (i = 0; i < gFilesCount; i++)
{
if (!strcasecmp(fileName, gFiles[i]))
{
return gFiles[i];
}
}
return NULL;
}
// system
void toggle_fullscreen(Display* dpy, Window win) {
const size_t _NET_WM_STATE_TOGGLE=2;
@@ -447,6 +517,8 @@ int main(int argc, char **argv) {
Core::defLang = checkLanguage();
fsInit();
joyInit();
sndInit();
Game::init(argc > 1 ? argv[1] : NULL);
@@ -473,6 +545,8 @@ int main(int argc, char **argv) {
sndFree();
Game::deinit();
fsFree();
glXMakeCurrent(dpy, 0, 0);
XCloseDisplay(dpy);
return 0;

View File

@@ -1681,6 +1681,10 @@ extern void osCacheRead (Stream *stream);
extern void osReadSlot (Stream *stream);
extern void osWriteSlot (Stream *stream);
#ifdef _OS_LINUX
extern const char* osFixFileName(const char* fileName);
#endif;
#ifdef _OS_WEB
extern void osDownload (Stream *stream);
#endif
@@ -1864,7 +1868,13 @@ private:
if (contentDir[0] && (!cacheDir[0] || !strstr(name, cacheDir))) {
strcpy(path, contentDir);
}
#ifdef _OS_LINUX
strcat(path, osFixFileName(name));
#else
strcat(path, name);
#endif
fixBackslash(path);
f = fopen(path, "rb");
@@ -2116,10 +2126,15 @@ public:
}
static bool exists(const char *name) {
#ifdef _OS_LINUX
name = osFixFileName(name);
return (name != NULL);
#else
FILE *f = fopen(name, "rb");
if (!f) return false;
fclose(f);
return true;
#endif
}
static bool existsContent(const char *name) {