Fixed pathing issues in launcher

actorid
graffy76 11 years ago
parent 8d12e2b99d
commit 973803eb2f

@ -5,7 +5,6 @@
#include <QCheckBox> #include <QCheckBox>
#include <QMenu> #include <QMenu>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QDebug>
#include <components/files/configurationmanager.hpp> #include <components/files/configurationmanager.hpp>
@ -37,6 +36,10 @@ Launcher::DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSet
void Launcher::DataFilesPage::loadSettings() void Launcher::DataFilesPage::loadSettings()
{ {
QStringList paths = mGameSettings.getDataDirs();
paths.insert (0, mDataLocal);
PathIterator pathIterator (paths);
QString profileName = ui.profilesComboBox->currentText(); QString profileName = ui.profilesComboBox->currentText();
QStringList files = mLauncherSettings.values(QString("Profiles/") + profileName + QString("/game"), Qt::MatchExactly); QStringList files = mLauncherSettings.values(QString("Profiles/") + profileName + QString("/game"), Qt::MatchExactly);
@ -47,10 +50,37 @@ void Launcher::DataFilesPage::loadSettings()
QString gameFile (""); QString gameFile ("");
if (files.size()>0) if (files.size()>0)
gameFile = files.at (0); {
gameFile = pathIterator.findFirstPath (files.at(0));
if (!gameFile.isEmpty())
mSelector->setGameFile (gameFile);
/* else
{
//throw gamefile error here.
}*/
}
QStringList missingFiles;
QStringList foundFiles;
mSelector->setGameFile(gameFile); foreach (const QString &addon, addons)
mSelector->setCheckStates(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) void Launcher::DataFilesPage::saveSettings(const QString &profile)
@ -191,10 +221,10 @@ void Launcher::DataFilesPage::setupDataFiles()
foreach (const QString &path, paths) foreach (const QString &path, paths)
mSelector->addFiles(path); mSelector->addFiles(path);
QString dataLocal = mGameSettings.getDataLocal(); mDataLocal = mGameSettings.getDataLocal();
if (!dataLocal.isEmpty()) if (!mDataLocal.isEmpty())
mSelector->addFiles(dataLocal); mSelector->addFiles(mDataLocal);
QStringList profiles = mLauncherSettings.subKeys(QString("Profiles/")); QStringList profiles = mLauncherSettings.subKeys(QString("Profiles/"));
QString profile = mLauncherSettings.value(QString("Profiles/currentprofile")); QString profile = mLauncherSettings.value(QString("Profiles/currentprofile"));

@ -4,6 +4,10 @@
#include "ui_datafilespage.h" #include "ui_datafilespage.h"
#include <QWidget> #include <QWidget>
#include <QDir>
#include <QFile>
class QSortFilterProxyModel; class QSortFilterProxyModel;
class QAbstractItemModel; class QAbstractItemModel;
class QMenu; class QMenu;
@ -61,6 +65,8 @@ namespace Launcher
GameSettings &mGameSettings; GameSettings &mGameSettings;
LauncherSettings &mLauncherSettings; LauncherSettings &mLauncherSettings;
QString mDataLocal;
void setPluginsCheckstates(Qt::CheckState state); void setPluginsCheckstates(Qt::CheckState state);
void buildView(); void buildView();
@ -73,6 +79,58 @@ namespace Launcher
bool showDeleteMessageBox (const QString &text); bool showDeleteMessageBox (const QString &text);
void addProfile (const QString &profile, bool setAsCurrent); void addProfile (const QString &profile, bool setAsCurrent);
void checkForDefaultProfile(); 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 #endif

@ -169,7 +169,7 @@ bool Launcher::GameSettings::writeFile(QTextStream &stream)
return true; return true;
} }
bool GameSettings::hasMaster() bool Launcher::GameSettings::hasMaster()
{ {
bool result = false; bool result = false;
QStringList content = mSettings.values(QString("content")); QStringList content = mSettings.values(QString("content"));

@ -51,11 +51,6 @@ namespace Launcher
bool hasMaster(); 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()); QStringList values(const QString &key, const QStringList &defaultValues = QStringList());
bool readFile(QTextStream &stream); bool readFile(QTextStream &stream);
bool writeFile(QTextStream &stream); bool writeFile(QTextStream &stream);

@ -10,9 +10,6 @@
#include <QLabel> #include <QLabel>
#include <QStyle> #include <QStyle>
#include <QDebug>
CSVDoc::AdjusterWidget::AdjusterWidget (QWidget *parent) CSVDoc::AdjusterWidget::AdjusterWidget (QWidget *parent)
: QWidget (parent), mValid (false), mAction (ContentAction_Undefined) : QWidget (parent), mValid (false), mAction (ContentAction_Undefined)
{ {
@ -79,8 +76,7 @@ void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon)
path.extension() == ".esp"); path.extension() == ".esp");
bool isFilePathChanged = (path.parent_path().string() != mLocalData.string()); bool isFilePathChanged = (path.parent_path().string() != mLocalData.string());
qDebug() << "current path: " << path.parent_path().c_str();
qDebug() << "data-local: " << mLocalData.c_str();
if (isLegacyPath) if (isLegacyPath)
path.replace_extension (addon ? ".omwaddon" : ".omwgame"); path.replace_extension (addon ? ".omwaddon" : ".omwgame");

