Skip to content

Commit

Permalink
Fixed the issue with art manager that caused you to need to restart t…
Browse files Browse the repository at this point in the history
…he app after adding pair

Fixed some other small mistakes
  • Loading branch information
T0biasCZe committed Jan 25, 2024
1 parent 034830d commit e74ad09
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Discord WMP/AlbumArtAdder.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 16 additions & 12 deletions Discord WMP/AlbumArtAdder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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:;
}
Expand All @@ -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:;
}
Expand All @@ -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:;
}
Expand All @@ -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:;
}
Expand All @@ -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");
Expand All @@ -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)");
}
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Discord WMP/CurrentCommit.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45acca4
034830d
7 changes: 3 additions & 4 deletions Discord WMP/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down
39 changes: 15 additions & 24 deletions Discord WMP/albummanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,21 @@
using System.Windows.Forms;

namespace Discord_WMP {
public class albummanager {
public List<pair> pairList = new List<pair>();
public static class albummanager {
public static List<pair> pairList = new List<pair>();
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<pair>().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<pair>().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<pair>();
Expand All @@ -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) {
Expand Down

0 comments on commit e74ad09

Please sign in to comment.