mirror of
https://github.com/EpicMorg/SteamPathsLib.git
synced 2025-04-27 15:29:28 +03:00
Add info directly from Steam
This commit is contained in:
parent
9b2de02338
commit
e60a695b83
@ -45,14 +45,22 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="model\ActiveProcessSteamData.cs" />
|
<Compile Include="Model\ActiveProcessSteamRegistryData.cs" />
|
||||||
<Compile Include="model\SteamAppData.cs" />
|
<Compile Include="Model\ConfigSteamData.cs" />
|
||||||
<Compile Include="model\SteamData.cs" />
|
<Compile Include="Model\LibrarySteamData.cs" />
|
||||||
|
<Compile Include="Model\SteamAppManifestData.cs" />
|
||||||
|
<Compile Include="Model\SteamAppRegistryData.cs" />
|
||||||
|
<Compile Include="Model\SteamRegistryData.cs" />
|
||||||
<Compile Include="SteamPathsUtil.cs" />
|
<Compile Include="SteamPathsUtil.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="steam.ico" />
|
<Content Include="steam.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Gameloop.Vdf">
|
||||||
|
<Version>0.5.0</Version>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
@ -4,9 +4,9 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace EpicMorg.SteamPathsLib.model
|
namespace EpicMorg.SteamPathsLib.Model
|
||||||
{
|
{
|
||||||
public class ActiveProcessSteamData
|
public class ActiveProcessSteamRegistryData
|
||||||
{
|
{
|
||||||
public string RegistryKey;
|
public string RegistryKey;
|
||||||
|
|
11
src/EpicMorg.SteamPathsLib/Model/ConfigSteamData.cs
Normal file
11
src/EpicMorg.SteamPathsLib/Model/ConfigSteamData.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace EpicMorg.SteamPathsLib.Model {
|
||||||
|
public class ConfigSteamData {
|
||||||
|
public string[] SteamLibraryFolders;
|
||||||
|
}
|
||||||
|
}
|
13
src/EpicMorg.SteamPathsLib/Model/LibrarySteamData.cs
Normal file
13
src/EpicMorg.SteamPathsLib/Model/LibrarySteamData.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace EpicMorg.SteamPathsLib.Model {
|
||||||
|
public class LibrarySteamData {
|
||||||
|
public string Path;
|
||||||
|
|
||||||
|
public List<SteamAppManifestData> AppManifestDataList;
|
||||||
|
}
|
||||||
|
}
|
15
src/EpicMorg.SteamPathsLib/Model/SteamAppManifestData.cs
Normal file
15
src/EpicMorg.SteamPathsLib/Model/SteamAppManifestData.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 SteamAppManifestData {
|
||||||
|
public int AppId;
|
||||||
|
public string Name;
|
||||||
|
public string InstallDir;
|
||||||
|
|
||||||
|
public string Path;
|
||||||
|
}
|
||||||
|
}
|
@ -4,9 +4,9 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace EpicMorg.SteamPathsLib.model
|
namespace EpicMorg.SteamPathsLib.Model
|
||||||
{
|
{
|
||||||
public class SteamAppData
|
public class SteamAppRegistryData
|
||||||
{
|
{
|
||||||
public string RegistryKey;
|
public string RegistryKey;
|
||||||
public string Name;
|
public string Name;
|
@ -4,9 +4,9 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace EpicMorg.SteamPathsLib.model
|
namespace EpicMorg.SteamPathsLib.Model
|
||||||
{
|
{
|
||||||
public class SteamData
|
public class SteamRegistryData
|
||||||
{
|
{
|
||||||
public string RegistryKey;
|
public string RegistryKey;
|
||||||
public string LastGameNameUsed;
|
public string LastGameNameUsed;
|
@ -1,12 +1,15 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using EpicMorg.SteamPathsLib.model;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using EpicMorg.SteamPathsLib.Model;
|
||||||
|
using Gameloop.Vdf;
|
||||||
|
using Gameloop.Vdf.Linq;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
|
||||||
namespace EpicMorg.SteamPathsLib
|
namespace EpicMorg.SteamPathsLib {
|
||||||
{
|
public class SteamPathsUtil {
|
||||||
public class SteamPathsUtil
|
|
||||||
{
|
|
||||||
private static readonly string _valveKey = @"Software\Valve";
|
private static readonly string _valveKey = @"Software\Valve";
|
||||||
private static readonly string _valveSteamKey = @"Software\Valve\Steam";
|
private static readonly string _valveSteamKey = @"Software\Valve\Steam";
|
||||||
private static readonly string _valveSteamAppsKey = @"Software\Valve\Steam\Apps";
|
private static readonly string _valveSteamAppsKey = @"Software\Valve\Steam\Apps";
|
||||||
@ -14,58 +17,44 @@ namespace EpicMorg.SteamPathsLib
|
|||||||
|
|
||||||
private static readonly string _valveSteamAppsPattern = @"Software\Valve\Steam\Apps\";
|
private static readonly string _valveSteamAppsPattern = @"Software\Valve\Steam\Apps\";
|
||||||
|
|
||||||
public static string GetValveKeyRegistry()
|
public static string GetValveKeyRegistry() {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
return Registry.CurrentUser.OpenSubKey(_valveKey).ToString();
|
return Registry.CurrentUser.OpenSubKey(_valveKey).ToString();
|
||||||
}
|
} catch (Exception) {
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetSteamAppsKeyRegistry()
|
public static string GetSteamAppsKeyRegistry() {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
return Registry.CurrentUser.OpenSubKey(_valveSteamAppsKey).ToString();
|
return Registry.CurrentUser.OpenSubKey(_valveSteamAppsKey).ToString();
|
||||||
}
|
} catch (Exception) {
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ActiveProcessSteamData GetActiveProcessSteamData()
|
public static ActiveProcessSteamRegistryData GetActiveProcessSteamData() {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
var regData = Registry.CurrentUser.OpenSubKey(_valveActiveProcessPID);
|
var regData = Registry.CurrentUser.OpenSubKey(_valveActiveProcessPID);
|
||||||
|
|
||||||
var result = new ActiveProcessSteamData();
|
var result = new ActiveProcessSteamRegistryData();
|
||||||
|
|
||||||
result.RegistryKey = regData.ToString();
|
result.RegistryKey = regData.ToString();
|
||||||
result.PID = Convert.ToInt32((regData.GetValue("pid") ?? 0));
|
result.PID = Convert.ToInt32((regData.GetValue("pid") ?? 0));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
} catch (Exception) {
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SteamAppData GetSteamAppDataById(int appId)
|
public static SteamAppRegistryData GetSteamAppDataById(int appId) {
|
||||||
{
|
|
||||||
var appKey = _valveSteamAppsPattern + appId;
|
var appKey = _valveSteamAppsPattern + appId;
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
var regData = Registry.CurrentUser.OpenSubKey(appKey);
|
var regData = Registry.CurrentUser.OpenSubKey(appKey);
|
||||||
|
|
||||||
var result = new SteamAppData();
|
var result = new SteamAppRegistryData();
|
||||||
|
|
||||||
result.RegistryKey = regData.ToString();
|
result.RegistryKey = regData.ToString();
|
||||||
result.Name = (regData.GetValue("Name") ?? "").ToString();
|
result.Name = (regData.GetValue("Name") ?? "").ToString();
|
||||||
@ -77,20 +66,16 @@ namespace EpicMorg.SteamPathsLib
|
|||||||
result.Runnig = (regData.GetValue("Running") ?? 0).Equals(1);
|
result.Runnig = (regData.GetValue("Running") ?? 0).Equals(1);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
} catch (Exception) {
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SteamData GetSteamData()
|
public static SteamRegistryData GetSteamData() {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
var regData = Registry.CurrentUser.OpenSubKey(_valveSteamKey);
|
var regData = Registry.CurrentUser.OpenSubKey(_valveSteamKey);
|
||||||
|
|
||||||
var result = new SteamData();
|
var result = new SteamRegistryData();
|
||||||
|
|
||||||
result.RegistryKey = regData.ToString();
|
result.RegistryKey = regData.ToString();
|
||||||
result.LastGameNameUsed = (regData.GetValue("LastGameNameUsed") ?? "").ToString();
|
result.LastGameNameUsed = (regData.GetValue("LastGameNameUsed") ?? "").ToString();
|
||||||
@ -107,11 +92,76 @@ namespace EpicMorg.SteamPathsLib
|
|||||||
result.AlreadyRetriedOfflineMode = (regData.GetValue("AlreadyRetriedOfflineMode") ?? 0).Equals(1);
|
result.AlreadyRetriedOfflineMode = (regData.GetValue("AlreadyRetriedOfflineMode") ?? 0).Equals(1);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
} catch (Exception) {
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static ConfigSteamData GetSteamConfig() {
|
||||||
|
var result = new ConfigSteamData();
|
||||||
|
var libraryPaths = new List<string>();
|
||||||
|
|
||||||
|
var steamPath = new DirectoryInfo(GetSteamData().SteamPath).FullName;
|
||||||
|
var configPath = Path.Combine(steamPath, "config", "config.vdf");
|
||||||
|
|
||||||
|
libraryPaths.Add(Path.Combine(steamPath, "steamapps"));
|
||||||
|
|
||||||
|
dynamic configObject = VdfConvert.Deserialize(File.ReadAllText(configPath)).Value;
|
||||||
|
var configLibraryPaths = ((VObject)configObject.Software.Valve.Steam)
|
||||||
|
.Children()
|
||||||
|
.Where(item => item.Key.StartsWith("BaseInstallFolder"))
|
||||||
|
.Select(item => item.Value.ToString())
|
||||||
|
.Select(line => new DirectoryInfo(line).FullName)
|
||||||
|
.Select(line => Path.Combine(line, "steamapps"));
|
||||||
|
|
||||||
|
libraryPaths.AddRange(configLibraryPaths);
|
||||||
|
|
||||||
|
result.SteamLibraryFolders = libraryPaths.ToArray();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<LibrarySteamData> GetLibrarySteamDataList() {
|
||||||
|
var configData = GetSteamConfig();
|
||||||
|
var result = new List<LibrarySteamData>();
|
||||||
|
|
||||||
|
foreach (var path in configData.SteamLibraryFolders) {
|
||||||
|
var libraryData = new LibrarySteamData();
|
||||||
|
libraryData.Path = path;
|
||||||
|
libraryData.AppManifestDataList = new List<SteamAppManifestData>();
|
||||||
|
|
||||||
|
var files = new DirectoryInfo(path).GetFiles("appmanifest_*.acf");
|
||||||
|
|
||||||
|
foreach (var file in files) {
|
||||||
|
var appData = new SteamAppManifestData();
|
||||||
|
dynamic appManifestObject = VdfConvert.Deserialize(File.ReadAllText(file.FullName)).Value;
|
||||||
|
|
||||||
|
appData.AppId = Convert.ToInt32(appManifestObject.appid.Value);
|
||||||
|
appData.Name = appManifestObject.name.Value;
|
||||||
|
appData.InstallDir = appManifestObject.installdir.Value;
|
||||||
|
|
||||||
|
appData.Path = Path.Combine(path, "common", appData.InstallDir);
|
||||||
|
|
||||||
|
libraryData.AppManifestDataList.Add(appData);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Add(libraryData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<SteamAppManifestData> GetAllSteamAppManifestData() {
|
||||||
|
var result = new List<SteamAppManifestData>();
|
||||||
|
|
||||||
|
var libraries = GetLibrarySteamDataList();
|
||||||
|
|
||||||
|
foreach (var library in libraries) {
|
||||||
|
result.AddRange(library.AppManifestDataList);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SteamAppManifestData GetSteamAppManifestDataById(int appId) => GetAllSteamAppManifestData().FirstOrDefault(appData => appData.AppId == appId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user