From 47d5aef404e0a5c27d49b37faff9bd32ced6f3ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCssig?= Date: Tue, 6 Dec 2016 23:02:37 +0100 Subject: [PATCH] SMAPI installer is able to read SDV install path from registry key --- .../InteractiveInstaller.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs index ffdef37b..49014352 100644 --- a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs +++ b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using System.Reflection; +using Microsoft.Win32; using StardewModdingApi.Installer.Enums; namespace StardewModdingApi.Installer @@ -318,6 +319,41 @@ namespace StardewModdingApi.Installer return new DirectoryInfo(defaultPath); } + if (platform == Platform.Windows) + { + // Needed to get 64Keys + RegistryKey localKey = Environment.Is64BitOperatingSystem ? RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64) : Registry.LocalMachine; + + string stardewValleyPath; + var registry = localKey.OpenSubKey(@"SOFTWARE\WOW6432Node\GOG.com\Games\1453375253"); + if (registry != null) + { + stardewValleyPath = (string)registry.GetValue("PATH"); + if (!string.IsNullOrEmpty(stardewValleyPath)) + { + registry.Close(); + if (Directory.Exists(stardewValleyPath)) + { + return new DirectoryInfo(stardewValleyPath); + } + } + } + + registry = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 413150"); + if (registry != null) + { + stardewValleyPath = (string)registry.GetValue("InstallLocation"); + if (!string.IsNullOrEmpty(stardewValleyPath)) + { + registry.Close(); + if (Directory.Exists(stardewValleyPath)) + { + return new DirectoryInfo(stardewValleyPath); + } + } + } + } + // ask user Console.WriteLine("Oops, couldn't find the game automatically."); while (true)