public static string getFileFromDiff(SongInfo si, string diff) { string fullDir = Path.GetFullPath("songs\\" + si.Dir); string tempFileName = ""; foreach (string s in Directory.GetFiles(fullDir)) { bool found = false; if (Path.GetExtension(s).Equals(".pnc")) { using (StreamReader sr = new StreamReader(s)) { string thisLine = ""; while ((thisLine = sr.ReadLine()) != null) { if (thisLine.Contains("=")) { string[] splitted = thisLine.Split('='); if (splitted[0].Equals("difficulty") && splitted[1].Equals(diff)) { tempFileName = s; found = true; break; } } } if (found) { break; } } } } return tempFileName; }
//This class was to prevent a bug with songs that occured when adding a new song for the first time - SongLibrary.Songs has new songs appended to the end of the list; however, since songInfos is a sorted dictionary it is sorted based on key, and the new song is not added to the end of the list. Song labels are added based on songInfos, while selection is based on the Song, causing a conflict public SongPair(SelectComponent t, SongInfo s) { select = t; Info = s; }
public void setSong(ref SongInfo s) { currentSong = SongLibrary.loadSong(s); music = AudioManager.loadFromFile("songs\\" + currentSong.Dir + "\\" + currentSong.FileName); music.Volume = Config.Volume / 100.0f; updateText = true; if (currentSong.FileVersion > 0) { if (currentSong.ID == -1) { NameValueCollection nvc = new NameValueCollection(); nvc.Add("c", Utils.calcHash(currentSong.Charts[0].Path)); int id = Convert.ToInt32(Utils.HttpUploadFile("http://p.ulse.net/idchart", nvc)); if (id == -1) { id = -2; } currentSong.ID = id; SongLibrary.Songs[SongLibrary.Songs.IndexOf(s)].ID = id; SongLibrary.songInfos[currentSong.Dir].ID = id; } } else { Console.WriteLine("Cannot get song id, pncv0"); } }
//This class was to prevent a bug with songs that occured when adding a new song for the first time - SongLibrary.Songs has new songs appended to the end of the list; however, since songInfos is a sorted dictionary it is sorted based on key, and the new song is not added to the end of the list. Song labels are added based on songInfos, while selection is based on the Song, causing a conflict public SongPair(SelectComponent t, SongInfo s) { select = t; Info = s; }
/* public static void cacheSongInfo1() { if (!Directory.Exists("songs")) { Directory.CreateDirectory("songs"); } DirectoryInfo directory = new DirectoryInfo("songs"); DirectoryInfo[] subDirs = directory.GetDirectories(); foreach (DirectoryInfo d in subDirs) { FileInfo[] files = d.GetFiles(); if (songInfos.ContainsKey(d.Name)) { foreach (FileInfo f in files) { if (f.Extension.Equals(".pnc")) { if(songInfos[d.Name].Diffs.ContainsKey(f.Name)) { bool different = !songInfos[d.Name].Diffs[f.Name].Equals(Utils.calcHash(f.FullName)); } } } } } }*/ public static void cacheSongInfo() { if (!Directory.Exists("songs")) { Directory.CreateDirectory("songs"); } DirectoryInfo directory = new DirectoryInfo("songs"); DirectoryInfo[] subDirs = directory.GetDirectories(); foreach (DirectoryInfo d in subDirs) { FileInfo[] files = d.GetFiles(); foreach (FileInfo f in files) { if (f.Extension.Equals(".pnc")) { string filename = f.Name.Substring(0, f.Name.Length - 4); bool changed = false; String hash = ""; if (songInfos.ContainsKey(d.Name)) { //note... probably should make check more dynamically? (when song is loaded) don't know how expensive calculating hash is hash = Utils.calcHash(f.FullName); // Console.WriteLine(f.FullName); //changed = !songInfos[d.Name].Hash.Equals(hash); } if (!songInfos.ContainsKey(d.Name) || changed) { if (changed) { //SongLibrary.Songs.Remove(songInfos[d.Name]); //songInfos.Remove(d.Name); } string artist = ""; string songName = ""; List<String> diffNames = new List<String>(); using (StreamReader sr = new StreamReader("songs\\" + d.Name + "\\" + f.Name)) { string tempS; while ((tempS = sr.ReadLine()) != null) { if (tempS.Substring(0, 1).Equals("[")) { if (!tempS.Substring(1, tempS.Length - 2).Equals("song") && !tempS.Substring(1, tempS.Length - 2).Equals("timing")) { diffNames.Add(tempS.Substring(1, tempS.Length - 2)); } } else { string[] split = tempS.Split('='); switch (split[0].ToLower(Config.cultureEnglish)) { case "artist": artist = split[1]; break; case "songname": songName = split[1]; break; case "difficulty": break; } } } } SongInfo temp = new SongInfo(d.Name, filename, artist, songName, diffNames, string.IsNullOrWhiteSpace(hash) ? Utils.calcHash(f.FullName) : hash); if (!temp.ChartMd5s.Contains(Utils.calcHash(f.FullName))) { temp.ChartMd5s.Add(Utils.calcHash(f.FullName)); } songInfos.Add(d.Name, temp); Songs.Add(temp); } else { if (changed) Console.WriteLine("ignoring " + filename); SongInfo temp = songInfos[d.Name]; if (!temp.ChartMd5s.Contains(Utils.calcHash(f.FullName))) { temp.ChartMd5s.Add(Utils.calcHash(f.FullName)); } } } } } }
public static Song loadSong(SongInfo song) { if (song.FileVersion == 0) { if (File.Exists("songs\\" + song.Dir + "\\" + song.Name + ".pnc")) { Song temp = new Song(song.Dir + "\\" + song.Name + ".pnc"); temp.ID = song.ID; return temp; } else { Game.addToast("press f1, failed to load song " + song.Name); Songs.Remove(song); songInfos.Remove(song.Name); return new Song(); } } else if (song.FileVersion == 1) { Song temp2 = new Song(song.Dir); temp2.ID = song.ID; return temp2; } return null; }