mirror of
https://github.com/EpicMorg/SteamPathsLib.git
synced 2024-12-25 14:05:28 +03:00
Code cleanup
This commit is contained in:
parent
5006877670
commit
18f13665cb
@ -9,4 +9,4 @@
|
||||
* `1.1.0.3` Whats new:
|
||||
* Fixed loading appmanifest data if we have an invalid *.acf.
|
||||
* `1.1.0.4` Whats new:
|
||||
* Code review and optimizations
|
||||
* Code review and optimizations, dotNetCore support
|
@ -17,7 +17,7 @@
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>steam epicmorg registry path helper vdf</PackageTags>
|
||||
<PackageReleaseNotes>Code review and optimizations</PackageReleaseNotes>
|
||||
<PackageReleaseNotes>Code review and optimizations, dotNetCore support</PackageReleaseNotes>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="steam.png">
|
||||
@ -30,5 +30,9 @@
|
||||
<None Include="steam.ico">
|
||||
<Pack>True</Pack>
|
||||
</None>
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,15 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EpicMorg.SteamPathsLib.Model
|
||||
namespace EpicMorg.SteamPathsLib.Model
|
||||
{
|
||||
public class ActiveProcessSteamRegistryData
|
||||
{
|
||||
public string RegistryKey;
|
||||
public string RegistryKey { get; set; }
|
||||
|
||||
public int PID;
|
||||
public int PID { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,7 @@
|
||||
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;
|
||||
namespace EpicMorg.SteamPathsLib.Model
|
||||
{
|
||||
public class ConfigSteamData
|
||||
{
|
||||
public string[] SteamLibraryFolders { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace EpicMorg.SteamPathsLib.Model
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace EpicMorg.SteamPathsLib.Model {
|
||||
public class LibrarySteamData {
|
||||
public string Path;
|
||||
public class LibrarySteamData
|
||||
{
|
||||
public List<SteamAppManifestData> AppManifestDataList { get; set; }
|
||||
|
||||
public List<SteamAppManifestData> AppManifestDataList;
|
||||
public string Path { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,13 @@
|
||||
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 { get; set; }
|
||||
|
||||
namespace EpicMorg.SteamPathsLib.Model {
|
||||
public class SteamAppManifestData {
|
||||
public int AppId;
|
||||
public string Name;
|
||||
public string InstallDir;
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Path;
|
||||
public string InstallDir { get; set; }
|
||||
|
||||
public string Path { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EpicMorg.SteamPathsLib.Model
|
||||
namespace EpicMorg.SteamPathsLib.Model
|
||||
{
|
||||
public class SteamAppRegistryData
|
||||
{
|
||||
public string RegistryKey;
|
||||
public string Name;
|
||||
public bool Installed { get; set; }
|
||||
|
||||
public int AppId;
|
||||
public bool Running { get; set; }
|
||||
|
||||
public bool Installed;
|
||||
public bool Runnig;
|
||||
public bool Updating;
|
||||
public bool Updating { get; set; }
|
||||
|
||||
public int AppId { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string RegistryKey { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EpicMorg.SteamPathsLib.Model
|
||||
namespace EpicMorg.SteamPathsLib.Model
|
||||
{
|
||||
public class SteamRegistryData
|
||||
{
|
||||
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 string RegistryKey { get; set; }
|
||||
|
||||
public int RunningAppID;
|
||||
public string LastGameNameUsed { get; set; }
|
||||
|
||||
public bool AlreadyRetriedOfflineMode;
|
||||
public bool RememberPassword;
|
||||
public string SourceModInstallPath { get; set; }
|
||||
|
||||
public string SteamExe { get; set; }
|
||||
|
||||
public string SteamPath { get; set; }
|
||||
|
||||
public string Language { get; set; }
|
||||
|
||||
public string PseudoUUID { get; set; }
|
||||
|
||||
public string ModInstallPath { get; set; }
|
||||
|
||||
public int RunningAppID { get; set; }
|
||||
|
||||
public bool AlreadyRetriedOfflineMode { get; set; }
|
||||
|
||||
public bool RememberPassword { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,185 +1,173 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using EpicMorg.SteamPathsLib.Model;
|
||||
using Gameloop.Vdf;
|
||||
using Gameloop.Vdf.Linq;
|
||||
using Microsoft.Win32;
|
||||
namespace EpicMorg.SteamPathsLib
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using EpicMorg.SteamPathsLib.Model;
|
||||
using Gameloop.Vdf;
|
||||
using Gameloop.Vdf.Linq;
|
||||
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";
|
||||
public static class SteamPathsUtil
|
||||
{
|
||||
private const string ValveKey = @"Software\Valve";
|
||||
private const string ValveSteamKey = @"Software\Valve\Steam";
|
||||
private const string ValveSteamAppsKey = @"Software\Valve\Steam\Apps";
|
||||
private const string ValveActiveProcessPID = @"Software\Valve\Steam\ActiveProcess";
|
||||
|
||||
private static readonly string _valveSteamAppsPattern = @"Software\Valve\Steam\Apps\";
|
||||
private const string ValveSteamAppsPattern = @"Software\Valve\Steam\Apps\";
|
||||
|
||||
public static string GetValveKeyRegistry() {
|
||||
try {
|
||||
return Registry.CurrentUser.OpenSubKey(_valveKey).ToString();
|
||||
} catch (Exception) {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
public static string GetValveKeyRegistry() => TryOrDefault(() => Registry.CurrentUser.OpenSubKey(ValveKey).ToString());
|
||||
|
||||
public static string GetSteamAppsKeyRegistry() {
|
||||
try {
|
||||
return Registry.CurrentUser.OpenSubKey(_valveSteamAppsKey).ToString();
|
||||
} catch (Exception) {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
public static string GetSteamAppsKeyRegistry() => TryOrDefault(() => Registry.CurrentUser.OpenSubKey(ValveSteamAppsKey).ToString());
|
||||
|
||||
public static ActiveProcessSteamRegistryData GetActiveProcessSteamData() {
|
||||
try {
|
||||
var regData = Registry.CurrentUser.OpenSubKey(_valveActiveProcessPID);
|
||||
public static ActiveProcessSteamRegistryData GetActiveProcessSteamData() => TryOrDefault(() =>
|
||||
{
|
||||
using (var regData = Registry.CurrentUser.OpenSubKey(ValveActiveProcessPID))
|
||||
{
|
||||
return new ActiveProcessSteamRegistryData
|
||||
{
|
||||
RegistryKey = regData.ToString(),
|
||||
PID = Convert.ToInt32(regData.GetValue("pid") ?? 0),
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
var result = new ActiveProcessSteamRegistryData();
|
||||
public static SteamAppRegistryData GetSteamAppDataById(int appId) => TryOrDefault(() =>
|
||||
{
|
||||
using (var regData = Registry.CurrentUser.OpenSubKey(ValveSteamAppsPattern + appId))
|
||||
{
|
||||
return new SteamAppRegistryData
|
||||
{
|
||||
RegistryKey = regData.ToString(),
|
||||
Name = (regData.GetValue("Name") ?? string.Empty).ToString(),
|
||||
|
||||
result.RegistryKey = regData.ToString();
|
||||
result.PID = Convert.ToInt32((regData.GetValue("pid") ?? 0));
|
||||
AppId = appId,
|
||||
|
||||
return result;
|
||||
} catch (Exception) {
|
||||
return null;
|
||||
Installed = (regData.GetValue("Installed") ?? 0).Equals(1),
|
||||
Updating = (regData.GetValue("Updating") ?? 0).Equals(1),
|
||||
Running = (regData.GetValue("Running") ?? 0).Equals(1),
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
public static SteamAppRegistryData GetSteamAppDataById(int appId) {
|
||||
var appKey = _valveSteamAppsPattern + appId;
|
||||
public static SteamRegistryData GetSteamData() => TryOrDefault(() =>
|
||||
{
|
||||
using (var regData = Registry.CurrentUser.OpenSubKey(ValveSteamKey))
|
||||
{
|
||||
return new SteamRegistryData
|
||||
{
|
||||
RegistryKey = regData.ToString(),
|
||||
LastGameNameUsed = (regData.GetValue("LastGameNameUsed") ?? string.Empty).ToString(),
|
||||
SourceModInstallPath = (regData.GetValue("SourceModInstallPath") ?? string.Empty).ToString(),
|
||||
SteamExe = (regData.GetValue("SteamExe") ?? string.Empty).ToString(),
|
||||
SteamPath = (regData.GetValue("SteamPath") ?? string.Empty).ToString(),
|
||||
Language = (regData.GetValue("Language") ?? string.Empty).ToString(),
|
||||
PseudoUUID = (regData.GetValue("PseudoUUID") ?? string.Empty).ToString(),
|
||||
ModInstallPath = (regData.GetValue("ModInstallPath") ?? string.Empty).ToString(),
|
||||
|
||||
try {
|
||||
var regData = Registry.CurrentUser.OpenSubKey(appKey);
|
||||
RunningAppID = Convert.ToInt32((regData.GetValue("RunningAppID") ?? "0").ToString()),
|
||||
|
||||
var result = new SteamAppRegistryData();
|
||||
|
||||
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;
|
||||
RememberPassword = (regData.GetValue("RememberPassword") ?? 0).Equals(1),
|
||||
AlreadyRetriedOfflineMode = (regData.GetValue("AlreadyRetriedOfflineMode") ?? 0).Equals(1),
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
public static SteamRegistryData GetSteamData() {
|
||||
try {
|
||||
var regData = Registry.CurrentUser.OpenSubKey(_valveSteamKey);
|
||||
public static ConfigSteamData GetSteamConfig() => TryOrDefault(() =>
|
||||
{
|
||||
var result = new ConfigSteamData();
|
||||
var libraryPaths = new List<string>();
|
||||
|
||||
var result = new SteamRegistryData();
|
||||
var steamPath = new DirectoryInfo(GetSteamData().SteamPath).FullName;
|
||||
var configPath = Path.Combine(steamPath, "config", "config.vdf");
|
||||
|
||||
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();
|
||||
libraryPaths.Add(Path.Combine(steamPath, "steamapps"));
|
||||
|
||||
result.RunningAppID = Convert.ToInt32((regData.GetValue("RunningAppID") ?? "0").ToString());
|
||||
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"));
|
||||
|
||||
result.RememberPassword = (regData.GetValue("RememberPassword") ?? 0).Equals(1);
|
||||
result.AlreadyRetriedOfflineMode = (regData.GetValue("AlreadyRetriedOfflineMode") ?? 0).Equals(1);
|
||||
libraryPaths.AddRange(configLibraryPaths);
|
||||
|
||||
return result;
|
||||
} catch (Exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static ConfigSteamData GetSteamConfig() {
|
||||
try {
|
||||
var result = new ConfigSteamData();
|
||||
var libraryPaths = new List<string>();
|
||||
result.SteamLibraryFolders = libraryPaths.ToArray();
|
||||
|
||||
var steamPath = new DirectoryInfo(GetSteamData().SteamPath).FullName;
|
||||
var configPath = Path.Combine(steamPath, "config", "config.vdf");
|
||||
return result;
|
||||
});
|
||||
|
||||
libraryPaths.Add(Path.Combine(steamPath, "steamapps"));
|
||||
public static List<LibrarySteamData> GetLibrarySteamDataList() => TryOrDefault(() =>
|
||||
{
|
||||
var configData = GetSteamConfig();
|
||||
var result = new List<LibrarySteamData>();
|
||||
|
||||
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"));
|
||||
foreach (var path in configData.SteamLibraryFolders)
|
||||
{
|
||||
var libraryData = new LibrarySteamData
|
||||
{
|
||||
Path = path,
|
||||
AppManifestDataList = new List<SteamAppManifestData>(),
|
||||
};
|
||||
|
||||
libraryPaths.AddRange(configLibraryPaths);
|
||||
var files = new DirectoryInfo(path).GetFiles("appmanifest_*.acf");
|
||||
|
||||
result.SteamLibraryFolders = libraryPaths.ToArray();
|
||||
foreach (var file in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appData = new SteamAppManifestData();
|
||||
dynamic appManifestObject = VdfConvert.Deserialize(File.ReadAllText(file.FullName)).Value;
|
||||
|
||||
return result;
|
||||
} catch (Exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
appData.AppId = Convert.ToInt32(appManifestObject.appid.Value);
|
||||
appData.Name = appManifestObject.name.Value;
|
||||
appData.InstallDir = appManifestObject.installdir.Value;
|
||||
|
||||
public static List<LibrarySteamData> GetLibrarySteamDataList() {
|
||||
try {
|
||||
var configData = GetSteamConfig();
|
||||
var result = new List<LibrarySteamData>();
|
||||
appData.Path = Path.Combine(path, "common", appData.InstallDir);
|
||||
|
||||
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) {
|
||||
try {
|
||||
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);
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
libraryData.AppManifestDataList.Add(appData);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
|
||||
result.Add(libraryData);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e);
|
||||
|
||||
return null;
|
||||
result.Add(libraryData);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<SteamAppManifestData> GetAllSteamAppManifestData() {
|
||||
try {
|
||||
var result = new List<SteamAppManifestData>();
|
||||
return result;
|
||||
});
|
||||
|
||||
var libraries = GetLibrarySteamDataList();
|
||||
public static List<SteamAppManifestData> GetAllSteamAppManifestData() => TryOrDefault(() =>
|
||||
{
|
||||
var result = new List<SteamAppManifestData>();
|
||||
|
||||
foreach (var library in libraries) {
|
||||
result.AddRange(library.AppManifestDataList);
|
||||
}
|
||||
var libraries = GetLibrarySteamDataList();
|
||||
|
||||
return result;
|
||||
} catch (Exception) {
|
||||
return null;
|
||||
foreach (var library in libraries)
|
||||
{
|
||||
result.AddRange(library.AppManifestDataList);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
public static SteamAppManifestData GetSteamAppManifestDataById(int appId) => GetAllSteamAppManifestData()?.FirstOrDefault(appData => appData.AppId == appId);
|
||||
|
||||
private static T TryOrDefault<T>(Func<T> action)
|
||||
{
|
||||
try
|
||||
{
|
||||
return action();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SteamTest
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
|
Loading…
Reference in New Issue
Block a user