void DataFilesModel::addMasters(const QString &path) { QDir dir(path); dir.setNameFilters(QStringList(QLatin1String("*.esp"))); // Read the dependencies from the plugins foreach (const QString &path, dir.entryList()) { try { ESM::ESMReader fileReader; fileReader.setEncoding(mEncoding.toStdString()); fileReader.open(dir.absoluteFilePath(path).toStdString()); ESM::ESMReader::MasterList mlist = fileReader.getMasters(); for (unsigned int i = 0; i < mlist.size(); ++i) { QString master = QString::fromStdString(mlist[i].name); // Add the plugin to the internal dependency map mDependencies[master].append(path); // Don't add esps if (master.endsWith(".esp", Qt::CaseInsensitive)) continue; QFileInfo info(dir.absoluteFilePath(master)); EsmFile *file = new EsmFile(master); file->setDates(info.lastModified(), info.lastRead()); // Add the master to the table if (findItem(master) == 0) addFile(file); } } catch(std::runtime_error &e) { // An error occurred while reading the .esp qWarning() << "Error reading esp: " << e.what(); continue; } } // See if the masters actually exist in the filesystem dir.setNameFilters(QStringList(QLatin1String("*.esm"))); foreach (const QString &path, dir.entryList()) { QFileInfo info(dir.absoluteFilePath(path)); if (findItem(path) == 0) { EsmFile *file = new EsmFile(path); file->setDates(info.lastModified(), info.lastRead()); addFile(file); } // Make the master selectable mAvailableFiles.append(path); } }
void DataFilesModel::addPlugins(const QString &path) { QDir dir(path); dir.setNameFilters(QStringList(QLatin1String("*.esp"))); foreach (const QString &path, dir.entryList()) { QFileInfo info(dir.absoluteFilePath(path)); EsmFile *file = new EsmFile(path); try { ESM::ESMReader fileReader; ToUTF8::Utf8Encoder encoder (ToUTF8::calculateEncoding(mEncoding.toStdString())); fileReader.setEncoder(&encoder); fileReader.open(dir.absoluteFilePath(path).toStdString()); ESM::ESMReader::MasterList mlist = fileReader.getMasters(); QStringList masters; for (unsigned int i = 0; i < mlist.size(); ++i) { QString master = QString::fromStdString(mlist[i].name); masters.append(master); // Add the plugin to the internal dependency map mDependencies[master].append(path); } file->setAuthor(QString::fromStdString(fileReader.getAuthor())); file->setSize(info.size()); file->setDates(info.lastModified(), info.lastRead()); file->setVersion(fileReader.getFVer()); file->setPath(info.absoluteFilePath()); file->setMasters(masters); file->setDescription(QString::fromStdString(fileReader.getDesc())); // Put the file in the table addFile(file); } catch(std::runtime_error &e) { // An error occurred while reading the .esp qWarning() << "Error reading esp: " << e.what(); continue; } } }
void DataFilesModel::addFiles(const QString &path) { QDir dir(path); QStringList filters; filters << "*.esp" << "*.esm"; dir.setNameFilters(filters); // Create a decoder for non-latin characters in esx metadata QTextCodec *codec; if (mEncoding == QLatin1String("win1252")) { codec = QTextCodec::codecForName("windows-1252"); } else if (mEncoding == QLatin1String("win1251")) { codec = QTextCodec::codecForName("windows-1251"); } else if (mEncoding == QLatin1String("win1250")) { codec = QTextCodec::codecForName("windows-1250"); } else { return; // This should never happen; } QTextDecoder *decoder = codec->makeDecoder(); foreach (const QString &path, dir.entryList()) { QFileInfo info(dir.absoluteFilePath(path)); EsmFile *file = new EsmFile(path); try { ESM::ESMReader fileReader; ToUTF8::Utf8Encoder encoder(ToUTF8::calculateEncoding(mEncoding.toStdString())); fileReader.setEncoder(&encoder); fileReader.open(dir.absoluteFilePath(path).toStdString()); std::vector<ESM::Header::MasterData> mlist = fileReader.getMasters(); QStringList masters; for (unsigned int i = 0; i < mlist.size(); ++i) { QString master = QString::fromStdString(mlist[i].name); masters.append(master); } file->setAuthor(decoder->toUnicode(fileReader.getAuthor().c_str())); file->setSize(info.size()); file->setDates(info.lastModified(), info.lastRead()); file->setVersion(fileReader.getFVer()); file->setPath(info.absoluteFilePath()); file->setMasters(masters); file->setDescription(decoder->toUnicode(fileReader.getDesc().c_str())); // Put the file in the table if (findItem(path) == 0) addFile(file); } catch(std::runtime_error &e) { // An error occurred while reading the .esp qWarning() << "Error reading esp: " << e.what(); continue; } } delete decoder; }
void ESMStore::load(ESM::ESMReader &esm) { std::set<std::string> missing; ESM::Dialogue *dialogue = 0; // Cache parent esX files by tracking their indices in the global list of // all files/readers used by the engine. This will greaty accelerate // refnumber mangling, as required for handling moved references. int index = ~0; const ESM::ESMReader::MasterList &masters = esm.getMasters(); std::vector<ESM::ESMReader> *allPlugins = esm.getGlobalReaderList(); for (size_t j = 0; j < masters.size(); j++) { ESM::MasterData &mast = const_cast<ESM::MasterData&>(masters[j]); std::string fname = mast.name; for (int i = 0; i < esm.getIndex(); i++) { const std::string &candidate = allPlugins->at(i).getContext().filename; std::string fnamecandidate = boost::filesystem::path(candidate).filename().string(); if (fname == fnamecandidate) { index = i; break; } } if (index == (int)~0) { // Tried to load a parent file that has not been loaded yet. This is bad, // the launcher should have taken care of this. std::string fstring = "File " + fname + " asks for parent file " + masters[j].name + ", but it has not been loaded yet. Please check your load order."; esm.fail(fstring); } mast.index = index; } // Loop through all records while(esm.hasMoreRecs()) { ESM::NAME n = esm.getRecName(); esm.getRecHeader(); // Look up the record type. std::map<int, StoreBase *>::iterator it = mStores.find(n.val); if (it == mStores.end()) { if (n.val == ESM::REC_INFO) { if (dialogue) { dialogue->mInfo.push_back(ESM::DialInfo()); dialogue->mInfo.back().load(esm); } else { std::cerr << "error: info record without dialog" << std::endl; esm.skipRecord(); } } else if (n.val == ESM::REC_MGEF) { mMagicEffects.load (esm); } else if (n.val == ESM::REC_SKIL) { mSkills.load (esm); } else { // Not found (this would be an error later) esm.skipRecord(); missing.insert(n.toString()); } } else { // Load it std::string id = esm.getHNOString("NAME"); // ... unless it got deleted! This means that the following record // has been deleted, and trying to load it using standard assumptions // on the structure will (probably) fail. if (esm.isNextSub("DELE")) { esm.skipRecord(); it->second->eraseStatic(id); continue; } it->second->load(esm, id); if (n.val==ESM::REC_DIAL) { // dirty hack, but it is better than non-const search() // or friends //dialogue = &mDialogs.mStatic.back(); dialogue = const_cast<ESM::Dialogue*>(mDialogs.find(id)); assert (dialogue->mId == id); } else { dialogue = 0; } // Insert the reference into the global lookup if (!id.empty() && isCacheableRecord(n.val)) { mIds[id] = n.val; } } } /* This information isn't needed on screen. But keep the code around for debugging purposes later. cout << "\n" << mStores.size() << " record types:\n"; for(RecListList::iterator it = mStores.begin(); it != mStores.end(); it++) cout << " " << toStr(it->first) << ": " << it->second->getSize() << endl; cout << "\nNot implemented yet: "; for(set<string>::iterator it = missing.begin(); it != missing.end(); it++ ) cout << *it << " "; cout << endl; */ }