Working on a Morrowind.ini reader

pull/136/head
pvdk 11 years ago
parent 30710bad70
commit 8ea31e5050

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

@ -0,0 +1,68 @@
#include "inisettings.hpp"
#include <QTextStream>
#include <QFile>
#include <QString>
#include <QRegExp>
#include <QDebug>
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;
}

@ -0,0 +1,45 @@
#ifndef INISETTINGS_HPP
#define INISETTINGS_HPP
#include <QHash>
#include <QVariant>
class QTextStream;
namespace Wizard
{
typedef QHash<QString, QVariant> 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

@ -1,8 +1,12 @@
#include "installationpage.hpp"
#include <QDebug>
#include <QFile>
#include <QTextCodec>
#include <QMessageBox>
#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("<br><b>Could not open %0 for reading</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").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

Loading…
Cancel
Save