feat(autoupdate): detect install type
This commit is contained in:
38
CarManagerV3/Util/InstallModeDetector.cs
Normal file
38
CarManagerV3/Util/InstallModeDetector.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace CarManagerV3.Util
|
||||
{
|
||||
public static class InstallModeDetector
|
||||
{
|
||||
private const string _keyPath = @"Software\Jaro Digital\CarManager3";
|
||||
private const string KeyPath = _keyPath;
|
||||
private const string ValueName = "InstallType";
|
||||
|
||||
public static bool IsInstalledViaMsi()
|
||||
{
|
||||
// Prefer HKLM if your MSI is per-machine; fallback to HKCU if per-user.
|
||||
System.Diagnostics.Debug.WriteLine($"Checking registry for install type at HKLM\\{KeyPath} and HKCU\\{KeyPath}");
|
||||
object? val =
|
||||
Registry.GetValue($@"HKEY_LOCAL_MACHINE\{KeyPath}", ValueName, null)
|
||||
?? Registry.GetValue($@"HKEY_CURRENT_USER\{KeyPath}", ValueName, null);
|
||||
|
||||
return val is string s && string.Equals(s, "MSI", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public static bool IsPortable() => !IsInstalledViaMsi();
|
||||
|
||||
public static string GetInstallType()
|
||||
{
|
||||
object? val =
|
||||
Registry.GetValue($@"HKEY_LOCAL_MACHINE\{KeyPath}", ValueName, null)
|
||||
?? Registry.GetValue($@"HKEY_CURRENT_USER\{KeyPath}", ValueName, null);
|
||||
return val as string ?? "Unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user