WATCHMAKER: Optimize t3dGetFileDate slightly

By avoiding opening the files just to check their existence.
This commit is contained in:
Einar Johan Trøan Sømåen 2023-04-09 10:11:30 +02:00 committed by Eugene Sandulenko
parent 2b3ef5e360
commit 6ece7cfbc4
2 changed files with 29 additions and 10 deletions

View File

@ -162,20 +162,38 @@ int t3dAccessFile(char *name) {
}
bool t3dGetFileDate(uint32 *date, uint32 *time, const char *name) {
auto stream = openFile(name);
warning("TODO: t3dGetFileDate is currently super-inefficient");
if (stream)
return true;
warning("TODO: t3dGetFileDate is currently super-inefficient: %s", name);
return checkFileExists(name);
}
Common::String adjustPath(const Common::String &path) {
Common::String adjustedPath;
if (path.hasPrefix("./")) {
adjustedPath = path.substr(2, path.size());
} else {
adjustedPath = path;
}
return adjustedPath;
}
bool checkFileExists(const Common::String &filename) {
Common::String adjustedPath = adjustPath(filename);
Common::ArchiveMemberList files;
SearchMan.listMatchingMembers(files, adjustedPath);
for (Common::ArchiveMemberList::iterator it = files.begin(); it != files.end(); ++it) {
if ((*it)->getName().equalsIgnoreCase(lastPathComponent(adjustedPath, '/'))) {
return true;
}
}
return false;
}
Common::SharedPtr<Common::SeekableReadStream> openFile(const Common::String &filename, int offset, int size) {
Common::String adjustedPath;
if (filename.hasPrefix("./")) {
adjustedPath = filename.substr(2, filename.size());
} else {
adjustedPath = filename;
}
Common::String adjustedPath = adjustPath(filename);
Common::SeekableReadStream *file = nullptr;
// Try directly from SearchMan first
Common::ArchiveMemberList files;

View File

@ -58,6 +58,7 @@ bool t3dFastFileInit(const char *name);
void t3dForceNOFastFile(char valore);
int t3dAccessFile(char *name);
bool t3dGetFileDate(uint32 *date, uint32 *time, const char *name);
bool checkFileExists(const Common::String &filename);
Common::SeekableReadStream *resolveFile(const char *path);
Common::SharedPtr<Common::SeekableReadStream> openFile(const Common::String &filename, int offset = 0, int size = -1);