forked from teamnwah/openmw-tes3coop
Fixed stylesheet and configuration problems with the launcher and code cleanup
This commit is contained in:
parent
b2b09320fc
commit
280babc719
9 changed files with 169 additions and 270 deletions
|
@ -329,7 +329,7 @@ if(WIN32)
|
|||
FILE(GLOB files "${OpenMW_BINARY_DIR}/Release/*.*")
|
||||
INSTALL(FILES ${files} DESTINATION ".")
|
||||
INSTALL(FILES "${OpenMW_BINARY_DIR}/openmw.cfg.install" DESTINATION "." RENAME "openmw.cfg")
|
||||
INSTALL(FILES "${OpenMW_BINARY_DIR}/launcher.cfg" "${OpenMW_BINARY_DIR}/launcher.qss" DESTINATION ".")
|
||||
INSTALL(FILES "${OpenMW_BINARY_DIR}/launcher.qss" "${OpenMW_BINARY_DIR}/launcher.qss" DESTINATION ".")
|
||||
INSTALL(DIRECTORY "${OpenMW_BINARY_DIR}/resources" DESTINATION ".")
|
||||
|
||||
SET(CPACK_GENERATOR "NSIS")
|
||||
|
|
|
@ -26,7 +26,7 @@ bool rowSmallerThan(const QModelIndex &index1, const QModelIndex &index2)
|
|||
return index1.row() <= index2.row();
|
||||
}
|
||||
|
||||
DataFilesPage::DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent)
|
||||
DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, mCfgMgr(cfg)
|
||||
{
|
||||
|
@ -123,25 +123,89 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent)
|
|||
|
||||
|
||||
setupConfig();
|
||||
setupDataFiles();
|
||||
createActions();
|
||||
}
|
||||
|
||||
void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict)
|
||||
void DataFilesPage::setupConfig()
|
||||
{
|
||||
// Put the paths in a boost::filesystem vector to use with Files::Collections
|
||||
Files::PathContainer dataDirs;
|
||||
QString config = QString::fromStdString((mCfgMgr.getLocalPath() / "launcher.cfg").string());
|
||||
QFile file(config);
|
||||
|
||||
foreach (const QString ¤tPath, paths) {
|
||||
dataDirs.push_back(boost::filesystem::path(currentPath.toStdString()));
|
||||
if (!file.exists()) {
|
||||
config = QString::fromStdString((mCfgMgr.getUserPath() / "launcher.cfg").string());
|
||||
}
|
||||
|
||||
// Open our config file
|
||||
mLauncherConfig = new QSettings(config, QSettings::IniFormat);
|
||||
mLauncherConfig->sync();
|
||||
|
||||
|
||||
// Make sure we have no groups open
|
||||
while (!mLauncherConfig->group().isEmpty()) {
|
||||
mLauncherConfig->endGroup();
|
||||
}
|
||||
|
||||
mLauncherConfig->beginGroup("Profiles");
|
||||
QStringList profiles = mLauncherConfig->childGroups();
|
||||
|
||||
if (profiles.isEmpty()) {
|
||||
// Add a default profile
|
||||
profiles.append("Default");
|
||||
}
|
||||
|
||||
mProfilesComboBox->addItems(profiles);
|
||||
|
||||
QString currentProfile = mLauncherConfig->value("CurrentProfile").toString();
|
||||
|
||||
if (currentProfile.isEmpty()) {
|
||||
// No current profile selected
|
||||
currentProfile = "Default";
|
||||
}
|
||||
mProfilesComboBox->setCurrentIndex(mProfilesComboBox->findText(currentProfile));
|
||||
|
||||
mLauncherConfig->endGroup();
|
||||
|
||||
// Now we connect the combobox to do something if the profile changes
|
||||
// This prevents strange behaviour while reading and appending the profiles
|
||||
connect(mProfilesComboBox, SIGNAL(textChanged(const QString&, const QString&)), this, SLOT(profileChanged(const QString&, const QString&)));
|
||||
}
|
||||
|
||||
|
||||
void DataFilesPage::setupDataFiles()
|
||||
{
|
||||
// We use the Configuration Manager to retrieve the configuration values
|
||||
boost::program_options::variables_map variables;
|
||||
boost::program_options::options_description desc;
|
||||
|
||||
desc.add_options()
|
||||
("data", boost::program_options::value<Files::PathContainer>()->default_value(Files::PathContainer(), "data")->multitoken())
|
||||
("data-local", boost::program_options::value<std::string>()->default_value(""))
|
||||
("fs-strict", boost::program_options::value<bool>()->implicit_value(true)->default_value(false))
|
||||
("encoding", boost::program_options::value<std::string>()->default_value("win1252"));
|
||||
|
||||
mCfgMgr.readConfiguration(variables, desc);
|
||||
|
||||
// Put the paths in a boost::filesystem vector to use with Files::Collections
|
||||
Files::PathContainer dataDirs(variables["data"].as<Files::PathContainer>());
|
||||
mCfgMgr.processPaths(dataDirs);
|
||||
|
||||
std::string local(variables["data-local"].as<std::string>());
|
||||
if (!local.empty())
|
||||
{
|
||||
dataDirs.push_back(Files::PathContainer::value_type(local));
|
||||
}
|
||||
|
||||
if (dataDirs.empty())
|
||||
{
|
||||
dataDirs.push_back(mCfgMgr.getLocalPath());
|
||||
}
|
||||
|
||||
// Create a file collection for the dataDirs
|
||||
Files::Collections mFileCollections(dataDirs, strict);
|
||||
Files::Collections fileCollections(dataDirs, !variables["fs-strict"].as<bool>());
|
||||
|
||||
// First we add all the master files
|
||||
const Files::MultiDirCollection &esm = mFileCollections.getCollection(".esm");
|
||||
const Files::MultiDirCollection &esm = fileCollections.getCollection(".esm");
|
||||
unsigned int i = 0; // Row number
|
||||
|
||||
for (Files::MultiDirCollection::TIter iter(esm.begin()); iter!=esm.end(); ++iter)
|
||||
|
@ -161,14 +225,14 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict)
|
|||
}
|
||||
|
||||
// Now on to the plugins
|
||||
const Files::MultiDirCollection &esp = mFileCollections.getCollection(".esp");
|
||||
const Files::MultiDirCollection &esp = fileCollections.getCollection(".esp");
|
||||
|
||||
for (Files::MultiDirCollection::TIter iter(esp.begin()); iter!=esp.end(); ++iter)
|
||||
{
|
||||
ESMReader fileReader;
|
||||
QStringList availableMasters; // Will contain all found masters
|
||||
|
||||
fileReader.setEncoding("win1252"); // FIXME: This should be configurable!
|
||||
fileReader.setEncoding(variables["encoding"].as<std::string>());
|
||||
fileReader.open(iter->second.string());
|
||||
|
||||
// First we fill the availableMasters and the mMastersWidget
|
||||
|
@ -238,52 +302,6 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict)
|
|||
readConfig();
|
||||
}
|
||||
|
||||
void DataFilesPage::setupConfig()
|
||||
{
|
||||
QString config = (mCfgMgr.getLocalPath() / "launcher.cfg").string().c_str();
|
||||
QFile file(config);
|
||||
|
||||
if (!file.exists()) {
|
||||
config = QString::fromStdString((mCfgMgr.getUserPath() / "launcher.cfg").string());
|
||||
}
|
||||
|
||||
file.setFileName(config); // Just for displaying information
|
||||
|
||||
// Open our config file
|
||||
mLauncherConfig = new QSettings(config, QSettings::IniFormat);
|
||||
mLauncherConfig->sync();
|
||||
|
||||
|
||||
// Make sure we have no groups open
|
||||
while (!mLauncherConfig->group().isEmpty()) {
|
||||
mLauncherConfig->endGroup();
|
||||
}
|
||||
|
||||
mLauncherConfig->beginGroup("Profiles");
|
||||
QStringList profiles = mLauncherConfig->childGroups();
|
||||
|
||||
if (profiles.isEmpty()) {
|
||||
// Add a default profile
|
||||
profiles.append("Default");
|
||||
}
|
||||
|
||||
mProfilesComboBox->addItems(profiles);
|
||||
|
||||
QString currentProfile = mLauncherConfig->value("CurrentProfile").toString();
|
||||
|
||||
if (currentProfile.isEmpty()) {
|
||||
// No current profile selected
|
||||
currentProfile = "Default";
|
||||
}
|
||||
mProfilesComboBox->setCurrentIndex(mProfilesComboBox->findText(currentProfile));
|
||||
|
||||
mLauncherConfig->endGroup();
|
||||
|
||||
// Now we connect the combobox to do something if the profile changes
|
||||
// This prevents strange behaviour while reading and appending the profiles
|
||||
connect(mProfilesComboBox, SIGNAL(textChanged(const QString&, const QString&)), this, SLOT(profileChanged(const QString&, const QString&)));
|
||||
}
|
||||
|
||||
void DataFilesPage::createActions()
|
||||
{
|
||||
// Refresh the plugins
|
||||
|
@ -983,6 +1001,53 @@ void DataFilesPage::writeConfig(QString profile)
|
|||
return;
|
||||
}
|
||||
|
||||
// Prepare the OpenMW config
|
||||
|
||||
// Open the config as a QFile
|
||||
QFile file(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string()));
|
||||
|
||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
||||
// File cannot be opened or created
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle("Error writing OpenMW configuration file");
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setText(tr("<br><b>Could not open or create %0</b><br><br> \
|
||||
Please make sure you have the right permissions and try again.<br>").arg(file.fileName()));
|
||||
msgBox.exec();
|
||||
|
||||
QApplication::exit(1);
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
QByteArray buffer;
|
||||
|
||||
// Remove all previous master/plugin entries from config
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
if (!line.contains("master") && !line.contains("plugin")) {
|
||||
buffer += line += "\n";
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
// Now we write back the other config entries
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle("Error writing OpenMW configuration file");
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setText(tr("<br><b>Could not write to %0</b><br><br> \
|
||||
Please make sure you have the right permissions and try again.<br>").arg(file.fileName()));
|
||||
msgBox.exec();
|
||||
|
||||
QApplication::exit(1);
|
||||
}
|
||||
|
||||
file.write(buffer);
|
||||
QTextStream gameConfig(&file);
|
||||
|
||||
// Make sure we have no groups open
|
||||
while (!mLauncherConfig->group().isEmpty()) {
|
||||
mLauncherConfig->endGroup();
|
||||
|
@ -995,13 +1060,16 @@ void DataFilesPage::writeConfig(QString profile)
|
|||
mLauncherConfig->beginGroup(profile);
|
||||
mLauncherConfig->remove(""); // Clear the subgroup
|
||||
|
||||
// First write the masters to the config
|
||||
const QStringList masterList = selectedMasters();
|
||||
// First write the masters to the configs
|
||||
const QStringList masters = selectedMasters();
|
||||
|
||||
// We don't use foreach because we need i
|
||||
for (int i = 0; i < masterList.size(); ++i) {
|
||||
const QString master = masterList.at(i);
|
||||
mLauncherConfig->setValue(QString("Master%0").arg(i), master);
|
||||
for (int i = 0; i < masters.size(); ++i) {
|
||||
const QString currentMaster = masters.at(i);
|
||||
|
||||
mLauncherConfig->setValue(QString("Master%0").arg(i), currentMaster);
|
||||
gameConfig << "master=" << currentMaster << endl;
|
||||
|
||||
}
|
||||
|
||||
// Now write all checked plugins
|
||||
|
@ -1009,9 +1077,12 @@ void DataFilesPage::writeConfig(QString profile)
|
|||
|
||||
for (int i = 0; i < plugins.size(); ++i)
|
||||
{
|
||||
mLauncherConfig->setValue(QString("Plugin%1").arg(i), plugins.at(i));
|
||||
const QString currentPlugin = plugins.at(i);
|
||||
mLauncherConfig->setValue(QString("Plugin%1").arg(i), currentPlugin);
|
||||
gameConfig << "plugin=" << currentPlugin << endl;
|
||||
}
|
||||
|
||||
file.close();
|
||||
mLauncherConfig->endGroup();
|
||||
mLauncherConfig->endGroup();
|
||||
|
||||
|
|
|
@ -29,16 +29,9 @@ public:
|
|||
DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent = 0);
|
||||
|
||||
ComboBox *mProfilesComboBox;
|
||||
QSettings *mLauncherConfig;
|
||||
|
||||
const QStringList checkedPlugins();
|
||||
const QStringList selectedMasters();
|
||||
void setupConfig();
|
||||
void readConfig();
|
||||
void writeConfig(QString profile = QString());
|
||||
|
||||
void setupDataFiles(const QStringList &paths, bool strict);
|
||||
|
||||
public slots:
|
||||
void masterSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||
void setCheckState(QModelIndex index);
|
||||
|
@ -83,13 +76,20 @@ private:
|
|||
QAction *mCheckAction;
|
||||
QAction *mUncheckAction;
|
||||
|
||||
Files::ConfigurationManager& mCfgMgr;
|
||||
Files::ConfigurationManager &mCfgMgr;
|
||||
|
||||
QSettings *mLauncherConfig;
|
||||
|
||||
const QStringList checkedPlugins();
|
||||
const QStringList selectedMasters();
|
||||
|
||||
void addPlugins(const QModelIndex &index);
|
||||
void removePlugins(const QModelIndex &index);
|
||||
void uncheckPlugins();
|
||||
void createActions();
|
||||
|
||||
void setupDataFiles();
|
||||
void setupConfig();
|
||||
void readConfig();
|
||||
void scrollToSelection();
|
||||
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "graphicspage.hpp"
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
|
||||
GraphicsPage::GraphicsPage(Files::ConfigurationManager& cfg, QWidget *parent)
|
||||
GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, mCfgMgr(cfg)
|
||||
{
|
||||
|
|
|
@ -20,9 +20,7 @@ class GraphicsPage : public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GraphicsPage(Files::ConfigurationManager& cfg, QWidget *parent = 0);
|
||||
|
||||
QSettings *mOgreConfig;
|
||||
GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent = 0);
|
||||
|
||||
void writeConfig();
|
||||
|
||||
|
@ -30,7 +28,6 @@ public slots:
|
|||
void rendererChanged(const QString &renderer);
|
||||
|
||||
private:
|
||||
Files::ConfigurationManager& mCfgMgr;
|
||||
Ogre::Root *mOgre;
|
||||
Ogre::RenderSystem *mSelectedRenderSystem;
|
||||
Ogre::RenderSystem *mOpenGLRenderSystem;
|
||||
|
@ -60,6 +57,10 @@ private:
|
|||
QCheckBox *mD3DVSyncCheckBox;
|
||||
QCheckBox *mD3DFullScreenCheckBox;
|
||||
|
||||
QSettings *mOgreConfig;
|
||||
|
||||
Files::ConfigurationManager &mCfgMgr;
|
||||
|
||||
QString getConfigValue(const QString &key, Ogre::RenderSystem *renderer);
|
||||
QStringList getAvailableOptions(const QString &key, Ogre::RenderSystem *renderer);
|
||||
|
||||
|
|
|
@ -31,13 +31,6 @@ int main(int argc, char *argv[])
|
|||
|
||||
QDir::setCurrent(dir.absolutePath());
|
||||
|
||||
// Load the stylesheet
|
||||
QFile file("./launcher.qss");
|
||||
|
||||
file.open(QFile::ReadOnly);
|
||||
QString styleSheet = QLatin1String(file.readAll());
|
||||
app.setStyleSheet(styleSheet);
|
||||
|
||||
MainDialog dialog;
|
||||
return dialog.exec();
|
||||
|
||||
|
|
|
@ -45,6 +45,20 @@ MainDialog::MainDialog()
|
|||
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
setMinimumSize(QSize(575, 575));
|
||||
|
||||
// Load the stylesheet
|
||||
QString config = QString::fromStdString((mCfgMgr.getGlobalDataPath() / "launcher.qss").string());
|
||||
QFile file(config);
|
||||
|
||||
if (!file.exists()) {
|
||||
file.setFileName(QString::fromStdString((mCfgMgr.getLocalPath() / "launcher.qss").string()));
|
||||
}
|
||||
|
||||
file.open(QFile::ReadOnly);
|
||||
QString styleSheet = QLatin1String(file.readAll());
|
||||
qApp->setStyleSheet(styleSheet);
|
||||
file.close();
|
||||
|
||||
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(play()));
|
||||
|
||||
|
@ -85,116 +99,13 @@ void MainDialog::createIcons()
|
|||
|
||||
}
|
||||
|
||||
QStringList MainDialog::readConfig(const QString &fileName)
|
||||
{
|
||||
// We can't use QSettings directly because it
|
||||
// does not support multiple keys with the same name
|
||||
QFile file(fileName);
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle("Error opening OpenMW configuration file");
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setText(tr("<br><b>Could not open %0</b><br><br> \
|
||||
Please make sure you have the right permissions and try again.<br>").arg(file.fileName()));
|
||||
msgBox.exec();
|
||||
|
||||
QApplication::exit(); // File cannot be opened or created
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
QStringList dataDirs;
|
||||
QString dataLocal;
|
||||
|
||||
// Read the config line by line
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
|
||||
if (line.startsWith("data=")) {
|
||||
dataDirs.append(line.remove("data="));
|
||||
}
|
||||
|
||||
// Read the data-local key, if more than one are found only the last is used
|
||||
if (line.startsWith("data-local=")) {
|
||||
dataLocal = line.remove("data-local=");
|
||||
}
|
||||
|
||||
// Read fs-strict key
|
||||
if (line.startsWith("fs-strict=")) {
|
||||
QString value = line.remove("fs-strict=");
|
||||
|
||||
(value.toLower() == QLatin1String("true"))
|
||||
? mStrict = true
|
||||
: mStrict = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Add the data-local= key to the end of the dataDirs for priority reasons
|
||||
if (!dataLocal.isEmpty()) {
|
||||
dataDirs.append(dataLocal);
|
||||
}
|
||||
|
||||
if (!dataDirs.isEmpty())
|
||||
{
|
||||
// Reset the global datadirs to the newly read entries
|
||||
// Else return the previous dataDirs because nothing was found in this file;
|
||||
mDataDirs = dataDirs;
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
return mDataDirs;
|
||||
}
|
||||
|
||||
void MainDialog::createPages()
|
||||
{
|
||||
mPlayPage = new PlayPage(this);
|
||||
mGraphicsPage = new GraphicsPage(mCfgMgr, this);
|
||||
mDataFilesPage = new DataFilesPage(mCfgMgr, this);
|
||||
|
||||
// Retrieve all data entries from the configs
|
||||
QStringList dataDirs;
|
||||
|
||||
// Global location
|
||||
QFile file(QString::fromStdString((mCfgMgr.getGlobalPath()/"openmw.cfg").string()));
|
||||
if (file.exists()) {
|
||||
dataDirs = readConfig(file.fileName());
|
||||
}
|
||||
|
||||
// Local location
|
||||
file.setFileName("./openmw.cfg");
|
||||
|
||||
if (file.exists()) {
|
||||
dataDirs = readConfig(file.fileName());
|
||||
}
|
||||
|
||||
// User location
|
||||
file.setFileName(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string()));
|
||||
if (file.exists()) {
|
||||
dataDirs = readConfig(file.fileName());
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
if (!dataDirs.isEmpty()) {
|
||||
// Now pass the datadirs on to the DataFilesPage
|
||||
mDataFilesPage->setupDataFiles(dataDirs, mStrict);
|
||||
} else {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle("Error reading OpenMW configuration file");
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setText(tr("<br><b>Could not read the location of the data files</b><br><br> \
|
||||
Please make sure OpenMW is correctly configured and try again.<br>"));
|
||||
msgBox.exec();
|
||||
|
||||
QApplication::exit(); // No data or data-local entries in openmw.cfg
|
||||
}
|
||||
|
||||
// Set the combobox of the play page to imitate the comobox on the datafilespage
|
||||
// Set the combobox of the play page to imitate the combobox on the datafilespage
|
||||
mPlayPage->mProfilesComboBox->setModel(mDataFilesPage->mProfilesComboBox->model());
|
||||
mPlayPage->mProfilesComboBox->setCurrentIndex(mDataFilesPage->mProfilesComboBox->currentIndex());
|
||||
|
||||
|
@ -246,14 +157,16 @@ void MainDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
|
|||
void MainDialog::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
// Now write all config files
|
||||
writeConfig();
|
||||
mDataFilesPage->writeConfig();
|
||||
mGraphicsPage->writeConfig();
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void MainDialog::play()
|
||||
{
|
||||
// First do a write of all the configs, just to be sure
|
||||
writeConfig();
|
||||
mDataFilesPage->writeConfig();
|
||||
mGraphicsPage->writeConfig();
|
||||
|
||||
#ifdef Q_WS_WIN
|
||||
QString game = "./openmw.exe";
|
||||
|
@ -313,75 +226,3 @@ void MainDialog::play()
|
|||
close();
|
||||
}
|
||||
}
|
||||
|
||||
void MainDialog::writeConfig()
|
||||
{
|
||||
// Write the profiles
|
||||
mDataFilesPage->writeConfig();
|
||||
mDataFilesPage->mLauncherConfig->sync();
|
||||
|
||||
// Write the graphics settings
|
||||
mGraphicsPage->writeConfig();
|
||||
mGraphicsPage->mOgreConfig->sync();
|
||||
|
||||
QStringList dataFiles = mDataFilesPage->selectedMasters();
|
||||
dataFiles.append(mDataFilesPage->checkedPlugins());
|
||||
|
||||
// Open the config as a QFile
|
||||
QFile file(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string()));
|
||||
|
||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
||||
// File cannot be opened or created
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle("Error writing OpenMW configuration file");
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setText(tr("<br><b>Could not open or create %0</b><br><br> \
|
||||
Please make sure you have the right permissions and try again.<br>").arg(file.fileName()));
|
||||
msgBox.exec();
|
||||
|
||||
QApplication::exit(1);
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
QByteArray buffer;
|
||||
|
||||
// Remove all previous master/plugin entries from config
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
if (!line.contains("master") && !line.contains("plugin")) {
|
||||
buffer += line += "\n";
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
// Now we write back the other config entries
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle("Error writing OpenMW configuration file");
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setText(tr("<br><b>Could not write to %0</b><br><br> \
|
||||
Please make sure you have the right permissions and try again.<br>").arg(file.fileName()));
|
||||
msgBox.exec();
|
||||
|
||||
QApplication::exit(1);
|
||||
}
|
||||
|
||||
file.write(buffer);
|
||||
|
||||
QTextStream out(&file);
|
||||
|
||||
// Write the list of game files to the config
|
||||
foreach (const QString ¤tFile, dataFiles) {
|
||||
|
||||
if (currentFile.endsWith(QString(".esm"), Qt::CaseInsensitive)) {
|
||||
out << "master=" << currentFile << endl;
|
||||
} else if (currentFile.endsWith(QString(".esp"), Qt::CaseInsensitive)) {
|
||||
out << "plugin=" << currentFile << endl;
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
|
|
@ -28,15 +28,11 @@ public slots:
|
|||
void play();
|
||||
void profileChanged(int index);
|
||||
|
||||
|
||||
private:
|
||||
void createIcons();
|
||||
void createPages();
|
||||
void writeConfig();
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
||||
QStringList readConfig(const QString &fileName);
|
||||
|
||||
QListWidget *mIconWidget;
|
||||
QStackedWidget *mPagesWidget;
|
||||
|
||||
|
@ -44,9 +40,6 @@ private:
|
|||
GraphicsPage *mGraphicsPage;
|
||||
DataFilesPage *mDataFilesPage;
|
||||
|
||||
QStringList mDataDirs;
|
||||
bool mStrict;
|
||||
|
||||
Files::ConfigurationManager mCfgMgr;
|
||||
};
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ void ConfigurationManager::loadConfig(const boost::filesystem::path& path,
|
|||
if (configFileStream.is_open())
|
||||
{
|
||||
boost::program_options::store(boost::program_options::parse_config_file(
|
||||
configFileStream, description), variables);
|
||||
configFileStream, description, true), variables);
|
||||
|
||||
std::cout << "done." << std::endl;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue