2023-07-12 09:19:33 +02:00
|
|
|
|
using System.Diagnostics;
|
2022-07-09 13:14:03 -04:00
|
|
|
|
using System.Runtime.InteropServices;
|
2023-07-12 09:19:33 +02:00
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
using SPTInstaller.Models;
|
|
|
|
|
|
|
|
|
|
namespace SPTInstaller.Helpers;
|
2022-05-14 12:19:40 +01:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public static class PreCheckHelper
|
2022-05-14 12:19:40 +01:00
|
|
|
|
{
|
2024-05-01 10:31:55 -04:00
|
|
|
|
private const string registryInstall =
|
|
|
|
|
@"Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\EscapeFromTarkov";
|
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public static string DetectOriginalGamePath()
|
2022-05-14 12:19:40 +01:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
// We can't detect the installed path on non-Windows
|
|
|
|
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
return null;
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
var uninstallStringValue = Registry.LocalMachine.OpenSubKey(registryInstall, false)
|
2023-12-19 14:58:12 -05:00
|
|
|
|
?.GetValue("InstallLocation");
|
|
|
|
|
var info = (uninstallStringValue is string key) ? new DirectoryInfo(key) : null;
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-12-19 14:58:12 -05:00
|
|
|
|
return info?.FullName;
|
2023-07-12 09:19:33 +02:00
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public static Result DetectOriginalGameVersion(string gamePath)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-01 10:31:55 -04:00
|
|
|
|
string version = FileVersionInfo.GetVersionInfo(Path.Join(gamePath, "/EscapeFromTarkov.exe")).ProductVersion
|
|
|
|
|
.Replace('-', '.').Split('.')[^2];
|
2023-07-12 09:19:33 +02:00
|
|
|
|
return Result.FromSuccess(version);
|
2022-05-14 12:19:40 +01:00
|
|
|
|
}
|
2023-07-12 09:19:33 +02:00
|
|
|
|
catch (Exception ex)
|
2022-05-14 12:19:40 +01:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
return Result.FromError($"File not found: {ex.Message}");
|
2022-05-14 12:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-12 09:19:33 +02:00
|
|
|
|
}
|