Code cleanups and improvements

- Make use of new UnixFileMode, always one native method we need to maintain less
- Add madness support for it, because new feature of course
- Add optional netstandard target and required compatibility for it, so I can test netf-oriented changes easier
This commit is contained in:
Archi
2023-02-09 02:25:11 +01:00
parent b2c34694ae
commit 8008a04354
24 changed files with 114 additions and 139 deletions

View File

@@ -11,7 +11,7 @@
<PackageReference Include="System.Composition.AttributedModel" IncludeAssets="compile" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<ItemGroup Condition="'$(TargetFramework)' == 'net481' OR '$(TargetFramework)' == 'netstandard2.1'">
<!-- Madness is already included in netf build of ASF, so we don't need to emit it ourselves -->
<PackageReference Update="JustArchiNET.Madness" IncludeAssets="compile" />

View File

@@ -9,7 +9,7 @@
<PackageReference Include="System.Composition.AttributedModel" IncludeAssets="compile" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<ItemGroup Condition="'$(TargetFramework)' == 'net481' OR '$(TargetFramework)' == 'netstandard2.1'">
<!-- Madness is already included in netf build of ASF, so we don't need to emit it ourselves -->
<PackageReference Update="JustArchiNET.Madness" IncludeAssets="compile" />
</ItemGroup>

View File

@@ -11,11 +11,14 @@
<PackageReference Include="System.Composition.AttributedModel" IncludeAssets="compile" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<ItemGroup Condition="'$(TargetFramework)' == 'net481' OR '$(TargetFramework)' == 'netstandard2.1'">
<!-- Madness is already included in netf build of ASF, so we don't need to emit it ourselves -->
<PackageReference Update="JustArchiNET.Madness" IncludeAssets="compile" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" IncludeAssets="compile" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<Reference Include="System.Net.Http" HintPath="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8.1\System.Net.Http.dll" />
</ItemGroup>

View File

@@ -13,10 +13,12 @@
<PackageReference Include="System.Linq.Async" IncludeAssets="compile" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<ItemGroup Condition="'$(TargetFramework)' == 'net481' OR '$(TargetFramework)' == 'netstandard2.1'">
<!-- Madness is already included in netf build of ASF, so we don't need to emit it ourselves -->
<PackageReference Update="JustArchiNET.Madness" IncludeAssets="compile" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<Reference Include="System.Net.Http" HintPath="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8.1\System.Net.Http.dll" />
</ItemGroup>

View File