@ -17,8 +17,6 @@
#include "filewidget.hpp" #include "filewidget.hpp"
#include "adjusterwidget.hpp" #include "adjusterwidget.hpp"
#include <QDebug>
CSVDoc::FileDialog::FileDialog(QWidget *parent) : CSVDoc::FileDialog::FileDialog(QWidget *parent) :
QDialog(parent), mSelector (0), mFileWidget (0), mAdjusterWidget (0) 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();; ContentSelectorModel::EsmFile *file = mSelector->selectedFiles().back();;
mAdjusterWidget->setName (file->filePath(), !file->isGameFile()); mAdjusterWidget->setName (file->filePath(), !file->isGameFile());
qDebug() << "setting filepath " << file->filePath();
} }
ui.projectButtonBox->button (QDialogButtonBox::Ok)->setEnabled (success); ui.projectButtonBox->button (QDialogButtonBox::Ok)->setEnabled (success);

@ -3,9 +3,11 @@
#include <QDir> #include <QDir>
#include <QTextCodec> #include <QTextCodec>
#include <components/esm/esmreader.hpp> #include <QMessageBox>
#include <QDebug> #include <QDebug>
#include "components/esm/esmreader.hpp"
ContentSelectorModel::ContentModel::ContentModel(QObject *parent) : ContentSelectorModel::ContentModel::ContentModel(QObject *parent) :
QAbstractTableModel(parent), QAbstractTableModel(parent),
mMimeType ("application/omwcontent"), mMimeType ("application/omwcontent"),
@ -380,15 +382,18 @@ bool ContentSelectorModel::ContentModel::canBeChecked(const EsmFile *file) const
//addon can be checked if its gamefile is //addon can be checked if its gamefile is
foreach (const QString &fileName, file->gameFiles()) foreach (const QString &fileName, file->gameFiles())
{ {
const EsmFile *dependency = item(fileName); foreach (EsmFile *dependency, mFiles)
if (!dependency)
continue;
if (dependency->isGameFile())
{ {
if (isChecked(fileName)) //compare filenames only. Multiple instances
return true; //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; return false;
@ -396,7 +401,6 @@ bool ContentSelectorModel::ContentModel::canBeChecked(const EsmFile *file) const
void ContentSelectorModel::ContentModel::addFile(EsmFile *file) void ContentSelectorModel::ContentModel::addFile(EsmFile *file)
{ {
qDebug() << "adding file: " << file->filePath();
beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count()); beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count());
mFiles.append(file); mFiles.append(file);
endInsertRows(); endInsertRows();
@ -418,8 +422,6 @@ void ContentSelectorModel::ContentModel::addFiles(const QString &path)
// Create a decoder for non-latin characters in esx metadata // Create a decoder for non-latin characters in esx metadata
QTextDecoder *decoder = codec->makeDecoder(); QTextDecoder *decoder = codec->makeDecoder();
qDebug() << "searching path: " << path << " files found: " << dir.entryList().size();
foreach (const QString &path, dir.entryList()) foreach (const QString &path, dir.entryList())
{ {
QFileInfo info(dir.absoluteFilePath(path)); QFileInfo info(dir.absoluteFilePath(path));
@ -433,10 +435,7 @@ void ContentSelectorModel::ContentModel::addFiles(const QString &path)
fileReader.open(dir.absoluteFilePath(path).toStdString()); fileReader.open(dir.absoluteFilePath(path).toStdString());
foreach (const ESM::Header::MasterData &item, fileReader.getGameFiles()) foreach (const ESM::Header::MasterData &item, fileReader.getGameFiles())
{
qDebug() << "adding gamefile: " << item.name.c_str();
file->addGameFile(QString::fromStdString(item.name)); file->addGameFile(QString::fromStdString(item.name));
}
file->setAuthor (decoder->toUnicode(fileReader.getAuthor().c_str())); file->setAuthor (decoder->toUnicode(fileReader.getAuthor().c_str()));
file->setDate (info.lastModified()); file->setDate (info.lastModified());
@ -447,10 +446,7 @@ void ContentSelectorModel::ContentModel::addFiles(const QString &path)
// Put the file in the table // Put the file in the table
if (item(file->filePath()) == 0) if (item(file->filePath()) == 0)
{
qDebug () << "adding file " << file->filePath();
addFile(file); addFile(file);
}
} catch(std::runtime_error &e) { } catch(std::runtime_error &e) {
// An error occurred while reading the .esp // An error occurred while reading the .esp
@ -510,10 +506,23 @@ bool ContentSelectorModel::ContentModel::isChecked(const QString& name) const
return false; 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()) if (name.isEmpty())
return; return false;
const EsmFile *file = item(name);
if (!file)
return false;
Qt::CheckState state = Qt::Unchecked; Qt::CheckState state = Qt::Unchecked;
@ -523,8 +532,6 @@ void ContentSelectorModel::ContentModel::setCheckState(const QString &name, bool
mCheckStates[name] = state; mCheckStates[name] = state;
emit dataChanged(indexFromItem(item(name)), indexFromItem(item(name))); emit dataChanged(indexFromItem(item(name)), indexFromItem(item(name)));
const EsmFile *file = item(name);
if (file->isGameFile()) if (file->isGameFile())
emit dataChanged (index(0,0), index(rowCount()-1,0)); 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 ContentSelectorModel::ContentFileList ContentSelectorModel::ContentModel::checkedItems() const
{ {
ContentFileList list; ContentFileList list;
// TODO:
// First search for game files and next addons, // First search for game files and next addons,
// so we get more or less correct game files vs addons order. // so we get more or less correct game files vs addons order.
foreach (EsmFile *file, mFiles) foreach (EsmFile *file, mFiles)
{
<<<<<<< HEAD
if (isChecked(file->filePath())) 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; list << file;
}
return list; return list;
} }

@ -45,7 +45,8 @@ namespace ContentSelectorModel
const EsmFile *item(const QString &name) const; const EsmFile *item(const QString &name) const;
bool isChecked(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; ContentFileList checkedItems() const;
void uncheckAll(); void uncheckAll();

@ -6,8 +6,9 @@
int ContentSelectorModel::EsmFile::sPropertyCount = 7; int ContentSelectorModel::EsmFile::sPropertyCount = 7;
QString ContentSelectorModel::EsmFile::sToolTip = QString("<b>Author:</b> %1<br/> \ QString ContentSelectorModel::EsmFile::sToolTip = QString("<b>Author:</b> %1<br/> \
<b>Version:</b> %2<br/> \ <b>Version:</b> %2<br/> \
<br/><b>Description:</b><br/>%3<br/> \ <b>Path:</b><br/>%3<br/> \
<br/><b>Dependencies: </b>%4<br/>"); <br/><b>Description:</b><br/>%4<br/> \
<br/><b>Dependencies: </b>%5<br/>");
ContentSelectorModel::EsmFile::EsmFile(QString fileName, ModelItem *parent) ContentSelectorModel::EsmFile::EsmFile(QString fileName, ModelItem *parent)

@ -57,6 +57,7 @@ namespace ContentSelectorModel
inline QString description() const { return mDescription; } inline QString description() const { return mDescription; }
inline QString toolTip() const { return sToolTip.arg(mAuthor) inline QString toolTip() const { return sToolTip.arg(mAuthor)
.arg(mFormat) .arg(mFormat)
.arg(mPath)
.arg(mDescription) .arg(mDescription)
.arg(mGameFiles.join(", ")); .arg(mGameFiles.join(", "));
} }

@ -67,10 +67,15 @@ void ContentSelectorView::ContentSelector::setGameFile(const QString &filename)
if (!filename.isEmpty()) 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 //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); ui.gameFileView->setCurrentIndex(index);
@ -86,8 +91,7 @@ void ContentSelectorView::ContentSelector::setCheckStates(const QStringList &lis
if (list.isEmpty()) if (list.isEmpty())
return; return;
foreach (const QString &file, list) mContentModel->setCheckStates (list, true);
mContentModel->setCheckState(file, Qt::Checked);
} }
ContentSelectorModel::ContentFileList ContentSelectorModel::ContentFileList

Loading…
Cancel
Save