Include ASF's windows-only parts only in generic and windows builds (#2404)

* Include ASF's windows-only parts only in generic and windows builds

* Apply Abry's note
This commit is contained in:
Łukasz Domeradzki
2021-08-13 23:07:17 +02:00
committed by GitHub
parent 1fda77a72d
commit bb513921f1
7 changed files with 44 additions and 6 deletions

View File

@@ -29,7 +29,7 @@
<PackageReference Include="System.Linq.Async" /> <PackageReference Include="System.Linq.Async" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net48'"> <ItemGroup Condition="'$(TargetFramework)' != 'net48' AND ('$(TargetGeneric)' == 'true' OR '$(TargetWindows)' == 'true')">
<PackageReference Include="Microsoft.Win32.SystemEvents" /> <PackageReference Include="Microsoft.Win32.SystemEvents" />
<PackageReference Include="System.IO.FileSystem.AccessControl" /> <PackageReference Include="System.IO.FileSystem.AccessControl" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" /> <PackageReference Include="System.Security.Cryptography.ProtectedData" />

View File

@@ -74,10 +74,12 @@ namespace ArchiSteamFarm.Core {
} }
} }
#if TARGET_GENERIC || TARGET_WINDOWS
internal static void OnTimeChanged(object? sender, EventArgs e) { internal static void OnTimeChanged(object? sender, EventArgs e) {
lock (LockObject) { lock (LockObject) {
Timer.Change(TimeSpan.Zero, Timeout.InfiniteTimeSpan); Timer.Change(TimeSpan.Zero, Timeout.InfiniteTimeSpan);
} }
} }
#endif
} }
} }

View File

