From 042e4cbd9e28341d757fe479742073189219c897 Mon Sep 17 00:00:00 2001 From: LelouBil Date: Tue, 5 Jan 2021 19:03:27 +0100 Subject: [PATCH 1/2] Added error handling to the Steam connection. --- Reactor.Greenhouse/Program.cs | 17 +++++++++++-- .../Setup/Provider/BaseProvider.cs | 10 +++++++- .../Setup/Provider/SteamProvider.cs | 24 +++++++++++++++++-- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Reactor.Greenhouse/Program.cs b/Reactor.Greenhouse/Program.cs index 744d047..9c2f625 100644 --- a/Reactor.Greenhouse/Program.cs +++ b/Reactor.Greenhouse/Program.cs @@ -11,6 +11,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using Reactor.Greenhouse.Setup; +using Reactor.Greenhouse.Setup.Provider; using Reactor.OxygenFilter; namespace Reactor.Greenhouse @@ -30,10 +31,20 @@ private static Task Main(string[] args) return rootCommand.InvokeAsync(args); } - public static async Task GenerateAsync(bool steam, bool itch) + public static async Task GenerateAsync(bool steam, bool itch) { var gameManager = new GameManager(); - await gameManager.SetupAsync(steam, itch); + + try + { + await gameManager.SetupAsync(steam, itch); + } + catch (ProviderConnectionException e) + { + Console.WriteLine($"Error downloading version : {e.Message}"); + return 1; + } + JsonConvert.DefaultSettings = () => new JsonSerializerSettings { @@ -55,6 +66,8 @@ public static async Task GenerateAsync(bool steam, bool itch) { await GenerateAsync(gameManager.Itch, old); } + + return 0; } private static async Task GenerateAsync(Game game, ModuleDefinition old) diff --git a/Reactor.Greenhouse/Setup/Provider/BaseProvider.cs b/Reactor.Greenhouse/Setup/Provider/BaseProvider.cs index b552ab7..296ea93 100644 --- a/Reactor.Greenhouse/Setup/Provider/BaseProvider.cs +++ b/Reactor.Greenhouse/Setup/Provider/BaseProvider.cs @@ -1,3 +1,4 @@ +using System; using System.Threading.Tasks; namespace Reactor.Greenhouse.Setup.Provider @@ -10,4 +11,11 @@ public abstract class BaseProvider public abstract Task DownloadAsync(); public abstract bool IsUpdateNeeded(); } -} + + public abstract class ProviderConnectionException : Exception + { + protected ProviderConnectionException(string message) : base(message) + { + } + } +} \ No newline at end of file diff --git a/Reactor.Greenhouse/Setup/Provider/SteamProvider.cs b/Reactor.Greenhouse/Setup/Provider/SteamProvider.cs index 543e323..76de562 100644 --- a/Reactor.Greenhouse/Setup/Provider/SteamProvider.cs +++ b/Reactor.Greenhouse/Setup/Provider/SteamProvider.cs @@ -67,7 +67,15 @@ public override void Setup() if (environmentVariable != null) { var split = environmentVariable.Split(":"); - ContentDownloader.InitializeSteam3(split[0], split[1]); + if(!ContentDownloader.InitializeSteam3(split[0], split[1])) + { + throw new SteamProviderConnectionException("Wrong password"); + } + + if (ContentDownloader.steam3 == null || !ContentDownloader.steam3.bConnected) + { + throw new SteamProviderConnectionException("Unable to initialize Steam"); + } } else { @@ -85,7 +93,11 @@ public override void Setup() Console.WriteLine(); } - ContentDownloader.InitializeSteam3(username, password); + if (!ContentDownloader.InitializeSteam3(username, password)) + { + throw new SteamProviderConnectionException("Unable to initialize Steam"); + } + } ContentDownloader.Config.UsingFileList = true; @@ -106,4 +118,12 @@ public override Task DownloadAsync() return ContentDownloader.DownloadAppAsync(AppId, DepotId, IsPreObfuscation ? PreObfuscationManifest : ContentDownloader.INVALID_MANIFEST_ID); } } + + public class SteamProviderConnectionException : ProviderConnectionException + { + public SteamProviderConnectionException(string message) : base(message) + { + + } + } } From 0ef29de19ebd899b61edda42c8260b223c5acda3 Mon Sep 17 00:00:00 2001 From: js6pak Date: Tue, 5 Jan 2021 21:06:47 +0100 Subject: [PATCH 2/2] Refactor ProviderConnectionException --- Reactor.Greenhouse/Program.cs | 21 +++++++---------- .../Setup/Provider/BaseProvider.cs | 9 +++++--- .../Setup/Provider/ItchProvider.cs | 3 +-- .../Setup/Provider/SteamProvider.cs | 23 ++++++------------- 4 files changed, 22 insertions(+), 34 deletions(-) diff --git a/Reactor.Greenhouse/Program.cs b/Reactor.Greenhouse/Program.cs index 9c2f625..616d7e4 100644 --- a/Reactor.Greenhouse/Program.cs +++ b/Reactor.Greenhouse/Program.cs @@ -31,20 +31,11 @@ private static Task Main(string[] args) return rootCommand.InvokeAsync(args); } - public static async Task GenerateAsync(bool steam, bool itch) + public static async Task GenerateAsync(bool steam, bool itch) { var gameManager = new GameManager(); - try - { - await gameManager.SetupAsync(steam, itch); - } - catch (ProviderConnectionException e) - { - Console.WriteLine($"Error downloading version : {e.Message}"); - return 1; - } - + await gameManager.SetupAsync(steam, itch); JsonConvert.DefaultSettings = () => new JsonSerializerSettings { @@ -57,6 +48,12 @@ public static async Task GenerateAsync(bool steam, bool itch) Console.WriteLine($"Generating mappings from {gameManager.PreObfuscation.Name} ({gameManager.PreObfuscation.Version})"); using var old = ModuleDefinition.ReadModule(File.OpenRead(gameManager.PreObfuscation.Dll)); + if (!steam && !itch) + { + Console.WriteLine("No game providers used! (use --help for more info)"); + return; + } + if (steam) { await GenerateAsync(gameManager.Steam, old); @@ -66,8 +63,6 @@ public static async Task GenerateAsync(bool steam, bool itch) { await GenerateAsync(gameManager.Itch, old); } - - return 0; } private static async Task GenerateAsync(Game game, ModuleDefinition old) diff --git a/Reactor.Greenhouse/Setup/Provider/BaseProvider.cs b/Reactor.Greenhouse/Setup/Provider/BaseProvider.cs index 296ea93..5c72ef5 100644 --- a/Reactor.Greenhouse/Setup/Provider/BaseProvider.cs +++ b/Reactor.Greenhouse/Setup/Provider/BaseProvider.cs @@ -12,10 +12,13 @@ public abstract class BaseProvider public abstract bool IsUpdateNeeded(); } - public abstract class ProviderConnectionException : Exception + public class ProviderConnectionException : Exception { - protected ProviderConnectionException(string message) : base(message) + public BaseProvider Provider { get; } + + public ProviderConnectionException(BaseProvider provider, string message) : base(message) { + Provider = provider; } } -} \ No newline at end of file +} diff --git a/Reactor.Greenhouse/Setup/Provider/ItchProvider.cs b/Reactor.Greenhouse/Setup/Provider/ItchProvider.cs index 4d3144c..e56d5aa 100644 --- a/Reactor.Greenhouse/Setup/Provider/ItchProvider.cs +++ b/Reactor.Greenhouse/Setup/Provider/ItchProvider.cs @@ -41,7 +41,6 @@ public override void Setup() Console.Write("itch.io password: "); Password = Util.ReadPassword(); - Console.WriteLine(); } } @@ -63,7 +62,7 @@ public override async Task DownloadAsync() if (!loginResponse.IsSuccessStatusCode || (await loginResponse.Content.ReadAsStringAsync()).Contains("Errors")) { - throw new Exception("itch.io authentication failed"); + throw new ProviderConnectionException(this, "Authentication failed"); } Console.WriteLine("Logged into itch.io"); diff --git a/Reactor.Greenhouse/Setup/Provider/SteamProvider.cs b/Reactor.Greenhouse/Setup/Provider/SteamProvider.cs index 76de562..6efbe84 100644 --- a/Reactor.Greenhouse/Setup/Provider/SteamProvider.cs +++ b/Reactor.Greenhouse/Setup/Provider/SteamProvider.cs @@ -67,14 +67,9 @@ public override void Setup() if (environmentVariable != null) { var split = environmentVariable.Split(":"); - if(!ContentDownloader.InitializeSteam3(split[0], split[1])) + if (!ContentDownloader.InitializeSteam3(split[0], split[1])) { - throw new SteamProviderConnectionException("Wrong password"); - } - - if (ContentDownloader.steam3 == null || !ContentDownloader.steam3.bConnected) - { - throw new SteamProviderConnectionException("Unable to initialize Steam"); + throw new ProviderConnectionException(this, "Incorrect credentials."); } } else @@ -95,9 +90,13 @@ public override void Setup() if (!ContentDownloader.InitializeSteam3(username, password)) { - throw new SteamProviderConnectionException("Unable to initialize Steam"); + throw new ProviderConnectionException(this, "Incorrect credentials."); } + } + if (ContentDownloader.steam3 == null || !ContentDownloader.steam3.bConnected) + { + throw new ProviderConnectionException(this, "Unable to initialize Steam3 session."); } ContentDownloader.Config.UsingFileList = true; @@ -118,12 +117,4 @@ public override Task DownloadAsync() return ContentDownloader.DownloadAppAsync(AppId, DepotId, IsPreObfuscation ? PreObfuscationManifest : ContentDownloader.INVALID_MANIFEST_ID); } } - - public class SteamProviderConnectionException : ProviderConnectionException - { - public SteamProviderConnectionException(string message) : base(message) - { - - } - } }