Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
WereDev committed Jul 8, 2019
2 parents 304d632 + f76bd7b commit 55dab69
Show file tree
Hide file tree
Showing 24 changed files with 760 additions and 1,136 deletions.
367 changes: 190 additions & 177 deletions AdvancedInstaller/wu10man.aip

Large diffs are not rendered by default.

171 changes: 0 additions & 171 deletions AdvancedInstaller/wu10man.back.aip

This file was deleted.

53 changes: 33 additions & 20 deletions Wu10Man/App.config
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="WereDev.Utils.Wu10Man.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<appSettings>
<add key="WindowsUpdateUrls" value="stats.microsoft.com,download.microsoft.com,update.microsoft.com,windowsupdate.microsoft.com,windowsupdate.com,download.windowsupdate.com,ntservicepack.microsoft.com,wustat.windows.com" />
</appSettings>
<userSettings>
<WereDev.Utils.Wu10Man.Properties.Settings>
<setting name="ShowAdvanced" serializeAs="String">
<value>False</value>
</setting>
</WereDev.Utils.Wu10Man.Properties.Settings>
</userSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="WereDev.Utils.Wu10Man.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<appSettings>
<add key="WindowsUpdateUrls" value="stats.microsoft.com,download.microsoft.com,update.microsoft.com,windowsupdate.microsoft.com,windowsupdate.com,download.windowsupdate.com,ntservicepack.microsoft.com,wustat.windows.com" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<userSettings>
<WereDev.Utils.Wu10Man.Properties.Settings>
<setting name="ShowAdvanced" serializeAs="String">
<value>False</value>
</setting>
</WereDev.Utils.Wu10Man.Properties.Settings>
</userSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>
8 changes: 0 additions & 8 deletions Wu10Man/App.xaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<Application x:Class="WereDev.Utils.Wu10Man.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WereDev.Utils.Wu10Man"
StartupUri="MainWindow.xaml"
ShutdownMode="OnExplicitShutdown">
<Application.Resources>
<!--<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>-->
</Application.Resources>
<Application.MainWindow>
<local:MainWindow/>
</Application.MainWindow>
</Application>
16 changes: 8 additions & 8 deletions Wu10Man/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ namespace WereDev.Utils.Wu10Man
/// </summary>
public partial class App : Application
{
readonly Wu10Logger _logger;

public App() : base()
{
_logger = new Wu10Logger();
_logger.LogInfo("Application started");
this.Dispatcher.UnhandledException += OnDispatcherUnhandledException;
{
Wu10Logger.LogInfo("Application starting");
this.Dispatcher.UnhandledException += OnDispatcherUnhandledException;
this.MainWindow = new MainWindow();
this.MainWindow.Show();
Wu10Logger.LogInfo("Application started");
}

protected override void OnExit(ExitEventArgs e)
{
_logger.LogInfo("Application ended");
Wu10Logger.LogInfo("Application ended");
base.OnExit(e);
}

void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
_logger.LogError(e.Exception);
Wu10Logger.LogError(e.Exception);
string errorMessage = string.Format("{0}\r\n\r\nCheck the logs for more details.", e.Exception.Message);
MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
e.Handled = true;
Expand Down
12 changes: 6 additions & 6 deletions Wu10Man/Editors/RegistryEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ internal static class RegistryEditor
{
public static string ReadLocalMachineRegistryValue(string registryKey, string registryName)
{
if (String.IsNullOrWhiteSpace(registryKey)) throw new ArgumentNullException(nameof(registryKey));
if (String.IsNullOrWhiteSpace(registryName)) throw new ArgumentNullException(nameof(registryName));
if (string.IsNullOrWhiteSpace(registryKey)) throw new ArgumentNullException(nameof(registryKey));
if (string.IsNullOrWhiteSpace(registryName)) throw new ArgumentNullException(nameof(registryName));
using (var regKey = Registry.LocalMachine.OpenSubKey(registryKey))
{
var regValue = regKey?.GetValue(registryName);
Expand Down Expand Up @@ -56,8 +56,8 @@ public static void DeleteLocalMachineRegistryValue(string registryKey, string re
private static void WriteRegistryValue(RegistryKey registryRoot, string registryKey, string registryName, string registryValue, RegistryValueKind registryValueKind)
{
if (registryRoot == null) throw new ArgumentNullException(nameof(registryRoot));
if (String.IsNullOrWhiteSpace(registryKey)) throw new ArgumentNullException(nameof(registryKey));
if (String.IsNullOrWhiteSpace(registryName)) throw new ArgumentNullException(nameof(registryName));
if (string.IsNullOrWhiteSpace(registryKey)) throw new ArgumentNullException(nameof(registryKey));
if (string.IsNullOrWhiteSpace(registryName)) throw new ArgumentNullException(nameof(registryName));

using (var regKey = OpenOrCreateRegistryKey(registryRoot, registryKey, true))
{
Expand All @@ -78,8 +78,8 @@ private static RegistryKey OpenOrCreateRegistryKey(RegistryKey registryRoot, str
private static void DeleteRegistryValue(RegistryKey registryRoot, string registryKey, string registryName)
{
if (registryRoot == null) throw new ArgumentNullException(nameof(registryRoot));
if (String.IsNullOrWhiteSpace(registryKey)) throw new ArgumentNullException(nameof(registryKey));
if (String.IsNullOrWhiteSpace(registryName)) throw new ArgumentNullException(nameof(registryName));
if (string.IsNullOrWhiteSpace(registryKey)) throw new ArgumentNullException(nameof(registryKey));
if (string.IsNullOrWhiteSpace(registryName)) throw new ArgumentNullException(nameof(registryName));

using (var regKey = registryRoot.OpenSubKey(registryKey, false))
{
Expand Down
37 changes: 18 additions & 19 deletions Wu10Man/Editors/ServiceCredentialsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ internal static class ServiceCredentialsEditor
private const uint SERVICE_NO_CHANGE = 0xffffffff; //this value is found in winsvc.h
private const uint SERVICE_QUERY_CONFIG = 0x00000001;
private const uint SERVICE_CHANGE_CONFIG = 0x00000002;
private const uint SERVICE_QUERY_STATUS = 0x00000004;
private const uint SERVICE_ENUMERATE_DEPENDENTS = 0x00000008;
private const uint SERVICE_START = 0x00000010;
private const uint SERVICE_STOP = 0x00000020;
private const uint SERVICE_PAUSE_CONTINUE = 0x00000040;
private const uint SERVICE_INTERROGATE = 0x00000080;
private const uint SERVICE_USER_DEFINED_CONTROL = 0x00000100;
private const uint STANDARD_RIGHTS_REQUIRED = 0x000F0000;
private const uint SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED |
SERVICE_CHANGE_CONFIG |
SERVICE_QUERY_STATUS |
SERVICE_ENUMERATE_DEPENDENTS |
SERVICE_START |
SERVICE_STOP |
SERVICE_PAUSE_CONTINUE |
SERVICE_INTERROGATE |
SERVICE_USER_DEFINED_CONTROL);
//private const uint SERVICE_QUERY_STATUS = 0x00000004;
//private const uint SERVICE_ENUMERATE_DEPENDENTS = 0x00000008;
//private const uint SERVICE_START = 0x00000010;
//private const uint SERVICE_STOP = 0x00000020;
//private const uint SERVICE_PAUSE_CONTINUE = 0x00000040;
//private const uint SERVICE_INTERROGATE = 0x00000080;
//private const uint SERVICE_USER_DEFINED_CONTROL = 0x00000100;
//private const uint STANDARD_RIGHTS_REQUIRED = 0x000F0000;
//private const uint SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED |
// SERVICE_CHANGE_CONFIG |
// SERVICE_QUERY_STATUS |
// SERVICE_ENUMERATE_DEPENDENTS |
// SERVICE_START |
// SERVICE_STOP |
// SERVICE_PAUSE_CONTINUE |
// SERVICE_INTERROGATE |
// SERVICE_USER_DEFINED_CONTROL);

public const string LOCAL_SYSTEM_USER = @".\LocalSystem";

Expand All @@ -45,7 +45,6 @@ public static string GetWindowsServiceUserName(string serviceName)
{
IntPtr hManager = IntPtr.Zero;
IntPtr hService = IntPtr.Zero;
uint bytesNeeded;

try
{
Expand All @@ -61,7 +60,7 @@ public static string GetWindowsServiceUserName(string serviceName)
ThrowWin32Exception();
}

bool retCode = QueryServiceConfig(hService, IntPtr.Zero, 0, out bytesNeeded);
bool retCode = QueryServiceConfig(hService, IntPtr.Zero, 0, out uint bytesNeeded);
if (!retCode && bytesNeeded == 0)
ThrowWin32Exception();

Expand Down
12 changes: 0 additions & 12 deletions Wu10Man/Helpers/GroupPolicyHelper.cs

This file was deleted.

6 changes: 0 additions & 6 deletions Wu10Man/Helpers/HostsFileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ internal class HostsFileHelper
{
private readonly HostsEditor _hostsEditor;
private readonly HashSet<string> _hostUrls;
private readonly Wu10Logger _logger;

public HostsFileHelper()
{
_hostsEditor = new HostsEditor();
_hostUrls = GetWindowsUpdateUrls();
_logger = new Wu10Logger();
}

//TODO: I don't like this here because of the dependency on ConfigurationManager.
Expand Down Expand Up @@ -48,14 +46,12 @@ public void BlockHostUrl(string hostUrl)
var hostsList = currentHosts.ToList();
hostsList.Add(hostUrl);
_hostsEditor.SetHostsEntries(hostsList);
_logger.LogInfo(string.Format("Host blocked: {0}", hostUrl));
}
}

public void BlockAllHostUrls()
{
_hostsEditor.SetHostsEntries(_hostUrls);
_logger.LogInfo("All Hosts blocked.");

}

Expand All @@ -72,14 +68,12 @@ public void UnblockHostUrl(string hostUrl)
var hostsList = currentHosts.ToList();
hostsList.Remove(hostUrl);
_hostsEditor.SetHostsEntries(hostsList);
_logger.LogInfo(string.Format("Host unblocked: {0}", hostUrl));
}
}

public void UnblockAllHostUrls()
{
_hostsEditor.ClearHostsEntries();
_logger.LogInfo("All Hosts unblocked.");
}

public string[] GetBlockedHostUrls()
Expand Down
7 changes: 1 addition & 6 deletions Wu10Man/Helpers/WindowsServiceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ internal class WindowsServiceHelper
public const string UPDATE_MEDIC_SERVICE = "WaaSMedicSvc";
public const string SHOULD_NOT_EXIST = "ShouldNotExist";

private readonly Wu10Logger _logger;
private readonly FilesHelper _filesHelper;
private readonly FilesHelper _filesHelper = new FilesHelper();
private readonly string _wu10FilePrefix = "Wu10Man_";

public WindowsServiceHelper()
{
_logger = new Wu10Logger();
_filesHelper = new FilesHelper();
}

public string[] ListAllServices()
Expand Down Expand Up @@ -94,7 +91,6 @@ public bool EnableService(string serviceName)
service.SetAccountAsLocalSystem();
enabledRealtime = service.EnableService();
}
_logger.LogInfo($"Service enabled: {serviceName}");
return enabledRealtime;
}

Expand All @@ -106,7 +102,6 @@ public void DisableService(string serviceName)
service.DisableService();
}
AddWu10ToFileName(serviceName);
_logger.LogInfo($"Service disabled: {serviceName}");
}

public void AddWu10ToFileName(string serviceName)
Expand Down
104 changes: 52 additions & 52 deletions Wu10Man/Helpers/Wu10Logger.cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
using NLog;
using NLog.Targets;
using System;
using System.IO;

namespace WereDev.Utils.Wu10Man.Helpers
{
internal class Wu10Logger
{
private readonly NLog.Logger _logger = LogManager.GetCurrentClassLogger();

public string LogFolder
{
get
{
var targets = LogManager.Configuration.AllTargets;
foreach (var target in targets)
{
var fileTarget = target as FileTarget;
if (fileTarget != null)
{
var logEventInfo = new LogEventInfo { TimeStamp = DateTime.Now };
var fileName = fileTarget.FileName.Render(logEventInfo);
var folder = Path.GetDirectoryName(fileName);
return folder;
}
}
throw new InvalidOperationException("No file logging has been configured in nlog.config");
}
}

public void LogError(Exception ex)
{
var exception = ex;
while (exception != null)
{
LogError(string.Format("{0} \r\n {1}", ex.Message, ex.StackTrace.Replace("\r\n", "\r\n\t")));
exception = exception.InnerException;
}
}

public void LogError(string message)
{
_logger.Error(message);
}

public void LogInfo(string message)
{
_logger.Info(message ?? string.Empty);
}
}
}
using NLog;
using NLog.Targets;
using System;
using System.IO;

namespace WereDev.Utils.Wu10Man.Helpers
{
internal static class Wu10Logger
{
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();

public static string LogFolder
{
get
{
var targets = LogManager.Configuration.AllTargets;
foreach (var target in targets)
{
var fileTarget = target as FileTarget;
if (fileTarget != null)
{
var logEventInfo = new LogEventInfo { TimeStamp = DateTime.Now };
var fileName = fileTarget.FileName.Render(logEventInfo);
var folder = Path.GetDirectoryName(fileName);
return folder;
}
}
throw new InvalidOperationException("No file logging has been configured in nlog.config");
}
}

public static void LogError(Exception ex)
{
var exception = ex;
while (exception != null)
{
LogError($"{ex.GetType().ToString()}: {ex.Message}\r\n{ex.StackTrace}");
exception = exception.InnerException;
}
}

public static void LogError(string message)
{
_logger.Error(message);
}

public static void LogInfo(string message)
{
_logger.Info(message ?? string.Empty);
}
}
}
Loading

0 comments on commit 55dab69

Please sign in to comment.