mirror of
https://github.com/EpicMorg/SteamPathsLib.git
synced 2024-12-27 06:55:28 +03:00
v1.1
- refract methods
This commit is contained in:
parent
5d56f7df6b
commit
badcd62897
@ -44,6 +44,9 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="model\ActiveProcessSteamData.cs" />
|
||||||
|
<Compile Include="model\SteamAppData.cs" />
|
||||||
|
<Compile Include="model\SteamData.cs" />
|
||||||
<Compile Include="SteamPathsUtil.cs" />
|
<Compile Include="SteamPathsUtil.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using EpicMorg.SteamPathsLib.model;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
|
||||||
namespace EpicMorg.SteamPathsLib
|
namespace EpicMorg.SteamPathsLib
|
||||||
@ -13,21 +14,6 @@ namespace EpicMorg.SteamPathsLib
|
|||||||
|
|
||||||
private static readonly string _valveSteamAppsPattern = @"Software\Valve\Steam\Apps\";
|
private static readonly string _valveSteamAppsPattern = @"Software\Valve\Steam\Apps\";
|
||||||
|
|
||||||
public static Dictionary<string, string> GetInfo()
|
|
||||||
{
|
|
||||||
var result = new Dictionary<string, string>();
|
|
||||||
|
|
||||||
result["ValveKeyRegistry"] = GetValveKeyRegistry();
|
|
||||||
result["SteamKeyRegistry"] = GetSteamKeyRegistry();
|
|
||||||
result["SteamAppsKeyRegistry"] = GetSteamAppsKeyRegistry();
|
|
||||||
result["SteamDirectoryPath"] = GetSteamDirectoryPath();
|
|
||||||
result["SteamExePath"] = GetSteamExePath();
|
|
||||||
result["SteamExePid"] = GetSteamExePid();
|
|
||||||
result["OriginalSourceModDirectoryPath"] = GetOriginalSourceModDirectoryPath();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetValveKeyRegistry()
|
public static string GetValveKeyRegistry()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -40,18 +26,6 @@ namespace EpicMorg.SteamPathsLib
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetSteamKeyRegistry()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return Registry.CurrentUser.OpenSubKey(_valveSteamKey).ToString();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetSteamAppsKeyRegistry()
|
public static string GetSteamAppsKeyRegistry()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -64,109 +38,80 @@ namespace EpicMorg.SteamPathsLib
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetSteamDirectoryPath()
|
public static ActiveProcessSteamData GetActiveProcessSteamData()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var key = Registry.CurrentUser.OpenSubKey(_valveSteamKey))
|
var regData = Registry.CurrentUser.OpenSubKey(_valveActiveProcessPID);
|
||||||
{
|
|
||||||
var path = key.GetValue("SteamPath").ToString();
|
|
||||||
if (path != @"")
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception) { };
|
|
||||||
|
|
||||||
return null;
|
var result = new ActiveProcessSteamData();
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetSteamExePath()
|
result.RegistryKey = regData.ToString();
|
||||||
{
|
result.PID = Convert.ToInt32((regData.GetValue("pid") ?? 0));
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var key = Registry.CurrentUser.OpenSubKey(_valveSteamKey))
|
|
||||||
{
|
|
||||||
var path = key.GetValue("SteamExe").ToString();
|
|
||||||
if (path != @"")
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception) { };
|
|
||||||
|
|
||||||
return null;
|
return result;
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetSteamExePid()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var key = Registry.CurrentUser.OpenSubKey(_valveActiveProcessPID))
|
|
||||||
{
|
|
||||||
var pid = key.GetValue("pid").ToString();
|
|
||||||
if (pid != @"0")
|
|
||||||
{
|
|
||||||
return pid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception) { };
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetOriginalSourceModDirectoryPath()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var key = Registry.CurrentUser.OpenSubKey(_valveSteamKey))
|
|
||||||
{
|
|
||||||
var path = key.GetValue("SourceModInstallPath").ToString();
|
|
||||||
if (path != @"")
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception) { };
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetInstalledAppKeyRegistryById(int appId)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return Registry.CurrentUser.OpenSubKey(_valveSteamAppsPattern + appId).ToString();
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsInstalledApps(int appId)
|
public static SteamAppData GetSteamAppDataById(int appId)
|
||||||
|
{
|
||||||
|
var appKey = _valveSteamAppsPattern + appId;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var regData = Registry.CurrentUser.OpenSubKey(appKey);
|
||||||
|
|
||||||
|
var result = new SteamAppData();
|
||||||
|
|
||||||
|
result.RegistryKey = regData.ToString();
|
||||||
|
result.Name = (regData.GetValue("Name") ?? "").ToString();
|
||||||
|
|
||||||
|
result.AppId = appId;
|
||||||
|
|
||||||
|
result.Installed = (regData.GetValue("Installed") ?? 0).Equals(1);
|
||||||
|
result.Updating = (regData.GetValue("Updating") ?? 0).Equals(1);
|
||||||
|
result.Runnig = (regData.GetValue("Running") ?? 0).Equals(1);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SteamData GetSteamData()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var appKey = _valveSteamAppsPattern + appId;
|
var regData = Registry.CurrentUser.OpenSubKey(_valveSteamKey);
|
||||||
|
|
||||||
using (var key = Registry.CurrentUser.OpenSubKey(appKey))
|
var result = new SteamData();
|
||||||
{
|
|
||||||
var installedValue = key.GetValue("Installed");
|
result.RegistryKey = regData.ToString();
|
||||||
if (installedValue.Equals(1))
|
result.LastGameNameUsed = (regData.GetValue("LastGameNameUsed") ?? "").ToString();
|
||||||
{
|
result.SourceModInstallPath = (regData.GetValue("SourceModInstallPath") ?? "").ToString();
|
||||||
return true;
|
result.SteamExe = (regData.GetValue("SteamExe") ?? "").ToString();
|
||||||
}
|
result.SteamPath = (regData.GetValue("SteamPath") ?? "").ToString();
|
||||||
}
|
result.Language = (regData.GetValue("Language") ?? "").ToString();
|
||||||
|
result.PseudoUUID = (regData.GetValue("PseudoUUID") ?? "").ToString();
|
||||||
|
result.ModInstallPath = (regData.GetValue("ModInstallPath") ?? "").ToString();
|
||||||
|
|
||||||
|
result.RunningAppID = Convert.ToInt32((regData.GetValue("RunningAppID") ?? "0").ToString());
|
||||||
|
|
||||||
|
result.RememberPassword = (regData.GetValue("RememberPassword") ?? 0).Equals(1);
|
||||||
|
result.AlreadyRetriedOfflineMode = (regData.GetValue("AlreadyRetriedOfflineMode") ?? 0).Equals(1);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
catch (Exception) { };
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
src/EpicMorg.SteamPathsLib/model/ActiveProcessSteamData.cs
Normal file
15
src/EpicMorg.SteamPathsLib/model/ActiveProcessSteamData.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace EpicMorg.SteamPathsLib.model
|
||||||
|
{
|
||||||
|
public class ActiveProcessSteamData
|
||||||
|
{
|
||||||
|
public string RegistryKey;
|
||||||
|
|
||||||
|
public int PID;
|
||||||
|
}
|
||||||
|
}
|
20
src/EpicMorg.SteamPathsLib/model/SteamAppData.cs
Normal file
20
src/EpicMorg.SteamPathsLib/model/SteamAppData.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace EpicMorg.SteamPathsLib.model
|
||||||
|
{
|
||||||
|
public class SteamAppData
|
||||||
|
{
|
||||||
|
public string RegistryKey;
|
||||||
|
public string Name;
|
||||||
|
|
||||||
|
public int AppId;
|
||||||
|
|
||||||
|
public bool Installed;
|
||||||
|
public bool Runnig;
|
||||||
|
public bool Updating;
|
||||||
|
}
|
||||||
|
}
|
26
src/EpicMorg.SteamPathsLib/model/SteamData.cs
Normal file
26
src/EpicMorg.SteamPathsLib/model/SteamData.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace EpicMorg.SteamPathsLib.model
|
||||||
|
{
|
||||||
|
public class SteamData
|
||||||
|
{
|
||||||
|
public string RegistryKey;
|
||||||
|
public string LastGameNameUsed;
|
||||||
|
public string SourceModInstallPath;
|
||||||
|
public string SteamExe;
|
||||||
|
public string SteamPath;
|
||||||
|
public string Language;
|
||||||
|
public string PseudoUUID;
|
||||||
|
public string ModInstallPath;
|
||||||
|
|
||||||
|
public int RunningAppID;
|
||||||
|
|
||||||
|
public bool AlreadyRetriedOfflineMode;
|
||||||
|
public bool RememberPassword;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -33,7 +33,8 @@ namespace SteamTest
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
textBoxTestAppId.Value = (decimal)SOURCE_SDK_BASE_2013_SINGLEPLAYER_APP_ID;
|
textBoxTestAppId.Value = (decimal)SOURCE_SDK_BASE_2013_SINGLEPLAYER_APP_ID;
|
||||||
this.Text = Text + " " + Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
this.Text = Text + " " + Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||||
; }
|
;
|
||||||
|
}
|
||||||
|
|
||||||
private void FrmMain_Load(object sender, EventArgs e)
|
private void FrmMain_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -85,7 +86,8 @@ namespace SteamTest
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Example of using this awesome library
|
// Example of using this awesome library
|
||||||
var text = SteamPathsUtil.GetSteamKeyRegistry();
|
var steamData = SteamPathsUtil.GetSteamData();
|
||||||
|
var text = steamData != null ? steamData.RegistryKey : "";
|
||||||
|
|
||||||
checkBoxVavleSteamReg.Checked = true;
|
checkBoxVavleSteamReg.Checked = true;
|
||||||
checkBoxVavleSteamReg.ForeColor = Color.Green;
|
checkBoxVavleSteamReg.ForeColor = Color.Green;
|
||||||
@ -126,7 +128,8 @@ namespace SteamTest
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Example of using this awesome library
|
// Example of using this awesome library
|
||||||
var text = SteamPathsUtil.GetSteamExePath();
|
var steamData = SteamPathsUtil.GetSteamData();
|
||||||
|
var text = steamData != null ? steamData.SteamExe : "";
|
||||||
|
|
||||||
checkBoxVavleSteamExe.Checked = true;
|
checkBoxVavleSteamExe.Checked = true;
|
||||||
checkBoxVavleSteamExe.ForeColor = Color.Green;
|
checkBoxVavleSteamExe.ForeColor = Color.Green;
|
||||||
@ -156,7 +159,8 @@ namespace SteamTest
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Example of using this awesome library
|
// Example of using this awesome library
|
||||||
var text = SteamPathsUtil.GetSteamExePid();
|
var activeProcess = SteamPathsUtil.GetActiveProcessSteamData();
|
||||||
|
var text = (activeProcess != null ? activeProcess.PID : 0).ToString();
|
||||||
|
|
||||||
checkBoxVavleSteamPID.Checked = true;
|
checkBoxVavleSteamPID.Checked = true;
|
||||||
checkBoxVavleSteamPID.ForeColor = Color.Green;
|
checkBoxVavleSteamPID.ForeColor = Color.Green;
|
||||||
@ -187,7 +191,8 @@ namespace SteamTest
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Example of using this awesome library
|
// Example of using this awesome library
|
||||||
var text = SteamPathsUtil.GetSteamDirectoryPath();
|
var steamData = SteamPathsUtil.GetSteamData();
|
||||||
|
var text = steamData != null ? steamData.SteamPath : "";
|
||||||
|
|
||||||
checkBoxVavleSteamPath.Checked = true;
|
checkBoxVavleSteamPath.Checked = true;
|
||||||
checkBoxVavleSteamPath.ForeColor = Color.Green;
|
checkBoxVavleSteamPath.ForeColor = Color.Green;
|
||||||
@ -217,7 +222,8 @@ namespace SteamTest
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Example of using this awesome library
|
// Example of using this awesome library
|
||||||
var text = SteamPathsUtil.GetOriginalSourceModDirectoryPath();
|
var steamData = SteamPathsUtil.GetSteamData();
|
||||||
|
var text = steamData != null ? steamData.SourceModInstallPath : "";
|
||||||
|
|
||||||
checkBoxVavleSteamSmodPath.Checked = true;
|
checkBoxVavleSteamSmodPath.Checked = true;
|
||||||
checkBoxVavleSteamSmodPath.ForeColor = Color.Green;
|
checkBoxVavleSteamSmodPath.ForeColor = Color.Green;
|
||||||
@ -261,10 +267,12 @@ namespace SteamTest
|
|||||||
CheckSteamAppById(appId, txtBoxVavleSteamAppsCustom, checkBoxVavleSteamAppsCustom, checkBoxVavleSteamAppsCustomInstalled);
|
CheckSteamAppById(appId, txtBoxVavleSteamAppsCustom, checkBoxVavleSteamAppsCustom, checkBoxVavleSteamAppsCustomInstalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckSteamAppById(int appId, TextBox outputTextBox, CheckBox outputCheckBox, CheckBox outputInstalledCheckBox)
|
private void CheckSteamAppById(int appId, TextBox outputTextBox, CheckBox outputCheckBox, CheckBox outputInstalledCheckBox)
|
||||||
{
|
{
|
||||||
var check = SteamPathsUtil.IsInstalledApps(appId);
|
var appData = SteamPathsUtil.GetSteamAppDataById(appId);
|
||||||
var path = SteamPathsUtil.GetInstalledAppKeyRegistryById(appId);
|
|
||||||
|
var check = appData != null ? appData.Installed : false;
|
||||||
|
var path = appData != null ? appData.RegistryKey : "";
|
||||||
|
|
||||||
outputTextBox.Text = path;
|
outputTextBox.Text = path;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user