diff --git a/engines/kyra/engine/util.cpp b/engines/kyra/engine/util.cpp index 9b4670d54b4..e94872ef0d7 100644 --- a/engines/kyra/engine/util.cpp +++ b/engines/kyra/engine/util.cpp @@ -20,6 +20,8 @@ * */ +#include "common/macresman.h" +#include "common/punycode.h" #include "kyra/engine/util.h" namespace Kyra { @@ -115,4 +117,40 @@ Common::String Util::decodeString2(const Common::String &src) { return tmp; } +Common::String Util::findMacResourceFile(const char *baseName) { + // The original executable has a TM char as its last character (character + // 0xAA from Mac code page). Depending on the emulator or platform used to + // copy the file it might have been reencoded to something else. So I look + // for multiple versions, also for punycode encoded files and also for the + // case where the user might have just removed the last character by + // renaming the file. + + const Common::CodePage tryCodePages[] = { + Common::kMacRoman, + Common::kISO8859_1 + }; + + Common::String tryName(baseName); + Common::String fileName; + + for (int i = 0; i < ARRAYSIZE(tryCodePages); ++i) { + for (int ii = 0; ii < 2; ++ii) { + Common::MacResManager resource; + + Common::U32String fn(tryName, tryCodePages[i]); + fileName = fn.encode(Common::kUtf8); + if (resource.exists(fileName)) + return fileName; + fileName = Common::punycode_encodefilename(fn); + if (resource.exists(fileName)) + return fileName; + + tryName += "\xAA"; + } + } + + fileName.clear(); + return fileName; +} + } // End of namespace Kyra diff --git a/engines/kyra/engine/util.h b/engines/kyra/engine/util.h index fd8e9f90a12..7f5fdc451ab 100644 --- a/engines/kyra/engine/util.h +++ b/engines/kyra/engine/util.h @@ -40,6 +40,8 @@ public: static Common::String convertUTF8ToDOS(Common::String &str); static Common::String convertISOToUTF8(Common::String &str); static void convertISOToDOS(char &c); + + static Common::String findMacResourceFile(const char *baseName); }; } // End of namespace Kyra diff --git a/engines/kyra/resource/resource.cpp b/engines/kyra/resource/resource.cpp index fc6311b2055..0d2cdc80de9 100644 --- a/engines/kyra/resource/resource.cpp +++ b/engines/kyra/resource/resource.cpp @@ -20,12 +20,13 @@ * */ +#include "kyra/engine/util.h" #include "kyra/resource/resource.h" #include "kyra/resource/resource_intern.h" #include "common/config-manager.h" -#include "common/macresman.h" -#include "common/punycode.h" +//#include "common/macresman.h" +//#include "common/punycode.h" #include "common/fs.h" namespace Kyra { @@ -66,33 +67,7 @@ bool Resource::reset() { error("invalid game path '%s'", dir.getPath().c_str()); if (_vm->game() == GI_KYRA1 && _vm->gameFlags().platform == Common::kPlatformMacintosh && _vm->gameFlags().useInstallerPackage) { - const char *const tryFileNames[] = { - "Install Legend of Kyrandia", - "Install Legend of Kyrandia\xaa" - }; - - const Common::CodePage tryCodePages[] = { - Common::kMacRoman, - Common::kISO8859_1 - }; - - Common::MacResManager resource; - Common::String kyraInstaller; - - for (int i = 0; i < ARRAYSIZE(tryCodePages); ++i) { - for (int ii = 0; ii < ARRAYSIZE(tryFileNames); ++ii) { - Common::U32String fn(tryFileNames[ii], tryCodePages[i]); - kyraInstaller = fn.encode(Common::kUtf8); - if (resource.exists(kyraInstaller)) - break; - kyraInstaller = Common::punycode_encodefilename(fn); - if (resource.exists(kyraInstaller)) - break; - kyraInstaller.clear(); - } - if (!kyraInstaller.empty()) - break; - } + Common::String kyraInstaller = Util::findMacResourceFile("Install Legend of Kyrandia"); if (kyraInstaller.empty()) { error("Could not find Legend of Kyrandia installer file"); diff --git a/engines/kyra/sound/sound_mac_lok.cpp b/engines/kyra/sound/sound_mac_lok.cpp index ff4a1baacd1..34b988c062a 100644 --- a/engines/kyra/sound/sound_mac_lok.cpp +++ b/engines/kyra/sound/sound_mac_lok.cpp @@ -20,6 +20,7 @@ * */ +#include "kyra/engine/util.h" #include "kyra/resource/resource.h" #include "kyra/sound/sound_intern.h" #include "kyra/sound/sound_mac_res.h" @@ -27,7 +28,6 @@ #include "common/config-manager.h" #include "common/macresman.h" -#include "common/punycode.h" #include "common/stuffit.h" #include "audio/mixer.h" @@ -54,37 +54,7 @@ bool SoundMacRes::init() { return false; if (!_stuffItArchive) { - // The original executable has a TM char as its last character - // (character 0xaa from Mac code page). Depending on the emulator or - // platform used to copy the file it might have been reencoded to - // something else. So I look for multiple versions, also for punycode - // encoded files and also for the case where the user might have just - // removed the last character by renaming the file. - - const Common::CodePage tryCodePages[] = { - Common::kMacRoman, - Common::kISO8859_1 - }; - - const char *const tryExeNames[] = { - "Legend of Kyrandia\xaa", - "Legend of Kyrandia" - }; - - for (int i = 0; i < ARRAYSIZE(tryCodePages); ++i) { - for (int ii = 0; ii < ARRAYSIZE(tryExeNames); ++ii) { - Common::U32String fn(tryExeNames[ii], tryCodePages[i]); - _kyraMacExe = fn.encode(Common::kUtf8); - if (_macRes->exists(_kyraMacExe)) - break; - _kyraMacExe = Common::punycode_encodefilename(fn); - if (_macRes->exists(_kyraMacExe)) - break; - _kyraMacExe.clear(); - } - if (!_kyraMacExe.empty()) - break; - } + _kyraMacExe = Util::findMacResourceFile("Legend of Kyrandia"); if (_kyraMacExe.empty()) { warning("SoundMacRes::init(): Legend of Kyrandia resource fork not found");