Fixed pathing issues in launcher

actorid
graffy76 11 years ago
parent 8d12e2b99d
commit 973803eb2f

@ -5,7 +5,6 @@
#include <QCheckBox>
#include <QMenu>
#include <QSortFilterProxyModel>
#include <QDebug>
#include <components/files/configurationmanager.hpp>
@ -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));
if (!gameFile.isEmpty())
mSelector->setGameFile (gameFile);
/* else
{
//throw gamefile error here.
}*/
}
QStringList missingFiles;
QStringList foundFiles;
mSelector->setGameFile(gameFile);
mSelector->setCheckStates(addons);
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"));

@ -4,6 +4,10 @@
#include "ui_datafilespage.h"
#include <QWidget>
#include <QDir>
#include <QFile>
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

@ -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"));

@ -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);

@ -10,9 +10,6 @@
#include <QLabel>
#include <QStyle>
#include <QDebug>
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");

@ -17,8 +17,6 @@
#include "filewidget.hpp"
#include "adjusterwidget.hpp"
#include <QDebug>
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);

@ -3,9 +3,11 @@
#include <QDir>
#include <QTextCodec>
#include <components/esm/esmreader.hpp>
#include <QMessageBox>
#include <QDebug>
#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;
}

@ -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();

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

@ -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(", "));
}

@ -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

Loading…
Cancel
Save