From 44c6a28ae02c622808b46a1b6c2df84269ab153c Mon Sep 17 00:00:00 2001 From: Manuel Lauss <123231678+mlauss2@users.noreply.github.com> Date: Mon, 19 Aug 2024 18:58:43 +0200 Subject: [PATCH] Fix #437 (#441) * Recreate DARKPILO.CFG if it's invalid. * fileutil-posix: copyFile(): assume src filename is case insensitive When copying a file, assume the source name is case insensitive so we can find a match. Signed-off-by: Manuel Lauss --------- Signed-off-by: Manuel Lauss --- TheForceEngine/TFE_DarkForces/agent.cpp | 11 ++++++++++- TheForceEngine/TFE_FileSystem/fileutil-posix.cpp | 10 ++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/TheForceEngine/TFE_DarkForces/agent.cpp b/TheForceEngine/TFE_DarkForces/agent.cpp index 34fb26de5..f3dd7387a 100644 --- a/TheForceEngine/TFE_DarkForces/agent.cpp +++ b/TheForceEngine/TFE_DarkForces/agent.cpp @@ -510,6 +510,7 @@ namespace TFE_DarkForces // Also, later, the TFE based save format will likely change - so importing will be necessary anyway. JBool openDarkPilotConfig(FileStream* file) { + bool triedonce = false; assert(file); // TFE uses its own local copy of the save game data to avoid corrupting existing data. @@ -542,6 +543,7 @@ namespace TFE_DarkForces { // Finally generate a new one. TFE_System::logWrite(LOG_WARNING, "DarkForcesMain", "Cannot find 'DARKPILO.CFG' at '%s'. Creating a new file for save data.", sourcePath); +newpilo: createDarkPilotConfig(documentsPath); } } @@ -549,6 +551,7 @@ namespace TFE_DarkForces // Then try opening the file. if (!file->open(documentsPath, Stream::MODE_READWRITE)) { + TFE_System::logWrite(LOG_ERROR, "DarkForcesMain", "cannot open DARKPILO.CFG"); return JFALSE; } // Then verify the file. @@ -560,6 +563,12 @@ namespace TFE_DarkForces } // If it is not correct, then close the file and return false. file->close(); + if (!triedonce) + { + TFE_System::logWrite(LOG_ERROR, "DarkForcesMain", "DARKPILO.CFG corrupted; creating new"); + triedonce = true; + goto newpilo; + } return JFALSE; } -} // namespace TFE_DarkForces \ No newline at end of file +} // namespace TFE_DarkForces diff --git a/TheForceEngine/TFE_FileSystem/fileutil-posix.cpp b/TheForceEngine/TFE_FileSystem/fileutil-posix.cpp index 4f68a7090..4939e7e65 100644 --- a/TheForceEngine/TFE_FileSystem/fileutil-posix.cpp +++ b/TheForceEngine/TFE_FileSystem/fileutil-posix.cpp @@ -192,10 +192,16 @@ namespace FileUtil void copyFile(const char *src, const char *dst) { ssize_t rd, wr; - char buf[1024]; + char buf[1024], *fnd; int s, d; - s = open(src, O_RDONLY); + // assume the source is case-insensitive + fnd = findFileObjectNoCase(src, false); + if (!fnd) + return; + + s = open(fnd, O_RDONLY); + free(fnd); if (!s) return; d = open(dst, O_WRONLY | O_CREAT, 00644);