From 8ea31e5050f5ed83009b68a41effb57903218ee3 Mon Sep 17 00:00:00 2001 From: pvdk Date: Tue, 24 Dec 2013 19:38:21 +0100 Subject: [PATCH] Working on a Morrowind.ini reader --- apps/wizard/CMakeLists.txt | 32 ++++----------- apps/wizard/inisettings.cpp | 68 ++++++++++++++++++++++++++++++++ apps/wizard/inisettings.hpp | 45 +++++++++++++++++++++ apps/wizard/installationpage.cpp | 64 ++++++++++++++++++++++++++++++ 4 files changed, 185 insertions(+), 24 deletions(-) create mode 100644 apps/wizard/inisettings.cpp create mode 100644 apps/wizard/inisettings.hpp diff --git a/apps/wizard/CMakeLists.txt b/apps/wizard/CMakeLists.txt index 741f790b5a..7639cc8e17 100644 --- a/apps/wizard/CMakeLists.txt +++ b/apps/wizard/CMakeLists.txt @@ -3,6 +3,7 @@ set(WIZARD conclusionpage.cpp existinginstallationpage.cpp importpage.cpp + inisettings.cpp installationpage.cpp installationtargetpage.cpp intropage.cpp @@ -10,31 +11,27 @@ set(WIZARD main.cpp mainwizard.cpp methodselectionpage.cpp + unshieldthread.cpp utils/componentlistwidget.cpp ) -# if(NOT WIN32) -# LIST(APPEND WIZARD unshieldthread.cpp) -# endif(NOT WIN32) set(WIZARD_HEADER componentselectionpage.hpp conclusionpage.hpp existinginstallationpage.hpp importpage.hpp + inisettings.hpp installationpage.hpp installationtargetpage.hpp intropage.hpp languageselectionpage.hpp mainwizard.hpp methodselectionpage.hpp + unshieldthread.hpp utils/componentlistwidget.hpp ) -# if(NOT WIN32) -# LIST(APPEND WIZARD_HEADER unshieldthread.hpp) -# endif(NOT WIN32) - # Headers that must be pre-processed set(WIZARD_HEADER_MOC @@ -48,15 +45,11 @@ set(WIZARD_HEADER_MOC languageselectionpage.hpp mainwizard.hpp methodselectionpage.hpp + unshieldthread.hpp utils/componentlistwidget.hpp ) -# if(NOT WIN32) -# LIST(APPEND WIZARD_HEADER_MOC unshieldthread.hpp) -# endif(NOT WIN32) - - set(WIZARD_UI ${CMAKE_SOURCE_DIR}/files/ui/wizard/componentselectionpage.ui ${CMAKE_SOURCE_DIR}/files/ui/wizard/conclusionpage.ui @@ -86,10 +79,7 @@ QT4_WRAP_UI(UI_HDRS ${WIZARD_UI}) include(${QT_USE_FILE}) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) -if(NOT WIN32) - include_directories(${LIBUNSHIELD_INCLUDE}) -endif(NOT WIN32) +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${LIBUNSHIELD_INCLUDE}) add_executable(openmw-wizard ${GUI_TYPE} @@ -101,16 +91,10 @@ add_executable(openmw-wizard ) target_link_libraries(openmw-wizard -# ${Boost_LIBRARIES} + ${Boost_LIBRARIES} ${QT_LIBRARIES} + ${LIBUNSHIELD_LIBRARY} ) -if(NOT WIN32) - target_link_libraries(openmw-wizard - ${LIBUNSHIELD_LIBRARY} - ) -endif(NOT WIN32) - - if(DPKG_PROGRAM) INSTALL(TARGETS openmw-wizard RUNTIME DESTINATION games COMPONENT openmw-wizard) diff --git a/apps/wizard/inisettings.cpp b/apps/wizard/inisettings.cpp new file mode 100644 index 0000000000..8bdac5ad0f --- /dev/null +++ b/apps/wizard/inisettings.cpp @@ -0,0 +1,68 @@ +#include "inisettings.hpp" + + +#include +#include +#include +#include +#include + +Wizard::IniSettings::IniSettings() +{ +} + +Wizard::IniSettings::~IniSettings() +{ +} + +bool Wizard::IniSettings::readFile(QTextStream &stream) +{ + // Look for a square bracket, "'\\[" + // that has one or more "not nothing" in it, "([^]]+)" + // and is closed with a square bracket, "\\]" + QRegExp sectionRe("^\\[([^]]+)\\]"); + + // Find any character(s) that is/are not equal sign(s), "[^=]+" + // followed by an optional whitespace, an equal sign, and another optional whitespace, "\\s*=\\s*" + // and one or more periods, "(.+)" + QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$"); + + QString currentSection; + + while (!stream.atEnd()) + { + const QString &line = stream.readLine(); + + if (line.isEmpty() || line.startsWith(";")) + continue; + + if (sectionRe.exactMatch(line)) + { + currentSection = sectionRe.cap(1); + } + else if (keyRe.indexIn(line) != -1) + { + QString key = keyRe.cap(1).trimmed(); + QString value = keyRe.cap(2).trimmed(); + + // Append the section, but only if there is one + if (!currentSection.isEmpty()) + key = currentSection + QLatin1Char('/') + key; + + mSettings[key] = QVariant(value); + } + } + + return true; +} + +bool Wizard::IniSettings::writeFile(QTextStream &stream) +{ + qDebug() << "test! " << stream.readAll(); + + while (!stream.atEnd()) { + qDebug() << "test! " << stream.readLine(); + } + + return true; +} diff --git a/apps/wizard/inisettings.hpp b/apps/wizard/inisettings.hpp new file mode 100644 index 0000000000..66fe96ec1f --- /dev/null +++ b/apps/wizard/inisettings.hpp @@ -0,0 +1,45 @@ +#ifndef INISETTINGS_HPP +#define INISETTINGS_HPP + +#include +#include + +class QTextStream; + +namespace Wizard +{ + + typedef QHash SettingsMap; + + class IniSettings + { + public: + explicit IniSettings(); + ~IniSettings(); + + inline QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const + { + return mSettings.value(key, defaultValue); + } + + inline void setValue(const QString &key, const QVariant &value) + { + mSettings.insert(key, value); + } + + inline void remove(const QString &key) + { + mSettings.remove(key); + } + + bool readFile(QTextStream &stream); + bool writeFile(QTextStream &stream); + + private: + + SettingsMap mSettings; + }; + +} + +#endif // INISETTINGS_HPP diff --git a/apps/wizard/installationpage.cpp b/apps/wizard/installationpage.cpp index 632b9c6a62..5d943dbfa2 100644 --- a/apps/wizard/installationpage.cpp +++ b/apps/wizard/installationpage.cpp @@ -1,8 +1,12 @@ #include "installationpage.hpp" #include +#include +#include +#include #include "mainwizard.hpp" +#include "inisettings.hpp" Wizard::InstallationPage::InstallationPage(MainWizard *wizard) : QWizardPage(wizard), @@ -19,6 +23,66 @@ void Wizard::InstallationPage::initializePage() logTextEdit->append(QString("Installing to %1").arg(path)); logTextEdit->append(QString("Installing %1.").arg(components.join(", "))); + installProgressBar->setMinimum(0); + + // Set the progressbar maximum to a multiple of 100 + // That way installing all three components would yield 300% + // When one component is done the bar will be filled by 33% + + if (field("installation.new").toBool() == true) + { + installProgressBar->setMaximum((components.count() * 100)); + } + else + { + if (components.contains("Tribunal") && mWizard->mInstallations[path]->hasTribunal == false) + installProgressBar->setMaximum(100); + + if (components.contains("Bloodmoon") && mWizard->mInstallations[path]->hasBloodmoon == false) + installProgressBar->setMaximum(installProgressBar->maximum() + 100); + } + + installProgressBar->setValue(100); + + // Test settings + IniSettings iniSettings; + + QFile file("/home/pvdk/.wine/drive_c/Program Files/Bethesda Softworks/Morrowind/Morrowind.ini"); + + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error opening OpenMW configuration file")); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(QObject::tr("
Could not open %0 for reading

\ + Please make sure you have the right permissions \ + and try again.
").arg(file.fileName())); + msgBox.exec(); + } + + QTextStream stream(&file); + + QString language = field("installation.language").toString(); + + if (language == QLatin1String("English") || + language == QLatin1String("German") || + language == QLatin1String("French")) + { + stream.setCodec(QTextCodec::codecForName("windows-1252")); + } + else if (language == QLatin1String("Russian")) + { + stream.setCodec(QTextCodec::codecForName("windows-1251")); + } + else if (language == QLatin1String("Polish")) + { + stream.setCodec(QTextCodec::codecForName("windows-1250")); + } + + iniSettings.readFile(stream); + + qDebug() << iniSettings.value("Game Files/GameFile0"); + } int Wizard::InstallationPage::nextId() const