mirror of
https://github.com/ayufan/steam-deck-tools.git
synced 2026-03-20 11:44:37 +01:00
Validate that all dependencies are installed
This commit is contained in:
parent
19a7a479d9
commit
54354fe9e9
137
CommonHelpers/Dependencies.cs
Normal file
137
CommonHelpers/Dependencies.cs
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace CommonHelpers
|
||||
{
|
||||
public static class Dependencies
|
||||
{
|
||||
public static string[] Hidapi = new string[]
|
||||
{
|
||||
"hidapi.dll"
|
||||
};
|
||||
|
||||
public static string[] RTSSShared = new string[]
|
||||
{
|
||||
"RTSSSharedMemoryNET.dll"
|
||||
};
|
||||
|
||||
private static string[] VCRuntime = new string[]
|
||||
{
|
||||
"vcruntime140.dll"
|
||||
};
|
||||
|
||||
private static string[] RTSS = new string[]
|
||||
{
|
||||
"C:\\Program Files (x86)\\RivaTuner Statistics Server\\RTSSHooks64.dll"
|
||||
};
|
||||
|
||||
private static string VCRuntimeURL = "https://aka.ms/vs/17/release/vc_redist.x64.exe";
|
||||
private static string RTSSURL = "https://www.guru3d.com/files-details/rtss-rivatuner-statistics-server-download.html";
|
||||
|
||||
public static void ValidateHidapi(string title)
|
||||
{
|
||||
ValidateVCRuntime(title);
|
||||
ValidateDependency(title, "HidAPI", Hidapi, false);
|
||||
}
|
||||
|
||||
public static void ValidateRTSSSharedMemoryNET(string title)
|
||||
{
|
||||
ValidateVCRuntime(title);
|
||||
ValidateDependency(title, "RTSSSharedMemoryNET", RTSSShared, false);
|
||||
}
|
||||
|
||||
public static void ValidateRTSS(string title)
|
||||
{
|
||||
InstallDependency(title, "Rivatuner Statistics Server", RTSS, RTSSURL, false, false);
|
||||
}
|
||||
|
||||
private static void ValidateVCRuntime(string title)
|
||||
{
|
||||
InstallDependency(title, "Microsoft Visual C++ Runtime", VCRuntime, VCRuntimeURL, true, false);
|
||||
}
|
||||
|
||||
private static void ValidateDependency(string title, string name, string[] dllNames, bool unload = true)
|
||||
{
|
||||
if (TryToLoad(dllNames, unload))
|
||||
return;
|
||||
|
||||
Log.TraceError("Cannot load: {0}", dllNames);
|
||||
|
||||
MessageBox.Show(
|
||||
"Cannot load: " + string.Join(", ", dllNames) + ".\n\n" +
|
||||
"Application will exit.\n",
|
||||
title,
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error
|
||||
);
|
||||
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
private static void InstallDependency(string title, string name, string[] dllNames, string url, bool required = true, bool unload = true)
|
||||
{
|
||||
if (TryToLoad(dllNames, unload))
|
||||
return;
|
||||
|
||||
Log.TraceError("Cannot load: {0}", dllNames);
|
||||
|
||||
var result = MessageBox.Show(
|
||||
"Missing '" + name + "' (" + string.Join(", ", dllNames) + ").\n\n" +
|
||||
"Click Yes to download and install?\n",
|
||||
title,
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Error
|
||||
);
|
||||
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
ExecuteLink(url);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
if (required)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"The '" + name + "' is required. " +
|
||||
"Application will exit now. " +
|
||||
"Once installed start application again.",
|
||||
title,
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error
|
||||
);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryToLoad(string[] dllNames, bool unload = true)
|
||||
{
|
||||
foreach (var dllName in dllNames)
|
||||
{
|
||||
if (!TryToLoad(dllName, unload))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryToLoad(string dllName, bool unload = true)
|
||||
{
|
||||
var handle = LoadLibrary(dllName);
|
||||
if (unload)
|
||||
FreeLibrary(handle);
|
||||
return handle != IntPtr.Zero;
|
||||
}
|
||||
|
||||
private static void ExecuteLink(string link)
|
||||
{
|
||||
try { Process.Start("explorer.exe", link); }
|
||||
catch { }
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern IntPtr LoadLibrary(string lpFileName);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool FreeLibrary(IntPtr module);
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ namespace PerformanceOverlay
|
|||
internal class Controller : IDisposable
|
||||
{
|
||||
public const String Title = "Performance Overlay";
|
||||
public readonly String TitleWithVersion = Title + " v" + System.Windows.Forms.Application.ProductVersion.ToString();
|
||||
public static readonly String TitleWithVersion = Title + " v" + System.Windows.Forms.Application.ProductVersion.ToString();
|
||||
|
||||
Container components = new Container();
|
||||
RTSSSharedMemoryNET.OSD? osd;
|
||||
|
|
@ -24,6 +24,12 @@ namespace PerformanceOverlay
|
|||
|
||||
SharedData<OverlayModeSetting> sharedData = SharedData<OverlayModeSetting>.CreateNew();
|
||||
|
||||
static Controller()
|
||||
{
|
||||
Dependencies.ValidateRTSS(TitleWithVersion);
|
||||
Dependencies.ValidateRTSSSharedMemoryNET(TitleWithVersion);
|
||||
}
|
||||
|
||||
public Controller()
|
||||
{
|
||||
Instance.OnUninstall(() =>
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace PowerControl
|
|||
internal class Controller : IDisposable
|
||||
{
|
||||
public const String Title = "Power Control";
|
||||
public readonly String TitleWithVersion = Title + " v" + Application.ProductVersion.ToString();
|
||||
public static readonly String TitleWithVersion = Title + " v" + Application.ProductVersion.ToString();
|
||||
public const int KeyPressRepeatTime = 400;
|
||||
public const int KeyPressNextRepeatTime = 90;
|
||||
|
||||
|
|
@ -38,6 +38,12 @@ namespace PowerControl
|
|||
|
||||
SharedData<PowerControlSetting> sharedData = SharedData<PowerControlSetting>.CreateNew();
|
||||
|
||||
static Controller()
|
||||
{
|
||||
Dependencies.ValidateHidapi(TitleWithVersion);
|
||||
Dependencies.ValidateRTSSSharedMemoryNET(TitleWithVersion);
|
||||
}
|
||||
|
||||
public Controller()
|
||||
{
|
||||
Instance.OnUninstall(() =>
|
||||
|
|
|
|||
|
|
@ -15,3 +15,4 @@
|
|||
- Add `Setup.exe` installer to install all except RTSS
|
||||
- Add `Sentry` error tracking
|
||||
- Use `white` icons when using `Dark Theme` (thanks @maniman303 https://github.com/ayufan/steam-deck-tools/pull/23)
|
||||
- Validate that all dependencies are installed
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace SteamController
|
|||
internal class Controller : IDisposable
|
||||
{
|
||||
public const String Title = "Steam Controller";
|
||||
public readonly String TitleWithVersion = Title + " v" + Application.ProductVersion.ToString();
|
||||
public static readonly String TitleWithVersion = Title + " v" + Application.ProductVersion.ToString();
|
||||
|
||||
Container components = new Container();
|
||||
NotifyIcon notifyIcon;
|
||||
|
|
@ -32,6 +32,11 @@ namespace SteamController
|
|||
}
|
||||
};
|
||||
|
||||
static Controller()
|
||||
{
|
||||
Dependencies.ValidateHidapi(TitleWithVersion);
|
||||
}
|
||||
|
||||
public Controller()
|
||||
{
|
||||
Instance.OnUninstall(() =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue