mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
Working on a Morrowind.ini reader
This commit is contained in:
parent
30710bad70
commit
8ea31e5050
4 changed files with 185 additions and 24 deletions
|
@ -3,6 +3,7 @@ set(WIZARD
|
||||||
conclusionpage.cpp
|
conclusionpage.cpp
|
||||||
existinginstallationpage.cpp
|
existinginstallationpage.cpp
|
||||||
importpage.cpp
|
importpage.cpp
|
||||||
|
inisettings.cpp
|
||||||
installationpage.cpp
|
installationpage.cpp
|
||||||
installationtargetpage.cpp
|
installationtargetpage.cpp
|
||||||
intropage.cpp
|
intropage.cpp
|
||||||
|
@ -10,31 +11,27 @@ set(WIZARD
|
||||||
main.cpp
|
main.cpp
|
||||||
mainwizard.cpp
|
mainwizard.cpp
|
||||||
methodselectionpage.cpp
|
methodselectionpage.cpp
|
||||||
|
unshieldthread.cpp
|
||||||
|
|
||||||
utils/componentlistwidget.cpp
|
utils/componentlistwidget.cpp
|
||||||
)
|
)
|
||||||
# if(NOT WIN32)
|
|
||||||
# LIST(APPEND WIZARD unshieldthread.cpp)
|
|
||||||
# endif(NOT WIN32)
|
|
||||||
|
|
||||||
set(WIZARD_HEADER
|
set(WIZARD_HEADER
|
||||||
componentselectionpage.hpp
|
componentselectionpage.hpp
|
||||||
conclusionpage.hpp
|
conclusionpage.hpp
|
||||||
existinginstallationpage.hpp
|
existinginstallationpage.hpp
|
||||||
importpage.hpp
|
importpage.hpp
|
||||||
|
inisettings.hpp
|
||||||
installationpage.hpp
|
installationpage.hpp
|
||||||
installationtargetpage.hpp
|
installationtargetpage.hpp
|
||||||
intropage.hpp
|
intropage.hpp
|
||||||
languageselectionpage.hpp
|
languageselectionpage.hpp
|
||||||
mainwizard.hpp
|
mainwizard.hpp
|
||||||
methodselectionpage.hpp
|
methodselectionpage.hpp
|
||||||
|
unshieldthread.hpp
|
||||||
|
|
||||||
utils/componentlistwidget.hpp
|
utils/componentlistwidget.hpp
|
||||||
)
|
)
|
||||||
# if(NOT WIN32)
|
|
||||||
# LIST(APPEND WIZARD_HEADER unshieldthread.hpp)
|
|
||||||
# endif(NOT WIN32)
|
|
||||||
|
|
||||||
|
|
||||||
# Headers that must be pre-processed
|
# Headers that must be pre-processed
|
||||||
set(WIZARD_HEADER_MOC
|
set(WIZARD_HEADER_MOC
|
||||||
|
@ -48,15 +45,11 @@ set(WIZARD_HEADER_MOC
|
||||||
languageselectionpage.hpp
|
languageselectionpage.hpp
|
||||||
mainwizard.hpp
|
mainwizard.hpp
|
||||||
methodselectionpage.hpp
|
methodselectionpage.hpp
|
||||||
|
unshieldthread.hpp
|
||||||
|
|
||||||
utils/componentlistwidget.hpp
|
utils/componentlistwidget.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# if(NOT WIN32)
|
|
||||||
# LIST(APPEND WIZARD_HEADER_MOC unshieldthread.hpp)
|
|
||||||
# endif(NOT WIN32)
|
|
||||||
|
|
||||||
|
|
||||||
set(WIZARD_UI
|
set(WIZARD_UI
|
||||||
${CMAKE_SOURCE_DIR}/files/ui/wizard/componentselectionpage.ui
|
${CMAKE_SOURCE_DIR}/files/ui/wizard/componentselectionpage.ui
|
||||||
${CMAKE_SOURCE_DIR}/files/ui/wizard/conclusionpage.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(${QT_USE_FILE})
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${LIBUNSHIELD_INCLUDE})
|
||||||
if(NOT WIN32)
|
|
||||||
include_directories(${LIBUNSHIELD_INCLUDE})
|
|
||||||
endif(NOT WIN32)
|
|
||||||
|
|
||||||
add_executable(openmw-wizard
|
add_executable(openmw-wizard
|
||||||
${GUI_TYPE}
|
${GUI_TYPE}
|
||||||
|
@ -101,16 +91,10 @@ add_executable(openmw-wizard
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(openmw-wizard
|
target_link_libraries(openmw-wizard
|
||||||
# ${Boost_LIBRARIES}
|
${Boost_LIBRARIES}
|
||||||
${QT_LIBRARIES}
|
${QT_LIBRARIES}
|
||||||
|
${LIBUNSHIELD_LIBRARY}
|
||||||
)
|
)
|
||||||
if(NOT WIN32)
|
|
||||||
target_link_libraries(openmw-wizard
|
|
||||||
${LIBUNSHIELD_LIBRARY}
|
|
||||||
)
|
|
||||||
endif(NOT WIN32)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(DPKG_PROGRAM)
|
if(DPKG_PROGRAM)
|
||||||
INSTALL(TARGETS openmw-wizard RUNTIME DESTINATION games COMPONENT openmw-wizard)
|
INSTALL(TARGETS openmw-wizard RUNTIME DESTINATION games COMPONENT openmw-wizard)
|
||||||
|
|
68
apps/wizard/inisettings.cpp
Normal file
68
apps/wizard/inisettings.cpp
Normal file
|
@ -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;
|
||||||
|
}
|
45
apps/wizard/inisettings.hpp
Normal file
45
apps/wizard/inisettings.hpp
Normal file
|
@ -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 "installationpage.hpp"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QTextCodec>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "mainwizard.hpp"
|
#include "mainwizard.hpp"
|
||||||
|
#include "inisettings.hpp"
|
||||||
|
|
||||||
Wizard::InstallationPage::InstallationPage(MainWizard *wizard) :
|
Wizard::InstallationPage::InstallationPage(MainWizard *wizard) :
|
||||||
QWizardPage(wizard),
|
QWizardPage(wizard),
|
||||||
|
@ -19,6 +23,66 @@ void Wizard::InstallationPage::initializePage()
|
||||||
logTextEdit->append(QString("Installing to %1").arg(path));
|
logTextEdit->append(QString("Installing to %1").arg(path));
|
||||||
logTextEdit->append(QString("Installing %1.").arg(components.join(", ")));
|
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
|
int Wizard::InstallationPage::nextId() const
|
||||||
|
|
Loading…
Reference in a new issue