From c9a2fc114040bc5e246081651bb213445e1af221 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Wed, 30 Jan 2019 20:35:29 +0100 Subject: [PATCH 1/6] #10 Fixed handling of outdated / wrong logintokens --- DML.Client/DMLClient.cs | 2 +- .../Classes/Core.cs | 41 +++++++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/DML.Client/DMLClient.cs b/DML.Client/DMLClient.cs index 691f563..07060f0 100644 --- a/DML.Client/DMLClient.cs +++ b/DML.Client/DMLClient.cs @@ -22,4 +22,4 @@ namespace DML.Client return Client.LoginState == LoginState.LoggedIn && Client.ConnectionState == ConnectionState.Connected; } } -} +} \ No newline at end of file diff --git a/Discord Media Loader.Application/Classes/Core.cs b/Discord Media Loader.Application/Classes/Core.cs index 00104dd..930e251 100644 --- a/Discord Media Loader.Application/Classes/Core.cs +++ b/Discord Media Loader.Application/Classes/Core.cs @@ -1,11 +1,5 @@ -using System; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Runtime; -using System.Threading.Tasks; -using System.Windows.Forms; -using Discord; +using Discord; +using Discord.Net; using Discord.WebSocket; using DML.AppCore.Classes; using DML.Application.Dialogs; @@ -16,6 +10,13 @@ using SharpRaven.Data; using SweetLib.Utils; using SweetLib.Utils.Logger; using SweetLib.Utils.Logger.Memory; +using System; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Runtime; +using System.Threading.Tasks; +using System.Windows.Forms; using Logger = SweetLib.Utils.Logger.Logger; namespace DML.Application.Classes @@ -175,7 +176,6 @@ namespace DML.Application.Classes Logger.Info("Trying to log into discord..."); - var abort = false; DMLClient.Client.Connected += Client_Connected; @@ -183,10 +183,19 @@ namespace DML.Application.Classes while (!loggedIn) { - if (!string.IsNullOrEmpty(Settings.LoginToken)) + var token = "abc"; + try { - Logger.Debug("Trying to login with last known token..."); - loggedIn = await DMLClient.Login(Settings.LoginToken); + if (!string.IsNullOrEmpty(Settings.LoginToken)) + { + Logger.Debug("Trying to login with last known token..."); + loggedIn = await DMLClient.Login(token); + } + + } + catch (HttpException e) + { + Logger.Warn("HTTPException occured during login. Probably from login token."); } if (!loggedIn) @@ -248,12 +257,16 @@ namespace DML.Application.Classes var isError = false; var guild = FindServerById(job.GuildId); if (guild == null) + { isError = true; + } else { var channel = FindChannelById(guild, job.ChannelId); if (channel == null) + { isError = true; + } } if (isError) @@ -280,9 +293,11 @@ namespace DML.Application.Classes } catch (Exception ex) { - Logger.Error($"{ex.Message} occured at: {ex.StackTrace}"); + Logger.Error($"{ex.Message} [{ex.GetType().Name}] occured at: {ex.StackTrace}"); if (MessageBox.Show($"An error occured while running Discord Media Loader:\n{ex.GetType().Name}: {ex.Message}\n\nDo you aggree to sending the error report to the creator of the tool?", "Discord Media Loader", MessageBoxButtons.YesNo) == DialogResult.Yes) + { Raven.Capture(new SentryEvent(ex)); + } } } From 224273d97b356f694e3634998ff9e485b6f68bf7 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Wed, 30 Jan 2019 20:47:13 +0100 Subject: [PATCH 2/6] #10 Removed dead code --- .../Classes/Core.cs | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/Discord Media Loader.Application/Classes/Core.cs b/Discord Media Loader.Application/Classes/Core.cs index 930e251..f570af6 100644 --- a/Discord Media Loader.Application/Classes/Core.cs +++ b/Discord Media Loader.Application/Classes/Core.cs @@ -206,42 +206,6 @@ namespace DML.Application.Classes } } - /*while ((Client.LoginState != LoginState.LoggedIn || Client.ConnectionState!=ConnectionState.Connected) && !abort) - { - Logger.Debug(Client.ConnectionState.ToString()); - Logger.Debug(Client.LoginState.ToString()); - - Logger.Trace("Entering login loop."); - - try - { - if (Client.ConnectionState == ConnectionState.Connecting) - continue; - - if (!string.IsNullOrEmpty(Settings.LoginToken)) - { - Logger.Debug("Trying to login with last known token..."); - await Client.LoginAsync(TokenType.User, Settings.LoginToken); - await Client.StartAsync(); - await Task.Delay(1000); - } - - } - catch (HttpException ex) - { - Logger.Warn($"Login seems to have failed or gone wrong: {ex.GetType().Name} - {ex.Message}"); - } - - if (Client.LoginState == LoginState.LoggedOut) - { - Settings.Password = string.Empty; - Logger.Debug("Showing dialog for username and password..."); - var loginDlg = new LoginDialog(); - loginDlg.ShowDialog(); - Logger.Trace("Dialog closed."); - } - }*/ - Logger.Debug("Start checking for invalid jobs..."); //Client From ff52b5eb8ac83ae5fb0af63cbc0d5a56e982c52e Mon Sep 17 00:00:00 2001 From: Serraniel Date: Wed, 30 Jan 2019 20:50:22 +0100 Subject: [PATCH 3/6] #10 Fixed testing code --- Discord Media Loader.Application/Classes/Core.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Discord Media Loader.Application/Classes/Core.cs b/Discord Media Loader.Application/Classes/Core.cs index f570af6..8036846 100644 --- a/Discord Media Loader.Application/Classes/Core.cs +++ b/Discord Media Loader.Application/Classes/Core.cs @@ -183,13 +183,12 @@ namespace DML.Application.Classes while (!loggedIn) { - var token = "abc"; try { if (!string.IsNullOrEmpty(Settings.LoginToken)) { Logger.Debug("Trying to login with last known token..."); - loggedIn = await DMLClient.Login(token); + loggedIn = await DMLClient.Login(Settings.LoginToken); } } From 560c3711fa203ebab232a339581f716a35d23c5c Mon Sep 17 00:00:00 2001 From: Serraniel Date: Wed, 30 Jan 2019 20:50:53 +0100 Subject: [PATCH 4/6] #10 Some optimization --- Discord Media Loader.Application/Classes/Core.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Discord Media Loader.Application/Classes/Core.cs b/Discord Media Loader.Application/Classes/Core.cs index 8036846..fa97eeb 100644 --- a/Discord Media Loader.Application/Classes/Core.cs +++ b/Discord Media Loader.Application/Classes/Core.cs @@ -192,7 +192,7 @@ namespace DML.Application.Classes } } - catch (HttpException e) + catch (HttpException) { Logger.Warn("HTTPException occured during login. Probably from login token."); } From d90457b6e3221ea50e408b40fca45ab428c0e5d9 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Wed, 30 Jan 2019 20:54:07 +0100 Subject: [PATCH 5/6] #20 Only continue after login dialog if "ok" is the dialog result. --- Discord Media Loader.Application/Classes/Core.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Discord Media Loader.Application/Classes/Core.cs b/Discord Media Loader.Application/Classes/Core.cs index f570af6..477643e 100644 --- a/Discord Media Loader.Application/Classes/Core.cs +++ b/Discord Media Loader.Application/Classes/Core.cs @@ -193,7 +193,7 @@ namespace DML.Application.Classes } } - catch (HttpException e) + catch (HttpException) { Logger.Warn("HTTPException occured during login. Probably from login token."); } @@ -202,7 +202,10 @@ namespace DML.Application.Classes { Logger.Debug("Showing dialog for username and password..."); var loginDlg = new LoginDialog(); - loginDlg.ShowDialog(); + if (loginDlg.ShowDialog() != DialogResult.OK) + { + return; + } } } From 6b6991f3096ab19a9b3f809982ce754483e8db43 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Wed, 30 Jan 2019 21:01:16 +0100 Subject: [PATCH 6/6] Build preperation --- Discord Media Loader.Application/Properties/AssemblyInfo.cs | 6 +++--- Discord Media Loader/Properties/AssemblyInfo.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Discord Media Loader.Application/Properties/AssemblyInfo.cs b/Discord Media Loader.Application/Properties/AssemblyInfo.cs index 8d7d910..1f4853b 100644 --- a/Discord Media Loader.Application/Properties/AssemblyInfo.cs +++ b/Discord Media Loader.Application/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Serraniel")] [assembly: AssemblyProduct("Discord Media Loader.Application")] -[assembly: AssemblyCopyright("Copyright © 2017 - 2018 by Serraniel")] +[assembly: AssemblyCopyright("Copyright © 2017 - 2019 by Serraniel")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0.0")] -[assembly: AssemblyFileVersion("1.2.0.0")] +[assembly: AssemblyVersion("1.2.1.0")] +[assembly: AssemblyFileVersion("1.2.1.0")] diff --git a/Discord Media Loader/Properties/AssemblyInfo.cs b/Discord Media Loader/Properties/AssemblyInfo.cs index 1222c99..682e27d 100644 --- a/Discord Media Loader/Properties/AssemblyInfo.cs +++ b/Discord Media Loader/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Serraniel")] [assembly: AssemblyProduct("Discord Media Loader")] -[assembly: AssemblyCopyright("Copyright © 2017 - 2018 by Serraniel")] +[assembly: AssemblyCopyright("Copyright © 2017 - 2019 by Serraniel")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")]