Fixed pathing issues in launcher

This commit is contained in:
graffy76 2013-11-03 00:02:46 -05:00
parent 8d12e2b99d
commit 973803eb2f
11 changed files with 143 additions and 62 deletions

View file

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

View file

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

View file

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

View file

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

View file

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