From f2992f37e9d163d59667adec25cb5d8bf73eaa1f Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sun, 5 Dec 2021 20:39:46 +0100 Subject: [PATCH] Removed unused uses --- .../Classes/Job.cs | 30 +++------ .../Classes/JobScheduler.cs | 41 ++++++------ .../Helper/IdentifiedString.cs | 21 +++---- Discord Media Loader.Application/MainForm.cs | 63 ++++++++++--------- .../Properties/AssemblyInfo.cs | 3 +- Discord Media Loader/Program.cs | 12 ++-- .../Properties/AssemblyInfo.cs | 3 +- 7 files changed, 79 insertions(+), 94 deletions(-) diff --git a/Discord Media Loader.Application/Classes/Job.cs b/Discord Media Loader.Application/Classes/Job.cs index ce8aa33..149e298 100644 --- a/Discord Media Loader.Application/Classes/Job.cs +++ b/Discord Media Loader.Application/Classes/Job.cs @@ -6,7 +6,6 @@ using Discord; using Discord.WebSocket; using DML.Application.Classes; using DML.Client; -using SweetLib.Utils; using SweetLib.Utils.Extensions; using static SweetLib.Utils.Logger.Logger; @@ -18,7 +17,7 @@ namespace DML.AppCore.Classes public ulong GuildId { get; set; } public ulong ChannelId { get; set; } public double KnownTimestamp { get; set; } = 0; - private double StopTimestamp { get; set; } = 0; + private double StopTimestamp { get; set; } private bool IsValid { get; set; } = true; internal void Store() @@ -30,13 +29,9 @@ namespace DML.AppCore.Classes Trace("Adding new value..."); if (jobDb.Find(x => x.ChannelId == ChannelId && x.GuildId == GuildId).Any()) - { jobDb.Update(this); - } else - { jobDb.Insert(this); - } } public void Delete() @@ -98,27 +93,20 @@ namespace DML.AppCore.Classes var realMessages = await channel.GetMessagesAsync(limit).ToArrayAsync(); foreach (var realMessageArray in realMessages) - { - foreach (var realMessage in realMessageArray) - { - messages.Add(realMessage); - } - } + foreach (var realMessage in realMessageArray) + messages.Add(realMessage); } else { var realMessages = await channel.GetMessagesAsync(lastId, Direction.Before, limit).ToArrayAsync(); foreach (var realMessageArray in realMessages) - { - foreach (var realMessage in realMessageArray) - { - messages.Add(realMessage); - } - } + foreach (var realMessage in realMessageArray) + messages.Add(realMessage); //messages = await channel.GetMessagesAsync(lastId, Direction.Before, limit).ToArray() as SocketMessage[]; } + Trace($"Downloaded {messages.Count} messages."); isFirst = false; @@ -148,14 +136,16 @@ namespace DML.AppCore.Classes if (m.Attachments.Count > 0) { result.Add(m); - Core.Scheduler.TotalAttachments += (ulong)m.Attachments.Count; + Core.Scheduler.TotalAttachments += (ulong) m.Attachments.Count; Trace($"Added message {m.Id}"); } + Debug($"Finished message {m.Id}"); } finished = finished || messages.Count < limit; } + Trace($"Downloaded all messages for guild {GuildId} channel {ChannelId}."); Trace("Sorting messages..."); @@ -187,4 +177,4 @@ namespace DML.AppCore.Classes return jobDb.FindAll(); } } -} +} \ No newline at end of file diff --git a/Discord Media Loader.Application/Classes/JobScheduler.cs b/Discord Media Loader.Application/Classes/JobScheduler.cs index 3af4e48..9eaa19b 100644 --- a/Discord Media Loader.Application/Classes/JobScheduler.cs +++ b/Discord Media Loader.Application/Classes/JobScheduler.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using Discord; using Discord.WebSocket; using DML.Application.Classes; -using SweetLib.Utils; using SweetLib.Utils.Extensions; using SweetLib.Utils.Logger; @@ -15,14 +14,14 @@ namespace DML.AppCore.Classes { public class JobScheduler { - private ulong messageScanned = 0; - private ulong totalAttachments = 0; - private ulong attachmentsDownloaded = 0; - - private bool Run { get; set; } = false; - public List JobList { get; set; } = new List(); + private ulong attachmentsDownloaded; + private ulong messageScanned; public Dictionary> RunningJobs = new Dictionary>(); - internal int RunningThreads { get; set; } = 0; + private ulong totalAttachments; + + private bool Run { get; set; } + public List JobList { get; set; } = new List(); + internal int RunningThreads { get; set; } internal ulong MessagesScanned { @@ -91,7 +90,6 @@ namespace DML.AppCore.Classes { Logger.Info("Started JobScheduler..."); while (Run) - { try { Logger.Debug("Entering job list handler loop..."); @@ -108,6 +106,7 @@ namespace DML.AppCore.Classes Logger.Trace("Checking if job is already performed..."); hasJob = RunningJobs.ContainsKey(job.Id); } + Logger.Trace("Unlocked scheduler."); if (!hasJob) @@ -121,6 +120,7 @@ namespace DML.AppCore.Classes Logger.Trace("Adding job to running jobs."); RunningJobs.Add(job.Id, queue); } + Logger.Trace("Unlocked scheduler."); Logger.Trace("Issuing job message scan..."); @@ -130,10 +130,7 @@ namespace DML.AppCore.Classes continue; Logger.Trace($"Adding {messages.Count} messages to queue..."); - foreach (var msg in messages) - { - queue.Enqueue(msg); - } + foreach (var msg in messages) queue.Enqueue(msg); Logger.Trace($"Added {queue.Count} messages to queue."); if (messages.Count != queue.Count) @@ -155,6 +152,7 @@ namespace DML.AppCore.Classes RunningThreads++; startedDownload = true; } + Logger.Trace("Unlocked scheduler."); } @@ -167,7 +165,6 @@ namespace DML.AppCore.Classes { Logger.Error(ex.Message); } - } }); } @@ -184,6 +181,7 @@ namespace DML.AppCore.Classes Logger.Warn($"Associating job not found! JobId: {jobId}"); return; } + Logger.Trace("Found job."); Queue queue; @@ -196,8 +194,10 @@ namespace DML.AppCore.Classes Logger.Warn($"Queue for job {jobId} not found!"); return; } + Logger.Trace("Queue found."); } + Logger.Trace("Unlocked scheduler."); Logger.Debug($"Messages to process for job {jobId}: {queue.Count}"); @@ -212,8 +212,10 @@ namespace DML.AppCore.Classes Logger.Warn($"Queue for job {jobId} not found!"); return; } + Logger.Trace("Continue working..."); } + Logger.Trace("Unlocked scheduler."); Logger.Trace("Dequeueing message..."); @@ -221,7 +223,6 @@ namespace DML.AppCore.Classes Logger.Debug($"Attachments for message {message.Id}: {message.Attachments.Count}"); foreach (var a in message.Attachments) - { try { var fileName = Path.Combine(Core.Settings.OperatingFolder, Core.Settings.FileNameScheme); @@ -236,11 +237,13 @@ namespace DML.AppCore.Classes if (socketTextChannel != null) { serverName = socketTextChannel.Guild.Name; - serverName = Path.GetInvalidFileNameChars().Aggregate(serverName, (current, c) => current.Replace(c, ' ')); + serverName = Path.GetInvalidFileNameChars() + .Aggregate(serverName, (current, c) => current.Replace(c, ' ')); } var channelName = message.Channel.Name; - channelName = Path.GetInvalidFileNameChars().Aggregate(channelName, (current, c) => current.Replace(c, ' ')); + channelName = Path.GetInvalidFileNameChars() + .Aggregate(channelName, (current, c) => current.Replace(c, ' ')); fileName = fileName.Replace("%guild%", serverName) @@ -287,7 +290,6 @@ namespace DML.AppCore.Classes { AttachmentsDownloaded++; } - } } } finally @@ -300,8 +302,9 @@ namespace DML.AppCore.Classes Logger.Trace("Decreasing thread count..."); RunningThreads--; } + Logger.Trace("Unlocked scheduler."); } } } -} +} \ No newline at end of file diff --git a/Discord Media Loader.Application/Helper/IdentifiedString.cs b/Discord Media Loader.Application/Helper/IdentifiedString.cs index 828d6cf..98e671f 100644 --- a/Discord Media Loader.Application/Helper/IdentifiedString.cs +++ b/Discord Media Loader.Application/Helper/IdentifiedString.cs @@ -1,22 +1,19 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DML.Application.Helper +namespace DML.Application.Helper { internal class IdentifiedString { - internal T Id { get; set; } - internal string Caption { get; set; } - internal IdentifiedString(T id, string caption) { Id = id; Caption = caption; } - public override string ToString() => Caption; + internal T Id { get; set; } + internal string Caption { get; set; } + + public override string ToString() + { + return Caption; + } } -} +} \ No newline at end of file diff --git a/Discord Media Loader.Application/MainForm.cs b/Discord Media Loader.Application/MainForm.cs index ddf87c6..9b434fb 100644 --- a/Discord Media Loader.Application/MainForm.cs +++ b/Discord Media Loader.Application/MainForm.cs @@ -1,37 +1,37 @@ using System; -using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; -using System.Threading.Tasks; using System.Windows.Forms; using Discord; using Discord.WebSocket; using DML.AppCore.Classes; using DML.Application.Classes; using DML.Application.Helper; +using DML.Application.Properties; using DML.Client; -using static DML.Client.DMLClient; using static SweetLib.Utils.Logger.Logger; namespace DML.Application { - enum OnlineState + internal enum OnlineState { Online, Idle, DoNotDisturb, Invisible } + public partial class MainForm : Form { - private bool IsInitialized { get; set; } = false; public MainForm() { InitializeComponent(); } - private void MainForm_Shown(object sender, System.EventArgs e) + private bool IsInitialized { get; set; } + + private void MainForm_Shown(object sender, EventArgs e) { Trace("MainForm shown executed."); RefreshComponents(); @@ -61,7 +61,8 @@ namespace DML.Application { Trace("Adding guilds to component..."); - cbGuild.Items.AddRange(DMLClient.Client.Guilds.Where(g => g.Name != null).OrderBy(g => g.Name).Select(g => new IdentifiedString(g.Id, g.Name)).ToArray()); + cbGuild.Items.AddRange(DMLClient.Client.Guilds.Where(g => g.Name != null).OrderBy(g => g.Name) + .Select(g => new IdentifiedString(g.Id, g.Name)).ToArray()); cbGuild.SelectedIndex = 0; Trace("Guild component initialized."); @@ -71,15 +72,14 @@ namespace DML.Application var oldIndex = lbxJobs.SelectedIndex; lbxJobs.Items.Clear(); foreach (var job in Core.Scheduler.JobList) - { - lbxJobs.Items.Add(new IdentifiedString(job.Id, $"{FindServerById(job.GuildId)?.Name}:{FindChannelById(FindServerById(job.GuildId), job.ChannelId)?.Name}")); - } + lbxJobs.Items.Add(new IdentifiedString(job.Id, + $"{FindServerById(job.GuildId)?.Name}:{FindChannelById(FindServerById(job.GuildId), job.ChannelId)?.Name}")); lbxJobs.SelectedIndex = oldIndex; lbStatus.Text = DMLClient.Client.CurrentUser.Status.ToString(); } - private void DoSomethingChanged(object sender, System.EventArgs e) + private void DoSomethingChanged(object sender, EventArgs e) { Debug($"DoSomethingChanged excuted by {sender}."); if (!IsInitialized) @@ -98,7 +98,7 @@ namespace DML.Application Core.Settings.SkipExistingFiles = cbSkipExisting.Checked; Trace("Updating thread limit..."); - Core.Settings.ThreadLimit = (int)edThreadLimit.Value; + Core.Settings.ThreadLimit = (int) edThreadLimit.Value; Trace("Storing new settings..."); Core.Settings.Store(); @@ -106,7 +106,7 @@ namespace DML.Application Info("New settings have been saved."); } - private void btnSearchFolders_Click(object sender, System.EventArgs e) + private void btnSearchFolders_Click(object sender, EventArgs e) { Trace("Operating folder button pressed."); using (var browserDialog = new FolderBrowserDialog()) @@ -149,7 +149,7 @@ namespace DML.Application return (from c in server.TextChannels where c.Id == id select c).FirstOrDefault(); } - private void cbGuild_SelectedIndexChanged(object sender, System.EventArgs e) + private void cbGuild_SelectedIndexChanged(object sender, EventArgs e) { Trace("Guild index changed."); Debug("Updating channel dropdown component..."); @@ -157,7 +157,7 @@ namespace DML.Application UseWaitCursor = true; try { - var guild = FindServerById(((IdentifiedString)cbGuild.SelectedItem).Id); + var guild = FindServerById(((IdentifiedString) cbGuild.SelectedItem).Id); if (guild != null) { @@ -166,7 +166,8 @@ namespace DML.Application Trace("Adding new channels..."); - cbChannel.Items.AddRange(guild.TextChannels.OrderBy(c => c.Position).Select(c => new IdentifiedString(c.Id, c.Name)).ToArray()); + cbChannel.Items.AddRange(guild.TextChannels.OrderBy(c => c.Position) + .Select(c => new IdentifiedString(c.Id, c.Name)).ToArray()); Trace($"Added {cbChannel.Items.Count} channels."); @@ -185,17 +186,17 @@ namespace DML.Application Debug("Finished updating channel dropdown component."); } - private void btnAddJob_Click(object sender, System.EventArgs e) + private void btnAddJob_Click(object sender, EventArgs e) { var job = new Job { - GuildId = ((IdentifiedString)cbGuild.SelectedItem).Id, - ChannelId = ((IdentifiedString)cbChannel.SelectedItem).Id + GuildId = ((IdentifiedString) cbGuild.SelectedItem).Id, + ChannelId = ((IdentifiedString) cbChannel.SelectedItem).Id }; if (!(from j in Core.Scheduler.JobList - where j.GuildId == job.GuildId && j.ChannelId == job.ChannelId - select j).Any()) + where j.GuildId == job.GuildId && j.ChannelId == job.ChannelId + select j).Any()) { job.Store(); Core.Scheduler.JobList.Add(job); @@ -204,7 +205,7 @@ namespace DML.Application RefreshComponents(); } - private void btnDelete_Click(object sender, System.EventArgs e) + private void btnDelete_Click(object sender, EventArgs e) { Trace("Deleting job pressed."); @@ -214,7 +215,7 @@ namespace DML.Application MessageBox.Show("No job has been seleted.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } - var jobId = ((IdentifiedString)lbxJobs.SelectedItem).Id; + var jobId = ((IdentifiedString) lbxJobs.SelectedItem).Id; var job = Core.Scheduler.JobList.FirstOrDefault(j => j.Id == jobId); if (job != null) @@ -229,13 +230,13 @@ namespace DML.Application RefreshComponents(); } - private void tmrRefreshProgress_Tick(object sender, System.EventArgs e) + private void tmrRefreshProgress_Tick(object sender, EventArgs e) { var scanned = Core.Scheduler.MessagesScanned; var totalAttachments = Core.Scheduler.TotalAttachments; var done = Core.Scheduler.AttachmentsDownloaded; - var progress = totalAttachments > 0 ? (int)(100 * done / totalAttachments) : 0; + var progress = totalAttachments > 0 ? (int) (100 * done / totalAttachments) : 0; progress = Math.Min(Math.Max(0, progress), 100); pgbProgress.Maximum = 100; pgbProgress.Value = progress; @@ -243,19 +244,19 @@ namespace DML.Application lbProgress.Text = $"Scanned: {scanned} Downloaded: {done} Open: {totalAttachments - done}"; } - private void aboutToolStripMenuItem_Click(object sender, System.EventArgs e) + private void aboutToolStripMenuItem_Click(object sender, EventArgs e) { - MessageBox.Show(Properties.Resources.AboutString); + MessageBox.Show(Resources.AboutString); } - private void visitGithubToolStripMenuItem_Click(object sender, System.EventArgs e) + private void visitGithubToolStripMenuItem_Click(object sender, EventArgs e) { Process.Start("https://github.com/Serraniel/DiscordMediaLoader/"); } private async void toolStripDropDownButton1_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { - OnlineState state = (OnlineState)Convert.ToInt32(e.ClickedItem.Tag); + var state = (OnlineState) Convert.ToInt32(e.ClickedItem.Tag); lbStatus.Text = state.ToString(); tmrTriggerRefresh.Start(); @@ -292,7 +293,7 @@ namespace DML.Application private void btnFileNameHelp_Click(object sender, EventArgs e) { - MessageBox.Show(Properties.Resources.FileNameInfo); + MessageBox.Show(Resources.FileNameInfo); } } -} +} \ No newline at end of file diff --git a/Discord Media Loader.Application/Properties/AssemblyInfo.cs b/Discord Media Loader.Application/Properties/AssemblyInfo.cs index 21791d3..4126abc 100644 --- a/Discord Media Loader.Application/Properties/AssemblyInfo.cs +++ b/Discord Media Loader.Application/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // Allgemeine Informationen über eine Assembly werden über die folgenden @@ -33,4 +32,4 @@ using System.Runtime.InteropServices; // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.4.0.0")] -[assembly: AssemblyFileVersion("1.4.0.0")] +[assembly: AssemblyFileVersion("1.4.0.0")] \ No newline at end of file diff --git a/Discord Media Loader/Program.cs b/Discord Media Loader/Program.cs index 7ce9201..f0082cb 100644 --- a/Discord Media Loader/Program.cs +++ b/Discord Media Loader/Program.cs @@ -5,23 +5,19 @@ using Nito.AsyncEx; namespace Discord_Media_Loader { - static class Program + internal static class Program { [STAThread] - static void Main(string[] paramStrings) + private static void Main(string[] paramStrings) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var splashScreen = new FrmSplash(); if (splashScreen.ShowDialog() == DialogResult.OK) - { - DoLaunch(paramStrings); - } + DoLaunch(paramStrings); else - { Application.Restart(); - } } private static void DoLaunch(string[] paramStrings) @@ -29,4 +25,4 @@ namespace Discord_Media_Loader AsyncContext.Run(() => Core.Run(paramStrings)); } } -} +} \ No newline at end of file diff --git a/Discord Media Loader/Properties/AssemblyInfo.cs b/Discord Media Loader/Properties/AssemblyInfo.cs index 91f52f3..5c976a9 100644 --- a/Discord Media Loader/Properties/AssemblyInfo.cs +++ b/Discord Media Loader/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // Allgemeine Informationen über eine Assembly werden über die folgenden @@ -33,4 +32,4 @@ using System.Runtime.InteropServices; // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.3.0")] -[assembly: AssemblyFileVersion("1.0.3.0")] +[assembly: AssemblyFileVersion("1.0.3.0")] \ No newline at end of file