private void addPatch_Click(object sender, EventArgs e) { PatchPicker patchPicker = new PatchPicker(workingDir); if (patchPicker.ShowDialog() == DialogResult.OK) { PatchConfig c = configs[configList.SelectedIndex]; List <string> patches = c.Patches.ToList(); for (int i = 0; i < patchPicker.dependencies.Length; i++) { if (!patches.Contains(patchPicker.dependencies[i])) { patches.Add(patchPicker.dependencies[i]); } } if (!patches.Contains(patchPicker.path)) { patches.Add(patchPicker.path); } c.Patches = patches.ToArray(); configs[configList.SelectedIndex] = c; UpdateInstalledPatchesList(); SaveConfig(configs[configList.SelectedIndex]); } }
void SaveConfig(PatchConfig config) { JObject json = new JObject(); json.Add("console", JToken.FromObject(config.Console)); json.Add("dat_dump", JToken.FromObject(config.Console)); JArray patches = new JArray(); for (int i = 0; i < config.Patches.Length; i++) { JObject obj = new JObject(); obj.Add("archive", JToken.FromObject(config.Patches[i])); patches.Add(obj); } json.Add("patches", patches); using (StreamWriter writer = new StreamWriter(workingDir + "\\config\\" + config.Name + ".js")) { using (JsonTextWriter jsonWriter = new JsonTextWriter(writer)) { json.WriteTo(jsonWriter); } } }
void LoadConfigs() { configs.Clear(); if (Directory.Exists(workingDir + "\\config")) { string[] files = Directory.GetFiles(workingDir + "\\config", "*.js"); for (int i = 0; i < files.Length; i++) { if (Path.GetFileName(files[i]) == "config.js" || Path.GetFileName(files[i]) == "games.js") { continue; } PatchConfig config = new PatchConfig(); JObject json = JObject.Parse(File.ReadAllText(files[i])); config.Name = Path.GetFileNameWithoutExtension(files[i]); config.Console = json["console"].Value <bool>(); config.DatDump = json["dat_dump"].Value <bool>(); List <string> patchList = new List <string>(); JArray patches = json["patches"].Value <JArray>(); foreach (JObject o in patches.Children <JObject>()) { patchList.Add(o["archive"].Value <string>()); } config.Patches = patchList.ToArray(); configs.Add(config); } } }
private void configDump_CheckedChanged(object sender, EventArgs e) { int index = configList.SelectedIndex; PatchConfig c = configs[index]; c.DatDump = configDump.Checked; configs[index] = c; SaveConfig(configs[index]); }
private void createConfig_Click(object sender, EventArgs e) { PatchConfig c = new PatchConfig(); c.Name = "new config"; c.Console = false; c.DatDump = false; c.Patches = new string[] { }; SaveConfig(c); configs.Add(c); UpdateConfigList(); }
void UpdateInstalledPatchesList() { installedPatches.Items.Clear(); if (configList.SelectedIndex >= 0) { PatchConfig c = configs[configList.SelectedIndex]; for (int i = 0; i < c.Patches.Length; i++) { installedPatches.Items.Add(c.Patches[i]); } configConsole.Checked = c.Console; configDump.Checked = c.DatDump; } }
private void nameConfig_Click(object sender, EventArgs e) { int index = configList.SelectedIndex; PatchConfig c = configs[index]; RenameWindow rename = new RenameWindow(c.Name); if (rename.ShowDialog() == DialogResult.OK) { File.Move(workingDir + "\\config\\" + c.Name + ".js", workingDir + "\\config\\" + rename.newName + ".js"); c.Name = rename.newName; configs[index] = c; UpdateConfigList(); configList.SelectedIndex = index; } }
private void mvBot_Click(object sender, EventArgs e) { int index = installedPatches.SelectedIndex; PatchConfig c = configs[configList.SelectedIndex]; string p = c.Patches[index]; List <string> patches = c.Patches.ToList(); patches.RemoveAt(index); patches.Add(p); c.Patches = patches.ToArray(); configs[configList.SelectedIndex] = c; UpdateInstalledPatchesList(); installedPatches.SelectedIndex = installedPatches.Items.Count - 1; SaveConfig(configs[configList.SelectedIndex]); }
private void delPatch_Click(object sender, EventArgs e) { int index = installedPatches.SelectedIndex; PatchConfig c = configs[configList.SelectedIndex]; List <string> patches = c.Patches.ToList(); patches.RemoveAt(index); c.Patches = patches.ToArray(); configs[configList.SelectedIndex] = c; UpdateInstalledPatchesList(); if (index >= c.Patches.Length) { installedPatches.SelectedIndex = c.Patches.Length - 1; } SaveConfig(configs[configList.SelectedIndex]); }
private void mvUp_Click(object sender, EventArgs e) { int index = installedPatches.SelectedIndex; if (index > 0) { PatchConfig c = configs[configList.SelectedIndex]; string p = c.Patches[index]; List <string> patches = c.Patches.ToList(); patches.RemoveAt(index); patches.Insert(index - 1, p); c.Patches = patches.ToArray(); configs[configList.SelectedIndex] = c; UpdateInstalledPatchesList(); installedPatches.SelectedIndex = index - 1; SaveConfig(configs[configList.SelectedIndex]); } }