detect game install path via Steam library path (#512)
Thanks to InkyQuill!
This commit is contained in:
parent
86a3f8dd46
commit
a6741cce9b
|
@ -66,6 +66,11 @@ namespace StardewModdingApi.Installer
|
||||||
if (!string.IsNullOrWhiteSpace(path))
|
if (!string.IsNullOrWhiteSpace(path))
|
||||||
yield return path;
|
yield return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// via Steam library path
|
||||||
|
string steampath = this.GetCurrentUserRegistryValue(@"Software\Valve\Steam", "SteamPath");
|
||||||
|
if (steampath != null)
|
||||||
|
yield return Path.Combine(steampath.Replace('/', '\\'), @"steamapps\common\Stardew Valley");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -431,7 +436,7 @@ namespace StardewModdingApi.Installer
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Get the value of a key in the Windows registry.</summary>
|
/// <summary>Get the value of a key in the Windows HKLM registry.</summary>
|
||||||
/// <param name="key">The full path of the registry key relative to HKLM.</param>
|
/// <param name="key">The full path of the registry key relative to HKLM.</param>
|
||||||
/// <param name="name">The name of the value.</param>
|
/// <param name="name">The name of the value.</param>
|
||||||
private string GetLocalMachineRegistryValue(string key, string name)
|
private string GetLocalMachineRegistryValue(string key, string name)
|
||||||
|
@ -444,6 +449,19 @@ namespace StardewModdingApi.Installer
|
||||||
return (string)openKey.GetValue(name);
|
return (string)openKey.GetValue(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Get the value of a key in the Windows HKCU registry.</summary>
|
||||||
|
/// <param name="key">The full path of the registry key relative to HKCU.</param>
|
||||||
|
/// <param name="name">The name of the value.</param>
|
||||||
|
private string GetCurrentUserRegistryValue(string key, string name)
|
||||||
|
{
|
||||||
|
RegistryKey currentuser = Environment.Is64BitOperatingSystem ? RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64) : Registry.CurrentUser;
|
||||||
|
RegistryKey openKey = currentuser.OpenSubKey(key);
|
||||||
|
if (openKey == null)
|
||||||
|
return null;
|
||||||
|
using (openKey)
|
||||||
|
return (string)openKey.GetValue(name);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Print a debug message.</summary>
|
/// <summary>Print a debug message.</summary>
|
||||||
/// <param name="text">The text to print.</param>
|
/// <param name="text">The text to print.</param>
|
||||||
private void PrintDebug(string text) => this.ConsoleWriter.WriteLine(text, ConsoleLogLevel.Debug);
|
private void PrintDebug(string text) => this.ConsoleWriter.WriteLine(text, ConsoleLogLevel.Debug);
|
||||||
|
@ -602,6 +620,8 @@ namespace StardewModdingApi.Installer
|
||||||
where dir.Exists && dir.EnumerateFiles(executableFilename).Any()
|
where dir.Exists && dir.EnumerateFiles(executableFilename).Any()
|
||||||
select dir
|
select dir
|
||||||
)
|
)
|
||||||
|
.GroupBy(p => p.FullName, StringComparer.InvariantCultureIgnoreCase) // ignore duplicate paths
|
||||||
|
.Select(p => p.First())
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
// choose where to install
|
// choose where to install
|
||||||
|
|
Loading…
Reference in New Issue