Skip to content

Portable Tool for an Ideal Windows Setup

upd. prevent backup overwriting

Greedekse2c17d32229d
diff --git a/.Source/GTweak/Utilities/Tweaks/DefenderManager/BackupRights.cs b/.Source/GTweak/Utilities/Tweaks/DefenderManager/BackupRights.cs
index c4150925..b3ca2732 100644
--- a/.Source/GTweak/Utilities/Tweaks/DefenderManager/BackupRights.cs
+++ b/.Source/GTweak/Utilities/Tweaks/DefenderManager/BackupRights.cs
@@ -58,43 +58,46 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
{
Directory.CreateDirectory(PathLocator.Folders.DefenderBackup);
- Dictionary<string, Dictionary<string, object>> allValues = new Dictionary<string, Dictionary<string, object>>();
- Dictionary<string, string> aclDataDict = new Dictionary<string, string>();
-
- if (_storageRegPaths == null || _storageRegPaths.Count == 0)
- {
- return;
- }
-
- foreach (var entry in _storageRegPaths)
+ if (!File.Exists(PathLocator.Files.BackupDataJson) && !File.Exists(PathLocator.Files.BackupRightsAcl))
{
- string path = entry.Key;
- RegistryKey baseKey = entry.Value;
+ Dictionary<string, Dictionary<string, object>> allValues = new Dictionary<string, Dictionary<string, object>>();
+ Dictionary<string, string> aclDataDict = new Dictionary<string, string>();
- using RegistryKey key = baseKey.OpenSubKey(path, false);
- if (key == null)
+ if (_storageRegPaths == null || _storageRegPaths.Count == 0)
{
- continue;
+ return;
}
- Dictionary<string, object> values = new Dictionary<string, object>();
- foreach (string valueName in key.GetValueNames())
+ foreach (var entry in _storageRegPaths)
{
- values[valueName] = key.GetValue(valueName);
- }
- allValues[path] = values;
+ string path = entry.Key;
+ RegistryKey baseKey = entry.Value;
- try
- {
- RegistrySecurity security = key.GetAccessControl();
- string aclData = security.GetSecurityDescriptorSddlForm(AccessControlSections.All);
- aclDataDict[path] = aclData;
+ using RegistryKey key = baseKey.OpenSubKey(path, false);
+ if (key == null)
+ {
+ continue;
+ }
+
+ Dictionary<string, object> values = new Dictionary<string, object>();
+ foreach (string valueName in key.GetValueNames())
+ {
+ values[valueName] = key.GetValue(valueName);
+ }
+ allValues[path] = values;
+
+ try
+ {
+ RegistrySecurity security = key.GetAccessControl();
+ string aclData = security.GetSecurityDescriptorSddlForm(AccessControlSections.All);
+ aclDataDict[path] = aclData;
+ }
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
}
- catch (Exception ex) { ErrorLogging.LogDebug(ex); }
- }
- File.WriteAllText(PathLocator.Files.BackupDataJson, JsonConvert.SerializeObject(allValues, Formatting.Indented));
- File.WriteAllText(PathLocator.Files.BackupRightsAcl, JsonConvert.SerializeObject(aclDataDict, Formatting.Indented));
+ File.WriteAllText(PathLocator.Files.BackupDataJson, JsonConvert.SerializeObject(allValues, Formatting.Indented));
+ File.WriteAllText(PathLocator.Files.BackupRightsAcl, JsonConvert.SerializeObject(aclDataDict, Formatting.Indented));
+ }
}
catch (Exception ex) { ErrorLogging.LogDebug(ex); }
}