Read Steam location and user from registry

This commit is contained in:
Norbi Peti 2021-01-20 02:38:33 +01:00
parent 3520015649
commit 5aa0f788c3
3 changed files with 14 additions and 1 deletions

View file

@ -24,6 +24,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.IO.Compression" Version="4.3.0" /> <PackageReference Include="System.IO.Compression" Version="4.3.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -64,6 +64,7 @@ You may also want to verify the game's files by right clicking the game in Steam
mods.Clear(); //This method may get called twice when ran from the command line mods.Clear(); //This method may get called twice when ran from the command line
UpdateButton(installbtn, false); UpdateButton(installbtn, false);
modinfobox.Text = defaultInfo; modinfobox.Text = defaultInfo;
GetSteamLocationAndUser(); //TODO: If user is null then start Steam
if (string.IsNullOrWhiteSpace(Settings.Default.GamePath) || GetExe() == null) if (string.IsNullOrWhiteSpace(Settings.Default.GamePath) || GetExe() == null)
{ {
Settings.Default.GamePath = GetGameFolder(); Settings.Default.GamePath = GetGameFolder();

View file

@ -1,4 +1,5 @@
using GCMM.Properties; using GCMM.Properties;
using Microsoft.Win32;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@ -35,7 +36,7 @@ namespace GCMM
{ //TODO { //TODO
string libs; string libs;
if (Environment.OSVersion.Platform == PlatformID.Win32NT) if (Environment.OSVersion.Platform == PlatformID.Win32NT)
libs = Settings.Default.SteamConfigFileForAutoLaunch + @"\steamapps\libraryfolders.vdf"; libs = Settings.Default.SteamConfigFileForAutoLaunch + @"\steamapps\libraryfolders.vdf"; //TODO: Not the Steam folder anymore!
else else
return null; return null;
foreach (var line in File.ReadAllLines(libs).Concat(new[] {@"C:\Program Files (x86)\Steam\"})) foreach (var line in File.ReadAllLines(libs).Concat(new[] {@"C:\Program Files (x86)\Steam\"}))
@ -83,7 +84,17 @@ namespace GCMM
private void UpdateSteamConfigToAutoStart(bool autoLaunch) private void UpdateSteamConfigToAutoStart(bool autoLaunch)
{ {
//TODO
}
private (string, int) GetSteamLocationAndUser()
{
if (Environment.OSVersion.Platform != PlatformID.Win32NT) return (null, 0);
using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Valve\Steam\ActiveProcess"))
{
string path = Directory.GetParent((string)key.GetValue("SteamClientDll")).FullName;
return (path, (int)key.GetValue("ActiveUser"));
}
} }
private void CheckStartGame(object sender, EventArgs e) private void CheckStartGame(object sender, EventArgs e)