0
0
mirror of https://github.com/sp-tarkov/launcher.git synced 2025-02-12 17:10:44 -05:00

Update registry handling to work with new JSON based registry redirect (!68)

- Remove the "Wipe Registry" button
- Remove the registry wipe on new profile creation/profile wipe

This is a companion to [#172](SPT/Modules#172) which moves SPTs "registry" into a JSON file to avoid cross contamination with live data

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: SPT/Launcher#68
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-10-26 08:16:03 +00:00 committed by chomp
parent 7181f22852
commit 313b936d96
4 changed files with 15 additions and 37 deletions

View File

@ -289,6 +289,7 @@ namespace SPT.Launcher
} }
SelectedAccount.edition = edition; SelectedAccount.edition = edition;
SelectedAccount.wipe = true;
LogManager.Instance.Info($"Account Wiped: {data.username} -> {edition}"); LogManager.Instance.Info($"Account Wiped: {data.username} -> {edition}");
return AccountStatus.OK; return AccountStatus.OK;
} }

View File

@ -21,6 +21,7 @@ using SPT.Launcher.Controllers;
using SPT.Launcher.Interfaces; using SPT.Launcher.Interfaces;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using SPT.Launcher.Models.SPT; using SPT.Launcher.Models.SPT;
using Newtonsoft.Json.Linq;
namespace SPT.Launcher namespace SPT.Launcher
{ {
@ -90,7 +91,7 @@ namespace SPT.Launcher
if (account.wipe) if (account.wipe)
{ {
LogManager.Instance.Info("[LaunchGame] Wipe profile requested"); LogManager.Instance.Info("[LaunchGame] Wipe profile requested");
RemoveRegistryKeys(); RemoveProfileRegistryKeys(account.id);
CleanTempFiles(); CleanTempFiles();
} }
@ -288,27 +289,24 @@ namespace SPT.Launcher
} }
/// <summary> /// <summary>
/// Remove the registry keys /// Remove the SPT JSON-based registry keys associated with the given profile ID
/// </summary> /// </summary>
/// <returns>returns true if the keys were removed. returns false if an exception occured</returns> public void RemoveProfileRegistryKeys(string profileId)
public bool RemoveRegistryKeys()
{ {
try var registryFile = new FileInfo(Path.Combine(Environment.CurrentDirectory, "user\\sptRegistry\\registry.json"));
{
var key = Registry.CurrentUser.OpenSubKey(registrySettings, true);
foreach (var value in key.GetValueNames()) if (!registryFile.Exists)
{
key.DeleteValue(value);
}
}
catch (Exception ex)
{ {
LogManager.Instance.Exception(ex); return;
return false;
} }
return true; JObject registryData = JObject.Parse(File.ReadAllText(registryFile.FullName));
// Find any property that has a key containing the profileId, and remove it
var propsToRemove = registryData.Properties().Where(prop => prop.Name.Contains(profileId, StringComparison.CurrentCultureIgnoreCase)).ToList();
propsToRemove.ForEach(prop => prop.Remove());
File.WriteAllText(registryFile.FullName, registryData.ToString());
} }
/// <summary> /// <summary>

View File

@ -151,23 +151,6 @@ namespace SPT.Launcher.ViewModels
} }
} }
public void RemoveRegistryKeysCommand()
{
LogManager.Instance.Info("[Settings] Removing registry keys ...");
bool regKeysRemoved = gameStarter.RemoveRegistryKeys();
if (regKeysRemoved)
{
LogManager.Instance.Info("[Settings] Registry keys removed");
SendNotification("", LocalizationProvider.Instance.remove_registry_keys_succeeded, Avalonia.Controls.Notifications.NotificationType.Success);
}
else
{
LogManager.Instance.Info("[Settings] Registry keys failed to remove");
SendNotification("", LocalizationProvider.Instance.remove_registry_keys_failed, Avalonia.Controls.Notifications.NotificationType.Error);
}
}
public async Task ResetGameSettingsCommand() public async Task ResetGameSettingsCommand()
{ {
LogManager.Instance.Info("[Settings] Reseting game settings ..."); LogManager.Instance.Info("[Settings] Reseting game settings ...");

View File

@ -16,10 +16,6 @@
Opacity=".7" Opacity=".7"
/> />
<WrapPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal"> <WrapPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal">
<Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=remove_registry_keys}"
Command="{Binding RemoveRegistryKeysCommand}"
Classes="outlined" Margin="0 0 10 5"
/>
<Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=load_live_settings}" <Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=load_live_settings}"
Command="{Binding ResetGameSettingsCommand}" Command="{Binding ResetGameSettingsCommand}"
Classes="outlined" Margin="0 0 10 5" Classes="outlined" Margin="0 0 10 5"