public InfoEntity ModifyInfoNum(int counter, double pp, InfoEntity info) { string counterString = ""; if (counter < 10) { counterString = "0000" + counter.ToString(); } else if (counter > 9 && counter < 100) { counterString = "000" + counter.ToString(); } else if (counter > 99 && counter < 1000) { counterString = "00" + counter.ToString(); } else if (counter > 999 && counter < 10000) { counterString = "0" + counter.ToString(); } else { counterString = counter.ToString(); } info.songName = counterString + ". " + " - " + pp.ToString() + " - " + info.songName; return(info); }
public InfoEntity ReturnInfos(string json) { var json2 = System.IO.File.ReadAllText(json); InfoEntity info = JsonConvert.DeserializeObject <InfoEntity>(json2); return(info); }
private void WriteInfos(InfoEntity info, string path) { var newJson = JsonConvert.SerializeObject(info, Newtonsoft.Json.Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); System.IO.File.WriteAllText(path + "\\info.json", newJson); }
public void DownloadSongs(List <DuoVRSong> downloadLinks) { int i2 = 1; for (int i = downloadLinks.Count() - 1; i >= 0; i--) { if (textBox3.Text != "") { if (i2 > int.Parse(textBox3.Text)) { break; } } if (textBox4.Text != "") { if (downloadLinks[i].Difficulty < double.Parse(textBox4.Text)) { continue; } } if (textBox5.Text != "") { if (downloadLinks[i].PP < double.Parse(textBox5.Text)) { continue; } } using (WebClient wc = new WebClient()) { label9.Text = "Downloading " + downloadLinks[i].Name; wc.DownloadProgressChanged += wc_DownloadProgressChanged; wc.DownloadFile( // Param1 = Link of file new Uri(downloadLinks[i].URL), // Param2 = Path to save textBox1.Text + downloadLinks[i].ID + ".zip" ); try { System.IO.Compression.ZipFile.ExtractToDirectory(textBox1.Text + downloadLinks[i].ID + ".zip", textBox2.Text); } catch { continue; } DateTime lastHigh = new DateTime(1900, 1, 1); string highDir = ""; foreach (string subdir in Directory.GetDirectories(textBox2.Text)) { DirectoryInfo fi1 = new DirectoryInfo(subdir); DateTime created = fi1.LastWriteTime; if (created > lastHigh) { highDir = subdir; lastHigh = created; } } string[] files = Directory.GetFiles(highDir); string infos = GetInfo(files); InfoEntity info = ReturnInfos(infos); info = ModifyInfoNum(i2, downloadLinks[i].PP, info); WriteInfos(info, highDir); i2++; } } MessageBox.Show("Download Complete!"); }