Browse Source

Small refactor game launch & added find steam function

Ivan Arkhipov 4 years ago
parent
commit
a39ef54d8a

+ 14 - 0
src/Legacy/models/filesystem.cpp

@@ -105,6 +105,20 @@ namespace FileSystem {
 
         return paths;
     }
+
+    QString findSteamFolder() {
+        QSettings path_x32("HKEY_LOCAL_MACHINE\\SOFTWARE\\Valve\\Steam", QSettings::NativeFormat);
+        if (path_x32.contains("InstallPath")) {
+            return path_x32.value("InstallPath").toString();
+        }
+
+        QSettings path_x64("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Valve\\Steam", QSettings::NativeFormat);
+        if (path_x64.contains("InstallPath")) {
+            return path_x64.value("InstallPath").toString();
+        }
+
+        return QString();
+    }
 }
 
 #endif // FILESYSTEM_H

+ 2 - 0
src/Legacy/models/filesystem.h

@@ -21,6 +21,8 @@ namespace FileSystem {
     extern void clearFolder(QDir &dir);
 
     extern QStringList recognizeRegistryLotroPath();
+
+    extern QString findSteamFolder();
 }
 
 #endif // FILESYSTEM_H

+ 10 - 11
src/Legacy/models/patchinstaller.cpp

@@ -433,6 +433,11 @@ void PatchInstaller::startGame(bool remove_dat_files) {
         return;
     }
 
+    if (!FileSystem::fileExists(game_folder + "/LotroLauncher.exe")) {
+        qCritical() << __FUNCTION__ << "Starting game FAILED - LotroLauncher.exe not found!";
+        return;
+    }
+
     QStringList args;
     args << "-nosplashscreen";
     if (_current_applied_patches_info.loadscreens_patch_hashsum != "") {
@@ -460,18 +465,12 @@ void PatchInstaller::startGame(bool remove_dat_files) {
 
     qDebug() << __FUNCTION__ << "Starting game with arguments: " << args;
 
-    QFile f(Settings::getValue("Lotro/game_path").toString() + "/LotroLauncher.exe");
-    QProcess process;
+    deinit();
 
-    if (FileSystem::fileExists(f.fileName())) {
-        if (f.fileName().contains(" ")) {
-            f.setFileName("\"" + f.fileName() + "\"");
-        }
-        deinit();
-        process.startDetached(f.fileName(), args);
-        process.waitForFinished(-1);
-        QMetaObject::invokeMethod(&LegacyApplication::instance(), &LegacyApplication::close, Qt::QueuedConnection);
-    }
+    QProcess process;
+    process.startDetached(game_folder + "/LotroLauncher.exe", args, game_folder);
+    process.waitForFinished(-1);
+    QMetaObject::invokeMethod(&LegacyApplication::instance(), &LegacyApplication::close, Qt::QueuedConnection);
 }
 
 void PatchInstaller::startPatchInstallationChain(bool force_reinstall_patches) {