From 2143afde6cfd3ee3f068861589fd45212ef755de Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 25 Sep 2010 19:48:05 +0000 Subject: SWORD25: Add support for language patch svn-id: r53377 --- engines/sword25/package/packagemanager.cpp | 17 ++++++++-- engines/sword25/sword25.cpp | 53 +++++++++--------------------- 2 files changed, 31 insertions(+), 39 deletions(-) (limited to 'engines') diff --git a/engines/sword25/package/packagemanager.cpp b/engines/sword25/package/packagemanager.cpp index 4cea4f578d..801f695f15 100644 --- a/engines/sword25/package/packagemanager.cpp +++ b/engines/sword25/package/packagemanager.cpp @@ -106,6 +106,8 @@ Common::ArchiveMemberPtr PackageManager::GetArchiveMember(const Common::String & } bool PackageManager::LoadPackage(const Common::String &fileName, const Common::String &mountPosition) { + debug(0, "LoadPackage(%s, %s)", fileName.c_str(), mountPosition.c_str()); + Common::Archive *zipFile = Common::makeZipArchive(fileName); if (zipFile == NULL) { BS_LOG_ERRORLN("Unable to mount file \"%s\" to \"%s\"", fileName.c_str(), mountPosition.c_str()); @@ -119,7 +121,7 @@ bool PackageManager::LoadPackage(const Common::String &fileName, const Common::S for (Common::ArchiveMemberList::iterator it = files.begin(); it != files.end(); ++it) debug(3, "%s", (*it)->getName().c_str()); - _archiveList.push_back(new ArchiveEntry(zipFile, mountPosition)); + _archiveList.push_front(new ArchiveEntry(zipFile, mountPosition)); return true; } @@ -271,7 +273,18 @@ int PackageManager::doSearch(Common::ArchiveMemberList &list, const Common::Stri for (Common::ArchiveMemberList::iterator it = memberList.begin(); it != memberList.end(); ++it) { if (((typeFilter & PackageManager::FT_DIRECTORY) && (*it)->getName().hasSuffix("/")) || ((typeFilter & PackageManager::FT_FILE) && !(*it)->getName().hasSuffix("/"))) { - list.push_back(*it); + + // Do not add duplicate files + bool found = false; + for (Common::ArchiveMemberList::iterator it1 = list.begin(); it1 != list.end(); ++it1) { + if ((*it1)->getName() == (*it)->getName()) { + found = true; + break; + } + } + + if (!found) + list.push_back(*it); num++; } } diff --git a/engines/sword25/sword25.cpp b/engines/sword25/sword25.cpp index 42772a86af..723775f133 100644 --- a/engines/sword25/sword25.cpp +++ b/engines/sword25/sword25.cpp @@ -155,8 +155,14 @@ bool Sword25Engine::LoadPackages() { if (!PackageManagerPtr->LoadPackage("data.b25c", "/")) return false; // Get the contents of the main program directory and sort them alphabetically - Common::StringArray Filenames = FileSystemUtil::GetInstance().GetFilesInDirectory("."); - Common::sort(Filenames.begin(), Filenames.end()); + Common::FSNode dir(ConfMan.get("path")); + Common::FSList files; + if (!dir.isDirectory() || !dir.getChildren(files, Common::FSNode::kListAll)) { + warning("Game data path does not exist or is not a directory"); + return false; + } + + Common::sort(files.begin(), files.end()); // Identity all patch packages // The filename of patch packages must have the form patch??.b25c, with the question marks @@ -164,45 +170,18 @@ bool Sword25Engine::LoadPackages() { // Since the filenames have been sorted, patches are mounted with low numbers first, through // to ones with high numbers. This is important, because newly mount packages overwrite // existing files in the virtual file system, if they include files with the same name. - for (Common::StringArray::const_iterator it = Filenames.begin(); it != Filenames.end(); ++it) { - const Common::String &CurFilename = *it; - - // Is the current file a patch package? - static const Common::String PatchPattern = "patch???.b25c"; - if (CurFilename.size() == PatchPattern.size()) { - // Check the file against the patch pattern character by character - Common::String::const_iterator PatchPatternIt = PatchPattern.begin(); - Common::String::const_iterator CurFilenameIt = CurFilename.begin(); - for (; PatchPatternIt != PatchPattern.end(); ++PatchPatternIt, ++CurFilenameIt) { - if (*PatchPatternIt == '?') { - if (*CurFilenameIt < '0' || *CurFilenameIt > '9') break; - } else { - if (*PatchPatternIt != *CurFilenameIt) break; - } - } - - if (PatchPatternIt == PatchPattern.end()) { - // The pattern fits, so the file should be mounted - if (!PackageManagerPtr->LoadPackage(CurFilename, "/")) return false; - } - } + for (Common::FSList::const_iterator it = files.begin(); it != files.end(); ++it) { + if (it->getName().matchString("patch???.b25c", true)) + if (!PackageManagerPtr->LoadPackage(it->getName(), "/")) + return false; } // Identity and mount all language packages // The filename of the packages have the form lang_*.b25c (eg. lang_de.b25c) - for (Common::StringArray::const_iterator it = Filenames.begin(); it != Filenames.end(); ++it) { - const Common::String &CurFilename = *it; - - static const Common::String Prefix = "lang_"; - static const Common::String Suffix = ".b25c"; - - // Make sure the filename prefix and suffix has characters between them - if ((CurFilename.size() >= Prefix.size() && Common::String(CurFilename.begin(), CurFilename.begin() + Prefix.size()) == Prefix) && // Prefix test - (CurFilename.size() >= Suffix.size() && Common::String(CurFilename.end() - Suffix.size(), CurFilename.end()) == Suffix) && // Suffix test - (CurFilename.size() > Prefix.size() + Suffix.size())) { - // Pattern matches - the file should be mounted - if (!PackageManagerPtr->LoadPackage(CurFilename, "/")) return false; - } + for (Common::FSList::const_iterator it = files.begin(); it != files.end(); ++it) { + if (it->getName().matchString("lang_*.b25c", true)) + if (!PackageManagerPtr->LoadPackage(it->getName(), "/")) + return false; } return true; -- cgit v1.2.3