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:
parent
7181f22852
commit
313b936d96
@ -289,6 +289,7 @@ namespace SPT.Launcher
|
||||
}
|
||||
|
||||
SelectedAccount.edition = edition;
|
||||
SelectedAccount.wipe = true;
|
||||
LogManager.Instance.Info($"Account Wiped: {data.username} -> {edition}");
|
||||
return AccountStatus.OK;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ using SPT.Launcher.Controllers;
|
||||
using SPT.Launcher.Interfaces;
|
||||
using System.Runtime.InteropServices;
|
||||
using SPT.Launcher.Models.SPT;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace SPT.Launcher
|
||||
{
|
||||
@ -90,7 +91,7 @@ namespace SPT.Launcher
|
||||
if (account.wipe)
|
||||
{
|
||||
LogManager.Instance.Info("[LaunchGame] Wipe profile requested");
|
||||
RemoveRegistryKeys();
|
||||
RemoveProfileRegistryKeys(account.id);
|
||||
CleanTempFiles();
|
||||
}
|
||||
|
||||
@ -288,27 +289,24 @@ namespace SPT.Launcher
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the registry keys
|
||||
/// Remove the SPT JSON-based registry keys associated with the given profile ID
|
||||
/// </summary>
|
||||
/// <returns>returns true if the keys were removed. returns false if an exception occured</returns>
|
||||
public bool RemoveRegistryKeys()
|
||||
public void RemoveProfileRegistryKeys(string profileId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var key = Registry.CurrentUser.OpenSubKey(registrySettings, true);
|
||||
var registryFile = new FileInfo(Path.Combine(Environment.CurrentDirectory, "user\\sptRegistry\\registry.json"));
|
||||
|
||||
foreach (var value in key.GetValueNames())
|
||||
if (!registryFile.Exists)
|
||||
{
|
||||
key.DeleteValue(value);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Instance.Exception(ex);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
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>
|
||||
|
@ -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()
|
||||
{
|
||||
LogManager.Instance.Info("[Settings] Reseting game settings ...");
|
||||
|
@ -16,10 +16,6 @@
|
||||
Opacity=".7"
|
||||
/>
|
||||
<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}"
|
||||
Command="{Binding ResetGameSettingsCommand}"
|
||||
Classes="outlined" Margin="0 0 10 5"
|
||||
|
Loading…
x
Reference in New Issue
Block a user