Skip to content

Commit

Permalink
Added more logs. Registry key renewed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlebansais committed Jun 21, 2019
1 parent 80147b1 commit 7b1efb2
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 33 deletions.
55 changes: 38 additions & 17 deletions Kill-Update-Plugin/Kill-Update-Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,34 +264,54 @@ private void UpdateTimerCallback(object parameter)
private delegate void OnUpdateHandler();
private void OnUpdate()
{
UpdateWatch.Restart();

try
{
Logger.AddLog("Running timer callback");
Logger.AddLog("%% Running timer callback");

UpdateWatch.Restart();

Logger.AddLog("Watch restarted");

Settings.RenewKey();

Logger.AddLog("Key renewed");

ServiceStartMode? PreviousStartType = StartType;
bool LockIt = IsSettingLock;

ServiceController[] Services = ServiceController.GetServices();
Logger.AddLog("Lock setting read");

foreach (ServiceController Service in Services)
if (Service.ServiceName == WindowsUpdateServiceName)
{
StartType = Service.StartType;
ServiceController[] Services = ServiceController.GetServices();
if (Services == null)
Logger.AddLog("Failed to get services");
else
{
Logger.AddLog($"Found {Services.Length} service(s)");

if (PreviousStartType.HasValue && PreviousStartType.Value != StartType.Value)
foreach (ServiceController Service in Services)
if (Service.ServiceName == WindowsUpdateServiceName)
{
Logger.AddLog("Start type changed");
Logger.AddLog($"Checking {Service.ServiceName}");

ChangeLockMode(Service, LockIt);
}
StartType = Service.StartType;

StopIfRunning(Service, LockIt);
Logger.AddLog($"Current start type: {StartType}");

PreviousStartType = StartType;
break;
}
if (PreviousStartType.HasValue && PreviousStartType.Value != StartType.Value)
{
Logger.AddLog("Start type changed");

ChangeLockMode(Service, LockIt);
}

StopIfRunning(Service, LockIt);

PreviousStartType = StartType;
break;
}
}

Logger.AddLog("%% Timer callback completed");
}
catch (Exception e)
{
Expand Down Expand Up @@ -332,14 +352,15 @@ private void StopIfRunning(ServiceController Service, bool lockIt)
{
if (lockIt && Service.Status == ServiceControllerStatus.Running && Service.CanStop)
{
Logger.AddLog("Stopping service");
Service.Stop();
Logger.AddLog("Service stopped");
}
}

private static readonly string WindowsUpdateServiceName = "wuauserv";
private static readonly string LockedSettingName = "Locked";
private readonly TimeSpan CheckInterval = TimeSpan.FromSeconds(10);
private readonly TimeSpan CheckInterval = TimeSpan.FromSeconds(15);
private ServiceStartMode? StartType;
private Timer UpdateTimer;
private Stopwatch UpdateWatch;
Expand Down
4 changes: 2 additions & 2 deletions Kill-Update-Plugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.60")]
[assembly: AssemblyFileVersion("1.0.0.42")]
[assembly: AssemblyVersion("1.0.0.64")]
[assembly: AssemblyFileVersion("1.0.0.46")]
[assembly: NeutralResourcesLanguage("en-US")]

45 changes: 33 additions & 12 deletions SinglePluginHost/Plugin/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ public class PluginSettings : IPluginSettings, IDisposable
#region Init
public PluginSettings(string pluginName, IPluginLogger logger)
{
PluginName = pluginName;
Logger = logger;

try
{
Logger.AddLog("InitSettings starting");

RegistryKey Key = Registry.CurrentUser.OpenSubKey(@"Software", true);
Key = Key.CreateSubKey("TaskbarIconHost");

if (pluginName != null)
SettingKey = Key.CreateSubKey("Settings-" + pluginName);
else
SettingKey = Key.CreateSubKey("Main Settings");
OpenPluginKey();

Logger.AddLog("InitSettings done");
}
Expand All @@ -29,9 +24,39 @@ public PluginSettings(string pluginName, IPluginLogger logger)
Logger.AddLog($"(from InitSettings) {e.Message}");
}
}

private void ClosePluginKey()
{
if (SettingKey != null)
{
SettingKey.Dispose();
SettingKey = null;
}
}

private void OpenPluginKey()
{
RegistryKey Key = Registry.CurrentUser.OpenSubKey(@"Software", true);
Key = Key.CreateSubKey("TaskbarIconHost");

if (PluginName != null)
SettingKey = Key.CreateSubKey("Settings-" + PluginName);
else
SettingKey = Key.CreateSubKey("Main Settings");
}
#endregion

#region Properties
public string PluginName { get; }
#endregion

#region Settings
public void RenewKey()
{
ClosePluginKey();
OpenPluginKey();
}

public bool IsBoolKeySet(string valueName)
{
int? value = GetSettingKey(valueName) as int?;
Expand Down Expand Up @@ -136,11 +161,7 @@ protected virtual void Dispose(bool isDisposing)

private void DisposeNow()
{
if (SettingKey != null)
{
SettingKey.Dispose();
SettingKey = null;
}
ClosePluginKey();
}

public void Dispose()
Expand Down
4 changes: 2 additions & 2 deletions SinglePluginHost/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.60")]
[assembly: AssemblyFileVersion("1.0.0.60")]
[assembly: AssemblyVersion("1.0.0.64")]
[assembly: AssemblyFileVersion("1.0.0.63")]
[assembly: NeutralResourcesLanguage("en-US")]

0 comments on commit 7b1efb2

Please sign in to comment.