Skip to content

Commit 9de5766

Browse files
committed
Add registry settings override. fix #872
1 parent d93cc50 commit 9de5766

7 files changed

+34
-15
lines changed

Analogy/ApplicationSettings/UpdateSettingsUC.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private void LoadSettings()
4242
{
4343
cbUpdates.Properties.Items.AddRange(typeof(UpdateMode).GetDisplayValues().Values);
4444
cbUpdates.SelectedItem = UpdateManager.Instance.UpdateMode.GetDisplay();
45-
if (AnalogyNonPersistSettings.Instance.DisableUpdatesByDataProvidersOverrides)
45+
if (AnalogyNonPersistSettings.Instance.UpdateAreDisabled)
4646
{
4747
lblDisableUpdates.Visible = true;
4848
cbUpdates.Enabled = false;

Analogy/CommonChangeLog.cs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public static IEnumerable<AnalogyChangeLog> GetChangeLog()
1111
{
1212
return new List<AnalogyChangeLog>
1313
{
14+
new AnalogyChangeLog("V4.5.1 - Add registry settings override. #872",AnalogChangeLogType.Improvement,"Lior Banai",new DateTime(2021,02,13)),
1415
new AnalogyChangeLog("V4.5.1 - [UI] Add additional skins #873",AnalogChangeLogType.Improvement,"Lior Banai",new DateTime(2021,02,13)),
1516
new AnalogyChangeLog("V4.5.1 - [Data providers] Add custom data provider notification mechanism #516",AnalogChangeLogType.Improvement,"Lior Banai",new DateTime(2021,02,12)),
1617
new AnalogyChangeLog("V4.5.1 - [UI] Do not load subfolders when root folder/drive is selected #868",AnalogChangeLogType.Improvement,"Lior Banai",new DateTime(2021,02,09)),

Analogy/Forms/MainForm.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private async void AnalogyMainForm_Load(object sender, EventArgs e)
241241
btnErrors.Visibility = BarItemVisibility.Always;
242242
}
243243

244-
if (!AnalogyNonPersistSettings.Instance.DisableUpdatesByDataProvidersOverrides)
244+
if (!AnalogyNonPersistSettings.Instance.UpdateAreDisabled)
245245
{
246246
var (_, release) = await UpdateManager.Instance.CheckVersion(false);
247247
if (release?.TagName != null && UpdateManager.Instance.NewestVersion != null)

Analogy/Forms/UpdateForm.Designer.cs

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Analogy/Forms/UpdateForm.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private void UpdateForm_Load(object sender, EventArgs e)
2121
lblLatestVersion.Text =
2222
$"Latest version is: {(Updater.LastVersionChecked?.TagName == null ? "not checked" : Updater.LastVersionChecked.TagName)}";
2323

24-
if (AnalogyNonPersistSettings.Instance.DisableUpdatesByDataProvidersOverrides)
24+
if (AnalogyNonPersistSettings.Instance.UpdateAreDisabled)
2525
{
2626
AnalogyLogManager.Instance.LogWarning("Update is disabled", nameof(UpdateForm));
2727
sbtnUpdateNow.Visible = false;

Analogy/Managers/AnalogyNonPersistSettings.cs

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
using System;
1+
using Microsoft.Win32;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
75

86
namespace Analogy.Managers
97
{
@@ -12,11 +10,32 @@ public class AnalogyNonPersistSettings
1210
private static readonly Lazy<AnalogyNonPersistSettings> _instance =
1311
new Lazy<AnalogyNonPersistSettings>(() => new AnalogyNonPersistSettings());
1412
public static AnalogyNonPersistSettings Instance { get; set; } = _instance.Value;
13+
private static string AnalogyRegistryKey => @"SOFTWARE\Analogy.LogViewer";
1514
public List<string> AdditionalAssembliesDependenciesLocations { get; }
1615
public bool DisableUpdatesByDataProvidersOverrides { get; set; }
16+
public bool DisableUpdateFromRegistry { get; set; }
17+
18+
public bool UpdateAreDisabled => DisableUpdateFromRegistry || DisableUpdatesByDataProvidersOverrides;
1719
public AnalogyNonPersistSettings()
1820
{
19-
AdditionalAssembliesDependenciesLocations=new List<string>();
21+
AdditionalAssembliesDependenciesLocations = new List<string>();
22+
try
23+
{
24+
using (RegistryKey? key = Registry.LocalMachine.OpenSubKey(AnalogyRegistryKey))
25+
{
26+
object? updateRegistryValue = key?.GetValue("DisableUpdates");
27+
if (updateRegistryValue != null && bool.TryParse(updateRegistryValue.ToString(), out var disable))
28+
{
29+
AnalogyLogger.Instance.LogInformation($"Disable mode: {disable}");
30+
DisableUpdateFromRegistry = disable;
31+
}
32+
}
33+
}
34+
catch (Exception e)
35+
{
36+
AnalogyLogManager.Instance.LogError($"Error reading registry: {e}", nameof(AnalogyNonPersistSettings));
37+
}
38+
2039
}
2140

2241
public void AddDependencyLocation(string path)
@@ -29,7 +48,7 @@ public void AddDependencyLocation(string path)
2948
}
3049
else
3150
{
32-
AnalogyLogManager.Instance.LogWarning($"{path} already exist in dependencies list",nameof(AddDependencyLocation));
51+
AnalogyLogManager.Instance.LogWarning($"{path} already exist in dependencies list", nameof(AddDependencyLocation));
3352
}
3453
}
3554
else

Analogy/Managers/UserSettingsManager.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
using System.Linq;
1616
using System.Reflection;
1717
using System.Runtime.CompilerServices;
18-
using Microsoft.Win32;
1918

2019
namespace Analogy
2120
{
@@ -26,7 +25,6 @@ public class UserSettingsManager
2625
private static readonly Lazy<UserSettingsManager> _instance =
2726
new Lazy<UserSettingsManager>(() => new UserSettingsManager());
2827

29-
private static string AnalogyRegistryKey => @"SOFTWARE\Analogy.LogViewer";
3028
private CommandLayout _ribbonStyle;
3129
private bool _enableFirstChanceException;
3230
public event EventHandler<bool> OnEnableFirstChanceExceptionChanged;
@@ -137,6 +135,7 @@ public CommandLayout RibbonStyle
137135
public bool ViewDetailedMessageWithHTML { get; set; }
138136

139137
public SettingsMode SettingsMode { get; set; }
138+
140139
public UserSettingsManager()
141140
{
142141
TryLoadPortableSettings();
@@ -483,7 +482,7 @@ private void DeletePortableSettings()
483482
{
484483
try
485484
{
486-
File.Delete(LocalSettingFileName);
485+
File.Delete(LocalSettingFileName);
487486
}
488487
catch (Exception e)
489488
{

0 commit comments

Comments
 (0)