Refactor ProviderConnectionException

This commit is contained in:
js6pak committed 2021-01-05 21:06:47 +01:00
1 parent 042e4cbd9e
commit 0ef29de19e
4 files changed
+22 -34

No files matched your search

+8 -13
View File
@@ -31,20 +31,11 @@ namespace Reactor.Greenhouse
return rootCommand.InvokeAsync(args);
}
public static async Task<int> 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 @@ namespace Reactor.Greenhouse
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 @@ namespace Reactor.Greenhouse
{
await GenerateAsync(gameManager.Itch, old);
}
return 0;
}
private static async Task GenerateAsync(Game game, ModuleDefinition old)
@@ -12,10 +12,13 @@ namespace Reactor.Greenhouse.Setup.Provider
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;
}
}
}
}
@@ -41,7 +41,6 @@ namespace Reactor.Greenhouse.Setup.Provider
Console.Write("itch.io password: ");
Password = Util.ReadPassword();
Console.WriteLine();
}
}
@@ -63,7 +62,7 @@ namespace Reactor.Greenhouse.Setup.Provider
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");
@@ -67,14 +67,9 @@ namespace Reactor.Greenhouse.Setup.Provider
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 @@ namespace Reactor.Greenhouse.Setup.Provider
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 @@ namespace Reactor.Greenhouse.Setup.Provider
return ContentDownloader.DownloadAppAsync(AppId, DepotId, IsPreObfuscation ? PreObfuscationManifest : ContentDownloader.INVALID_MANIFEST_ID);
}
}
public class SteamProviderConnectionException : ProviderConnectionException
{
public SteamProviderConnectionException(string message) : base(message)
{
}
}
}