private void RefreshPropertiesView() { if (listBox1.SelectedItem != null) { selectedModPack = (ModPack)listBox1.SelectedItem; } ; if (selectedModPack != null) { propertiesLocalPathTextBox.Text = selectedModPack.LocalPath; dataGridView1.Rows.Clear(); List <string> knownFiles = new List <string>(); foreach (Mod mod in selectedModPack.Mods) { List <string> texts = new List <string>(); texts.Add(mod.ModName); texts.Add(mod.ModFileName); if (File.Exists(Path.Combine(selectedModPack.LocalPath, mod.ModFileName))) { texts.Add("downloaded"); knownFiles.Add(mod.ModFileName); } else { texts.Add("not downloaded"); }; dataGridView1.Rows.Add(texts.ToArray()); } if (selectedModPack.LocalPath != "ignored") { foreach (string file in Directory.GetFiles(selectedModPack.LocalPath)) { if (!knownFiles.Contains(Path.GetFileName(file))) { List <string> texts = new List <string>(); texts.Add("unknown"); texts.Add(Path.GetFileName(file)); texts.Add("added locally"); dataGridView1.Rows.Add(texts.ToArray()); } } } } }
void DownloadSource() { WebClient client = new WebClient(); if (Properties.Settings.Default.ModsSourceURL == "") { MessageBox.Show("ModsSourceURL isn't set. Set that before proceeding.", "ModsSourceURL not set", MessageBoxButtons.OK, MessageBoxIcon.Warning); ShowModListEditForm(); } else { string path = Properties.Settings.Default.ModsSourceURL; if (IsLocalPath(path)) { if (File.Exists(path)) { File.Copy(path, ".modslist.txt"); } else { MessageBox.Show($"Cannot find file called {path}"); } } else { client.DownloadFile(path, ".modslist.txt"); WriteToConsole("Downloaded file (.modslist.txt)"); } string[] lines = File.ReadAllLines(".modslist.txt"); string fName = "./modpackLocalPaths.txt"; if (!File.Exists(fName)) { File.WriteAllText(fName, ""); MessageBox.Show("Modpack local paths aren't set.\r\nThey need to be set in order to synchronize the mods"); } string[] modPackLocalPathsLines = File.ReadAllLines(fName); for (int i = 0; i < lines.Length; i++) { Char[] charArray = lines[i].ToCharArray(); if (charArray[0].ToString() == "[") { // is a header ModPack newModPack = new ModPack(); newModPack.Name = lines[i].Replace("[", "").Replace("]", ""); newModPack.Mods = new List <Mod>(); newModPack.LocalPath = "ignored"; bool success = false; foreach (string localNameLine in modPackLocalPathsLines) { string[] splitString = localNameLine.Split("="); if (splitString[0] == newModPack.Name) { newModPack.LocalPath = splitString[1]; success = true; break; } } if (!success) { MessageBox.Show($"Failed to find local path for {newModPack.Name}"); } WriteToConsole($"Found modpack: {newModPack.Name}"); Mod newMod = new Mod(); while (true) { i++; if (lines[i].ToCharArray()[0].ToString() == "{") { newMod = new Mod(); } else if (lines[i].ToCharArray()[0].ToString() == "}") { newModPack.Mods.Add(newMod); } else if (lines[i].Contains("endmodpack")) { ModPacks.Add(newModPack); RefreshListBox(); WriteToConsole($"{newModPack.Name} has {newModPack.Mods.Count} mods"); break; } else { string[] splitLine = lines[i].Split("="); if (splitLine[0] == "modname") { newMod.ModName = splitLine[1]; } else if (splitLine[0] == "modurl") { newMod.ModURL = splitLine[1]; } else if (splitLine[0] == "modfilename") { newMod.ModFileName = splitLine[1]; } } } } } } }