mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
Decrease netf code burden with SupportedOSPlatform
This commit is contained in:
35
ArchiSteamFarm/Compatibility/SupportedOSPlatformAttribute.cs
Normal file
35
ArchiSteamFarm/Compatibility/SupportedOSPlatformAttribute.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
// _ _ _ ____ _ _____
|
||||
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
||||
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
||||
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
||||
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
||||
// |
|
||||
// Copyright 2015-2021 Łukasz "JustArchi" Domeradzki
|
||||
// Contact: JustArchi@JustArchi.net
|
||||
// |
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// |
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// |
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#if NETFRAMEWORK
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace ArchiSteamFarm.Compatibility {
|
||||
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Enum | AttributeTargets.Event | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Module | AttributeTargets.Property | AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]
|
||||
[PublicAPI]
|
||||
public sealed class SupportedOSPlatformAttribute : Attribute {
|
||||
public string PlatformName { get; }
|
||||
|
||||
public SupportedOSPlatformAttribute(string platformName) => PlatformName = platformName;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -178,11 +178,9 @@ namespace ArchiSteamFarm.Core {
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !NETFRAMEWORK
|
||||
[SupportedOSPlatform("FreeBSD")]
|
||||
[SupportedOSPlatform("Linux")]
|
||||
[SupportedOSPlatform("OSX")]
|
||||
#endif
|
||||
internal static void UnixSetFileAccess(string path, EUnixPermission permission) {
|
||||
if (string.IsNullOrEmpty(path)) {
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
@@ -250,9 +248,7 @@ namespace ArchiSteamFarm.Core {
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !NETFRAMEWORK
|
||||
[SupportedOSPlatform("Windows")]
|
||||
#endif
|
||||
private static void WindowsDisableQuickEditMode() {
|
||||
#if NETFRAMEWORK
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
||||
@@ -277,9 +273,7 @@ namespace ArchiSteamFarm.Core {
|
||||
}
|
||||
}
|
||||
|
||||
#if !NETFRAMEWORK
|
||||
[SupportedOSPlatform("Windows")]
|
||||
#endif
|
||||
private static void WindowsKeepSystemActive() {
|
||||
#if NETFRAMEWORK
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
||||
@@ -301,11 +295,9 @@ namespace ArchiSteamFarm.Core {
|
||||
}
|
||||
|
||||
[Flags]
|
||||
#if !NETFRAMEWORK
|
||||
[SupportedOSPlatform("FreeBSD")]
|
||||
[SupportedOSPlatform("Linux")]
|
||||
[SupportedOSPlatform("OSX")]
|
||||
#endif
|
||||
internal enum EUnixPermission : ushort {
|
||||
OtherExecute = 0x1,
|
||||
OtherWrite = 0x2,
|
||||
@@ -321,64 +313,46 @@ namespace ArchiSteamFarm.Core {
|
||||
}
|
||||
|
||||
private static class NativeMethods {
|
||||
#if !NETFRAMEWORK
|
||||
[SupportedOSPlatform("Windows")]
|
||||
#endif
|
||||
internal const EExecutionState AwakeExecutionState = EExecutionState.SystemRequired | EExecutionState.AwayModeRequired | EExecutionState.Continuous;
|
||||
|
||||
#if !NETFRAMEWORK
|
||||
[SupportedOSPlatform("Windows")]
|
||||
#endif
|
||||
internal const uint EnableQuickEditMode = 0x0040;
|
||||
|
||||
#if !NETFRAMEWORK
|
||||
[SupportedOSPlatform("Windows")]
|
||||
#endif
|
||||
internal const sbyte StandardInputHandle = -10;
|
||||
|
||||
#pragma warning disable CA2101 // False positive, we can't use unicode charset on Unix, and it uses UTF-8 by default anyway
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
[DllImport("libc", EntryPoint = "chmod", SetLastError = true)]
|
||||
#if !NETFRAMEWORK
|
||||
[SupportedOSPlatform("FreeBSD")]
|
||||
[SupportedOSPlatform("Linux")]
|
||||
[SupportedOSPlatform("OSX")]
|
||||
#endif
|
||||
internal static extern int Chmod(string path, int mode);
|
||||
#pragma warning restore CA2101 // False positive, we can't use unicode charset on Unix, and it uses UTF-8 by default anyway
|
||||
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
[DllImport("kernel32.dll")]
|
||||
#if !NETFRAMEWORK
|
||||
[SupportedOSPlatform("Windows")]
|
||||
#endif
|
||||
internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
|
||||
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
[DllImport("kernel32.dll")]
|
||||
#if !NETFRAMEWORK
|
||||
[SupportedOSPlatform("Windows")]
|
||||
#endif
|
||||
internal static extern IntPtr GetStdHandle(int nStdHandle);
|
||||
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
[DllImport("kernel32.dll")]
|
||||
#if !NETFRAMEWORK
|
||||
[SupportedOSPlatform("Windows")]
|
||||
#endif
|
||||
internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
|
||||
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
[DllImport("kernel32.dll")]
|
||||
#if !NETFRAMEWORK
|
||||
[SupportedOSPlatform("Windows")]
|
||||
#endif
|
||||
internal static extern EExecutionState SetThreadExecutionState(EExecutionState executionState);
|
||||
|
||||
[Flags]
|
||||
#if !NETFRAMEWORK
|
||||
[SupportedOSPlatform("Windows")]
|
||||
#endif
|
||||
internal enum EExecutionState : uint {
|
||||
None = 0,
|
||||
SystemRequired = 0x00000001,
|
||||
|
||||
Reference in New Issue
Block a user