From 19073d6d6022467d4bc1fff3e43cc8e4739833eb Mon Sep 17 00:00:00 2001 From: OmniBlade Date: Sat, 22 Jun 2024 22:59:18 +0100 Subject: [PATCH] Fix SC* expansion files not caching on none windows. Fixes any mod or expansion that relied on cached resources. --- common/file.cpp | 7 +++++-- common/file.h | 4 ++++ common/file_posix.cpp | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/common/file.cpp b/common/file.cpp index 55779b98..5a639b85 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -12,8 +12,11 @@ static void Resolve_File_Single(char* fname) return; } - if (ffblk->FindFirst(fname) && strlen(fname) == strlen(ffblk->GetName())) { - strncpy(fname, ffblk->GetName(), strlen(fname) + 1); + size_t name_len = strlen(fname); + size_t full_len = strlen(ffblk->GetFullName()); + + if (ffblk->FindFirst(fname) && name_len == full_len) { + strncpy(fname, ffblk->GetFullName(), name_len + 1); } delete ffblk; diff --git a/common/file.h b/common/file.h index 83b447ff..3e05794c 100644 --- a/common/file.h +++ b/common/file.h @@ -231,6 +231,10 @@ class Find_File_Data { } virtual const char* GetName() const = 0; + virtual const char* GetFullName() const + { + return nullptr; + }; virtual unsigned int GetTime() const = 0; virtual bool FindFirst(const char* fname) = 0; diff --git a/common/file_posix.cpp b/common/file_posix.cpp index 233ba0f9..bcc4d64e 100644 --- a/common/file_posix.cpp +++ b/common/file_posix.cpp @@ -18,6 +18,10 @@ class Find_File_Data_Posix : public Find_File_Data virtual ~Find_File_Data_Posix(); virtual const char* GetName() const; + virtual const char* GetFullName() const + { + return DirEntry != nullptr ? FullName : nullptr; + } virtual unsigned int GetTime() const; virtual bool FindFirst(const char* fname); @@ -50,7 +54,7 @@ const char* Find_File_Data_Posix::GetName() const if (DirEntry == nullptr) { return nullptr; } - return FullName; + return DirEntry->d_name; } unsigned int Find_File_Data_Posix::GetTime() const