From 221b2bdff99d043e1cccd334037d1431b4af6708 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Mon, 25 Sep 2017 19:50:59 +0200 Subject: [PATCH] Semi upgraded to new Discord.Net --- .../Classes/Job.cs | 27 +-- .../Classes/JobScheduler.cs | 33 ++- Discord Media Loader.Application/Core.cs | 70 +++--- .../DML.Application.csproj | 96 +++++++- .../Dialogs/LoginDialog.Designer.cs | 209 ++++-------------- .../Dialogs/LoginDialog.cs | 10 - Discord Media Loader.Application/MainForm.cs | 15 +- Discord Media Loader.Application/app.config | 19 ++ .../packages.config | 61 ++++- Discord Media Loader/App.config | 20 +- Discord Media Loader/FrmSplash.cs | 4 +- 11 files changed, 315 insertions(+), 249 deletions(-) create mode 100644 Discord Media Loader.Application/app.config diff --git a/Discord Media Loader.Application/Classes/Job.cs b/Discord Media Loader.Application/Classes/Job.cs index 78ed1c8..7132cee 100644 --- a/Discord Media Loader.Application/Classes/Job.cs +++ b/Discord Media Loader.Application/Classes/Job.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Discord; +using Discord.WebSocket; using SweetLib.Utils; using static SweetLib.Utils.Logger.Logger; @@ -47,22 +48,22 @@ namespace DML.Application.Classes jobDb.Delete(Id); } - private Server FindServerById(ulong id) + private SocketGuild FindServerById(ulong id) { Trace($"Trying to find server by Id: {id}"); - return (from s in Core.Client.Servers where s.Id == id select s).FirstOrDefault(); + return (from s in Core.Client.Guilds where s.Id == id select s).FirstOrDefault(); } - private Channel FindChannelById(Server server, ulong id) + private SocketTextChannel FindChannelById(SocketGuild server, ulong id) { Trace($"Trying to find channel in {server} by id: {id}"); return (from c in server.TextChannels where c.Id == id select c).FirstOrDefault(); } - internal async Task> Scan() + internal async Task> Scan() { Debug($"Starting scan of guild {GuildId} channel {ChannelId}..."); - var result = new List(); + var result = new List(); var limit = 100; var lastId = ulong.MaxValue; @@ -79,16 +80,16 @@ namespace DML.Application.Classes while (!finished) { Trace("Entering scanning loop..."); - Message[] messages; + SocketMessage[] messages; Trace($"Downloading next {limit} messages..."); if (isFirst) { - messages = await channel.DownloadMessages(limit, null); + messages = await channel.GetMessagesAsync(limit).ToArray() as SocketMessage[]; } else { - messages = await channel.DownloadMessages(limit, lastId); + messages = await channel.GetMessagesAsync(lastId, Direction.Before, limit).ToArray() as SocketMessage[]; } Trace($"Downloaded {messages.Length} messages."); @@ -106,15 +107,15 @@ namespace DML.Application.Classes lastId = m.Id; } - if (SweetUtils.DateTimeToUnixTimeStamp(m.Timestamp) <= StopTimestamp) + if (SweetUtils.DateTimeToUnixTimeStamp(m.CreatedAt.UtcDateTime) <= StopTimestamp) { Debug("Found a message with a known timestamp...Stopping scan."); finished = true; continue; } - Trace($"Message {m.Id} has {m.Attachments.Length} attachments."); - if (m.Attachments.Length > 0) + Trace($"Message {m.Id} has {m.Attachments.Count} attachments."); + if (m.Attachments.Count > 0) { result.Add(m); Core.Scheduler.TotalAttachments++; @@ -130,12 +131,12 @@ namespace DML.Application.Classes Trace($"Downloaded all messages for guild {GuildId} channel {ChannelId}."); Trace("Sorting messages..."); - result.Sort((a, b) => DateTime.Compare(a.Timestamp, b.Timestamp)); + result.Sort((a, b) => DateTime.Compare(a.CreatedAt.UtcDateTime, b.CreatedAt.UtcDateTime)); if (result.Count > 0) { Trace("Updating StopTimestamp for next scan..."); - StopTimestamp = SweetUtils.DateTimeToUnixTimeStamp(result[result.Count - 1].Timestamp); + StopTimestamp = SweetUtils.DateTimeToUnixTimeStamp(result[result.Count - 1].CreatedAt.UtcDateTime); } Debug($"Fisnished scan of guild {GuildId} channel {ChannelId}."); diff --git a/Discord Media Loader.Application/Classes/JobScheduler.cs b/Discord Media Loader.Application/Classes/JobScheduler.cs index f5eefcf..3340089 100644 --- a/Discord Media Loader.Application/Classes/JobScheduler.cs +++ b/Discord Media Loader.Application/Classes/JobScheduler.cs @@ -8,6 +8,8 @@ using System.Net; using System.Text; using System.Threading.Tasks; using Discord; +using Discord.Rpc; +using Discord.WebSocket; using SweetLib.Utils; using static SweetLib.Utils.Logger.Logger; @@ -21,7 +23,7 @@ namespace DML.Application.Classes private bool Run { get; set; } = false; internal List JobList { get; set; } = new List(); - internal Dictionary> RunningJobs = new Dictionary>(); + internal Dictionary> RunningJobs = new Dictionary>(); internal int RunningThreads { get; set; } = 0; internal ulong MessagesScanned @@ -96,7 +98,7 @@ namespace DML.Application.Classes { Debug("Entering job list handler loop..."); //foreach (var job in JobList) - for(var i = JobList.Count-1;i>=0;i--) + for (var i = JobList.Count - 1; i >= 0; i--) { var job = JobList[i]; Debug($"Checking job {job}"); @@ -113,7 +115,7 @@ namespace DML.Application.Classes if (!hasJob) { Debug("Job is not performed yet...Performing job..."); - var queue = new Queue(); + var queue = new Queue(); Trace("Locking scheduler..."); lock (this) @@ -126,7 +128,7 @@ namespace DML.Application.Classes Trace("Issuing job message scan..."); var messages = await job.Scan(); - if(messages==null) + if (messages == null) continue; Trace($"Adding {messages.Count} messages to queue..."); @@ -180,7 +182,7 @@ namespace DML.Application.Classes } Trace("Found job."); - Queue queue; + Queue queue; Trace("Locking scheduler..."); lock (this) { @@ -213,7 +215,7 @@ namespace DML.Application.Classes Trace("Dequeueing message..."); var message = queue.Dequeue(); - Debug($"Attachments for message {message.Id}: {message.Attachments.Length}"); + Debug($"Attachments for message {message.Id}: {message.Attachments.Count}"); foreach (var a in message.Attachments) { try @@ -224,18 +226,27 @@ namespace DML.Application.Classes var extensionRequired = !fileName.EndsWith("%name%"); + var serverName = "unknown"; + + var socketTextChannel = message.Channel as SocketTextChannel; + if (socketTextChannel != null) + { + serverName = socketTextChannel.Guild.Name.Replace(":", "").Replace("/", "") + .Replace("\\", ""); + } + fileName = - fileName.Replace("%guild%", message.Server.Name.Replace(":","").Replace("/","").Replace("\\","")) + fileName.Replace("%guild%", serverName) .Replace("%channel%", message.Channel.Name) - .Replace("%timestamp%", SweetUtils.DateTimeToUnixTimeStamp(message.Timestamp).ToString()) + .Replace("%timestamp%", SweetUtils.DateTimeToUnixTimeStamp(message.CreatedAt.UtcDateTime).ToString()) .Replace("%name%", a.Filename) - .Replace("%id%", a.Id); + .Replace("%id%", a.Id.ToString()); if (extensionRequired) fileName += Path.GetExtension(a.Filename); Trace($"Detemined file name: {fileName}."); - + if (File.Exists(fileName) && new FileInfo(fileName).Length == a.Size) { @@ -260,7 +271,7 @@ namespace DML.Application.Classes Debug($"Downloaded attachment {a.Id}."); Trace("Updating known timestamp for job..."); - job.KnownTimestamp = SweetUtils.DateTimeToUnixTimeStamp(message.Timestamp); + job.KnownTimestamp = SweetUtils.DateTimeToUnixTimeStamp(message.CreatedAt.UtcDateTime); job.Store(); } finally diff --git a/Discord Media Loader.Application/Core.cs b/Discord Media Loader.Application/Core.cs index a30ea9d..0317fa3 100644 --- a/Discord Media Loader.Application/Core.cs +++ b/Discord Media Loader.Application/Core.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using Discord; using Discord.Net; +using Discord.WebSocket; using DML.Application.Classes; using DML.Application.Dialogs; using LiteDB; @@ -20,7 +21,7 @@ namespace DML.Application { public static class Core { - internal static DiscordClient Client { get; set; } + internal static DiscordSocketClient Client { get; set; } internal static LiteDatabase Database { get; set; } internal static Settings Settings { get; set; } internal static JobScheduler Scheduler { get; } = new JobScheduler(); @@ -127,11 +128,12 @@ namespace DML.Application } Debug("Creating discord client..."); - Client = new DiscordClient(); - Client.Log.Message += (sender, message) => + + Client = new DiscordSocketClient(); + Client.Log += (arg) => { - var logMessage = $"DiscordClient: {message.Message}"; - switch (message.Severity) + var logMessage = $"DiscordClient: {arg.Message}"; + switch (arg.Severity) { case LogSeverity.Verbose: Trace(logMessage); @@ -149,40 +151,42 @@ namespace DML.Application Error(logMessage); break; } + + return Task.CompletedTask; }; Info("Trying to log into discord..."); var abort = false; - while (Client.State != ConnectionState.Connected && !abort) - { - Trace("Entering login loop."); + Client.Connected += Client_Connected; + while (Client.LoginState != LoginState.LoggedIn && !abort) + { + Debug(Client.ConnectionState.ToString()); + Debug(Client.LoginState.ToString()); + + Trace("Entering login loop."); + try { + if (Client.ConnectionState == ConnectionState.Connecting) + continue; + if (!string.IsNullOrEmpty(Settings.LoginToken)) { Debug("Trying to login with last known token..."); - await Client.Connect(Settings.LoginToken, TokenType.User); + await Client.LoginAsync(TokenType.User, Settings.LoginToken); + await Task.Delay(1000); } - if (Client.State != ConnectionState.Connected && Settings.UseUserData && - !string.IsNullOrEmpty(Settings.Email) && - !string.IsNullOrEmpty(Settings.Password)) - { - Settings.LoginToken = string.Empty; - - Debug("Trying to login with email and password..."); - await Client.Connect(Settings.Email, Settings.Password); - } } - catch (HttpException) + catch (HttpException ex) { - Warn("Login seems to have failed or gone wrong."); + Warn($"Login seems to have failed or gone wrong: {ex.GetType().Name} - {ex.Message}"); } - if (Client.State != ConnectionState.Connected) + if (Client.LoginState == LoginState.LoggedOut) { Settings.Password = string.Empty; Debug("Showing dialog for username and password..."); @@ -193,6 +197,14 @@ namespace DML.Application } Debug("Start checking for invalid jobs..."); + + //Client + + while (Client.Guilds.Count==0) + { + // wait until guilds are loaded + } + for (var i = Scheduler.JobList.Count - 1; i >= 0; i--) { var job = Scheduler.JobList[i]; @@ -235,14 +247,20 @@ namespace DML.Application } } - //TODO: this is thrid time we implement this.....this has to be fixed!!! - private static Server FindServerById(ulong id) + private static Task Client_Connected() { - Trace($"Trying to find server by Id: {id}"); - return (from s in Core.Client.Servers where s.Id == id select s).FirstOrDefault(); + Debug("Connected"); + return Task.CompletedTask; } - private static Channel FindChannelById(Server server, ulong id) + //TODO: this is thrid time we implement this.....this has to be fixed!!! + private static SocketGuild FindServerById(ulong id) + { + Trace($"Trying to find server by Id: {id}"); + return (from s in Core.Client.Guilds where s.Id == id select s).FirstOrDefault(); + } + + private static SocketTextChannel FindChannelById(SocketGuild server, ulong id) { Trace($"Trying to find channel in {server} by id: {id}"); return (from c in server.TextChannels where c.Id == id select c).FirstOrDefault(); diff --git a/Discord Media Loader.Application/DML.Application.csproj b/Discord Media Loader.Application/DML.Application.csproj index 84faa2b..1279c18 100644 --- a/Discord Media Loader.Application/DML.Application.csproj +++ b/Discord Media Loader.Application/DML.Application.csproj @@ -30,17 +30,39 @@ 4 - - ..\packages\Discord.Net.0.9.6\lib\net45\Discord.Net.dll - True + + ..\packages\Discord.Net.Commands.1.0.2\lib\netstandard1.1\Discord.Net.Commands.dll + + + ..\packages\Discord.Net.Core.1.0.2\lib\net45\Discord.Net.Core.dll + + + ..\packages\Discord.Net.Rest.1.0.2\lib\net45\Discord.Net.Rest.dll + + + ..\packages\Discord.Net.Rpc.1.0.2\lib\net45\Discord.Net.Rpc.dll + + + ..\packages\Discord.Net.Webhook.1.0.2\lib\netstandard1.1\Discord.Net.Webhook.dll + + + ..\packages\Discord.Net.WebSocket.1.0.2\lib\net45\Discord.Net.WebSocket.dll ..\packages\LiteDB.3.1.0\lib\net35\LiteDB.dll True - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll - True + + ..\packages\Microsoft.Extensions.DependencyInjection.1.1.1\lib\netstandard1.1\Microsoft.Extensions.DependencyInjection.dll + + + ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.1.1.1\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll + + + ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll ..\packages\Nito.AsyncEx.3.0.1\lib\net45\Nito.AsyncEx.dll @@ -59,15 +81,74 @@ True + + ..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll + + + ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + True + + + + ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll + + + ..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll + + + ..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll + + + ..\packages\System.Interactive.Async.3.1.1\lib\net46\System.Interactive.Async.dll + + + ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + True + + + + ..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll + + + ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll + + + ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll + + + ..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll + + + ..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + + + ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll + + + ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + - + + ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll + ..\packages\WebSocket4Net.0.14.1\lib\net45\WebSocket4Net.dll True @@ -119,6 +200,7 @@ + diff --git a/Discord Media Loader.Application/Dialogs/LoginDialog.Designer.cs b/Discord Media Loader.Application/Dialogs/LoginDialog.Designer.cs index fd09c4b..0a48921 100644 --- a/Discord Media Loader.Application/Dialogs/LoginDialog.Designer.cs +++ b/Discord Media Loader.Application/Dialogs/LoginDialog.Designer.cs @@ -30,25 +30,12 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LoginDialog)); this.pnlButtons = new System.Windows.Forms.Panel(); - this.tbcLoginMethods = new System.Windows.Forms.TabControl(); - this.tpgToken = new System.Windows.Forms.TabPage(); - this.tpgUserdata = new System.Windows.Forms.TabPage(); - this.lbToken = new System.Windows.Forms.Label(); - this.edToken = new System.Windows.Forms.TextBox(); - this.lbHowToToken = new System.Windows.Forms.Label(); - this.edEmail = new System.Windows.Forms.TextBox(); - this.edPassword = new System.Windows.Forms.TextBox(); - this.lbEmail = new System.Windows.Forms.Label(); - this.lbPassword = new System.Windows.Forms.Label(); - this.cbUseUserdata = new System.Windows.Forms.CheckBox(); - this.cbSavePassword = new System.Windows.Forms.CheckBox(); - this.lbUserdataHints = new System.Windows.Forms.Label(); - this.btnOk = new System.Windows.Forms.Button(); this.btnAbort = new System.Windows.Forms.Button(); + this.btnOk = new System.Windows.Forms.Button(); + this.lbHowToToken = new System.Windows.Forms.Label(); + this.edToken = new System.Windows.Forms.TextBox(); + this.lbToken = new System.Windows.Forms.Label(); this.pnlButtons.SuspendLayout(); - this.tbcLoginMethods.SuspendLayout(); - this.tpgToken.SuspendLayout(); - this.tpgUserdata.SuspendLayout(); this.SuspendLayout(); // // pnlButtons @@ -62,133 +49,15 @@ this.pnlButtons.Size = new System.Drawing.Size(426, 51); this.pnlButtons.TabIndex = 0; // - // tbcLoginMethods + // btnAbort // - this.tbcLoginMethods.Controls.Add(this.tpgToken); - this.tbcLoginMethods.Controls.Add(this.tpgUserdata); - this.tbcLoginMethods.Dock = System.Windows.Forms.DockStyle.Fill; - this.tbcLoginMethods.Location = new System.Drawing.Point(0, 0); - this.tbcLoginMethods.Name = "tbcLoginMethods"; - this.tbcLoginMethods.SelectedIndex = 0; - this.tbcLoginMethods.Size = new System.Drawing.Size(426, 168); - this.tbcLoginMethods.TabIndex = 1; - // - // tpgToken - // - this.tpgToken.Controls.Add(this.lbHowToToken); - this.tpgToken.Controls.Add(this.edToken); - this.tpgToken.Controls.Add(this.lbToken); - this.tpgToken.Location = new System.Drawing.Point(4, 22); - this.tpgToken.Name = "tpgToken"; - this.tpgToken.Padding = new System.Windows.Forms.Padding(3); - this.tpgToken.Size = new System.Drawing.Size(418, 142); - this.tpgToken.TabIndex = 0; - this.tpgToken.Text = "Token"; - this.tpgToken.UseVisualStyleBackColor = true; - // - // tpgUserdata - // - this.tpgUserdata.Controls.Add(this.lbUserdataHints); - this.tpgUserdata.Controls.Add(this.cbSavePassword); - this.tpgUserdata.Controls.Add(this.cbUseUserdata); - this.tpgUserdata.Controls.Add(this.lbPassword); - this.tpgUserdata.Controls.Add(this.lbEmail); - this.tpgUserdata.Controls.Add(this.edPassword); - this.tpgUserdata.Controls.Add(this.edEmail); - this.tpgUserdata.Location = new System.Drawing.Point(4, 22); - this.tpgUserdata.Name = "tpgUserdata"; - this.tpgUserdata.Padding = new System.Windows.Forms.Padding(3); - this.tpgUserdata.Size = new System.Drawing.Size(418, 142); - this.tpgUserdata.TabIndex = 1; - this.tpgUserdata.Text = "Userdata"; - this.tpgUserdata.UseVisualStyleBackColor = true; - // - // lbToken - // - this.lbToken.AutoSize = true; - this.lbToken.Location = new System.Drawing.Point(3, 9); - this.lbToken.Name = "lbToken"; - this.lbToken.Size = new System.Drawing.Size(66, 13); - this.lbToken.TabIndex = 0; - this.lbToken.Text = "Login token:"; - // - // edToken - // - this.edToken.Location = new System.Drawing.Point(75, 6); - this.edToken.Name = "edToken"; - this.edToken.Size = new System.Drawing.Size(335, 20); - this.edToken.TabIndex = 1; - // - // lbHowToToken - // - this.lbHowToToken.Location = new System.Drawing.Point(3, 52); - this.lbHowToToken.Name = "lbHowToToken"; - this.lbHowToToken.Size = new System.Drawing.Size(412, 87); - this.lbHowToToken.TabIndex = 2; - this.lbHowToToken.Text = resources.GetString("lbHowToToken.Text"); - // - // edEmail - // - this.edEmail.Location = new System.Drawing.Point(47, 6); - this.edEmail.Name = "edEmail"; - this.edEmail.Size = new System.Drawing.Size(133, 20); - this.edEmail.TabIndex = 0; - // - // edPassword - // - this.edPassword.Location = new System.Drawing.Point(279, 6); - this.edPassword.Name = "edPassword"; - this.edPassword.PasswordChar = '•'; - this.edPassword.Size = new System.Drawing.Size(133, 20); - this.edPassword.TabIndex = 1; - // - // lbEmail - // - this.lbEmail.AutoSize = true; - this.lbEmail.Location = new System.Drawing.Point(6, 9); - this.lbEmail.Name = "lbEmail"; - this.lbEmail.Size = new System.Drawing.Size(35, 13); - this.lbEmail.TabIndex = 2; - this.lbEmail.Text = "Email:"; - // - // lbPassword - // - this.lbPassword.AutoSize = true; - this.lbPassword.Location = new System.Drawing.Point(217, 9); - this.lbPassword.Name = "lbPassword"; - this.lbPassword.Size = new System.Drawing.Size(56, 13); - this.lbPassword.TabIndex = 3; - this.lbPassword.Text = "Password:"; - // - // cbUseUserdata - // - this.cbUseUserdata.AutoSize = true; - this.cbUseUserdata.Location = new System.Drawing.Point(6, 32); - this.cbUseUserdata.Name = "cbUseUserdata"; - this.cbUseUserdata.Size = new System.Drawing.Size(139, 17); - this.cbUseUserdata.TabIndex = 4; - this.cbUseUserdata.Text = "Use login with user data"; - this.cbUseUserdata.UseVisualStyleBackColor = true; - // - // cbSavePassword - // - this.cbSavePassword.AutoSize = true; - this.cbSavePassword.Location = new System.Drawing.Point(313, 32); - this.cbSavePassword.Name = "cbSavePassword"; - this.cbSavePassword.Size = new System.Drawing.Size(99, 17); - this.cbSavePassword.TabIndex = 5; - this.cbSavePassword.Text = "Save password"; - this.cbSavePassword.UseVisualStyleBackColor = true; - // - // lbUserdataHints - // - this.lbUserdataHints.Location = new System.Drawing.Point(3, 52); - this.lbUserdataHints.Name = "lbUserdataHints"; - this.lbUserdataHints.Size = new System.Drawing.Size(412, 87); - this.lbUserdataHints.TabIndex = 6; - this.lbUserdataHints.Text = "Login with email and password is not recommended. If you use two factor authentic" + - "ation this can cause a ban of your discord account.\r\n\r\nFor safety reasons we rec" + - "ommend to login with login token."; + this.btnAbort.Location = new System.Drawing.Point(348, 16); + this.btnAbort.Name = "btnAbort"; + this.btnAbort.Size = new System.Drawing.Size(75, 23); + this.btnAbort.TabIndex = 1; + this.btnAbort.Text = "&Abort"; + this.btnAbort.UseVisualStyleBackColor = true; + this.btnAbort.Click += new System.EventHandler(this.btnAbort_Click); // // btnOk // @@ -200,22 +69,38 @@ this.btnOk.UseVisualStyleBackColor = true; this.btnOk.Click += new System.EventHandler(this.btnOk_Click); // - // btnAbort + // lbHowToToken // - this.btnAbort.Location = new System.Drawing.Point(348, 16); - this.btnAbort.Name = "btnAbort"; - this.btnAbort.Size = new System.Drawing.Size(75, 23); - this.btnAbort.TabIndex = 1; - this.btnAbort.Text = "&Abort"; - this.btnAbort.UseVisualStyleBackColor = true; - this.btnAbort.Click += new System.EventHandler(this.btnAbort_Click); + this.lbHowToToken.Location = new System.Drawing.Point(7, 58); + this.lbHowToToken.Name = "lbHowToToken"; + this.lbHowToToken.Size = new System.Drawing.Size(412, 87); + this.lbHowToToken.TabIndex = 5; + this.lbHowToToken.Text = resources.GetString("lbHowToToken.Text"); + // + // edToken + // + this.edToken.Location = new System.Drawing.Point(79, 12); + this.edToken.Name = "edToken"; + this.edToken.Size = new System.Drawing.Size(335, 20); + this.edToken.TabIndex = 4; + // + // lbToken + // + this.lbToken.AutoSize = true; + this.lbToken.Location = new System.Drawing.Point(7, 15); + this.lbToken.Name = "lbToken"; + this.lbToken.Size = new System.Drawing.Size(66, 13); + this.lbToken.TabIndex = 3; + this.lbToken.Text = "Login token:"; // // LoginDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(426, 219); - this.Controls.Add(this.tbcLoginMethods); + this.Controls.Add(this.lbHowToToken); + this.Controls.Add(this.edToken); + this.Controls.Add(this.lbToken); this.Controls.Add(this.pnlButtons); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); @@ -227,32 +112,18 @@ this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.LoginDialog_FormClosing); this.Shown += new System.EventHandler(this.LoginDialog_Shown); this.pnlButtons.ResumeLayout(false); - this.tbcLoginMethods.ResumeLayout(false); - this.tpgToken.ResumeLayout(false); - this.tpgToken.PerformLayout(); - this.tpgUserdata.ResumeLayout(false); - this.tpgUserdata.PerformLayout(); this.ResumeLayout(false); + this.PerformLayout(); } #endregion private System.Windows.Forms.Panel pnlButtons; - private System.Windows.Forms.TabControl tbcLoginMethods; - private System.Windows.Forms.TabPage tpgToken; + private System.Windows.Forms.Button btnAbort; + private System.Windows.Forms.Button btnOk; private System.Windows.Forms.Label lbHowToToken; private System.Windows.Forms.TextBox edToken; private System.Windows.Forms.Label lbToken; - private System.Windows.Forms.TabPage tpgUserdata; - private System.Windows.Forms.Button btnAbort; - private System.Windows.Forms.Button btnOk; - private System.Windows.Forms.Label lbUserdataHints; - private System.Windows.Forms.CheckBox cbSavePassword; - private System.Windows.Forms.CheckBox cbUseUserdata; - private System.Windows.Forms.Label lbPassword; - private System.Windows.Forms.Label lbEmail; - private System.Windows.Forms.TextBox edPassword; - private System.Windows.Forms.TextBox edEmail; } } \ No newline at end of file diff --git a/Discord Media Loader.Application/Dialogs/LoginDialog.cs b/Discord Media Loader.Application/Dialogs/LoginDialog.cs index 6163db7..6bc566a 100644 --- a/Discord Media Loader.Application/Dialogs/LoginDialog.cs +++ b/Discord Media Loader.Application/Dialogs/LoginDialog.cs @@ -22,12 +22,6 @@ namespace DML.Application.Dialogs { Trace("Login dialog shown."); edToken.Text = Core.Settings.LoginToken; - edEmail.Text = Core.Settings.Email; - edPassword.Text = Core.Settings.Password; - cbUseUserdata.Checked = Core.Settings.UseUserData; - cbSavePassword.Checked = Core.Settings.SavePassword; - - tbcLoginMethods.SelectedTab = Core.Settings.UseUserData ? tpgUserdata : tpgToken; } private void LoginDialog_FormClosing(object sender, FormClosingEventArgs e) @@ -38,10 +32,6 @@ namespace DML.Application.Dialogs Debug("Adjusting login settings..."); Core.Settings.LoginToken = edToken.Text; - Core.Settings.Email = edEmail.Text; - Core.Settings.Password = edPassword.Text; - Core.Settings.UseUserData = cbUseUserdata.Checked; - Core.Settings.SavePassword = cbSavePassword.Checked; Core.Settings.Store(); } diff --git a/Discord Media Loader.Application/MainForm.cs b/Discord Media Loader.Application/MainForm.cs index d630aef..72adc27 100644 --- a/Discord Media Loader.Application/MainForm.cs +++ b/Discord Media Loader.Application/MainForm.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using System.Windows.Forms; using Discord; +using Discord.WebSocket; using DML.Application.Classes; using static SweetLib.Utils.Logger.Logger; @@ -46,7 +47,7 @@ namespace DML.Application if (cbGuild.Items.Count == 0) { Trace("Adding guilds to component..."); - cbGuild.Items.AddRange(Core.Client.Servers.OrderBy(g => g.Name).Select(g => g.Name).ToArray()); + cbGuild.Items.AddRange(Core.Client.Guilds.OrderBy(g => g.Name).Select(g => g.Name).ToArray()); cbGuild.SelectedIndex = 0; Trace("Guild component initialized."); } @@ -108,25 +109,25 @@ namespace DML.Application } } - private Server FindServerByName(string name) + private SocketGuild FindServerByName(string name) { Trace($"Trying to find server by name: {name}"); - return (from s in Core.Client.Servers where s.Name == name select s).FirstOrDefault(); + return (from s in Core.Client.Guilds where s.Name == name select s).FirstOrDefault(); } - private Channel FindChannelByName(Server server, string name) + private SocketTextChannel FindChannelByName(SocketGuild server, string name) { Trace($"Trying to find channel in {server} by name: {name}"); return (from c in server.TextChannels where c.Name == name select c).FirstOrDefault(); } - private Server FindServerById(ulong id) + private SocketGuild FindServerById(ulong id) { Trace($"Trying to find server by Id: {id}"); - return (from s in Core.Client.Servers where s.Id == id select s).FirstOrDefault(); + return (from s in Core.Client.Guilds where s.Id == id select s).FirstOrDefault(); } - private Channel FindChannelById(Server server, ulong id) + private SocketTextChannel FindChannelById(SocketGuild server, ulong id) { Trace($"Trying to find channel in {server} by id: {id}"); return (from c in server.TextChannels where c.Id == id select c).FirstOrDefault(); diff --git a/Discord Media Loader.Application/app.config b/Discord Media Loader.Application/app.config new file mode 100644 index 0000000..5b184e5 --- /dev/null +++ b/Discord Media Loader.Application/app.config @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Discord Media Loader.Application/packages.config b/Discord Media Loader.Application/packages.config index f45fb55..1b50a5f 100644 --- a/Discord Media Loader.Application/packages.config +++ b/Discord Media Loader.Application/packages.config @@ -1,9 +1,66 @@  - + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Discord Media Loader/App.config b/Discord Media Loader/App.config index bae5d6d..3bddcc4 100644 --- a/Discord Media Loader/App.config +++ b/Discord Media Loader/App.config @@ -1,6 +1,22 @@ - + - + + + + + + + + + + + + + + + + + diff --git a/Discord Media Loader/FrmSplash.cs b/Discord Media Loader/FrmSplash.cs index 8d0957b..33558d1 100644 --- a/Discord Media Loader/FrmSplash.cs +++ b/Discord Media Loader/FrmSplash.cs @@ -25,7 +25,7 @@ namespace Discord_Media_Loader UseWaitCursor = true; try { - var releaseVersion = await VersionHelper.GetReleaseVersion(); + /*var releaseVersion = await VersionHelper.GetReleaseVersion(); if (releaseVersion > VersionHelper.CurrentVersion) { var tmpFile = Path.GetTempFileName(); @@ -52,7 +52,7 @@ namespace Discord_Media_Loader } File.Delete(tmpFile); - } + }*/ } finally {