Merge pull request #971 from Azaezel/alpha41/isFileFix

fix isFile detection, and aug for script extension searching
This commit is contained in:
Brian Roberts 2023-02-23 21:53:19 -06:00 committed by GitHub
commit bae7166cc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -387,7 +387,10 @@ DefineEngineFunction(isFile, bool, ( const char* fileName ),,
"@ingroup FileSystem")
{
Torque::Path givenPath(fileName);
String cleanfilename(Torque::Path::CleanSeparators(fileName));
Con::expandScriptFilename(sgScriptFilenameBuffer, sizeof(sgScriptFilenameBuffer), cleanfilename.c_str());
Torque::Path givenPath(Torque::Path::CompressPath(sgScriptFilenameBuffer));
if (givenPath.getFileName().isEmpty() && givenPath.getExtension().isNotEmpty())
{
@ -396,7 +399,16 @@ DefineEngineFunction(isFile, bool, ( const char* fileName ),,
givenPath.setFileName(String(".") + givenPath.getExtension());
givenPath.setExtension("");
}
if (Torque::FS::IsFile(givenPath)) return true;
//try with script file extension
if (!Torque::FS::IsFile(givenPath) && givenPath.getExtension().isEmpty())
givenPath.setExtension(TORQUE_SCRIPT_EXTENSION);
if (Torque::FS::IsFile(givenPath)) return true;
//finally, try with compiled script file extension
if (!Torque::FS::IsFile(givenPath))
givenPath.setExtension(String(TORQUE_SCRIPT_EXTENSION)+String(".dso"));
return Torque::FS::IsFile(givenPath);
}