Minimize define hell

Skipping a 20 KB stub in OS-specific non-windows builds and omitting a few very fast if checks isn't worth the code quality degradation that involves all of the ifdef options.

ifdefs should be reserved for stuff that either doesn't compile whatsoever in some specific configurations (NETFRAMEWORK), or is required to make logical decisions based on the compiler input (e.g. DEBUG for detecting debugging builds or ASF_VARIANT_* for hardcoding the platform identifier to use for auto-updates)

In all other situations, we should use OperatingSystem if condition, even if it's equal to hitting them on the platforms that are unlikely to hit them.

And I say unlikely, because nothing stops me from downloading a win-x64 build and running it like a generic one on windows, what you gonna do?
This commit is contained in:
Archi
2021-11-10 19:03:05 +01:00
parent e62234892a
commit 0964cdac96
9 changed files with 11 additions and 68 deletions

View File

@@ -54,13 +54,13 @@ namespace ArchiSteamFarm {
internal static bool Service { get; private set; }
internal static bool ShutdownSequenceInitialized { get; private set; }
#if !NETFRAMEWORK && (TARGET_GENERIC || !TARGET_WINDOWS)
#if !NETFRAMEWORK
private static readonly Dictionary<PosixSignal, PosixSignalRegistration> RegisteredPosixSignals = new();
#endif
private static readonly TaskCompletionSource<byte> ShutdownResetEvent = new();
#if !NETFRAMEWORK && (TARGET_GENERIC || !TARGET_WINDOWS)
#if !NETFRAMEWORK
private static readonly ImmutableHashSet<PosixSignal> SupportedPosixSignals = ImmutableHashSet.Create(PosixSignal.SIGINT, PosixSignal.SIGTERM);
#endif
@@ -135,7 +135,7 @@ namespace ArchiSteamFarm {
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
#if !NETFRAMEWORK && (TARGET_GENERIC || !TARGET_WINDOWS)
#if !NETFRAMEWORK
if (OperatingSystem.IsFreeBSD() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) {
foreach (PosixSignal signal in SupportedPosixSignals) {
RegisteredPosixSignals[signal] = PosixSignalRegistration.Create(signal, OnPosixSignal);
@@ -382,7 +382,7 @@ namespace ArchiSteamFarm {
ShutdownSequenceInitialized = true;
#if !NETFRAMEWORK && (TARGET_GENERIC || !TARGET_WINDOWS)
#if !NETFRAMEWORK
if (OperatingSystem.IsFreeBSD() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) {
// Unregister from registered signals
foreach (PosixSignalRegistration registration in RegisteredPosixSignals.Values) {
@@ -429,7 +429,7 @@ namespace ArchiSteamFarm {
private static async void OnCancelKeyPress(object? sender, ConsoleCancelEventArgs e) => await Exit(130).ConfigureAwait(false);
#if !NETFRAMEWORK && (TARGET_GENERIC || !TARGET_WINDOWS)
#if !NETFRAMEWORK
private static async void OnPosixSignal(PosixSignalContext signal) {
if (signal == null) {
throw new ArgumentNullException(nameof(signal));