From 197539f3535db75d956730bbb4391cb83c59c8ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Domeradzki?= Date: Thu, 31 Aug 2017 07:30:09 +0200 Subject: [PATCH] Linker optimizations (#633) * Initial linker optimizations * Fix Windows build --- .travis.yml | 2 +- ArchiSteamFarm/ArchiSteamFarm.csproj | 6 ++--- ArchiSteamFarm/OS.cs | 39 +++++++++++++++++++++------- appveyor.yml | 2 +- nuget.config | 6 +++++ 5 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 nuget.config diff --git a/.travis.yml b/.travis.yml index 6d6dab8bc..02874b24e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,7 @@ script: publish() { if [ "$1" = 'generic' ]; then - dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -o "out/${1}" --no-restore /nologo + dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -o "out/${1}" --no-restore /nologo /p:LinkDuringPublish=false else dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -o "out/${1}" -r "$1" --no-restore /nologo fi diff --git a/ArchiSteamFarm/ArchiSteamFarm.csproj b/ArchiSteamFarm/ArchiSteamFarm.csproj index 201448784..7068bee5e 100644 --- a/ArchiSteamFarm/ArchiSteamFarm.csproj +++ b/ArchiSteamFarm/ArchiSteamFarm.csproj @@ -19,8 +19,6 @@ https://github.com/JustArchi/ArchiSteamFarm/raw/master/resources/ASF.ico Git - true - false true @@ -28,12 +26,14 @@ none false + true + - + diff --git a/ArchiSteamFarm/OS.cs b/ArchiSteamFarm/OS.cs index 7a20620e6..27a940b81 100644 --- a/ArchiSteamFarm/OS.cs +++ b/ArchiSteamFarm/OS.cs @@ -26,7 +26,6 @@ using System; using System.IO; using System.Runtime.InteropServices; using ArchiSteamFarm.Localization; -using Mono.Unix; namespace ArchiSteamFarm { internal static class OS { @@ -47,12 +46,13 @@ namespace ArchiSteamFarm { } internal static void UnixSetFileAccessExecutable(string path) { - if (!File.Exists(path) || !UnixFileSystemInfo.TryGetFileSystemEntry(path, out UnixFileSystemInfo entry)) { + if (!File.Exists(path)) { return; } - if (!entry.FileAccessPermissions.HasFlag(FileAccessPermissions.UserExecute)) { - entry.FileAccessPermissions = entry.FileAccessPermissions | FileAccessPermissions.UserExecute; + // Chmod() returns 0 on success, -1 on failure + if (NativeMethods.Chmod(path, (int) NativeMethods.UnixExecutePermission) != 0) { + ASF.ArchiLogger.LogGenericError(string.Format(Strings.WarningFailedWithError, Marshal.GetLastWin32Error())); } } @@ -76,7 +76,7 @@ namespace ArchiSteamFarm { // 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 // More info: https://msdn.microsoft.com/library/windows/desktop/aa373208(v=vs.85).aspx - NativeMethods.EExecutionState result = NativeMethods.SetThreadExecutionState(NativeMethods.EExecutionState.AwayModeRequired | NativeMethods.EExecutionState.Continuous | NativeMethods.EExecutionState.SystemRequired); + NativeMethods.EExecutionState result = NativeMethods.SetThreadExecutionState(NativeMethods.AwakeExecutionState); // SetThreadExecutionState() returns NULL on failure, which is mapped to 0 (EExecutionState.Error) in our case if (result == NativeMethods.EExecutionState.Error) { @@ -85,19 +85,24 @@ namespace ArchiSteamFarm { } private static class NativeMethods { + internal const EExecutionState AwakeExecutionState = EExecutionState.SystemRequired | EExecutionState.AwayModeRequired | EExecutionState.Continuous; internal const uint EnableQuickEditMode = 0x0040; internal const sbyte StandardInputHandle = -10; + internal const EUnixPermission UnixExecutePermission = EUnixPermission.UserRead | EUnixPermission.UserWrite | EUnixPermission.UserExecute | EUnixPermission.GroupRead | EUnixPermission.GroupExecute | EUnixPermission.OtherRead | EUnixPermission.OtherExecute; - [DllImport("kernel32.dll", CharSet = CharSet.Auto)] + [DllImport("libc", EntryPoint = "chmod", SetLastError = true)] + internal static extern int Chmod(string path, int mode); + + [DllImport("kernel32.dll")] internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode); - [DllImport("kernel32.dll", CharSet = CharSet.Auto)] + [DllImport("kernel32.dll")] internal static extern IntPtr GetStdHandle(int nStdHandle); - [DllImport("kernel32.dll", CharSet = CharSet.Auto)] + [DllImport("kernel32.dll")] internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode); - [DllImport("kernel32.dll", CharSet = CharSet.Auto)] + [DllImport("kernel32.dll")] internal static extern EExecutionState SetThreadExecutionState(EExecutionState executionState); [Flags] @@ -107,6 +112,22 @@ namespace ArchiSteamFarm { AwayModeRequired = 0x00000040, Continuous = 0x80000000 } + + [Flags] + internal enum EUnixPermission { + OtherExecute = 0x1, + OtherRead = 0x4, + GroupExecute = 0x8, + GroupRead = 0x20, + UserExecute = 0x40, + UserWrite = 0x80, + UserRead = 0x100 + + /* + OtherWrite = 0x2 + GroupWrite = 0x10 + */ + } } } } \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 63610448f..8274629c2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -62,7 +62,7 @@ after_test: Set-Location -Path "$env:APPVEYOR_BUILD_FOLDER" if ($RUNTIME -eq 'generic') { - dotnet publish ArchiSteamFarm -c "$env:CONFIGURATION" -o "out\$RUNTIME" --no-restore /nologo + dotnet publish ArchiSteamFarm -c "$env:CONFIGURATION" -o "out\$RUNTIME" --no-restore /nologo /p:LinkDuringPublish=false } else { dotnet publish ArchiSteamFarm -c "$env:CONFIGURATION" -o "out\$RUNTIME" -r "$RUNTIME" --no-restore /nologo } diff --git a/nuget.config b/nuget.config new file mode 100644 index 000000000..ff6b1c83d --- /dev/null +++ b/nuget.config @@ -0,0 +1,6 @@ + + + + + +