@@ -193,6 +193,7 @@ namespace ArchiSteamFarm.Helpers {
return null; return null;
} }
#if TARGET_GENERIC || TARGET_WINDOWS
try { try {
byte[] decryptedData = ProtectedData.Unprotect( byte[] decryptedData = ProtectedData.Unprotect(
Convert.FromBase64String(encryptedString), Convert.FromBase64String(encryptedString),
@@ -206,6 +207,9 @@ namespace ArchiSteamFarm.Helpers {
return null; return null;
} }
#else
throw new InvalidOperationException();
#endif
} }
private static string? EncryptAES(string decryptedString) { private static string? EncryptAES(string decryptedString) {
@@ -240,6 +244,7 @@ namespace ArchiSteamFarm.Helpers {
return null; return null;
} }
#if TARGET_GENERIC || TARGET_WINDOWS
try { try {
byte[] encryptedData = ProtectedData.Protect( byte[] encryptedData = ProtectedData.Protect(
Encoding.UTF8.GetBytes(decryptedString), Encoding.UTF8.GetBytes(decryptedString),
@@ -253,6 +258,9 @@ namespace ArchiSteamFarm.Helpers {
return null; return null;
} }
#else
throw new InvalidOperationException();
#endif
} }
public enum ECryptoMethod : byte { public enum ECryptoMethod : byte {

View File

@@ -22,10 +22,12 @@
#if NETFRAMEWORK #if NETFRAMEWORK
using OperatingSystem = JustArchiNET.Madness.OperatingSystemMadness.OperatingSystem; using OperatingSystem = JustArchiNET.Madness.OperatingSystemMadness.OperatingSystem;
#endif #endif
#if TARGET_GENERIC || TARGET_WINDOWS
using System.Security.AccessControl;
#endif
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Security.AccessControl;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using ArchiSteamFarm.Core; using ArchiSteamFarm.Core;
@@ -165,6 +167,7 @@ namespace ArchiSteamFarm.Helpers {
if (!Directory.Exists(directoryPath)) { if (!Directory.Exists(directoryPath)) {
Directory.CreateDirectory(directoryPath); Directory.CreateDirectory(directoryPath);
#if TARGET_GENERIC || TARGET_WINDOWS
if (OperatingSystem.IsWindows()) { if (OperatingSystem.IsWindows()) {
DirectoryInfo directoryInfo = new(directoryPath); DirectoryInfo directoryInfo = new(directoryPath);
@@ -176,14 +179,20 @@ namespace ArchiSteamFarm.Helpers {
// Non-critical, user might have no rights to manage the resource // Non-critical, user might have no rights to manage the resource
ASF.ArchiLogger.LogGenericDebuggingException(e); ASF.ArchiLogger.LogGenericDebuggingException(e);
} }
} else if (OperatingSystem.IsFreeBSD() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { }
#endif
#if TARGET_GENERIC || !TARGET_WINDOWS
if (OperatingSystem.IsFreeBSD() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) {
OS.UnixSetFileAccess(directoryPath, OS.EUnixPermission.Combined777); OS.UnixSetFileAccess(directoryPath, OS.EUnixPermission.Combined777);
} }
#endif
} }
try { try {
new FileStream(FilePath, FileMode.CreateNew).Dispose(); new FileStream(FilePath, FileMode.CreateNew).Dispose();
#if TARGET_GENERIC || TARGET_WINDOWS
if (OperatingSystem.IsWindows()) { if (OperatingSystem.IsWindows()) {
FileInfo fileInfo = new(FilePath); FileInfo fileInfo = new(FilePath);
@@ -195,9 +204,14 @@ namespace ArchiSteamFarm.Helpers {
// Non-critical, user might have no rights to manage the resource // Non-critical, user might have no rights to manage the resource
ASF.ArchiLogger.LogGenericDebuggingException(e); ASF.ArchiLogger.LogGenericDebuggingException(e);
} }
} else if (OperatingSystem.IsFreeBSD() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { }
#endif
#if TARGET_GENERIC || !TARGET_WINDOWS
if (OperatingSystem.IsFreeBSD() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) {
OS.UnixSetFileAccess(FilePath, OS.EUnixPermission.Combined777); OS.UnixSetFileAccess(FilePath, OS.EUnixPermission.Combined777);
} }
#endif
} catch (IOException) { } catch (IOException) {
// Ignored, if the file was already created in the meantime by another instance, this is fine // Ignored, if the file was already created in the meantime by another instance, this is fine
} }

View File

@@ -22,6 +22,9 @@
#if NETFRAMEWORK #if NETFRAMEWORK
using OperatingSystem = JustArchiNET.Madness.OperatingSystemMadness.OperatingSystem; using OperatingSystem = JustArchiNET.Madness.OperatingSystemMadness.OperatingSystem;
#endif #endif
#if TARGET_GENERIC || TARGET_WINDOWS
using Microsoft.Win32;
#endif
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@@ -42,7 +45,6 @@ using ArchiSteamFarm.NLog.Targets;
using ArchiSteamFarm.Steam; using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Storage; using ArchiSteamFarm.Storage;
using ArchiSteamFarm.Web; using ArchiSteamFarm.Web;
using Microsoft.Win32;
using Newtonsoft.Json; using Newtonsoft.Json;
using NLog; using NLog;
using NLog.Targets; using NLog.Targets;
@@ -274,9 +276,11 @@ namespace ArchiSteamFarm {
// April Fools easter egg logic // April Fools easter egg logic
AprilFools.Init(); AprilFools.Init();
#if TARGET_GENERIC || TARGET_WINDOWS
if (OperatingSystem.IsWindows()) { if (OperatingSystem.IsWindows()) {
SystemEvents.TimeChanged += AprilFools.OnTimeChanged; SystemEvents.TimeChanged += AprilFools.OnTimeChanged;
} }
#endif
} }
if (!string.IsNullOrEmpty(latestJson)) { if (!string.IsNullOrEmpty(latestJson)) {

View File

@@ -34,6 +34,16 @@
<DefineConstants>$(DefineConstants);ASF_VARIANT_$(ASFVariant.Replace('-', '_').ToUpperInvariant())</DefineConstants> <DefineConstants>$(DefineConstants);ASF_VARIANT_$(ASFVariant.Replace('-', '_').ToUpperInvariant())</DefineConstants>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net48' OR '$(RuntimeIdentifier)' == ''">
<DefineConstants>$(DefineConstants);TARGET_GENERIC</DefineConstants>
<TargetGeneric>true</TargetGeneric>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' != 'net48' AND ($(RuntimeIdentifier.StartsWith('win-')) OR $(RuntimeIdentifier.EndsWith('-windows')))">
<DefineConstants>$(DefineConstants);TARGET_WINDOWS</DefineConstants>
<TargetWindows>true</TargetWindows>
</PropertyGroup>
<!-- Default configuration for release builds --> <!-- Default configuration for release builds -->
<PropertyGroup Condition="'$(Configuration)' == 'Release'"> <PropertyGroup Condition="'$(Configuration)' == 'Release'">
<AssemblyOriginatorKeyFile>../resources/ArchiSteamFarm.snk.pub</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>../resources/ArchiSteamFarm.snk.pub</AssemblyOriginatorKeyFile>

View File

@@ -22,7 +22,7 @@
<PackageVersion Include="System.Linq.Async" Version="5.0.0" /> <PackageVersion Include="System.Linq.Async" Version="5.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net48'"> <ItemGroup Condition="'$(TargetFramework)' != 'net48' AND ('$(TargetGeneric)' == 'true' OR '$(TargetWindows)' == 'true')">
<PackageVersion Include="Microsoft.Win32.SystemEvents" Version="5.0.0" /> <PackageVersion Include="Microsoft.Win32.SystemEvents" Version="5.0.0" />
<PackageVersion Include="System.IO.FileSystem.AccessControl" Version="5.0.0" /> <PackageVersion Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
<PackageVersion Include="System.Security.Cryptography.ProtectedData" Version="5.0.0" /> <PackageVersion Include="System.Security.Cryptography.ProtectedData" Version="5.0.0" />