- refract methods
This commit is contained in:
AlexZ 2020-01-09 02:09:59 +03:00
parent 5d56f7df6b
commit badcd62897
6 changed files with 139 additions and 122 deletions

View File

@ -44,6 +44,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="model\ActiveProcessSteamData.cs" />
<Compile Include="model\SteamAppData.cs" />
<Compile Include="model\SteamData.cs" />
<Compile Include="SteamPathsUtil.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using EpicMorg.SteamPathsLib.model;
using Microsoft.Win32;
namespace EpicMorg.SteamPathsLib
@ -13,21 +14,6 @@ namespace EpicMorg.SteamPathsLib
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()
{
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()
{
try
@ -64,109 +38,80 @@ namespace EpicMorg.SteamPathsLib
};
}
public static string GetSteamDirectoryPath()
public static ActiveProcessSteamData GetActiveProcessSteamData()
{
try
{
using (var key = Registry.CurrentUser.OpenSubKey(_valveSteamKey))
{
var path = key.GetValue("SteamPath").ToString();
if (path != @"")
{
return path;
}
}
}
catch (Exception) { };
var regData = Registry.CurrentUser.OpenSubKey(_valveActiveProcessPID);
return null;
}
var result = new ActiveProcessSteamData();
public static string GetSteamExePath()
{
try
{
using (var key = Registry.CurrentUser.OpenSubKey(_valveSteamKey))
{
var path = key.GetValue("SteamExe").ToString();
if (path != @"")
{
return path;
}
}
}
catch (Exception) { };
result.RegistryKey = regData.ToString();
result.PID = Convert.ToInt32((regData.GetValue("pid") ?? 0));
return null;
}
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();
return result;
}
catch (Exception)
{
return null;
};
}
}
public static bool IsInstalledApps(int appId)
{
try
public static SteamAppData GetSteamAppDataById(int appId)
{
var appKey = _valveSteamAppsPattern + appId;
using (var key = Registry.CurrentUser.OpenSubKey(appKey))
try
{
var installedValue = key.GetValue("Installed");
if (installedValue.Equals(1))
{
return true;
}
}
}
catch (Exception) { };
var regData = Registry.CurrentUser.OpenSubKey(appKey);
return false;
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
{
var regData = Registry.CurrentUser.OpenSubKey(_valveSteamKey);
var result = new SteamData();
result.RegistryKey = regData.ToString();
result.LastGameNameUsed = (regData.GetValue("LastGameNameUsed") ?? "").ToString();
result.SourceModInstallPath = (regData.GetValue("SourceModInstallPath") ?? "").ToString();
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;
}
}
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View File

@ -33,7 +33,8 @@ namespace SteamTest
InitializeComponent();
textBoxTestAppId.Value = (decimal)SOURCE_SDK_BASE_2013_SINGLEPLAYER_APP_ID;
this.Text = Text + " " + Assembly.GetExecutingAssembly().GetName().Version.ToString();
; }
;
}
private void FrmMain_Load(object sender, EventArgs e)
{
@ -85,7 +86,8 @@ namespace SteamTest
try
{
// Example of using this awesome library
var text = SteamPathsUtil.GetSteamKeyRegistry();
var steamData = SteamPathsUtil.GetSteamData();
var text = steamData != null ? steamData.RegistryKey : "";
checkBoxVavleSteamReg.Checked = true;
checkBoxVavleSteamReg.ForeColor = Color.Green;
@ -126,7 +128,8 @@ namespace SteamTest
try
{
// Example of using this awesome library
var text = SteamPathsUtil.GetSteamExePath();
var steamData = SteamPathsUtil.GetSteamData();
var text = steamData != null ? steamData.SteamExe : "";
checkBoxVavleSteamExe.Checked = true;
checkBoxVavleSteamExe.ForeColor = Color.Green;
@ -156,7 +159,8 @@ namespace SteamTest
try
{
// 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.ForeColor = Color.Green;
@ -187,7 +191,8 @@ namespace SteamTest
try
{
// Example of using this awesome library
var text = SteamPathsUtil.GetSteamDirectoryPath();
var steamData = SteamPathsUtil.GetSteamData();
var text = steamData != null ? steamData.SteamPath : "";
checkBoxVavleSteamPath.Checked = true;
checkBoxVavleSteamPath.ForeColor = Color.Green;
@ -217,7 +222,8 @@ namespace SteamTest
try
{
// Example of using this awesome library
var text = SteamPathsUtil.GetOriginalSourceModDirectoryPath();
var steamData = SteamPathsUtil.GetSteamData();
var text = steamData != null ? steamData.SourceModInstallPath : "";
checkBoxVavleSteamSmodPath.Checked = true;
checkBoxVavleSteamSmodPath.ForeColor = Color.Green;
@ -263,8 +269,10 @@ namespace SteamTest
private void CheckSteamAppById(int appId, TextBox outputTextBox, CheckBox outputCheckBox, CheckBox outputInstalledCheckBox)
{
var check = SteamPathsUtil.IsInstalledApps(appId);
var path = SteamPathsUtil.GetInstalledAppKeyRegistryById(appId);
var appData = SteamPathsUtil.GetSteamAppDataById(appId);
var check = appData != null ? appData.Installed : false;
var path = appData != null ? appData.RegistryKey : "";
outputTextBox.Text = path;