From de0ee3a49713705c680ae9e0f34ff4c6236dc9c0 Mon Sep 17 00:00:00 2001 From: Archi Date: Tue, 10 Aug 2021 17:09:46 +0200 Subject: [PATCH] Make use of latest Madness 1.1.0 features --- ArchiSteamFarm/Core/ASF.cs | 6 +----- ArchiSteamFarm/Core/OS.cs | 19 ++----------------- ArchiSteamFarm/Helpers/ArchiCryptoHelper.cs | 10 +--------- .../Helpers/CrossProcessFileBasedSemaphore.cs | 18 +----------------- ArchiSteamFarm/Program.cs | 6 +----- 5 files changed, 6 insertions(+), 53 deletions(-) diff --git a/ArchiSteamFarm/Core/ASF.cs b/ArchiSteamFarm/Core/ASF.cs index 970db3896..30e9b5077 100644 --- a/ArchiSteamFarm/Core/ASF.cs +++ b/ArchiSteamFarm/Core/ASF.cs @@ -20,9 +20,9 @@ // limitations under the License. #if NETFRAMEWORK -using System.Runtime.InteropServices; using JustArchiNET.Madness; using File = JustArchiNET.Madness.FileMadness.File; +using OperatingSystem = JustArchiNET.Madness.OperatingSystemMadness.OperatingSystem; using Path = JustArchiNET.Madness.PathMadness.Path; #endif using System; @@ -314,11 +314,7 @@ namespace ArchiSteamFarm.Core { return null; } -#if NETFRAMEWORK - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { -#else if (OperatingSystem.IsFreeBSD() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { -#endif string executable = Path.Combine(SharedInfo.HomeDirectory, SharedInfo.AssemblyName); if (File.Exists(executable)) { diff --git a/ArchiSteamFarm/Core/OS.cs b/ArchiSteamFarm/Core/OS.cs index 58bb931d3..54d68491f 100644 --- a/ArchiSteamFarm/Core/OS.cs +++ b/ArchiSteamFarm/Core/OS.cs @@ -21,6 +21,7 @@ #if NETFRAMEWORK using JustArchiNET.Madness; +using OperatingSystem = JustArchiNET.Madness.OperatingSystemMadness.OperatingSystem; #else using System.Runtime.Versioning; #endif @@ -94,11 +95,7 @@ namespace ArchiSteamFarm.Core { private static Mutex? SingleInstance; internal static void CoreInit(bool systemRequired) { -#if NETFRAMEWORK - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { -#else if (OperatingSystem.IsWindows()) { -#endif if (systemRequired) { WindowsKeepSystemActive(); } @@ -197,11 +194,7 @@ namespace ArchiSteamFarm.Core { throw new ArgumentNullException(nameof(path)); } -#if NETFRAMEWORK - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && !RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { -#else if (!OperatingSystem.IsFreeBSD() && !OperatingSystem.IsLinux() && !OperatingSystem.IsMacOS()) { -#endif throw new PlatformNotSupportedException(); } @@ -238,7 +231,7 @@ namespace ArchiSteamFarm.Core { } // All windows variants have valid .NET Core build, and generic-netf is supported only on mono - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || !RuntimeMadness.IsRunningOnMono) { + if (OperatingSystem.IsWindows() || !RuntimeMadness.IsRunningOnMono) { return false; } @@ -261,11 +254,7 @@ namespace ArchiSteamFarm.Core { [SupportedOSPlatform("Windows")] private static void WindowsDisableQuickEditMode() { -#if NETFRAMEWORK - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { -#else if (!OperatingSystem.IsWindows()) { -#endif throw new PlatformNotSupportedException(); } @@ -286,11 +275,7 @@ namespace ArchiSteamFarm.Core { [SupportedOSPlatform("Windows")] private static void WindowsKeepSystemActive() { -#if NETFRAMEWORK - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { -#else if (!OperatingSystem.IsWindows()) { -#endif throw new PlatformNotSupportedException(); } diff --git a/ArchiSteamFarm/Helpers/ArchiCryptoHelper.cs b/ArchiSteamFarm/Helpers/ArchiCryptoHelper.cs index 71cc7cfa0..bfb1ada89 100644 --- a/ArchiSteamFarm/Helpers/ArchiCryptoHelper.cs +++ b/ArchiSteamFarm/Helpers/ArchiCryptoHelper.cs @@ -20,7 +20,7 @@ // limitations under the License. #if NETFRAMEWORK -using System.Runtime.InteropServices; +using OperatingSystem = JustArchiNET.Madness.OperatingSystemMadness.OperatingSystem; #endif using System; using System.Collections.Generic; @@ -189,11 +189,7 @@ namespace ArchiSteamFarm.Helpers { throw new ArgumentNullException(nameof(encryptedString)); } -#if NETFRAMEWORK - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { -#else if (!OperatingSystem.IsWindows()) { -#endif return null; } @@ -240,11 +236,7 @@ namespace ArchiSteamFarm.Helpers { throw new ArgumentNullException(nameof(decryptedString)); } -#if NETFRAMEWORK - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { -#else if (!OperatingSystem.IsWindows()) { -#endif return null; } diff --git a/ArchiSteamFarm/Helpers/CrossProcessFileBasedSemaphore.cs b/ArchiSteamFarm/Helpers/CrossProcessFileBasedSemaphore.cs index 65d6e1f1b..2b4b07fb2 100644 --- a/ArchiSteamFarm/Helpers/CrossProcessFileBasedSemaphore.cs +++ b/ArchiSteamFarm/Helpers/CrossProcessFileBasedSemaphore.cs @@ -20,7 +20,7 @@ // limitations under the License. #if NETFRAMEWORK -using System.Runtime.InteropServices; +using OperatingSystem = JustArchiNET.Madness.OperatingSystemMadness.OperatingSystem; #endif using System; using System.Diagnostics; @@ -165,11 +165,7 @@ namespace ArchiSteamFarm.Helpers { if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); -#if NETFRAMEWORK - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { -#else if (OperatingSystem.IsWindows()) { -#endif DirectoryInfo directoryInfo = new(directoryPath); try { @@ -180,11 +176,7 @@ namespace ArchiSteamFarm.Helpers { // Non-critical, user might have no rights to manage the resource ASF.ArchiLogger.LogGenericDebuggingException(e); } -#if NETFRAMEWORK - } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { -#else } else if (OperatingSystem.IsFreeBSD() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { -#endif OS.UnixSetFileAccess(directoryPath, OS.EUnixPermission.Combined777); } } @@ -192,11 +184,7 @@ namespace ArchiSteamFarm.Helpers { try { new FileStream(FilePath, FileMode.CreateNew).Dispose(); -#if NETFRAMEWORK - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { -#else if (OperatingSystem.IsWindows()) { -#endif FileInfo fileInfo = new(FilePath); try { @@ -207,11 +195,7 @@ namespace ArchiSteamFarm.Helpers { // Non-critical, user might have no rights to manage the resource ASF.ArchiLogger.LogGenericDebuggingException(e); } -#if NETFRAMEWORK - } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { -#else } else if (OperatingSystem.IsFreeBSD() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { -#endif OS.UnixSetFileAccess(FilePath, OS.EUnixPermission.Combined777); } } catch (IOException) { diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 7ba0b5fc9..d7a265a74 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -20,7 +20,7 @@ // limitations under the License. #if NETFRAMEWORK -using System.Runtime.InteropServices; +using OperatingSystem = JustArchiNET.Madness.OperatingSystemMadness.OperatingSystem; #endif using System; using System.Collections; @@ -274,11 +274,7 @@ namespace ArchiSteamFarm { // April Fools easter egg logic AprilFools.Init(); -#if NETFRAMEWORK - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { -#else if (OperatingSystem.IsWindows()) { -#endif SystemEvents.TimeChanged += AprilFools.OnTimeChanged; } }