From 5006877670aacc02f24d481db4f1a2b43c78fd7a Mon Sep 17 00:00:00 2001 From: Konstantin Safonov Date: Wed, 18 Mar 2020 01:14:41 +0300 Subject: [PATCH 1/3] Migrate to .net core sdk --- CHANGELOG.md | 6 ++ nuget/EpicMorg.SteamPathsLib.nuspec | 29 ------ nuget/build.ps1 | 6 -- nuget/dummy_file | 1 - nuget/lib/net48/dummy_file | 1 - .../EpicMorg.SteamPathsLib.csproj | 88 ++++++------------ .../Properties/AssemblyInfo.cs | 18 ---- .../EpicMorg.SteamPathsLib/steam.png | Bin src/SteamTest/App.config | 2 +- src/SteamTest/Properties/AssemblyInfo.cs | 4 +- src/SteamTest/Properties/Settings.Designer.cs | 2 +- src/SteamTest/SteamTest.csproj | 2 +- 12 files changed, 39 insertions(+), 120 deletions(-) delete mode 100644 nuget/EpicMorg.SteamPathsLib.nuspec delete mode 100644 nuget/build.ps1 delete mode 100644 nuget/dummy_file delete mode 100644 nuget/lib/net48/dummy_file delete mode 100644 src/EpicMorg.SteamPathsLib/Properties/AssemblyInfo.cs rename nuget/images/icon.png => src/EpicMorg.SteamPathsLib/steam.png (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bf5b0a..facd848 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,3 +4,9 @@ * Added new info about steam and steam application * `1.1.0.1` Whats new: * Add info directly from Steam +* `1.1.0.2` Whats new: + * Fixed catching exceptions +* `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 \ No newline at end of file diff --git a/nuget/EpicMorg.SteamPathsLib.nuspec b/nuget/EpicMorg.SteamPathsLib.nuspec deleted file mode 100644 index 4a2d0c1..0000000 --- a/nuget/EpicMorg.SteamPathsLib.nuspec +++ /dev/null @@ -1,29 +0,0 @@ - - - - EpicMorg.SteamPathsLib - Steam Paths Library - 1.1.0.3 - EpicMorgDev, AurZum, stam - EpicMorgDev, AurZum, stam - en-US - https://github.com/EpicMorg/SteamPathsLib - - MIT - images\icon.png - false - Fixed loading appmanifest data if we have an invalid *.acf. - Small helper for getting some registry keys of Steam. - Copyright © 2020 EpicMorg - steam epicmorg registry path helper vdf - - - - - - - - - - - diff --git a/nuget/build.ps1 b/nuget/build.ps1 deleted file mode 100644 index fbbf36b..0000000 --- a/nuget/build.ps1 +++ /dev/null @@ -1,6 +0,0 @@ -Remove-Item './lib/net48/dummy_file' -Force -Remove-Item './*.nupkg' -Force - -& nuget.exe pack ./EpicMorg.SteamPathsLib.nuspec - -Copy-Item './dummy_file' -Destination './lib/net48/dummy_file' -Force \ No newline at end of file diff --git a/nuget/dummy_file b/nuget/dummy_file deleted file mode 100644 index 7b45d97..0000000 --- a/nuget/dummy_file +++ /dev/null @@ -1 +0,0 @@ -dummy_file \ No newline at end of file diff --git a/nuget/lib/net48/dummy_file b/nuget/lib/net48/dummy_file deleted file mode 100644 index 7b45d97..0000000 --- a/nuget/lib/net48/dummy_file +++ /dev/null @@ -1 +0,0 @@ -dummy_file \ No newline at end of file diff --git a/src/EpicMorg.SteamPathsLib/EpicMorg.SteamPathsLib.csproj b/src/EpicMorg.SteamPathsLib/EpicMorg.SteamPathsLib.csproj index 6219390..680a94b 100644 --- a/src/EpicMorg.SteamPathsLib/EpicMorg.SteamPathsLib.csproj +++ b/src/EpicMorg.SteamPathsLib/EpicMorg.SteamPathsLib.csproj @@ -1,66 +1,34 @@ - - - - - Debug - AnyCPU - {E34AE985-7C7E-49BA-A2B0-70D88F865265} - Library - Properties - EpicMorg.SteamPathsLib - EpicMorg.SteamPathsLib - v4.8 - 512 - true - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - + steam.ico + net46;netstandard1.3 + EpicMorg + true + false + https://github.com/EpicMorg/SteamPathsLib + steam.png + https://github.com/EpicMorg/SteamPathsLib + Copyright © EpicMorg 2020 + 1.1.0.4 + 1.1.0.4 + 1.1.0.4 + Small helper for getting some registry keys of Steam. + EpicMorgDev, AurZum, stam, kasthack + MIT + git + steam epicmorg registry path helper vdf + Code review and optimizations - - - - - - - - + + True + + + + + + + True + - - - - - - - - - - - - - - - - 0.5.0 - - - \ No newline at end of file diff --git a/src/EpicMorg.SteamPathsLib/Properties/AssemblyInfo.cs b/src/EpicMorg.SteamPathsLib/Properties/AssemblyInfo.cs deleted file mode 100644 index ec2abe0..0000000 --- a/src/EpicMorg.SteamPathsLib/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("EpicMorg.SteamPathsLib")] -[assembly: AssemblyDescription("Steam Paths Library")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("EpicMorg")] -[assembly: AssemblyProduct("EpicMorg.SteamPathsLib")] -[assembly: AssemblyCopyright("Copyright © EpicMorg 2020")] -[assembly: AssemblyTrademark("Valve")] -[assembly: AssemblyCulture("")] - -[assembly: ComVisible(false)] - -[assembly: Guid("e34ae985-7c7e-49ba-a2b0-70d88f865265")] - -[assembly: AssemblyVersion("1.1.0.3")] -[assembly: AssemblyFileVersion("1.1.0.3")] diff --git a/nuget/images/icon.png b/src/EpicMorg.SteamPathsLib/steam.png similarity index 100% rename from nuget/images/icon.png rename to src/EpicMorg.SteamPathsLib/steam.png diff --git a/src/SteamTest/App.config b/src/SteamTest/App.config index 4bfa005..2d2a12d 100644 --- a/src/SteamTest/App.config +++ b/src/SteamTest/App.config @@ -1,6 +1,6 @@ - + diff --git a/src/SteamTest/Properties/AssemblyInfo.cs b/src/SteamTest/Properties/AssemblyInfo.cs index 0159491..c61b2d9 100644 --- a/src/SteamTest/Properties/AssemblyInfo.cs +++ b/src/SteamTest/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.3")] -[assembly: AssemblyFileVersion("1.0.0.3")] +[assembly: AssemblyVersion("1.0.0.4")] +[assembly: AssemblyFileVersion("1.0.0.4")] diff --git a/src/SteamTest/Properties/Settings.Designer.cs b/src/SteamTest/Properties/Settings.Designer.cs index 0f9ec13..a957ce5 100644 --- a/src/SteamTest/Properties/Settings.Designer.cs +++ b/src/SteamTest/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace SteamTest.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.3.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.6.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/src/SteamTest/SteamTest.csproj b/src/SteamTest/SteamTest.csproj index 344ce1b..c8fa500 100644 --- a/src/SteamTest/SteamTest.csproj +++ b/src/SteamTest/SteamTest.csproj @@ -8,7 +8,7 @@ WinExe SteamTest SteamTest - v4.8 + v4.6 512 true From 18f13665cb53f2d9c07584fca1059e23e20a2534 Mon Sep 17 00:00:00 2001 From: Konstantin Safonov Date: Wed, 18 Mar 2020 01:36:10 +0300 Subject: [PATCH 2/3] Code cleanup --- CHANGELOG.md | 2 +- .../EpicMorg.SteamPathsLib.csproj | 6 +- .../Model/ActiveProcessSteamRegistryData.cs | 12 +- .../Model/ConfigSteamData.cs | 14 +- .../Model/LibrarySteamData.cs | 16 +- .../Model/SteamAppManifestData.cs | 20 +- .../Model/SteamAppRegistryData.cs | 23 +- .../Model/SteamRegistryData.cs | 37 +-- src/EpicMorg.SteamPathsLib/SteamPathsUtil.cs | 278 +++++++++--------- src/SteamTest/Program.cs | 3 - src/SteamTest/Properties/AssemblyInfo.cs | 1 - 11 files changed, 192 insertions(+), 220 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index facd848..ad3d018 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 \ No newline at end of file + * Code review and optimizations, dotNetCore support \ No newline at end of file diff --git a/src/EpicMorg.SteamPathsLib/EpicMorg.SteamPathsLib.csproj b/src/EpicMorg.SteamPathsLib/EpicMorg.SteamPathsLib.csproj index 680a94b..d2feb9e 100644 --- a/src/EpicMorg.SteamPathsLib/EpicMorg.SteamPathsLib.csproj +++ b/src/EpicMorg.SteamPathsLib/EpicMorg.SteamPathsLib.csproj @@ -17,7 +17,7 @@ MIT git steam epicmorg registry path helper vdf - Code review and optimizations + Code review and optimizations, dotNetCore support @@ -30,5 +30,9 @@ True + + all + runtime; build; native; contentfiles; analyzers + \ No newline at end of file diff --git a/src/EpicMorg.SteamPathsLib/Model/ActiveProcessSteamRegistryData.cs b/src/EpicMorg.SteamPathsLib/Model/ActiveProcessSteamRegistryData.cs index 574bdc4..0baa2df 100644 --- a/src/EpicMorg.SteamPathsLib/Model/ActiveProcessSteamRegistryData.cs +++ b/src/EpicMorg.SteamPathsLib/Model/ActiveProcessSteamRegistryData.cs @@ -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; } } } diff --git a/src/EpicMorg.SteamPathsLib/Model/ConfigSteamData.cs b/src/EpicMorg.SteamPathsLib/Model/ConfigSteamData.cs index 880af29..ef8ac0c 100644 --- a/src/EpicMorg.SteamPathsLib/Model/ConfigSteamData.cs +++ b/src/EpicMorg.SteamPathsLib/Model/ConfigSteamData.cs @@ -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; } } } diff --git a/src/EpicMorg.SteamPathsLib/Model/LibrarySteamData.cs b/src/EpicMorg.SteamPathsLib/Model/LibrarySteamData.cs index 47ed97e..d14840e 100644 --- a/src/EpicMorg.SteamPathsLib/Model/LibrarySteamData.cs +++ b/src/EpicMorg.SteamPathsLib/Model/LibrarySteamData.cs @@ -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 AppManifestDataList { get; set; } - public List AppManifestDataList; + public string Path { get; set; } } } diff --git a/src/EpicMorg.SteamPathsLib/Model/SteamAppManifestData.cs b/src/EpicMorg.SteamPathsLib/Model/SteamAppManifestData.cs index 32130ba..a4aec20 100644 --- a/src/EpicMorg.SteamPathsLib/Model/SteamAppManifestData.cs +++ b/src/EpicMorg.SteamPathsLib/Model/SteamAppManifestData.cs @@ -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; } } } diff --git a/src/EpicMorg.SteamPathsLib/Model/SteamAppRegistryData.cs b/src/EpicMorg.SteamPathsLib/Model/SteamAppRegistryData.cs index d659bbf..5b81227 100644 --- a/src/EpicMorg.SteamPathsLib/Model/SteamAppRegistryData.cs +++ b/src/EpicMorg.SteamPathsLib/Model/SteamAppRegistryData.cs @@ -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; } } } diff --git a/src/EpicMorg.SteamPathsLib/Model/SteamRegistryData.cs b/src/EpicMorg.SteamPathsLib/Model/SteamRegistryData.cs index 9529c89..153d7ca 100644 --- a/src/EpicMorg.SteamPathsLib/Model/SteamRegistryData.cs +++ b/src/EpicMorg.SteamPathsLib/Model/SteamRegistryData.cs @@ -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; } } } diff --git a/src/EpicMorg.SteamPathsLib/SteamPathsUtil.cs b/src/EpicMorg.SteamPathsLib/SteamPathsUtil.cs index 49343a6..793e82e 100644 --- a/src/EpicMorg.SteamPathsLib/SteamPathsUtil.cs +++ b/src/EpicMorg.SteamPathsLib/SteamPathsUtil.cs @@ -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(); - 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(); + 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 GetLibrarySteamDataList() => TryOrDefault(() => + { + var configData = GetSteamConfig(); + var result = new List(); - 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(), + }; - 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 GetLibrarySteamDataList() { - try { - var configData = GetSteamConfig(); - var result = new List(); + 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(); - - 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 GetAllSteamAppManifestData() { - try { - var result = new List(); + return result; + }); - var libraries = GetLibrarySteamDataList(); + public static List GetAllSteamAppManifestData() => TryOrDefault(() => + { + var result = new List(); - 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(Func action) + { + try + { + return action(); + } + catch + { + return default; + } + } } } diff --git a/src/SteamTest/Program.cs b/src/SteamTest/Program.cs index f26ab1c..b9e7764 100644 --- a/src/SteamTest/Program.cs +++ b/src/SteamTest/Program.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using System.Windows.Forms; namespace SteamTest diff --git a/src/SteamTest/Properties/AssemblyInfo.cs b/src/SteamTest/Properties/AssemblyInfo.cs index c61b2d9..e641e6b 100644 --- a/src/SteamTest/Properties/AssemblyInfo.cs +++ b/src/SteamTest/Properties/AssemblyInfo.cs @@ -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 From 7db191cf39ce1833e859e27763dea9e8f5420633 Mon Sep 17 00:00:00 2001 From: STAM Date: Thu, 19 Mar 2020 12:45:29 +0300 Subject: [PATCH 3/3] Update EpicMorg.SteamPathsLib.csproj --- src/EpicMorg.SteamPathsLib/EpicMorg.SteamPathsLib.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/EpicMorg.SteamPathsLib/EpicMorg.SteamPathsLib.csproj b/src/EpicMorg.SteamPathsLib/EpicMorg.SteamPathsLib.csproj index d2feb9e..0d4b000 100644 --- a/src/EpicMorg.SteamPathsLib/EpicMorg.SteamPathsLib.csproj +++ b/src/EpicMorg.SteamPathsLib/EpicMorg.SteamPathsLib.csproj @@ -1,7 +1,7 @@  steam.ico - net46;netstandard1.3 + net46;net461;net462;net47;net471;net472;net48;netstandard1.3;netcoreapp3.1 EpicMorg true false @@ -9,9 +9,9 @@ steam.png https://github.com/EpicMorg/SteamPathsLib Copyright © EpicMorg 2020 - 1.1.0.4 - 1.1.0.4 - 1.1.0.4 + 1.1.0.5 + 1.1.0.5 + 1.1.0.5 Small helper for getting some registry keys of Steam. EpicMorgDev, AurZum, stam, kasthack MIT