mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +00:00
Modified the launcher to use the new multi-dir plugin approach
This commit is contained in:
parent
ac965af671
commit
b877a94481
3 changed files with 71 additions and 33 deletions
|
@ -4,11 +4,14 @@
|
||||||
|
|
||||||
#include <components/esm/esm_reader.hpp>
|
#include <components/esm/esm_reader.hpp>
|
||||||
#include <components/files/path.hpp>
|
#include <components/files/path.hpp>
|
||||||
|
#include <components/files/collections.hpp>
|
||||||
|
#include <components/files/multidircollection.hpp>
|
||||||
|
|
||||||
#include "datafilespage.hpp"
|
#include "datafilespage.hpp"
|
||||||
#include "lineedit.hpp"
|
#include "lineedit.hpp"
|
||||||
|
|
||||||
using namespace ESM;
|
using namespace ESM;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent)
|
DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
|
@ -130,49 +133,51 @@ DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent)
|
||||||
setupConfig();
|
setupConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesPage::setupDataFiles(const QString &path)
|
void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict)
|
||||||
{
|
{
|
||||||
qDebug() << "setupDataFiles called!";
|
qDebug() << "setupDataFiles called!";
|
||||||
// TODO: Add a warning when a master is missing
|
|
||||||
|
|
||||||
QDir dataFilesDir(path);
|
// Put the paths in a boost::filesystem vector to use with Files::Collections
|
||||||
|
std::vector<boost::filesystem::path> dataDirs;
|
||||||
|
|
||||||
if (!dataFilesDir.exists())
|
foreach (const QString ¤tPath, paths) {
|
||||||
qWarning("Cannot find the plugin directory");
|
dataDirs.push_back(boost::filesystem::path(currentPath.toStdString()));
|
||||||
|
}
|
||||||
|
|
||||||
// First we add all the master files from the plugin dir
|
// Create a file collection for the dataDirs
|
||||||
dataFilesDir.setNameFilters((QStringList() << "*.esm")); // Only load masters
|
Files::Collections mFileCollections(dataDirs, strict);
|
||||||
|
|
||||||
QStringList masterFiles = dataFilesDir.entryList();
|
// First we add all the master files
|
||||||
|
const Files::MultiDirCollection &esm = mFileCollections.getCollection(".esm");
|
||||||
|
unsigned int i = 0; // Row number
|
||||||
|
|
||||||
for (int i=0; i<masterFiles.count(); ++i)
|
for (Files::MultiDirCollection::TIter iter(esm.begin()); iter!=esm.end(); ++iter)
|
||||||
{
|
{
|
||||||
QString currentMaster = masterFiles.at(i);
|
qDebug() << "Master: " << QString::fromStdString(iter->second.filename().string());
|
||||||
|
|
||||||
|
QString currentMaster = QString::fromStdString(iter->second.filename().string());
|
||||||
const QList<QTableWidgetItem*> itemList = mMastersWidget->findItems(currentMaster, Qt::MatchExactly);
|
const QList<QTableWidgetItem*> itemList = mMastersWidget->findItems(currentMaster, Qt::MatchExactly);
|
||||||
|
|
||||||
if (itemList.isEmpty()) // Master is not yet in the widget
|
if (itemList.isEmpty()) // Master is not yet in the widget
|
||||||
{
|
{
|
||||||
mMastersWidget->insertRow(i);
|
qDebug() << "Master not yet in the widget, rowcount is " << i;
|
||||||
QTableWidgetItem *item = new QTableWidgetItem(currentMaster);
|
|
||||||
mMastersWidget->setItem(i, 0, item);
|
mMastersWidget->insertRow(i);
|
||||||
}
|
QTableWidgetItem *item = new QTableWidgetItem(currentMaster);
|
||||||
|
mMastersWidget->setItem(i, 0, item);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now on to the plugins
|
// Now on to the plugins
|
||||||
dataFilesDir.setNameFilters((QStringList() << "*.esp")); // Only load plugins
|
const Files::MultiDirCollection &esp = mFileCollections.getCollection(".esp");
|
||||||
|
|
||||||
QStringList pluginFiles = dataFilesDir.entryList();
|
for (Files::MultiDirCollection::TIter iter(esp.begin()); iter!=esp.end(); ++iter)
|
||||||
|
|
||||||
for (int i=0; i<pluginFiles.count(); ++i)
|
|
||||||
{
|
{
|
||||||
ESMReader fileReader;
|
ESMReader fileReader;
|
||||||
QString currentFile = pluginFiles.at(i);
|
|
||||||
QStringList availableMasters; // Will contain all found masters
|
QStringList availableMasters; // Will contain all found masters
|
||||||
|
|
||||||
QString filePath = dataFilesDir.absolutePath();
|
fileReader.open(iter->second.string());
|
||||||
filePath.append("/");
|
|
||||||
filePath.append(currentFile);
|
|
||||||
fileReader.open(filePath.toStdString());
|
|
||||||
|
|
||||||
// First we fill the availableMasters and the mMastersWidget
|
// First we fill the availableMasters and the mMastersWidget
|
||||||
ESMReader::MasterList mlist = fileReader.getMasters();
|
ESMReader::MasterList mlist = fileReader.getMasters();
|
||||||
|
@ -185,6 +190,7 @@ void DataFilesPage::setupDataFiles(const QString &path)
|
||||||
|
|
||||||
if (itemList.isEmpty()) // Master is not yet in the widget
|
if (itemList.isEmpty()) // Master is not yet in the widget
|
||||||
{
|
{
|
||||||
|
// TODO: Show warning, missing master
|
||||||
mMastersWidget->insertRow(i);
|
mMastersWidget->insertRow(i);
|
||||||
QTableWidgetItem *item = new QTableWidgetItem(currentMaster);
|
QTableWidgetItem *item = new QTableWidgetItem(currentMaster);
|
||||||
mMastersWidget->setItem(i, 0, item);
|
mMastersWidget->setItem(i, 0, item);
|
||||||
|
@ -193,9 +199,9 @@ void DataFilesPage::setupDataFiles(const QString &path)
|
||||||
|
|
||||||
availableMasters.sort(); // Sort the masters alphabetically
|
availableMasters.sort(); // Sort the masters alphabetically
|
||||||
|
|
||||||
// Now we put the currentFile in the mDataFilesModel under its masters
|
// Now we put the current plugin in the mDataFilesModel under its masters
|
||||||
QStandardItem *parent = new QStandardItem(availableMasters.join(","));
|
QStandardItem *parent = new QStandardItem(availableMasters.join(","));
|
||||||
QStandardItem *child = new QStandardItem(currentFile);
|
QStandardItem *child = new QStandardItem(QString::fromStdString(iter->second.filename().string()));
|
||||||
|
|
||||||
const QList<QStandardItem*> masterList = mDataFilesModel->findItems(availableMasters.join(","));
|
const QList<QStandardItem*> masterList = mDataFilesModel->findItems(availableMasters.join(","));
|
||||||
|
|
||||||
|
@ -210,6 +216,8 @@ void DataFilesPage::setupDataFiles(const QString &path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Better dynamic resizing of rows
|
||||||
|
resizeRows();
|
||||||
readConfig();
|
readConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,11 +488,13 @@ void DataFilesPage::setCheckstate(QModelIndex index)
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (mPluginsModel->data(index, Qt::CheckStateRole) == Qt::Checked) {
|
QModelIndex sourceModelIndex = mPluginsProxyModel->mapToSource(index);
|
||||||
|
|
||||||
|
if (mPluginsModel->data(sourceModelIndex, Qt::CheckStateRole) == Qt::Checked) {
|
||||||
// Selected row is checked, uncheck it
|
// Selected row is checked, uncheck it
|
||||||
mPluginsModel->setData(index, Qt::Unchecked, Qt::CheckStateRole);
|
mPluginsModel->setData(sourceModelIndex, Qt::Unchecked, Qt::CheckStateRole);
|
||||||
} else {
|
} else {
|
||||||
mPluginsModel->setData(index, Qt::Checked, Qt::CheckStateRole);
|
mPluginsModel->setData(sourceModelIndex, Qt::Checked, Qt::CheckStateRole);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +552,7 @@ void DataFilesPage::filterChanged(const QString filter)
|
||||||
{
|
{
|
||||||
QRegExp regExp(filter, Qt::CaseInsensitive, QRegExp::FixedString);
|
QRegExp regExp(filter, Qt::CaseInsensitive, QRegExp::FixedString);
|
||||||
mPluginsProxyModel->setFilterRegExp(regExp);
|
mPluginsProxyModel->setFilterRegExp(regExp);
|
||||||
|
resizeRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesPage::profileChanged(const QString &previous, const QString ¤t)
|
void DataFilesPage::profileChanged(const QString &previous, const QString ¤t)
|
||||||
|
|
|
@ -32,7 +32,7 @@ public:
|
||||||
void readConfig();
|
void readConfig();
|
||||||
void writeConfig(QString profile = QString());
|
void writeConfig(QString profile = QString());
|
||||||
|
|
||||||
void setupDataFiles(const QString &path);
|
void setupDataFiles(const QStringList &paths, bool strict);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void masterSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
void masterSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
|
|
|
@ -94,8 +94,36 @@ void MainDialog::createPages()
|
||||||
mGraphicsPage = new GraphicsPage(this);
|
mGraphicsPage = new GraphicsPage(this);
|
||||||
mDataFilesPage = new DataFilesPage(this);
|
mDataFilesPage = new DataFilesPage(this);
|
||||||
|
|
||||||
QString dataDir = mGameConfig->value("data").toString();
|
// First we retrieve all data= keys from the config
|
||||||
mDataFilesPage->setupDataFiles(dataDir);
|
// We can't use QSettings directly because it
|
||||||
|
// does not support multiple keys with the same name
|
||||||
|
QFile file(mGameConfig->fileName());
|
||||||
|
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
return; // File cannot be opened or created TODO: throw error
|
||||||
|
}
|
||||||
|
|
||||||
|
QTextStream in(&file);
|
||||||
|
|
||||||
|
QStringList dataDirs;
|
||||||
|
|
||||||
|
// Add each data= value
|
||||||
|
while (!in.atEnd()) {
|
||||||
|
QString line = in.readLine();
|
||||||
|
|
||||||
|
if (line.startsWith("data=")) {
|
||||||
|
dataDirs.append(line.remove("data="));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the data-local= key
|
||||||
|
QString dataLocal = mGameConfig->value("data-local").toString();
|
||||||
|
if (!dataLocal.isEmpty()) {
|
||||||
|
dataDirs.append(dataLocal);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now pass the datadirs on to the DataFilesPage
|
||||||
|
mDataFilesPage->setupDataFiles(dataDirs, mGameConfig->value("fs-strict").toBool());
|
||||||
|
|
||||||
// Set the combobox of the play page to imitate the comobox on the datafilespage
|
// Set the combobox of the play page to imitate the comobox on the datafilespage
|
||||||
mPlayPage->mProfilesComboBox->setModel(mDataFilesPage->mProfilesComboBox->model());
|
mPlayPage->mProfilesComboBox->setModel(mDataFilesPage->mProfilesComboBox->model());
|
||||||
|
|
Loading…
Reference in a new issue