Skip to content

Commit

Permalink
Fix #437 (#441)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Signed-off-by: Manuel Lauss <[email protected]>
  • Loading branch information
mlauss2 authored Aug 19, 2024
1 parent 75f99fb commit 44c6a28
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 10 additions & 1 deletion TheForceEngine/TFE_DarkForces/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -542,13 +543,15 @@ 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);
}
}
}
// 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.
Expand All @@ -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
} // namespace TFE_DarkForces
10 changes: 8 additions & 2 deletions TheForceEngine/TFE_FileSystem/fileutil-posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 44c6a28

Please sign in to comment.