From e74ad09ed8944deaeab905d4b4a72b0da3de28d5 Mon Sep 17 00:00:00 2001 From: T0biasCZe Date: Thu, 25 Jan 2024 16:22:02 +0100 Subject: [PATCH] Fixed the issue with art manager that caused you to need to restart the app after adding pair Fixed some other small mistakes --- Discord WMP/AlbumArtAdder.Designer.cs | 2 +- Discord WMP/AlbumArtAdder.cs | 28 ++++++++++--------- Discord WMP/CurrentCommit.txt | 2 +- Discord WMP/Form1.cs | 7 +++-- Discord WMP/albummanager.cs | 39 +++++++++++---------------- 5 files changed, 36 insertions(+), 42 deletions(-) diff --git a/Discord WMP/AlbumArtAdder.Designer.cs b/Discord WMP/AlbumArtAdder.Designer.cs index 203bc68..9cfa0c2 100644 --- a/Discord WMP/AlbumArtAdder.Designer.cs +++ b/Discord WMP/AlbumArtAdder.Designer.cs @@ -255,7 +255,7 @@ private void InitializeComponent() { this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(224, 16); this.label6.TabIndex = 28; - this.label6.Text = "Finding art based on artist"; + this.label6.Text = "Finding art based on filename (inc file extension)"; // // filenameis_audiofilename // diff --git a/Discord WMP/AlbumArtAdder.cs b/Discord WMP/AlbumArtAdder.cs index 8f2f646..9781a53 100644 --- a/Discord WMP/AlbumArtAdder.cs +++ b/Discord WMP/AlbumArtAdder.cs @@ -16,7 +16,6 @@ namespace Discord_WMP { public partial class AlbumArtAdder : Form { - albummanager AlbumManager = new albummanager(); public AlbumArtAdder() { InitializeComponent(); titlecontainsword_contains_filename.SetWatermark("Filename of albumart"); @@ -55,7 +54,7 @@ private void button1_Click(object sender, EventArgs e) { bool aaa = int.TryParse(specificalbumname_priority.Text, out int bruh); if(aaa) per.priority = bruh; Thread.Sleep(66); - AlbumManager.pairList.Add(per); + albummanager.pairList.Add(per); showinlistbox(); end:; } @@ -71,7 +70,7 @@ private void button1_Click_1(object sender, EventArgs e) { bool aaa = int.TryParse(albumcontainsword_containsnot.Text, out int bruh); if(aaa) per.priority = bruh; Thread.Sleep(66); - AlbumManager.pairList.Add(per); + albummanager.pairList.Add(per); showinlistbox(); end:; } @@ -88,7 +87,7 @@ private void button2_Click(object sender, EventArgs e) { bool aaa = int.TryParse(titlecontainsword_priority.Text, out int bruh); if(aaa) per.priority = bruh; Thread.Sleep(66); - AlbumManager.pairList.Add(per); + albummanager.pairList.Add(per); showinlistbox(); end:; } @@ -104,7 +103,7 @@ private void artistname_add_Click(object sender, EventArgs e) { bool aaa = int.TryParse(artistsname_priority.Text, out int bruh); if(aaa) per.priority = bruh; Thread.Sleep(66); - AlbumManager.pairList.Add(per); + albummanager.pairList.Add(per); showinlistbox(); end:; } @@ -117,18 +116,18 @@ private void filenameis_add_Click(object sender, EventArgs e) { per.contains = filenameis_audiofilename.Text; per.doesntcontain = ""; per.priority = 0; - bool aaa = int.TryParse(artistsname_priority.Text, out int bruh); + bool aaa = int.TryParse(filenameis_priority.Text, out int bruh); if(aaa) per.priority = bruh; Thread.Sleep(66); - AlbumManager.pairList.Add(per); + albummanager.pairList.Add(per); showinlistbox(); end:; } private void AlbumArtAdder_Closing(object sender, FormClosingEventArgs e) { - AlbumManager.writecsv(); + albummanager.writecsv(); + Console.WriteLine("wrote csv"); } private void AlbumArtAdder_Load(object sender, EventArgs e) { - AlbumManager.LoadListFromCsv(); showinlistbox(); //else MessageBox.Show("didnt find albumarts.csv, will create new one"); @@ -142,7 +141,7 @@ private void showinlistbox() { listBox1.CustomTabOffsets.Add(300); listBox1.CustomTabOffsets.Add(340); listBox1.Items.Add("filename ;;; entry data \t priority \t entry type"); - foreach(pair pér in AlbumManager.pairList) { + foreach(pair pér in albummanager.pairList) { if(pér.type == 0) { listBox1.Items.Add((pér.filename + " ;;; " + pér.album).Truncate(75) + "\t" + pér.priority + "\t (album name)"); } @@ -152,7 +151,13 @@ private void showinlistbox() { else if(pér.type == pairtype.titlecontains) { listBox1.Items.Add(pér.filename + " ;;; " + pér.contains + " ;;; " + pér.doesntcontain + "\t" + pér.priority + "\t (words contained in title name)"); } - } + else if(pér.type == pairtype.artistname) { + listBox1.Items.Add(pér.filename + " ;;; " + pér.contains + " ;;; " + pér.doesntcontain + "\t" + pér.priority + "\t (artists name)"); + } + else if(pér.type == pairtype.audiofilename) { + listBox1.Items.Add(pér.filename + " ;;; " + pér.contains + " ;;; " + pér.doesntcontain + "\t" + pér.priority + "\t (audio file name)"); + } + } } private void label3_Click(object sender, EventArgs e) { @@ -178,7 +183,6 @@ private void AlbumArtAdder_FormClosed(object sender, FormClosedEventArgs e) { Form1.albummanageropen = false; Thread.Sleep(66); - AlbumManager.LoadListFromCsv(); } private void AlbumArtAdder_SizeChanged(object sender, EventArgs e) { diff --git a/Discord WMP/CurrentCommit.txt b/Discord WMP/CurrentCommit.txt index 63ea0d0..f33e285 100644 --- a/Discord WMP/CurrentCommit.txt +++ b/Discord WMP/CurrentCommit.txt @@ -1 +1 @@ -45acca4 +034830d diff --git a/Discord WMP/Form1.cs b/Discord WMP/Form1.cs index 2cec0fa..a590466 100644 --- a/Discord WMP/Form1.cs +++ b/Discord WMP/Form1.cs @@ -26,13 +26,12 @@ public partial class Form1 : Form { //public static string version = "2.0"; //public static string commit = "0c0b602"; //this value is always gonna be 1 commit behind in source code, because it is updated after commit - const string version = "v2.2.1"; + const string version = "v2.2.1b"; const string date = "25.1.24"; string versionn = $"{Discord_WMP.Properties.Resources.CurrentCommit.Trim()} {version} {date}"; public static string url = "https://github.com/T0biasCZe/Windows-Media-Player-Discord-RPC/"; - albummanager AlbumManager = new albummanager(); public RemotedWindowsMediaPlayer rm = new RemotedWindowsMediaPlayer(); //RemotedWindowsMediaPlayer rm; private bool show_author; @@ -294,7 +293,7 @@ private void update_Tick(object sender, EventArgs e) { data.album = data.title.Substring(data.title.IndexOf(" - ") + 3); } playeddata = data.title + "\n " + data.artist + "\n " + data.album + "\n " + "\n" + time + "\n" + progressbar(mil, 21); - string albumart = AlbumManager.getalbumart(data.album, data.title, data.artist, data.audiofilename); + string albumart = albummanager.getalbumart(data.album, data.title, data.artist, data.audiofilename); playeddata += "\n" + albumart; this.Refresh(); @@ -404,7 +403,7 @@ void Deinitialize() { private void Form1_Load(object sender, EventArgs e) { Console.WriteLine("veemo"); - AlbumManager.LoadListFromCsv(); + albummanager.LoadListFromCsv(); if(!show_console) { var handle = GetConsoleWindow(); // Show console during boot diff --git a/Discord WMP/albummanager.cs b/Discord WMP/albummanager.cs index 680affa..51b32b7 100644 --- a/Discord WMP/albummanager.cs +++ b/Discord WMP/albummanager.cs @@ -9,30 +9,21 @@ using System.Windows.Forms; namespace Discord_WMP { - public class albummanager { - public List pairList = new List(); + public static class albummanager { + public static List pairList = new List(); static int attempts = 0; - public void LoadListFromCsv() { - using(var reader = new StreamReader("albumsarts.csv")) - using(var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) { - csv.Read(); - csv.ReadHeader(); - pairList = csv.GetRecords().ToList(); - //try { - //pair per = pairList[0]; - //MessageBox.Show(per.album); - //} - //catch{ - //attempts++; - //if(attempts > 100) { - //MessageBox.Show("Failed to load album art list"); - //return; - //} - //else LoadListFromCsv(); - //} - } + public static void LoadListFromCsv() { + pairList.Clear(); + var reader = new StreamReader("albumsarts.csv"); + + var csv = new CsvReader(reader, CultureInfo.InvariantCulture); + csv.Read(); + csv.ReadHeader(); + pairList = csv.GetRecords().ToList(); + csv.Dispose(); + reader.Close(); } - public void writecsv() { + public static void writecsv() { using(var writer = new StreamWriter("albumsarts.csv")) using(var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) { csv.WriteHeader(); @@ -41,10 +32,10 @@ public void writecsv() { } } - public string getalbumart(string album, string title) { + public static string getalbumart(string album, string title) { return getalbumart(album, title, "", ""); } - public string getalbumart(string album, string title, string artist, string audiofilename) { + public static string getalbumart(string album, string title, string artist, string audiofilename) { for(int i = 0; i < 10; i++) { foreach(pair per in pairList) { if(per.priority == i) {