SMAPI installer is able to read SDV install path from registry key

This commit is contained in:
Patrick Müssig 2016-12-06 23:02:37 +01:00 committed by Jesse Plamondon-Willard
parent acbd33fb02
commit 47d5aef404
1 changed files with 36 additions and 0 deletions

View File

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