@@ -366,7 +366,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable {
LastAnnouncement = DateTime.UtcNow.AddYears(1);
return;
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
case (HttpStatusCode) 429:
#else
case HttpStatusCode.TooManyRequests:

View File

@@ -12,7 +12,7 @@
<PackageReference Include="System.Composition.AttributedModel" IncludeAssets="compile" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<ItemGroup Condition="'$(TargetFramework)' == 'net481' OR '$(TargetFramework)' == 'netstandard2.1'">
<!-- Madness is already included in netf build of ASF, so we don't need to emit it ourselves -->
<PackageReference Update="JustArchiNET.Madness" IncludeAssets="compile" />
</ItemGroup>

View File

@@ -623,7 +623,7 @@ internal sealed class SteamTokenDumperPlugin : OfficialPlugin, IASF, IBot, IBotC
GlobalCache.Reset(true);
break;
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
case (HttpStatusCode) 429:
#else
case HttpStatusCode.TooManyRequests:

View File

@@ -241,7 +241,6 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PassStringInterpolation/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PatternAlwaysMatches/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PatternAlwaysOfType/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PlaceAssignmentExpressionIntoBlock/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PropertyNotResolved/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantArrayCreationExpression/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantAttributeParentheses/@EntryIndexedValue">SUGGESTION</s:String>

View File

@@ -29,7 +29,7 @@
<PackageReference Include="System.Security.Cryptography.ProtectedData" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<ItemGroup Condition="'$(TargetFramework)' == 'net481' OR '$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="Microsoft.AspNetCore.Cors" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" />
<PackageReference Include="Microsoft.AspNetCore.HttpOverrides" />
@@ -39,10 +39,17 @@
<PackageReference Include="Microsoft.AspNetCore.WebSockets" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<Reference Include="System.Net.Http" HintPath="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8.1\System.Net.Http.dll" />
<Reference Include="System.Security" HintPath="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8.1\System.Security.dll" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="System.IO.FileSystem.AccessControl" />
</ItemGroup>
<ItemGroup>
<TrimmerRootDescriptor Include="TrimmerRoots.xml" />
</ItemGroup>

View File

@@ -1048,7 +1048,8 @@ public static class ASF {
return false;
}
if (!Directory.Exists(directory)) {
// ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework
if (!Directory.Exists(directory!)) {
// ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework
Directory.CreateDirectory(directory!);
}

View File

@@ -30,7 +30,7 @@ internal static partial class GeneratedRegexes {
private const string DigitsPattern = @"\d+";
private const string NonAsciiPattern = @"[^\u0000-\u007F]+";
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
internal static Regex CdKey() => new(CdKeyPattern, DefaultOptions);
internal static Regex Decimal() => new(DecimalPattern, DefaultOptions);
internal static Regex Digits() => new(DigitsPattern, DefaultOptions);

View File

@@ -26,48 +26,22 @@ using System.Runtime.Versioning;
namespace ArchiSteamFarm.Core;
internal static partial class NativeMethods {
[SupportedOSPlatform("Windows")]
internal const EExecutionState AwakeExecutionState = EExecutionState.SystemRequired | EExecutionState.AwayModeRequired | EExecutionState.Continuous;
[SupportedOSPlatform("Windows")]
internal const uint EnableQuickEditMode = 0x0040;
[SupportedOSPlatform("Windows")]
internal const byte ShowWindowMinimize = 6;
[SupportedOSPlatform("Windows")]
internal const sbyte StandardInputHandle = -10;
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[SupportedOSPlatform("FreeBSD")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("MacOS")]
#if NETFRAMEWORK
#pragma warning disable CA2101 // False positive, we can't use unicode charset on Unix, and it uses UTF-8 by default anyway
[DllImport("libc", EntryPoint = "chmod", SetLastError = true)]
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
#else
[LibraryImport("libc", EntryPoint = "chmod", SetLastError = true, StringMarshalling = StringMarshalling.Utf8)]
internal static partial int Chmod(string path, int mode);
#endif
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[SupportedOSPlatform("Windows")]
[return: MarshalAs(UnmanagedType.Bool)]
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
[DllImport("kernel32.dll")]
internal static extern bool GetConsoleMode(nint hConsoleHandle, out uint lpMode);
internal static extern bool GetConsoleMode(nint hConsoleHandle, out EConsoleMode lpMode);
#else
[LibraryImport("kernel32.dll")]
internal static partial bool GetConsoleMode(nint hConsoleHandle, out uint lpMode);
internal static partial bool GetConsoleMode(nint hConsoleHandle, out EConsoleMode lpMode);
#endif
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[SupportedOSPlatform("FreeBSD")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("MacOS")]
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
[DllImport("libc", EntryPoint = "geteuid", SetLastError = true)]
internal static extern uint GetEuid();
#else
@@ -77,28 +51,28 @@ internal static partial class NativeMethods {
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[SupportedOSPlatform("Windows")]
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
[DllImport("kernel32.dll")]
internal static extern nint GetStdHandle(int nStdHandle);
internal static extern nint GetStdHandle(EStandardHandle nStdHandle);
#else
[LibraryImport("kernel32.dll")]
internal static partial nint GetStdHandle(int nStdHandle);
internal static partial nint GetStdHandle(EStandardHandle nStdHandle);
#endif
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[SupportedOSPlatform("Windows")]
[return: MarshalAs(UnmanagedType.Bool)]
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
[DllImport("kernel32.dll")]
internal static extern bool SetConsoleMode(nint hConsoleHandle, uint dwMode);
internal static extern bool SetConsoleMode(nint hConsoleHandle, EConsoleMode dwMode);
#else
[LibraryImport("kernel32.dll")]
internal static partial bool SetConsoleMode(nint hConsoleHandle, uint dwMode);
internal static partial bool SetConsoleMode(nint hConsoleHandle, EConsoleMode dwMode);
#endif
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[SupportedOSPlatform("Windows")]
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
[DllImport("kernel32.dll")]
internal static extern EExecutionState SetThreadExecutionState(EExecutionState executionState);
#else
@@ -109,20 +83,37 @@ internal static partial class NativeMethods {
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[SupportedOSPlatform("Windows")]
[return: MarshalAs(UnmanagedType.Bool)]
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
[DllImport("user32.dll")]
internal static extern void ShowWindow(nint hWnd, int nCmdShow);
internal static extern void ShowWindow(nint hWnd, EShowWindow nCmdShow);
#else
[LibraryImport("user32.dll")]
internal static partial void ShowWindow(nint hWnd, int nCmdShow);
internal static partial void ShowWindow(nint hWnd, EShowWindow nCmdShow);
#endif
[Flags]
[SupportedOSPlatform("Windows")]
internal enum EConsoleMode : uint {
EnableQuickEditMode = 0x0040
}
[Flags]
[SupportedOSPlatform("Windows")]
internal enum EExecutionState : uint {
None = 0,
SystemRequired = 0x00000001,
AwayModeRequired = 0x00000040,
Continuous = 0x80000000
Continuous = 0x80000000,
Awake = SystemRequired | AwayModeRequired | Continuous
}
[SupportedOSPlatform("Windows")]
internal enum EShowWindow : uint {
Minimize = 6
}
[SupportedOSPlatform("Windows")]
internal enum EStandardHandle {
Input = -10
}
}

View File

@@ -43,7 +43,7 @@ internal static class OS {
internal static readonly string ProcessFileName = Environment.ProcessPath ?? throw new InvalidOperationException(nameof(ProcessFileName));
internal static DateTime ProcessStartTime {
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
get => RuntimeMadness.ProcessStartTime.ToUniversalTime();
#else
get {
@@ -67,7 +67,7 @@ internal static class OS {
framework = "Unknown Framework";
}
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
string runtime = RuntimeInformation.OSArchitecture.ToString();
#else
string runtime = RuntimeInformation.RuntimeIdentifier.Trim();
@@ -195,30 +195,6 @@ internal static class OS {
return true;
}
[SupportedOSPlatform("FreeBSD")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("MacOS")]
internal static void UnixSetFileAccess(string path, EUnixPermission permission) {
if (string.IsNullOrEmpty(path)) {
throw new ArgumentNullException(nameof(path));
}
if (!OperatingSystem.IsFreeBSD() && !OperatingSystem.IsLinux() && !OperatingSystem.IsMacOS()) {
throw new PlatformNotSupportedException();
}
if (!File.Exists(path) && !Directory.Exists(path)) {
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, $"!{nameof(path)}"));
return;
}
// Chmod() returns 0 on success, -1 on failure
if (NativeMethods.Chmod(path, (int) permission) != 0) {
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, Marshal.GetLastWin32Error()));
}
}
internal static void UnregisterProcess() {
if (SingleInstance == null) {
return;
@@ -237,7 +213,7 @@ internal static class OS {
}
if (SharedInfo.BuildInfo.Variant.EndsWith("-netf", StringComparison.Ordinal)) {
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
// All Windows variants (7+) have valid .NET Core build
if (OperatingSystem.IsWindows()) {
return false;
@@ -300,15 +276,15 @@ internal static class OS {
throw new PlatformNotSupportedException();
}
nint consoleHandle = NativeMethods.GetStdHandle(NativeMethods.StandardInputHandle);
nint consoleHandle = NativeMethods.GetStdHandle(NativeMethods.EStandardHandle.Input);
if (!NativeMethods.GetConsoleMode(consoleHandle, out uint consoleMode)) {
if (!NativeMethods.GetConsoleMode(consoleHandle, out NativeMethods.EConsoleMode consoleMode)) {
ASF.ArchiLogger.LogGenericError(Strings.WarningFailed);
return;
}
consoleMode &= ~NativeMethods.EnableQuickEditMode;
consoleMode &= ~NativeMethods.EConsoleMode.EnableQuickEditMode;
if (!NativeMethods.SetConsoleMode(consoleHandle, consoleMode)) {
ASF.ArchiLogger.LogGenericError(Strings.WarningFailed);
@@ -324,7 +300,7 @@ internal static class OS {
// This function calls unmanaged API in order to tell Windows OS that it should not enter sleep state while the program is running
// If user wishes to enter sleep mode, then he should use ShutdownOnFarmingFinished or manage ASF process with third-party tool or script
// See https://docs.microsoft.com/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate for more details
NativeMethods.EExecutionState result = NativeMethods.SetThreadExecutionState(NativeMethods.AwakeExecutionState);
NativeMethods.EExecutionState result = NativeMethods.SetThreadExecutionState(NativeMethods.EExecutionState.Awake);
// SetThreadExecutionState() returns NULL on failure, which is mapped to 0 (EExecutionState.None) in our case
if (result == NativeMethods.EExecutionState.None) {
@@ -340,23 +316,6 @@ internal static class OS {
using Process process = Process.GetCurrentProcess();
NativeMethods.ShowWindow(process.MainWindowHandle, NativeMethods.ShowWindowMinimize);
}
[Flags]
[SupportedOSPlatform("FreeBSD")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("MacOS")]
internal enum EUnixPermission : ushort {
OtherExecute = 0x1,
OtherWrite = 0x2,
OtherRead = 0x4,
GroupExecute = 0x8,
GroupWrite = 0x10,
GroupRead = 0x20,
UserExecute = 0x40,
UserWrite = 0x80,
UserRead = 0x100,
Combined777 = UserRead | UserWrite | UserExecute | GroupRead | GroupWrite | GroupExecute | OtherRead | OtherWrite | OtherExecute
NativeMethods.ShowWindow(process.MainWindowHandle, NativeMethods.EShowWindow.Minimize);
}
}

View File

@@ -85,7 +85,7 @@ public static class Utilities {
CookieCollection cookies = cookieContainer.GetCookies(uri);
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
return cookies.Count > 0 ? (from Cookie cookie in cookies where cookie.Name == name select cookie.Value).FirstOrDefault() : null;
#else
return cookies.Count > 0 ? cookies.FirstOrDefault(cookie => cookie.Name == name)?.Value : null;

View File

@@ -179,12 +179,12 @@ internal sealed class CrossProcessFileBasedSemaphore : IAsyncDisposable, ICrossP
return;
}
if (!Directory.Exists(directoryPath)) {
Directory.CreateDirectory(directoryPath);
// ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework
if (!Directory.Exists(directoryPath!)) {
// ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework
DirectoryInfo directoryInfo = Directory.CreateDirectory(directoryPath!);
if (OperatingSystem.IsWindows()) {
DirectoryInfo directoryInfo = new(directoryPath);
try {
DirectorySecurity directorySecurity = new(directoryPath, AccessControlSections.All);
@@ -194,17 +194,16 @@ internal sealed class CrossProcessFileBasedSemaphore : IAsyncDisposable, ICrossP
ASF.ArchiLogger.LogGenericDebuggingException(e);
}
} else if (OperatingSystem.IsFreeBSD() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) {
// ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework
OS.UnixSetFileAccess(directoryPath!, OS.EUnixPermission.Combined777);
directoryInfo.UnixFileMode |= UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute | UnixFileMode.GroupRead | UnixFileMode.GroupWrite | UnixFileMode.GroupExecute | UnixFileMode.OtherRead | UnixFileMode.OtherWrite | UnixFileMode.OtherExecute;
}
}
try {
new FileStream(FilePath, FileMode.CreateNew).Dispose();
if (OperatingSystem.IsWindows()) {
FileInfo fileInfo = new(FilePath);
if (OperatingSystem.IsWindows()) {
try {
FileSecurity fileSecurity = new(FilePath, AccessControlSections.All);
@@ -214,7 +213,7 @@ internal sealed class CrossProcessFileBasedSemaphore : IAsyncDisposable, ICrossP
ASF.ArchiLogger.LogGenericDebuggingException(e);
}
} else if (OperatingSystem.IsFreeBSD() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) {
OS.UnixSetFileAccess(FilePath, OS.EUnixPermission.Combined777);
fileInfo.UnixFileMode |= UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute | UnixFileMode.GroupRead | UnixFileMode.GroupWrite | UnixFileMode.GroupExecute | UnixFileMode.OtherRead | UnixFileMode.OtherWrite | UnixFileMode.OtherExecute;
}
} catch (IOException) {
// Ignored, if the file was already created in the meantime by another instance, this is fine

View File

@@ -19,7 +19,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
using IHost = Microsoft.AspNetCore.Hosting.IWebHost;
using HostBuilder = Microsoft.AspNetCore.Hosting.WebHostBuilder;
#endif

View File

@@ -19,7 +19,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
using MvcNewtonsoftJsonOptions = Microsoft.AspNetCore.Mvc.MvcJsonOptions;
#endif
using System;

View File

@@ -19,7 +19,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Converters;
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
@@ -134,7 +134,7 @@ internal sealed class Startup {
);
// Use routing for our API controllers, this should be called once we're done with all the static files mess
#if !NETFRAMEWORK
#if !NETFRAMEWORK && !NETSTANDARD
app.UseRouting();
#endif
@@ -153,7 +153,7 @@ internal sealed class Startup {
app.UseWebSockets();
// Finally register proper API endpoints once we're done with routing
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
app.UseMvcWithDefaultRoute();
#else
app.UseEndpoints(static endpoints => endpoints.MapControllers());
@@ -313,7 +313,7 @@ internal sealed class Startup {
mvc.AddControllersAsServices();
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
// Use latest compatibility version for MVC
mvc.SetCompatibilityVersion(CompatibilityVersion.Latest);
@@ -333,7 +333,7 @@ internal sealed class Startup {
options.SerializerSettings.Formatting = Formatting.Indented;
}
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
// .NET Framework serializes Version as object by default, serialize it as string just like .NET Core
options.SerializerSettings.Converters.Add(new VersionConverter());
#endif

View File

@@ -19,7 +19,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
#endif
@@ -35,7 +35,7 @@ using Newtonsoft.Json;
namespace ArchiSteamFarm.IPC;
internal static class WebUtilities {
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
internal static IMvcCoreBuilder AddControllers(this IServiceCollection services) {
ArgumentNullException.ThrowIfNull(services);

View File

@@ -43,7 +43,7 @@ using Newtonsoft.Json;
using NLog;
using NLog.Targets;
using SteamKit2;
#if !NETFRAMEWORK
#if !NETFRAMEWORK && !NETSTANDARD
using System.Net.Quic;
#endif
@@ -59,13 +59,13 @@ internal static class Program {
internal static bool ShutdownSequenceInitialized { get; private set; }
internal static bool SteamParentalGeneration { get; private set; } = true;
#if !NETFRAMEWORK
#if !NETFRAMEWORK && !NETSTANDARD
private static readonly Dictionary<PosixSignal, PosixSignalRegistration> RegisteredPosixSignals = new();
#endif
private static readonly TaskCompletionSource<byte> ShutdownResetEvent = new();
#if !NETFRAMEWORK
#if !NETFRAMEWORK && !NETSTANDARD
private static readonly ImmutableHashSet<PosixSignal> SupportedPosixSignals = ImmutableHashSet.Create(PosixSignal.SIGINT, PosixSignal.SIGTERM);
#endif
@@ -193,7 +193,7 @@ internal static class Program {
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
RuntimeMadness.Initialize();
#else
if (OperatingSystem.IsFreeBSD() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) {
@@ -465,7 +465,7 @@ internal static class Program {
ShutdownSequenceInitialized = true;
#if !NETFRAMEWORK
#if !NETFRAMEWORK && !NETSTANDARD
if (OperatingSystem.IsFreeBSD() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) {
// Unregister from registered signals
foreach (PosixSignalRegistration registration in RegisteredPosixSignals.Values) {
@@ -510,7 +510,7 @@ internal static class Program {
private static async void OnCancelKeyPress(object? sender, ConsoleCancelEventArgs e) => await Exit(130).ConfigureAwait(false);
#if !NETFRAMEWORK
#if !NETFRAMEWORK && !NETSTANDARD
private static async void OnPosixSignal(PosixSignalContext signal) {
ArgumentNullException.ThrowIfNull(signal);

View File

@@ -65,7 +65,7 @@ public sealed class WebBrowser : IDisposable {
HttpClientHandler = new HttpClientHandler {
AllowAutoRedirect = false, // This must be false if we want to handle custom redirection schemes such as "steammobile://"
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
#else
AutomaticDecompression = DecompressionMethods.All,
@@ -85,7 +85,7 @@ public sealed class WebBrowser : IDisposable {
}
}
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
if (!RuntimeMadness.IsRunningOnMono) {
HttpClientHandler.MaxConnectionsPerServer = MaxConnections;
}
@@ -106,7 +106,7 @@ public sealed class WebBrowser : IDisposable {
byte connectionTimeout = ASF.GlobalConfig?.ConnectionTimeout ?? GlobalConfig.DefaultConnectionTimeout;
HttpClient result = new(HttpClientHandler, false) {
#if !NETFRAMEWORK
#if !NETFRAMEWORK && !NETSTANDARD
DefaultRequestVersion = HttpVersion.Version30,
#endif
Timeout = TimeSpan.FromSeconds(extendedTimeout ? ExtendedTimeout : connectionTimeout)
@@ -662,7 +662,7 @@ public sealed class WebBrowser : IDisposable {
using StreamReader streamReader = new(response.Content);
#pragma warning disable CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose
JsonReader jsonReader = new JsonTextReader(streamReader);
JsonTextReader jsonReader = new(streamReader);
#pragma warning restore CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose
await using (jsonReader.ConfigureAwait(false)) {
@@ -766,7 +766,7 @@ public sealed class WebBrowser : IDisposable {
ServicePointManager.Expect100Continue = false;
// Reuse ports if possible
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
if (!RuntimeMadness.IsRunningOnMono) {
ServicePointManager.ReusePort = true;
}
@@ -801,7 +801,7 @@ public sealed class WebBrowser : IDisposable {
while (true) {
using (HttpRequestMessage requestMessage = new(httpMethod, request)) {
#if !NETFRAMEWORK
#if !NETFRAMEWORK && !NETSTANDARD
requestMessage.Version = HttpClient.DefaultRequestVersion;
#endif

View File

@@ -59,7 +59,7 @@ internal static class WebBrowserUtilities {
private static (Stream CompressionInput, string ContentEncoding) GetBestSupportedCompressionMethod(Stream output) {
ArgumentNullException.ThrowIfNull(output);
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD
return (new GZipStream(output, CompressionLevel.Optimal, true), "gzip");
#else
return (new BrotliStream(output, CompressionLevel.SmallestSize, true), "br");

View File

@@ -29,18 +29,19 @@
<RepositoryUrl>$(PackageProjectUrl).git</RepositoryUrl>
<RollForward>LatestMajor</RollForward>
<RuntimeIdentifiers>linux-arm;linux-arm64;linux-x64;osx-arm64;osx-x64;win-x64</RuntimeIdentifiers>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>
<PropertyGroup Condition="'$(OS)' == 'Windows_NT' OR '$(ASFNetFramework)' != ''">
<TargetFrameworks>net7.0;net481</TargetFrameworks>
<TargetFrameworks>$(TargetFrameworks);net481</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="'$(OS)' != 'Windows_NT' AND '$(ASFNetFramework)' == ''">
<TargetFramework>net7.0</TargetFramework>
<PropertyGroup Condition="'$(ASFNetStandard)' != ''">
<TargetFrameworks>$(TargetFrameworks);netstandard2.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<ItemGroup Condition="'$(TargetFramework)' == 'net481' OR '$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="JustArchiNET.Madness" />
<PackageReference Include="TA.System.Runtime.CompilerServices.RuntimeHelpers.GetSubArray" />
@@ -48,9 +49,13 @@
<Using Include="JustArchiNET.Madness.ArgumentNullExceptionMadness.ArgumentNullException" Alias="ArgumentNullException" />
<Using Include="JustArchiNET.Madness.ArrayMadness.Array" Alias="Array" />
<Using Include="JustArchiNET.Madness.ConvertMadness.Convert" Alias="Convert" />
<Using Include="JustArchiNET.Madness.DirectoryInfoMadness.DirectoryInfo" Alias="DirectoryInfo" />
<Using Include="JustArchiNET.Madness.DirectoryMadness.Directory" Alias="Directory" />
<Using Include="JustArchiNET.Madness.EnumMadness.Enum" Alias="Enum" />
<Using Include="JustArchiNET.Madness.EnvironmentMadness.Environment" Alias="Environment" />
<Using Include="JustArchiNET.Madness.FileInfoMadness.FileInfo" Alias="FileInfo" />
<Using Include="JustArchiNET.Madness.FileMadness.File" Alias="File" />
<Using Include="JustArchiNET.Madness.FileMadness.UnixFileMode" Alias="UnixFileMode" />
<Using Include="JustArchiNET.Madness.HashCodeMadness.HashCode" Alias="HashCode" />
<Using Include="JustArchiNET.Madness.HMACSHA1Madness.HMACSHA1" Alias="HMACSHA1" />
<Using Include="JustArchiNET.Madness.HttpRequestExceptionMadness.HttpRequestException" Alias="HttpRequestException" />
@@ -63,6 +68,11 @@
<Using Include="JustArchiNET.Madness.StringMadness.String" Alias="String" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<Using Include="JustArchiNET.Madness.NewtonsoftJsonMadness.JsonTextReader" Alias="JsonTextReader" />
<Using Include="JustArchiNET.Madness.NewtonsoftJsonMadness.JsonTextWriter" Alias="JsonTextWriter" />
</ItemGroup>
<PropertyGroup Condition="'$(ASFVariant)' != ''">
<DefineConstants>$(DefineConstants);ASF_VARIANT_$(ASFVariant.Replace('-', '_').ToUpperInvariant())</DefineConstants>
</PropertyGroup>

View File

@@ -26,8 +26,8 @@
<PackageVersion Include="System.Security.Cryptography.ProtectedData" Version="7.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<PackageVersion Include="JustArchiNET.Madness" Version="3.10.0" />
<ItemGroup Condition="'$(TargetFramework)' == 'net481' OR '$(TargetFramework)' == 'netstandard2.1'">
<PackageVersion Include="JustArchiNET.Madness" Version="3.11.0" />
<PackageVersion Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.HttpOverrides" Version="2.2.0" />
@@ -40,4 +40,8 @@
<PackageVersion Include="Microsoft.Extensions.Logging.Configuration" Version="3.1.32" />
<PackageVersion Include="TA.System.Runtime.CompilerServices.RuntimeHelpers.GetSubArray" Version="1.0.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageVersion Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
</ItemGroup>
</Project>