diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index e246b4515..71d072599 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include @@ -37,6 +36,10 @@ Launcher::DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSet void Launcher::DataFilesPage::loadSettings() { + QStringList paths = mGameSettings.getDataDirs(); + paths.insert (0, mDataLocal); + PathIterator pathIterator (paths); + QString profileName = ui.profilesComboBox->currentText(); QStringList files = mLauncherSettings.values(QString("Profiles/") + profileName + QString("/game"), Qt::MatchExactly); @@ -47,10 +50,37 @@ void Launcher::DataFilesPage::loadSettings() QString gameFile (""); if (files.size()>0) - gameFile = files.at (0); + { + gameFile = pathIterator.findFirstPath (files.at(0)); - mSelector->setGameFile(gameFile); - mSelector->setCheckStates(addons); + if (!gameFile.isEmpty()) + mSelector->setGameFile (gameFile); +/* else + { + //throw gamefile error here. + }*/ + } + + QStringList missingFiles; + QStringList foundFiles; + + foreach (const QString &addon, addons) + { + QString filePath = pathIterator.findFirstPath (addon); + + if (filePath.isEmpty()) + missingFiles << addon; + else + foundFiles << filePath; + } +/* + if (missingFiles.size() > 0) + { + //throw addons error here. + } +*/ + if (foundFiles.size() > 0) + mSelector->setCheckStates (foundFiles); } void Launcher::DataFilesPage::saveSettings(const QString &profile) @@ -191,10 +221,10 @@ void Launcher::DataFilesPage::setupDataFiles() foreach (const QString &path, paths) mSelector->addFiles(path); - QString dataLocal = mGameSettings.getDataLocal(); + mDataLocal = mGameSettings.getDataLocal(); - if (!dataLocal.isEmpty()) - mSelector->addFiles(dataLocal); + if (!mDataLocal.isEmpty()) + mSelector->addFiles(mDataLocal); QStringList profiles = mLauncherSettings.subKeys(QString("Profiles/")); QString profile = mLauncherSettings.value(QString("Profiles/currentprofile")); diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index e394e6f41..37603a210 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -4,6 +4,10 @@ #include "ui_datafilespage.h" #include + +#include +#include + class QSortFilterProxyModel; class QAbstractItemModel; class QMenu; @@ -61,6 +65,8 @@ namespace Launcher GameSettings &mGameSettings; LauncherSettings &mLauncherSettings; + QString mDataLocal; + void setPluginsCheckstates(Qt::CheckState state); void buildView(); @@ -73,6 +79,58 @@ namespace Launcher bool showDeleteMessageBox (const QString &text); void addProfile (const QString &profile, bool setAsCurrent); void checkForDefaultProfile(); + + class PathIterator + { + QStringList::ConstIterator mCitEnd; + QStringList::ConstIterator mCitCurrent; + QStringList::ConstIterator mCitBegin; + QString mFile; + QString mFilePath; + + public: + PathIterator (const QStringList &list) + { + mCitBegin = list.constBegin(); + mCitCurrent = mCitBegin; + mCitEnd = list.constEnd(); + } + + QString findFirstPath (const QString &file) + { + mCitCurrent = mCitBegin; + mFile = file; + return path(); + } + + QString findNextPath () { return path(); } + + private: + + QString path () + { + bool success = false; + QDir dir; + QFileInfo file; + + while (!success) + { + if (mCitCurrent == mCitEnd) + break; + + dir.setPath (*(mCitCurrent++)); + file.setFile (dir.absoluteFilePath (mFile)); + + success = file.exists(); + } + + if (success) + return file.absoluteFilePath(); + + return ""; + } + + }; }; } #endif diff --git a/apps/launcher/settings/gamesettings.cpp b/apps/launcher/settings/gamesettings.cpp index 32eb2071f..83c099529 100644 --- a/apps/launcher/settings/gamesettings.cpp +++ b/apps/launcher/settings/gamesettings.cpp @@ -169,7 +169,7 @@ bool Launcher::GameSettings::writeFile(QTextStream &stream) return true; } -bool GameSettings::hasMaster() +bool Launcher::GameSettings::hasMaster() { bool result = false; QStringList content = mSettings.values(QString("content")); diff --git a/apps/launcher/settings/gamesettings.hpp b/apps/launcher/settings/gamesettings.hpp index 56917a79f..60236200a 100644 --- a/apps/launcher/settings/gamesettings.hpp +++ b/apps/launcher/settings/gamesettings.hpp @@ -51,11 +51,6 @@ namespace Launcher bool hasMaster(); - inline QStringList getDataDirs() { return mDataDirs; } - inline void addDataDir(const QString &dir) { if(!dir.isEmpty()) mDataDirs.append(dir); } - inline QString getDataLocal() {return mDataLocal; } - inline bool hasMaster() { return mSettings.count(QString("master")) > 0; } - QStringList values(const QString &key, const QStringList &defaultValues = QStringList()); bool readFile(QTextStream &stream); bool writeFile(QTextStream &stream); diff --git a/apps/opencs/view/doc/adjusterwidget.cpp b/apps/opencs/view/doc/adjusterwidget.cpp index 5ebfacd03..09e58690f 100644 --- a/apps/opencs/view/doc/adjusterwidget.cpp +++ b/apps/opencs/view/doc/adjusterwidget.cpp @@ -10,9 +10,6 @@ #include #include -#include - - CSVDoc::AdjusterWidget::AdjusterWidget (QWidget *parent) : QWidget (parent), mValid (false), mAction (ContentAction_Undefined) { @@ -79,8 +76,7 @@ void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon) path.extension() == ".esp"); bool isFilePathChanged = (path.parent_path().string() != mLocalData.string()); - qDebug() << "current path: " << path.parent_path().c_str(); - qDebug() << "data-local: " << mLocalData.c_str(); + if (isLegacyPath) path.replace_extension (addon ? ".omwaddon" : ".omwgame"); diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index ce7d7dfb0..80b3066dd 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -17,8 +17,6 @@ #include "filewidget.hpp" #include "adjusterwidget.hpp" -#include - CSVDoc::FileDialog::FileDialog(QWidget *parent) : QDialog(parent), mSelector (0), mFileWidget (0), mAdjusterWidget (0) { @@ -142,7 +140,6 @@ void CSVDoc::FileDialog::slotUpdateAcceptButton(const QString &name, bool) { ContentSelectorModel::EsmFile *file = mSelector->selectedFiles().back();; mAdjusterWidget->setName (file->filePath(), !file->isGameFile()); - qDebug() << "setting filepath " << file->filePath(); } ui.projectButtonBox->button (QDialogButtonBox::Ok)->setEnabled (success); diff --git a/components/contentselector/model/contentmodel.cpp b/components/contentselector/model/contentmodel.cpp index 065b9c497..7661f9608 100644 --- a/components/contentselector/model/contentmodel.cpp +++ b/components/contentselector/model/contentmodel.cpp @@ -3,9 +3,11 @@ #include #include -#include +#include #include +#include "components/esm/esmreader.hpp" + ContentSelectorModel::ContentModel::ContentModel(QObject *parent) : QAbstractTableModel(parent), mMimeType ("application/omwcontent"), @@ -380,15 +382,18 @@ bool ContentSelectorModel::ContentModel::canBeChecked(const EsmFile *file) const //addon can be checked if its gamefile is foreach (const QString &fileName, file->gameFiles()) { - const EsmFile *dependency = item(fileName); - - if (!dependency) - continue; - - if (dependency->isGameFile()) + foreach (EsmFile *dependency, mFiles) { - if (isChecked(fileName)) - return true; + //compare filenames only. Multiple instances + //of the filename (with different paths) is not relevant here. + if (!(dependency->fileName() == fileName)) + continue; + + if (dependency->isGameFile()) + { + if (isChecked(dependency->filePath())) + return true; + } } } return false; @@ -396,7 +401,6 @@ bool ContentSelectorModel::ContentModel::canBeChecked(const EsmFile *file) const void ContentSelectorModel::ContentModel::addFile(EsmFile *file) { - qDebug() << "adding file: " << file->filePath(); beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count()); mFiles.append(file); endInsertRows(); @@ -418,8 +422,6 @@ void ContentSelectorModel::ContentModel::addFiles(const QString &path) // Create a decoder for non-latin characters in esx metadata QTextDecoder *decoder = codec->makeDecoder(); - qDebug() << "searching path: " << path << " files found: " << dir.entryList().size(); - foreach (const QString &path, dir.entryList()) { QFileInfo info(dir.absoluteFilePath(path)); @@ -433,10 +435,7 @@ void ContentSelectorModel::ContentModel::addFiles(const QString &path) fileReader.open(dir.absoluteFilePath(path).toStdString()); foreach (const ESM::Header::MasterData &item, fileReader.getGameFiles()) - { - qDebug() << "adding gamefile: " << item.name.c_str(); file->addGameFile(QString::fromStdString(item.name)); - } file->setAuthor (decoder->toUnicode(fileReader.getAuthor().c_str())); file->setDate (info.lastModified()); @@ -447,10 +446,7 @@ void ContentSelectorModel::ContentModel::addFiles(const QString &path) // Put the file in the table if (item(file->filePath()) == 0) - { - qDebug () << "adding file " << file->filePath(); addFile(file); - } } catch(std::runtime_error &e) { // An error occurred while reading the .esp @@ -510,10 +506,23 @@ bool ContentSelectorModel::ContentModel::isChecked(const QString& name) const return false; } -void ContentSelectorModel::ContentModel::setCheckState(const QString &name, bool checkState) +void ContentSelectorModel::ContentModel::setCheckStates (const QStringList &fileList, bool isChecked) +{ + foreach (const QString &file, fileList) + { + setCheckState (file, isChecked); + } +} + +bool ContentSelectorModel::ContentModel::setCheckState(const QString &name, bool checkState) { if (name.isEmpty()) - return; + return false; + + const EsmFile *file = item(name); + + if (!file) + return false; Qt::CheckState state = Qt::Unchecked; @@ -523,8 +532,6 @@ void ContentSelectorModel::ContentModel::setCheckState(const QString &name, bool mCheckStates[name] = state; emit dataChanged(indexFromItem(item(name)), indexFromItem(item(name))); - const EsmFile *file = item(name); - if (file->isGameFile()) emit dataChanged (index(0,0), index(rowCount()-1,0)); @@ -559,29 +566,20 @@ void ContentSelectorModel::ContentModel::setCheckState(const QString &name, bool } } } + + return true; } ContentSelectorModel::ContentFileList ContentSelectorModel::ContentModel::checkedItems() const { ContentFileList list; + // TODO: // First search for game files and next addons, // so we get more or less correct game files vs addons order. foreach (EsmFile *file, mFiles) - { -<<<<<<< HEAD if (isChecked(file->filePath())) -======= - if (isChecked(file->fileName()) && file->isGameFile()) list << file; - } - - foreach (EsmFile *file, mFiles) - { - if (isChecked(file->fileName()) && !file->isGameFile()) ->>>>>>> f5fbe7361fad698e8dd3330e9820a157800be8ae - list << file; - } return list; } diff --git a/components/contentselector/model/contentmodel.hpp b/components/contentselector/model/contentmodel.hpp index 0d6c52cc6..ae49dd27d 100644 --- a/components/contentselector/model/contentmodel.hpp +++ b/components/contentselector/model/contentmodel.hpp @@ -45,7 +45,8 @@ namespace ContentSelectorModel const EsmFile *item(const QString &name) const; bool isChecked(const QString &name) const; - void setCheckState(const QString &name, bool isChecked); + bool setCheckState(const QString &name, bool isChecked); + void setCheckStates (const QStringList &fileList, bool isChecked); ContentFileList checkedItems() const; void uncheckAll(); diff --git a/components/contentselector/model/esmfile.cpp b/components/contentselector/model/esmfile.cpp index 35f78386c..a0a09105a 100644 --- a/components/contentselector/model/esmfile.cpp +++ b/components/contentselector/model/esmfile.cpp @@ -6,8 +6,9 @@ int ContentSelectorModel::EsmFile::sPropertyCount = 7; QString ContentSelectorModel::EsmFile::sToolTip = QString("Author: %1
\ Version: %2
\ -
Description:
%3
\ -
Dependencies: %4
"); + Path:
%3
\ +
Description:
%4
\ +
Dependencies: %5
"); ContentSelectorModel::EsmFile::EsmFile(QString fileName, ModelItem *parent) diff --git a/components/contentselector/model/esmfile.hpp b/components/contentselector/model/esmfile.hpp index fc0cca8a2..ca24b52d1 100644 --- a/components/contentselector/model/esmfile.hpp +++ b/components/contentselector/model/esmfile.hpp @@ -57,6 +57,7 @@ namespace ContentSelectorModel inline QString description() const { return mDescription; } inline QString toolTip() const { return sToolTip.arg(mAuthor) .arg(mFormat) + .arg(mPath) .arg(mDescription) .arg(mGameFiles.join(", ")); } diff --git a/components/contentselector/view/contentselector.cpp b/components/contentselector/view/contentselector.cpp index d12c8cb24..4758dd5a0 100644 --- a/components/contentselector/view/contentselector.cpp +++ b/components/contentselector/view/contentselector.cpp @@ -67,10 +67,15 @@ void ContentSelectorView::ContentSelector::setGameFile(const QString &filename) if (!filename.isEmpty()) { - index = ui.gameFileView->findText(filename); + const ContentSelectorModel::EsmFile *file = mContentModel->item (filename); + index = ui.gameFileView->findText (file->fileName()); //verify that the current index is also checked in the model - mContentModel->setCheckState(filename, true); + if (!mContentModel->setCheckState(filename, true)) + { + //throw error in case file not found? + return; + } } ui.gameFileView->setCurrentIndex(index); @@ -86,8 +91,7 @@ void ContentSelectorView::ContentSelector::setCheckStates(const QStringList &lis if (list.isEmpty()) return; - foreach (const QString &file, list) - mContentModel->setCheckState(file, Qt::Checked); + mContentModel->setCheckStates (list, true); } ContentSelectorModel::ContentFileList