From 2ef7fc4e2c4c5e0ecf3f15bbec027b796a452a78 Mon Sep 17 00:00:00 2001
From: dteviot
Date: Sun, 15 Mar 2015 08:08:55 +1300
Subject: [PATCH] Installer work for Windows (Fixes #1621)
1. Correctly reads Windows registry for vanilla MW install location.
2. Populates existing installation page with location of vanilla, when found.
3. On Windows, installer wizard now gets to Import page.
---
apps/wizard/componentselectionpage.cpp | 4 ++++
apps/wizard/existinginstallationpage.cpp | 6 +-----
apps/wizard/mainwizard.cpp | 25 +++++++++++++++++-------
apps/wizard/mainwizard.hpp | 2 ++
components/files/windowspath.cpp | 15 +++-----------
5 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/apps/wizard/componentselectionpage.cpp b/apps/wizard/componentselectionpage.cpp
index 1fcde7857..21a5c58d9 100644
--- a/apps/wizard/componentselectionpage.cpp
+++ b/apps/wizard/componentselectionpage.cpp
@@ -156,9 +156,13 @@ bool Wizard::ComponentSelectionPage::validatePage()
int Wizard::ComponentSelectionPage::nextId() const
{
+#ifdef OPENMW_USE_UNSHIELD
if (isCommitPage()) {
return MainWizard::Page_Installation;
} else {
return MainWizard::Page_Import;
}
+#else
+ return MainWizard::Page_Import;
+#endif
}
diff --git a/apps/wizard/existinginstallationpage.cpp b/apps/wizard/existinginstallationpage.cpp
index 83ea20f5a..f821b38ba 100644
--- a/apps/wizard/existinginstallationpage.cpp
+++ b/apps/wizard/existinginstallationpage.cpp
@@ -29,11 +29,7 @@ void Wizard::ExistingInstallationPage::initializePage()
QStringList paths(mWizard->mInstallations.keys());
// Hide the default item if there are installations to choose from
- if (paths.isEmpty()) {
- installationsList->item(0)->setHidden(false);
- } else {
- installationsList->item(0)->setHidden(true);
- }
+ installationsList->item(0)->setHidden(!paths.isEmpty());
foreach (const QString &path, paths) {
QListWidgetItem *item = new QListWidgetItem(path);
diff --git a/apps/wizard/mainwizard.cpp b/apps/wizard/mainwizard.cpp
index a1370b125..a61daa5a4 100644
--- a/apps/wizard/mainwizard.cpp
+++ b/apps/wizard/mainwizard.cpp
@@ -62,6 +62,12 @@ Wizard::MainWizard::MainWizard(QWidget *parent) :
setupLauncherSettings();
setupInstallations();
setupPages();
+
+ const boost::filesystem::path& installedPath = mCfgMgr.getInstallPath();
+ if (!installedPath.empty())
+ {
+ addInstallation(toQString(installedPath));
+ }
}
Wizard::MainWizard::~MainWizard()
@@ -71,7 +77,7 @@ Wizard::MainWizard::~MainWizard()
void Wizard::MainWizard::setupLog()
{
- QString logPath(QString::fromUtf8(mCfgMgr.getLogPath().string().c_str()));
+ QString logPath(toQString(mCfgMgr.getLogPath()));
logPath.append(QLatin1String("wizard.log"));
QFile file(logPath);
@@ -93,7 +99,7 @@ void Wizard::MainWizard::setupLog()
void Wizard::MainWizard::addLogText(const QString &text)
{
- QString logPath(QString::fromUtf8(mCfgMgr.getLogPath().string().c_str()));
+ QString logPath(toQString(mCfgMgr.getLogPath()));
logPath.append(QLatin1String("wizard.log"));
QFile file(logPath);
@@ -121,8 +127,8 @@ void Wizard::MainWizard::addLogText(const QString &text)
void Wizard::MainWizard::setupGameSettings()
{
- QString userPath(QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()));
- QString globalPath(QString::fromUtf8(mCfgMgr.getGlobalPath().string().c_str()));
+ QString userPath(toQString(mCfgMgr.getUserConfigPath()));
+ QString globalPath(toQString(mCfgMgr.getGlobalPath()));
QString message(tr("
Could not open %1 for reading
\
Please make sure you have the right permissions \
and try again.
"));
@@ -181,7 +187,7 @@ void Wizard::MainWizard::setupGameSettings()
void Wizard::MainWizard::setupLauncherSettings()
{
- QString path(QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()));
+ QString path(toQString(mCfgMgr.getUserConfigPath()));
path.append(QLatin1String(Config::LauncherSettings::sLauncherConfigFileName));
QString message(tr("Could not open %1 for reading
\
@@ -228,7 +234,7 @@ void Wizard::MainWizard::runSettingsImporter()
QString path(field(QLatin1String("installation.path")).toString());
// Create the file if it doesn't already exist, else the importer will fail
- QString userPath(QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()));
+ QString userPath(toQString(mCfgMgr.getUserConfigPath()));
QFile file(userPath + QLatin1String("openmw.cfg"));
if (!file.exists()) {
@@ -387,7 +393,7 @@ void Wizard::MainWizard::writeSettings()
mGameSettings.removeDataDir(path);
mGameSettings.addDataDir(path);
- QString userPath(QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()));
+ QString userPath(toQString(mCfgMgr.getUserConfigPath()));
QDir dir(userPath);
if (!dir.exists()) {
@@ -460,3 +466,8 @@ bool Wizard::MainWizard::findFiles(const QString &name, const QString &path)
return (dir.entryList().contains(name + QLatin1String(".esm"), Qt::CaseInsensitive)
&& dir.entryList().contains(name + QLatin1String(".bsa"), Qt::CaseInsensitive));
}
+
+QString Wizard::MainWizard::toQString(const boost::filesystem::path& path)
+{
+ return QString::fromUtf8(path.string().c_str());
+}
diff --git a/apps/wizard/mainwizard.hpp b/apps/wizard/mainwizard.hpp
index c22f20c25..7f6e48a87 100644
--- a/apps/wizard/mainwizard.hpp
+++ b/apps/wizard/mainwizard.hpp
@@ -59,6 +59,8 @@ namespace Wizard
void addLogText(const QString &text);
private:
+ /// convert boost::filesystem::path to QString
+ QString toQString(const boost::filesystem::path& path);
void setupLog();
void setupGameSettings();
diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp
index 6b58304a0..0df782702 100644
--- a/components/files/windowspath.cpp
+++ b/components/files/windowspath.cpp
@@ -94,18 +94,8 @@ boost::filesystem::path WindowsPath::getInstallPath() const
HKEY hKey;
- BOOL f64 = FALSE;
- LPCTSTR regkey;
- if ((IsWow64Process(GetCurrentProcess(), &f64) && f64) || sizeof(void*) == 8)
- {
- regkey = "SOFTWARE\\Wow6432Node\\Bethesda Softworks\\Morrowind";
- }
- else
- {
- regkey = "SOFTWARE\\Bethesda Softworks\\Morrowind";
- }
-
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(regkey), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
+ LPCTSTR regkey = TEXT("SOFTWARE\\Bethesda Softworks\\Morrowind");
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ | KEY_WOW64_32KEY, &hKey) == ERROR_SUCCESS)
{
//Key existed, let's try to read the install dir
std::vector buf(512);
@@ -115,6 +105,7 @@ boost::filesystem::path WindowsPath::getInstallPath() const
{
installPath = &buf[0];
}
+ RegCloseKey(hKey);
}
return installPath;