diff --git a/.travis.yml b/.travis.yml index ba7986278..d1e2dfe59 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ env: - CONFIGURATION: Release - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 - - VARIANTS="generic win-x64 linux-x64 linux-arm osx-x64" # NOTE: When modifying variants, don't forget to update ASF_VARIANT definitions in ASF.cs! + - VARIANTS="generic win-x64 linux-x64 linux-arm osx-x64" # NOTE: When modifying variants, don't forget to update ASF_VARIANT definitions in SharedInfo.cs! before_script: - | diff --git a/ArchiSteamFarm/ASF.cs b/ArchiSteamFarm/ASF.cs index 34cfc9912..e87bde7f6 100644 --- a/ArchiSteamFarm/ASF.cs +++ b/ArchiSteamFarm/ASF.cs @@ -33,22 +33,6 @@ using ArchiSteamFarm.Localization; namespace ArchiSteamFarm { internal static class ASF { - private const string SourceVariant = "source"; - -#if ASF_VARIANT_GENERIC - private const string Variant = "generic"; -#elif ASF_VARIANT_LINUX_ARM - private const string Variant = "linux-arm"; -#elif ASF_VARIANT_LINUX_X64 - private const string Variant = "linux-x64"; -#elif ASF_VARIANT_OSX_X64 - private const string Variant = "osx-x64"; -#elif ASF_VARIANT_WIN_X64 - private const string Variant = "win-x64"; -#else - private const string Variant = SourceVariant; -#endif - internal static readonly ArchiLogger ArchiLogger = new ArchiLogger(SharedInfo.ASF); private static readonly ConcurrentDictionary LastWriteTimes = new ConcurrentDictionary(); @@ -57,7 +41,7 @@ namespace ArchiSteamFarm { private static FileSystemWatcher FileSystemWatcher; internal static async Task CheckAndUpdateProgram(bool updateOverride = false) { - if (Variant.Equals(SourceVariant) || (Program.GlobalConfig.UpdateChannel == GlobalConfig.EUpdateChannel.None)) { + if (SharedInfo.IsCustomBuild || (Program.GlobalConfig.UpdateChannel == GlobalConfig.EUpdateChannel.None)) { return null; } @@ -153,7 +137,7 @@ namespace ArchiSteamFarm { return null; } - const string targetFile = SharedInfo.ASF + "-" + Variant + ".zip"; + const string targetFile = SharedInfo.ASF + "-" + SharedInfo.Variant + ".zip"; GitHub.ReleaseResponse.Asset binaryAsset = releaseResponse.Assets.FirstOrDefault(asset => asset.Name.Equals(targetFile, StringComparison.OrdinalIgnoreCase)); if (binaryAsset == null) { @@ -182,7 +166,7 @@ namespace ArchiSteamFarm { return null; } - if (IsUnixVariant(Variant)) { + if (IsUnixVariant(SharedInfo.Variant)) { string executable = Path.Combine(targetDirectory, SharedInfo.AssemblyName); if (File.Exists(executable)) { OS.UnixSetFileAccessExecutable(executable); diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index a992467d8..81ea50a6f 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -349,7 +349,7 @@ namespace ArchiSteamFarm { return null; } - internal async Task<(uint PlayableAppID, DateTime IgnoredUntil)> GetAppDataForIdling(uint appID, float hoursPlayed, bool allowRecursiveDiscovery = true) { + internal async Task<(uint PlayableAppID, DateTime IgnoredUntil)> GetAppDataForIdling(uint appID, float hoursPlayed, bool allowRecursiveDiscovery = true, bool optimisticDiscovery = true) { if ((appID == 0) || (hoursPlayed < 0)) { ArchiLogger.LogNullError(nameof(appID) + " || " + nameof(hoursPlayed)); return (0, DateTime.MaxValue); @@ -373,7 +373,7 @@ namespace ArchiSteamFarm { } } - if (mostRecent != DateTime.MinValue) { + if (mostRecent > DateTime.MinValue) { DateTime playableIn = mostRecent.AddDays(CardsFarmer.DaysForRefund); if (playableIn > DateTime.UtcNow) { return (0, playableIn); @@ -386,7 +386,7 @@ namespace ArchiSteamFarm { for (byte i = 0; (i < WebBrowser.MaxTries) && (productInfoResultSet == null); i++) { if (!IsConnectedAndLoggedOn) { - return (0, DateTime.MaxValue); + return (optimisticDiscovery ? appID : 0, DateTime.MinValue); } await PICSSemaphore.WaitAsync().ConfigureAwait(false); @@ -401,7 +401,7 @@ namespace ArchiSteamFarm { } if (productInfoResultSet == null) { - return (0, DateTime.MaxValue); + return (optimisticDiscovery ? appID : 0, DateTime.MinValue); } foreach (Dictionary productInfoApps in productInfoResultSet.Results.Select(result => result.Apps)) { @@ -466,7 +466,7 @@ namespace ArchiSteamFarm { } if (!allowRecursiveDiscovery) { - return (0, DateTime.MaxValue); + return (0, DateTime.MinValue); } string listOfDlc = productInfo["extended"]["listofdlc"].Value; @@ -481,7 +481,7 @@ namespace ArchiSteamFarm { break; } - (uint playableAppID, _) = await GetAppDataForIdling(dlcAppID, hoursPlayed, false).ConfigureAwait(false); + (uint playableAppID, _) = await GetAppDataForIdling(dlcAppID, hoursPlayed, false, false).ConfigureAwait(false); if (playableAppID != 0) { return (playableAppID, DateTime.MinValue); } @@ -491,7 +491,7 @@ namespace ArchiSteamFarm { } if (!productInfoResultSet.Complete || productInfoResultSet.Failed) { - return (0, DateTime.MaxValue); + return (optimisticDiscovery ? appID : 0, DateTime.MinValue); } return (appID, DateTime.MinValue); diff --git a/ArchiSteamFarm/CardsFarmer.cs b/ArchiSteamFarm/CardsFarmer.cs index f9c6ff415..96c558e82 100755 --- a/ArchiSteamFarm/CardsFarmer.cs +++ b/ArchiSteamFarm/CardsFarmer.cs @@ -895,14 +895,14 @@ namespace ArchiSteamFarm { private async Task IsPlayableGame(Game game) { (uint playableAppID, DateTime ignoredUntil) = await Bot.GetAppDataForIdling(game.AppID, game.HoursPlayed).ConfigureAwait(false); - if (playableAppID != 0) { - game.PlayableAppID = playableAppID; - return true; + if (playableAppID == 0) { + IgnoredAppIDs[game.AppID] = ignoredUntil < DateTime.MaxValue ? ignoredUntil : DateTime.UtcNow.AddHours(HoursToIgnore); + Bot.ArchiLogger.LogGenericInfo(string.Format(Strings.IdlingGameNotPossible, game.AppID, game.GameName)); + return false; } - IgnoredAppIDs[game.AppID] = ignoredUntil != DateTime.MaxValue ? ignoredUntil : DateTime.UtcNow.AddHours(HoursToIgnore); - Bot.ArchiLogger.LogGenericInfo(string.Format(Strings.IdlingGameNotPossible, game.AppID, game.GameName)); - return false; + game.PlayableAppID = playableAppID; + return true; } private async Task ShouldFarm(Game game) { diff --git a/ArchiSteamFarm/SharedInfo.cs b/ArchiSteamFarm/SharedInfo.cs index 8b5ee85c2..18f7a2d7d 100644 --- a/ArchiSteamFarm/SharedInfo.cs +++ b/ArchiSteamFarm/SharedInfo.cs @@ -20,14 +20,29 @@ // limitations under the License. using System; +using System.Diagnostics.CodeAnalysis; using System.Reflection; namespace ArchiSteamFarm { internal static class SharedInfo { +#if ASF_VARIANT_GENERIC + internal const string Variant = "generic"; +#elif ASF_VARIANT_LINUX_ARM + internal const string Variant = "linux-arm"; +#elif ASF_VARIANT_LINUX_X64 + internal const string Variant = "linux-x64"; +#elif ASF_VARIANT_OSX_X64 + internal const string Variant = "osx-x64"; +#elif ASF_VARIANT_WIN_X64 + internal const string Variant = "win-x64"; +#else + internal const string Variant = SourceVariant; +#endif + internal const ulong ArchiSteamID = 76561198006963719; - internal const string ASF = "ASF"; + internal const string ASF = nameof(ASF); internal const ulong ASFGroupSteamID = 103582791440160998; - internal const string AssemblyName = "ArchiSteamFarm"; + internal const string AssemblyName = nameof(ArchiSteamFarm); internal const string ConfigDirectory = "config"; internal const string DebugDirectory = "debug"; internal const string GithubReleaseURL = "https://api.github.com/repos/" + GithubRepo + "/releases"; // GitHub API is HTTPS only @@ -38,7 +53,13 @@ namespace ArchiSteamFarm { internal const string StatisticsServer = "asf.justarchi.net"; internal const string UpdateDirectory = "_old"; - internal static Guid ModuleVersion => Assembly.GetEntryAssembly().ManifestModule.ModuleVersionId; - internal static Version Version => Assembly.GetEntryAssembly().GetName().Version; + private const string SourceVariant = "source"; + + [SuppressMessage("ReSharper", "ConvertToConstant.Global")] + internal static readonly bool IsCustomBuild = Variant == SourceVariant; + + internal static readonly Guid ModuleVersion = Assembly.GetEntryAssembly().ManifestModule.ModuleVersionId; + internal static readonly string PublicIdentifier = AssemblyName + (IsCustomBuild ? "-custom" : ""); + internal static readonly Version Version = Assembly.GetEntryAssembly().GetName().Version; } } \ No newline at end of file diff --git a/ArchiSteamFarm/WebBrowser.cs b/ArchiSteamFarm/WebBrowser.cs index 99201358d..cc25271c7 100644 --- a/ArchiSteamFarm/WebBrowser.cs +++ b/ArchiSteamFarm/WebBrowser.cs @@ -58,7 +58,7 @@ namespace ArchiSteamFarm { HttpClient = new HttpClient(httpClientHandler) { Timeout = TimeSpan.FromSeconds(extendedTimeout ? ExtendedTimeoutMultiplier * Program.GlobalConfig.ConnectionTimeout : Program.GlobalConfig.ConnectionTimeout) }; // Most web services expect that UserAgent is set, so we declare it globally - HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd(SharedInfo.AssemblyName + "/" + SharedInfo.Version); + HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd(SharedInfo.PublicIdentifier + "/" + SharedInfo.Version); } public void Dispose() => HttpClient.Dispose(); diff --git a/appveyor.yml b/appveyor.yml index ef2fb9006..d6323cec0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,7 +12,7 @@ clone_depth: 10 environment: DOTNET_CLI_TELEMETRY_OPTOUT: true DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - VARIANTS: generic win-x64 linux-x64 linux-arm osx-x64 # NOTE: When modifying variants, don't forget to update ASF_VARIANT definitions in ASF.cs! + VARIANTS: generic win-x64 linux-x64 linux-arm osx-x64 # NOTE: When modifying variants, don't forget to update ASF_VARIANT definitions in SharedInfo.cs! matrix: fast_finish: true before_build: