ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

lang_filter.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/grim/update/lang_filter.h"
00024 
00025 #include "common/file.h"
00026 #include "common/archive.h"
00027 #include "common/str.h"
00028 
00029 namespace Grim {
00030 
00031 const char *LangFilter::kLanguages1[7] = { "@@_", "US_", "FR_", "GE_", "IT_", "PT_", "SP_" };
00032 const char *LangFilter::kLanguages2[7] = { "Common/", "Eng/", "Fra/", "Deu/", "Ita/", "Brz/", "Esp/" };
00033 
00034 LangFilter::LangFilter(Common::Archive *arc, Common::Language lang) : _arc(arc) {
00035     if (!_arc)
00036         return;
00037 
00038     switch (lang) {
00039         case Common::EN_ANY:
00040         case Common::EN_GRB:
00041         case Common::EN_USA:
00042             _lang = kEnglish;
00043             break;
00044         case Common::FR_FRA:
00045             _lang = kFrench;
00046             break;
00047         case Common::DE_DEU:
00048             _lang = kGerman;
00049             break;
00050         case Common::IT_ITA:
00051             _lang = kItalian;
00052             break;
00053         case Common::PT_BRA:
00054             _lang = kPortuguese;
00055             break;
00056         case Common::ES_ESP:
00057             _lang = kSpanish;
00058             break;
00059         default:
00060             _lang = kCommon;
00061             break;
00062     }
00063 }
00064 
00065 LangFilter::~LangFilter() {
00066     delete _arc;
00067 }
00068 
00069 bool LangFilter::hasFile(const Common::String &name) const {
00070     if (!_arc)
00071         return false;
00072 
00073     return (_arc->hasFile(kLanguages1[_lang] + name)) ||
00074             (_arc->hasFile(kLanguages1[kCommon] + name)) ||
00075             (_arc->hasFile(kLanguages2[_lang] + name)) ||
00076             (_arc->hasFile(kLanguages2[kCommon] + name));
00077 }
00078 
00079 int LangFilter::listMembers(Common::ArchiveMemberList &list) const {
00080     if (!_arc)
00081         return false;
00082 
00083     Common::ArchiveMemberList orgList;
00084     Common::String orgName, name;
00085 
00086     _arc->listMembers(orgList);
00087 
00088     int num = 0;
00089     //Search only files with the right language and create a list with their basenames
00090     for (Common::ArchiveMemberList::const_iterator it = orgList.begin(); it != orgList.end(); ++it) {
00091         orgName = (*it)->getName();
00092         if (orgName.hasPrefix(kLanguages1[_lang]) || orgName.hasPrefix(kLanguages1[kCommon]))
00093             name = Common::String(orgName.c_str() + 3);
00094         else if (orgName.hasPrefix(kLanguages2[_lang]) || orgName.hasPrefix(kLanguages2[kCommon])) {
00095             int i = 0;
00096             while (orgName[i++] != '/') {;}
00097             name = Common::String(orgName.c_str() + i);
00098 
00099             //If the file is a subfolder, reject it
00100             if (name.contains('/'))
00101                 continue;
00102         } else
00103             continue;
00104         name.toLowercase();
00105         list.push_back(getMember(name));
00106         ++num;
00107     }
00108 
00109     return num;
00110 }
00111 
00112 const Common::ArchiveMemberPtr LangFilter::getMember(const Common::String &name) const {
00113     return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this));
00114 }
00115 
00116 Common::SeekableReadStream *LangFilter::createReadStreamForMember(const Common::String &name) const {
00117     if (!_arc)
00118         return nullptr;
00119 
00120     //Search the right file
00121     Common::String fullName;
00122     Common::List<Common::String> namesToTry;
00123     namesToTry.push_front(kLanguages1[_lang] + name);
00124     namesToTry.push_front(kLanguages1[kCommon] + name);
00125     namesToTry.push_front(kLanguages2[_lang] + name);
00126     namesToTry.push_front(kLanguages2[kCommon] + name);
00127     for (Common::List<Common::String>::const_iterator it = namesToTry.begin(); it != namesToTry.end(); ++it)
00128         if (_arc->hasFile(*it)) {
00129             fullName = *it;
00130             break;
00131         }
00132 
00133     if (fullName.empty())
00134         return nullptr;
00135 
00136     return _arc->createReadStreamForMember(fullName);
00137 }
00138 
00139 } // End of namespace Grim


Generated on Sat Aug 24 2019 05:00:56 for ResidualVM by doxygen 1.7.1
curved edge   curved edge