From 5396b80b577a9ec2a98a5626b52e26412e4ea088 Mon Sep 17 00:00:00 2001 From: Alex Z Date: Fri, 7 May 2021 19:44:13 +0300 Subject: [PATCH] replace steampathslib to facepunch.steamworks --- src/UniversalValveToolbox/Program.cs | 5 ++- src/UniversalValveToolbox/UI/FormAbout.cs | 1 + src/UniversalValveToolbox/UI/FormAddons.cs | 9 +++- src/UniversalValveToolbox/UI/FormMain.cs | 45 ++++++++++--------- src/UniversalValveToolbox/UI/FormProjects.cs | 10 ++++- src/UniversalValveToolbox/Utils/EnvUtils.cs | 4 +- .../Utils/SteamManager.cs | 8 ++-- 7 files changed, 51 insertions(+), 31 deletions(-) diff --git a/src/UniversalValveToolbox/Program.cs b/src/UniversalValveToolbox/Program.cs index 6fa7345..b8b5fd0 100644 --- a/src/UniversalValveToolbox/Program.cs +++ b/src/UniversalValveToolbox/Program.cs @@ -1,4 +1,5 @@ -using System; +using Steamworks; +using System; using System.Windows.Forms; using UniversalValveToolbox.Model.Provider; using UniversalValveToolbox.Utils; @@ -10,6 +11,8 @@ namespace UniversalValveToolbox { /// [STAThread] static void Main() { + SteamClient.Init(480); + var dataProvide = new DataProvider(); var currSettings = dataProvide.Settings; diff --git a/src/UniversalValveToolbox/UI/FormAbout.cs b/src/UniversalValveToolbox/UI/FormAbout.cs index 36fb722..8b88286 100644 --- a/src/UniversalValveToolbox/UI/FormAbout.cs +++ b/src/UniversalValveToolbox/UI/FormAbout.cs @@ -13,6 +13,7 @@ namespace UniversalValveToolbox { System.Reflection.Assembly assemblykasthackbindingwf = System.Reflection.Assembly.LoadFrom("kasthack.binding.wf.dll"); System.Reflection.Assembly assemblyGameloopVdf = System.Reflection.Assembly.LoadFrom("Gameloop.Vdf.dll"); System.Reflection.Assembly assemblyNewtonsoftJson = System.Reflection.Assembly.LoadFrom("Newtonsoft.Json.dll"); + Version verEpicMorgSteamPathsLib = assemblyEpicMorgSteamPathsLib.GetName().Version; Version verFacepunchSteamworksWin32 = assemblyFacepunchSteamworksWin32.GetName().Version; Version verkasthackbindingwf = assemblykasthackbindingwf.GetName().Version; diff --git a/src/UniversalValveToolbox/UI/FormAddons.cs b/src/UniversalValveToolbox/UI/FormAddons.cs index 7269808..6022535 100644 --- a/src/UniversalValveToolbox/UI/FormAddons.cs +++ b/src/UniversalValveToolbox/UI/FormAddons.cs @@ -9,7 +9,7 @@ using System.Collections.Generic; using UniversalValveToolbox.Utils; using System.Globalization; using System.Collections; -using EpicMorg.SteamPathsLib; +using Steamworks; namespace UniversalValveToolbox { public partial class FormAddons : Form { @@ -30,7 +30,7 @@ namespace UniversalValveToolbox { .Cast() .ToArray(); - model = new FormAddonViewModel(dataProvider.Addons, dataProvider.Engines.Where(engine => SteamPathsUtil.GetSteamAppDataById(engine.Appid) != null).ToArray(), categories); + model = new FormAddonViewModel(dataProvider.Addons, dataProvider.Engines.Where(engine => isSteamAppInstall(engine.Appid)).ToArray(), categories); UpdateAddonsComboBox(); UpdateAddonCategoryComboBox(); @@ -106,6 +106,11 @@ namespace UniversalValveToolbox { } } + private bool isSteamAppInstall(int appId) { + var isInstall = SteamApps.IsAppInstalled(appId); + return isInstall; + } + private void UpdateAddonCategoryComboBox() { comboBoxCategory.Items.Clear(); comboBoxCategory.Items.AddRange(model.Categories.Select(c => c.Value).ToArray()); diff --git a/src/UniversalValveToolbox/UI/FormMain.cs b/src/UniversalValveToolbox/UI/FormMain.cs index f548089..4ff3fff 100644 --- a/src/UniversalValveToolbox/UI/FormMain.cs +++ b/src/UniversalValveToolbox/UI/FormMain.cs @@ -1,4 +1,4 @@ -using EpicMorg.SteamPathsLib; +using Steamworks; using System; using System.Collections.Generic; using System.Diagnostics; @@ -167,10 +167,9 @@ namespace UniversalValveToolbox { private void UpdateEngineList() { var dataProvider = new DataProvider(); Engines = dataProvider.Engines.Where(engine => { - var engineAppData = SteamPathsUtil.GetSteamAppDataById(engine.Appid); - - return engineAppData != null && engineAppData.Installed; - }).ToArray(); + var isInstall = SteamApps.IsAppInstalled(engine.Appid); + return isInstall; + }).ToArray(); if (Engines != null && Engines.Length != 0) { comboBoxEngine.Enabled = true; @@ -222,7 +221,7 @@ namespace UniversalValveToolbox { if (SelectedEngine == null) return; - var pathSelectedEngine = SteamPathsUtil.GetSteamAppManifestDataById(SelectedEngine.Appid)?.Path; + var pathSelectedEngine = SteamApps.AppInstallDir(SelectedEngine.Appid); if (pathSelectedEngine != null) { var pairPathIconTools = SelectedEngine.Tools @@ -260,20 +259,16 @@ namespace UniversalValveToolbox { listView.Items.AddRange(itemsTools); - var engineData = SteamPathsUtil.GetSteamAppManifestDataById(SelectedEngine.Appid); + var enginePath = SteamApps.AppInstallDir(SelectedEngine.Appid); var isAvailableProjectBySelectEngine = Projects.Any(project => project.Engine == SelectedEngine.Appid); - if (engineData != null && isAvailableProjectBySelectEngine) { - var enginePath = engineData.Path; + if (enginePath != null && isAvailableProjectBySelectEngine) { + var iconPathEngine = Path.Combine(enginePath, SelectedEngine.Bin); - if (enginePath != null) { - var iconPathEngine = Path.Combine(enginePath, SelectedEngine.Bin); + var runProjectListViewItem = new ListViewItem(Properties.translations.MenuItems.itmRunProject, iconPathEngine, listViewGroupTools); + runProjectListViewItem.Tag = RUN_PROJECT_ID; - var runProjectListViewItem = new ListViewItem(Properties.translations.MenuItems.itmRunProject, iconPathEngine, listViewGroupTools); - runProjectListViewItem.Tag = RUN_PROJECT_ID; - - listView.Items.Add(runProjectListViewItem); - } + listView.Items.Add(runProjectListViewItem); } } @@ -289,7 +284,7 @@ namespace UniversalValveToolbox { if (SelectedEngine == null) return; - var pathSelectedEngine = SteamPathsUtil.GetSteamAppManifestDataById(SelectedEngine.Appid)?.Path; + var pathSelectedEngine = SteamApps.AppInstallDir(SelectedEngine.Appid); var addonsSelectedEngine = dataProvider.Addons.Where(a => a.Engines.Contains(SelectedEngine.Appid)); @@ -374,15 +369,15 @@ namespace UniversalValveToolbox { if (selectItem.Group == listViewGroupTools) { if (RUN_PROJECT_ID.Equals(selectItem.Tag) && SelectedProject != null) { - var pathEngineBin = Path.Combine(SteamPathsUtil.GetSteamAppManifestDataById(SelectedEngine.Appid).Path, SelectedEngine.Bin); + var pathEngineBin = Path.Combine(SteamApps.AppInstallDir(SelectedEngine.Appid), SelectedEngine.Bin); + - Process.Start(pathEngineBin, $"-steam -game \"{SelectedProject?.Path ?? string.Empty}\" {SelectedProject.Args}"); } var selectedTool = SelectedEngine.Tools.FirstOrDefault(tool => tool.Name == selectItemText); if (selectedTool != null) { - var selectedEnginePath = SteamPathsUtil.GetSteamAppManifestDataById(SelectedEngine.Appid)?.Path; + var selectedEnginePath = SteamApps.AppInstallDir(SelectedEngine.Appid); if (selectedEnginePath != null) { var toolPath = Path.Combine(selectedEnginePath, selectedTool.Bin); @@ -394,7 +389,15 @@ namespace UniversalValveToolbox { finalArg += $" -game \"{SelectedProject?.Path ?? string.Empty}\" "; } - Process.Start(toolPath, finalArg); + SteamClient.Shutdown(); + SteamClient.Init(Convert.ToUInt32(SelectedEngine.Appid)); + var process = Process.Start(toolPath, finalArg); + process.EnableRaisingEvents = true; + process.Exited += (a, b) => { + SteamClient.Shutdown(); + SteamClient.Init(480); + }; + } else MessageBox.Show($"\"{selectedTool.Name}\" {Properties.translations.MessageBoxes.msgTextNotFound}\n{toolPath}", Properties.translations.MessageBoxes.msgWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); diff --git a/src/UniversalValveToolbox/UI/FormProjects.cs b/src/UniversalValveToolbox/UI/FormProjects.cs index 2915301..003a2ef 100644 --- a/src/UniversalValveToolbox/UI/FormProjects.cs +++ b/src/UniversalValveToolbox/UI/FormProjects.cs @@ -1,5 +1,6 @@ -using EpicMorg.SteamPathsLib; + using kasthack.binding.wf; +using Steamworks; using System; using System.Collections.Generic; using System.Linq; @@ -21,7 +22,7 @@ namespace UniversalValveToolbox { public FormProjects() { InitializeComponent(); - model = new FormProjectViewModel(dataProvider.Projects, dataProvider.Engines.Where(engine => SteamPathsUtil.GetSteamAppDataById(engine.Appid) != null).ToArray()); + model = new FormProjectViewModel(dataProvider.Projects, dataProvider.Engines.Where(engine => isAppInstalled(engine.Appid)).ToArray()); UpdateComboBoxProject(); UpdateComboBoxEngine(); @@ -34,6 +35,11 @@ namespace UniversalValveToolbox { comboBoxEngine.Bind(a => a.SelectedIndex, model, a => a.SelectEngineIndex); } + private bool isAppInstalled(int appId) { + var isInstall = SteamApps.IsAppInstalled(appId); + return isInstall; + } + private void Model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { UpdateComboBoxEngine(); } diff --git a/src/UniversalValveToolbox/Utils/EnvUtils.cs b/src/UniversalValveToolbox/Utils/EnvUtils.cs index 36309e6..4dc5ca1 100644 --- a/src/UniversalValveToolbox/Utils/EnvUtils.cs +++ b/src/UniversalValveToolbox/Utils/EnvUtils.cs @@ -1,4 +1,4 @@ -using EpicMorg.SteamPathsLib; +using Steamworks; using System; using System.IO; @@ -28,7 +28,7 @@ namespace UniversalValveToolbox.Utils { if (pathProject == null || pathProject.Length == 0) return; - var SFMpath = SteamPathsUtil.GetSteamAppManifestDataById(1840)?.Path; + var SFMpath = SteamApps.AppInstallDir(1840); if (SFMpath == null) return; diff --git a/src/UniversalValveToolbox/Utils/SteamManager.cs b/src/UniversalValveToolbox/Utils/SteamManager.cs index a63b3fd..23049ca 100644 --- a/src/UniversalValveToolbox/Utils/SteamManager.cs +++ b/src/UniversalValveToolbox/Utils/SteamManager.cs @@ -1,4 +1,5 @@ -using EpicMorg.SteamPathsLib; +using Steamworks; +using System.Diagnostics; using UniversalValveToolbox.Model.ViewModel; namespace UniversalValveToolbox.Utils { @@ -6,8 +7,9 @@ namespace UniversalValveToolbox.Utils { public static SteamDataViewModel SteamData { get { var result = new SteamDataViewModel(); - result.SteamPid = SteamPathsUtil.GetActiveProcessSteamData()?.PID ?? 0; - result.UserNameSteam = SteamPathsUtil.GetSteamData()?.LastGameNameUsed ?? null; + + result.SteamPid = Process.GetProcessesByName("steam")[0]?.Id ?? 0; + result.UserNameSteam = SteamClient.Name ?? null; return result; }