Skip to content

Commit

Permalink
Leverage C# primary constructors whenever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Fs00 committed Mar 1, 2024
1 parent 2922371 commit 58dc031
Show file tree
Hide file tree
Showing 21 changed files with 37 additions and 208 deletions.
17 changes: 3 additions & 14 deletions src/AppConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,6 @@ private void WriteToFile()
)]
internal partial class AppConfigurationSerializerContext : JsonSerializerContext {}

abstract class AppConfigurationException : Exception
{
protected AppConfigurationException(string message) : base(message) {}
}

class AppConfigurationLoadException : AppConfigurationException
{
public AppConfigurationLoadException(string message) : base(message) {}
}

class AppConfigurationWriteException : AppConfigurationException
{
public AppConfigurationWriteException(string message) : base(message) {}
}
abstract class AppConfigurationException(string message) : Exception(message) {}
class AppConfigurationLoadException(string message) : AppConfigurationException(message) {}
class AppConfigurationWriteException(string message) : AppConfigurationException(message) {}
11 changes: 1 addition & 10 deletions src/Operations/AskForRebootOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,8 @@

namespace Win10BloatRemover.Operations;

class AskForRebootOperation : IOperation
class AskForRebootOperation(IUserInterface ui, RebootRecommendedFlag rebootFlag) : IOperation
{
private readonly IUserInterface ui;
private readonly RebootRecommendedFlag rebootFlag;

public AskForRebootOperation(IUserInterface ui, RebootRecommendedFlag rebootFlag)
{
this.ui = ui;
this.rebootFlag = rebootFlag;
}

public void Run()
{
if (rebootFlag.IsRebootRecommended)
Expand Down
5 changes: 1 addition & 4 deletions src/Operations/AutoUpdatesDisabler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

namespace Win10BloatRemover.Operations;

public class AutoUpdatesDisabler : IOperation
public class AutoUpdatesDisabler(IUserInterface ui) : IOperation
{
private readonly IUserInterface ui;
public AutoUpdatesDisabler(IUserInterface ui) => this.ui = ui;

public void Run()
{
ui.PrintMessage("Writing values into the Registry...");
Expand Down
9 changes: 1 addition & 8 deletions src/Operations/BrowserOpener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@

namespace Win10BloatRemover.Operations;

public class BrowserOpener : IOperation
public class BrowserOpener(string url) : IOperation
{
private readonly string url;

public BrowserOpener(string url)
{
this.url = url;
}

public void Run()
{
var startInfo = new ProcessStartInfo {
Expand Down
5 changes: 1 addition & 4 deletions src/Operations/ConsumerFeaturesDisabler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

namespace Win10BloatRemover.Operations;

public class ConsumerFeaturesDisabler : IOperation
public class ConsumerFeaturesDisabler(IUserInterface ui) : IOperation
{
private readonly IUserInterface ui;
public ConsumerFeaturesDisabler(IUserInterface ui) => this.ui = ui;

public bool IsRebootRecommended { get; private set; }

public void Run()
Expand Down
11 changes: 1 addition & 10 deletions src/Operations/DefenderDisabler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Win10BloatRemover.Operations;

public class DefenderDisabler : IOperation
public class DefenderDisabler(IUserInterface ui, ServiceRemover serviceRemover) : IOperation
{
private static readonly string[] defenderServices = [
"wscsvc",
Expand All @@ -20,17 +20,8 @@ public class DefenderDisabler : IOperation
@"\Microsoft\Windows\Windows Defender\Windows Defender Verification"
];

private readonly IUserInterface ui;
private readonly ServiceRemover serviceRemover;

public bool IsRebootRecommended { get; private set; }

public DefenderDisabler(IUserInterface ui, ServiceRemover serviceRemover)
{
this.ui = ui;
this.serviceRemover = serviceRemover;
}

public void Run()
{
CheckForTamperProtection();
Expand Down
11 changes: 1 addition & 10 deletions src/Operations/EdgeRemover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,8 @@

namespace Win10BloatRemover.Operations;

public class EdgeRemover : IOperation
public class EdgeRemover(IUserInterface ui, AppxRemover appxRemover) : IOperation
{
private readonly IUserInterface ui;
private readonly AppxRemover appxRemover;

public EdgeRemover(IUserInterface ui, AppxRemover appxRemover)
{
this.ui = ui;
this.appxRemover = appxRemover;
}

public void Run()
{
UninstallEdgeChromium();
Expand Down
11 changes: 1 addition & 10 deletions src/Operations/ErrorReportingDisabler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,15 @@

namespace Win10BloatRemover.Operations;

public class ErrorReportingDisabler : IOperation
public class ErrorReportingDisabler(IUserInterface ui, ServiceRemover serviceRemover) : IOperation
{
private static readonly string[] errorReportingServices = ["WerSvc", "wercplsupport"];
private static readonly string[] errorReportingScheduledTasks = [
@"\Microsoft\Windows\Windows Error Reporting\QueueReporting"
];

private readonly IUserInterface ui;
private readonly ServiceRemover serviceRemover;

public bool IsRebootRecommended => serviceRemover.IsRebootRecommended;

public ErrorReportingDisabler(IUserInterface ui, ServiceRemover serviceRemover)
{
this.ui = ui;
this.serviceRemover = serviceRemover;
}

public void Run()
{
DisableErrorReporting();
Expand Down
11 changes: 1 addition & 10 deletions src/Operations/FeaturesRemover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@

namespace Win10BloatRemover.Operations;

public class FeaturesRemover : IOperation
public class FeaturesRemover(string[] featuresToRemove, IUserInterface ui) : IOperation
{
private readonly string[] featuresToRemove;
private readonly IUserInterface ui;

public bool IsRebootRecommended { get; private set; }

public FeaturesRemover(string[] featuresToRemove, IUserInterface ui)
{
this.featuresToRemove = featuresToRemove;
this.ui = ui;
}

public void Run()
{
using var dismClient = new DismClient();
Expand Down
5 changes: 1 addition & 4 deletions src/Operations/LicensePrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

namespace Win10BloatRemover.Operations;

public class LicensePrinter : IOperation
public class LicensePrinter(IUserInterface ui) : IOperation
{
private readonly IUserInterface ui;
public LicensePrinter(IUserInterface ui) => this.ui = ui;

public void Run()
{
Stream licenseFile = GetType().Assembly.GetManifestResourceStream("Win10BloatRemover.Resources.License.txt")!;
Expand Down
6 changes: 1 addition & 5 deletions src/Operations/OneDriveRemover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

namespace Win10BloatRemover.Operations;

public class OneDriveRemover : IOperation
public class OneDriveRemover(IUserInterface ui) : IOperation
{
private readonly IUserInterface ui;

public OneDriveRemover(IUserInterface ui) => this.ui = ui;

public void Run()
{
DisableOneDrive();
Expand Down
5 changes: 1 addition & 4 deletions src/Operations/PrivacySettingsTweaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Win10BloatRemover.Operations;

public class PrivacySettingsTweaker : IOperation
public class PrivacySettingsTweaker(IUserInterface ui) : IOperation
{
private static readonly string[] appPermissionsToDeny = [
"location",
Expand All @@ -14,9 +14,6 @@ public class PrivacySettingsTweaker : IOperation
"userAccountInformation"
];

private readonly IUserInterface ui;
public PrivacySettingsTweaker(IUserInterface ui) => this.ui = ui;

public void Run()
{
ui.PrintMessage("Writing values into the Registry...");
Expand Down
11 changes: 1 addition & 10 deletions src/Operations/ScheduledTasksDisabler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,8 @@

namespace Win10BloatRemover.Operations;

public class ScheduledTasksDisabler : IOperation
public class ScheduledTasksDisabler(string[] scheduledTasksToDisable, IUserInterface ui) : IOperation
{
private readonly string[] scheduledTasksToDisable;
private readonly IUserInterface ui;

public ScheduledTasksDisabler(string[] scheduledTasksToDisable, IUserInterface ui)
{
this.ui = ui;
this.scheduledTasksToDisable = scheduledTasksToDisable;
}

public void Run()
{
foreach (string task in scheduledTasksToDisable)
Expand Down
14 changes: 1 addition & 13 deletions src/Operations/ServiceRemover.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
using Microsoft.Win32;
using System.Diagnostics;
using System.IO;
using Win10BloatRemover.UI;
using Win10BloatRemover.Utils;

namespace Win10BloatRemover.Operations;

public class ServiceRemovalOperation : IOperation
public class ServiceRemovalOperation(string[] servicesToRemove, IUserInterface ui, ServiceRemover serviceRemover) : IOperation
{
private readonly string[] servicesToRemove;
private readonly IUserInterface ui;
private readonly ServiceRemover serviceRemover;

public bool IsRebootRecommended => serviceRemover.IsRebootRecommended;

public ServiceRemovalOperation(string[] servicesToRemove, IUserInterface ui, ServiceRemover serviceRemover)
{
this.servicesToRemove = servicesToRemove;
this.ui = ui;
this.serviceRemover = serviceRemover;
}

public void Run()
{
ui.PrintHeading("Backing up services...");
Expand Down
5 changes: 1 addition & 4 deletions src/Operations/SuggestionsDisabler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

namespace Win10BloatRemover.Operations;

public class SuggestionsDisabler : IOperation
public class SuggestionsDisabler(IUserInterface ui) : IOperation
{
private readonly IUserInterface ui;
public SuggestionsDisabler(IUserInterface ui) => this.ui = ui;

public void Run()
{
DisableSuggestions();
Expand Down
11 changes: 1 addition & 10 deletions src/Operations/TelemetryDisabler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Win10BloatRemover.Operations;

public class TelemetryDisabler : IOperation
public class TelemetryDisabler(IUserInterface ui, ServiceRemover serviceRemover) : IOperation
{
private static readonly string[] telemetryServices = [
"DiagTrack",
Expand Down Expand Up @@ -34,17 +34,8 @@ public class TelemetryDisabler : IOperation
@"\Microsoft\Windows\PI\Sqm-Tasks"
];

private readonly IUserInterface ui;
private readonly ServiceRemover serviceRemover;

public bool IsRebootRecommended { get; private set; }

public TelemetryDisabler(IUserInterface ui, ServiceRemover serviceRemover)
{
this.ui = ui;
this.serviceRemover = serviceRemover;
}

public void Run()
{
RemoveTelemetryServices();
Expand Down
10 changes: 1 addition & 9 deletions src/UI/ConsoleMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,14 @@

namespace Win10BloatRemover.UI;

class ConsoleMenu
class ConsoleMenu(MenuEntry[] entries, RebootRecommendedFlag rebootFlag)
{
private const int FirstMenuEntryNumber = 1;

private bool exitRequested = false;
private readonly MenuEntry[] entries;
private readonly RebootRecommendedFlag rebootFlag;

private static readonly Version programVersion = typeof(ConsoleMenu).Assembly.GetName().Version!;

public ConsoleMenu(MenuEntry[] entries, RebootRecommendedFlag rebootFlag)
{
this.entries = entries;
this.rebootFlag = rebootFlag;
}

public void RunLoopUntilExitRequested()
{
while (!exitRequested)
Expand Down
Loading

0 comments on commit 58dc031

Please sign in to comment.