LAB: Add a workaround for DOS version using long filenames

This commit is contained in:
Strangerke 2016-01-24 13:33:33 +01:00
parent 5fb0787bd7
commit 78b9a903ad
2 changed files with 33 additions and 5 deletions

View File

@ -175,22 +175,50 @@ Common::String Resource::translateFileName(const Common::String filename) {
upperFilename.deleteChar(0);
}
if (_vm->getPlatform() == Common::kPlatformDOS) {
// Some script of the DOS version uses names used in the Amiga (and Windows) version,
// which isn't limited to 8.3 characters. We need to parse upperFilename to detect
// the filename, and fix it if required so it matches a DOS filename.
while (upperFilename.contains('/') && upperFilename.size()) {
fileNameStrFinal += upperFilename[0];
upperFilename.deleteChar(0);
}
for (int i = 0; (i < 8) && upperFilename.size() && (upperFilename[0] != '.'); i++) {
fileNameStrFinal += upperFilename[0];
upperFilename.deleteChar(0);
}
// Remove the extra character in the filename
while (upperFilename.size() && (upperFilename[0] != '.'))
upperFilename.deleteChar(0);
// copy max 4 characters for the extension ('.foo')
for (int i = 0; (i < 4) && upperFilename.size(); i++) {
fileNameStrFinal += upperFilename[0];
upperFilename.deleteChar(0);
}
// Skip the extra characters of the extension
upperFilename.clear();
}
fileNameStrFinal += upperFilename;
return fileNameStrFinal;
}
Common::File *Resource::openDataFile(const Common::String fileName, uint32 fileHeader) {
Common::File *Resource::openDataFile(const Common::String filename, uint32 fileHeader) {
Common::File *dataFile = new Common::File();
dataFile->open(translateFileName(fileName));
dataFile->open(translateFileName(filename));
if (!dataFile->isOpen())
error("openDataFile: Couldn't open %s (%s)", translateFileName(fileName).c_str(), fileName.c_str());
error("openDataFile: Couldn't open %s (%s)", translateFileName(filename).c_str(), filename.c_str());
if (fileHeader > 0) {
uint32 headerTag = dataFile->readUint32BE();
if (headerTag != fileHeader) {
dataFile->close();
error("openDataFile: Unexpected header in %s (%s) - expected: %d, got: %d", translateFileName(fileName).c_str(), fileName.c_str(), fileHeader, headerTag);
error("openDataFile: Unexpected header in %s (%s) - expected: %d, got: %d", translateFileName(filename).c_str(), filename.c_str(), fileHeader, headerTag);
}
}

View File

@ -97,7 +97,7 @@ public:
Resource(LabEngine *vm);
~Resource() {}
Common::File *openDataFile(const Common::String fileName, uint32 fileHeader = 0);
Common::File *openDataFile(const Common::String filename, uint32 fileHeader = 0);
void readRoomData(const Common::String fileName);
InventoryData *readInventory(const Common::String fileName);
void readViews(uint16 roomNum);