initial code

❤️❤️❤️
This commit is contained in:
Alex Z 2020-01-02 00:31:31 +03:00
parent 89f0778e66
commit f9bf02bd5c
3 changed files with 156 additions and 9 deletions

View File

@ -41,7 +41,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="SteamPathsUtil.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@ -1,12 +1,159 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32;
namespace EpicMorg.SteamPathsLib
{
public class SteamPathsUtil
{
private static readonly string _valveKey = @"Software\Valve";
private static readonly string _valveSteamKey = @"Software\Valve\Steam";
private static readonly string _valveSteamAppsKey = @"Software\Valve\Steam\Apps";
private static readonly string _valveActiveProcessPID = @"Software\Valve\Steam\ActiveProcess";
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
{
return Registry.CurrentUser.OpenSubKey(_valveKey).ToString();
}
catch (Exception)
{
return null;
};
}
public static string GetSteamKeyRegistry()
{
try
{
return Registry.CurrentUser.OpenSubKey(_valveSteamKey).ToString();
}
catch (Exception)
{
return null;
};
}
public static string GetSteamAppsKeyRegistry()
{
try
{
return Registry.CurrentUser.OpenSubKey(_valveSteamAppsKey).ToString();
}
catch (Exception)
{
return null;
};
}
public static string GetSteamDirectoryPath()
{
try
{
using (var key = Registry.CurrentUser.OpenSubKey(_valveSteamKey))
{
var path = key.GetValue("SteamPath").ToString();
if (path != @"")
{
return path;
}
}
}
catch (Exception) { };
return null;
}
public static string GetSteamExePath()
{
try
{
using (var key = Registry.CurrentUser.OpenSubKey(_valveSteamKey))
{
var path = key.GetValue("SteamExe").ToString();
if (path != @"")
{
return path;
}
}
}
catch (Exception) { };
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 bool IsInstalledApps(int number)
{
try
{
var appKey = _valveSteamAppsPattern + number;
using (var key = Registry.CurrentUser.OpenSubKey(appKey))
{
var installedValue = key.GetValue("Installed");
if (installedValue.Equals(1))
{
return true;
}
}
}
catch (Exception) { };
return false;
}
}
}

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29509.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SteamPathsLib", "SteamPathsLib\SteamPathsLib.csproj", "{00E7A45F-69F7-41FC-B2A7-566E2904E49B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EpicMorg.SteamPathsLib", "EpicMorg.SteamPathsLib\EpicMorg.SteamPathsLib.csproj", "{E34AE985-7C7E-49BA-A2B0-70D88F865265}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -11,10 +11,10 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{00E7A45F-69F7-41FC-B2A7-566E2904E49B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00E7A45F-69F7-41FC-B2A7-566E2904E49B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00E7A45F-69F7-41FC-B2A7-566E2904E49B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00E7A45F-69F7-41FC-B2A7-566E2904E49B}.Release|Any CPU.Build.0 = Release|Any CPU
{E34AE985-7C7E-49BA-A2B0-70D88F865265}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E34AE985-7C7E-49BA-A2B0-70D88F865265}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E34AE985-7C7E-49BA-A2B0-70D88F865265}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E34AE985-7C7E-49BA-A2B0-70D88F865265}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE