From a5fafed4a4ebe29ac9e24dee69ffdbf970394d17 Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 7 Oct 2016 20:38:38 +0300 Subject: [PATCH] [SADXModManager] Added Submods, fixes #13 Also made modDir a field. --- SADXModManager/MainForm.cs | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/SADXModManager/MainForm.cs b/SADXModManager/MainForm.cs index 8a8cac73..5ca85a92 100644 --- a/SADXModManager/MainForm.cs +++ b/SADXModManager/MainForm.cs @@ -30,10 +30,12 @@ public MainForm() List codes; bool installed; bool suppressEvent; + string modDir; - private void MainForm_Load(object sender, EventArgs e) + private void MainForm_Load(object sender, EventArgs e) { - if (File.Exists("sadxmlver.txt")) + modDir = Path.Combine(Environment.CurrentDirectory, "mods"); + if (File.Exists("sadxmlver.txt")) { System.Net.WebClient wc = new System.Net.WebClient(); string msg = null; @@ -117,14 +119,34 @@ private void MainForm_Load(object sender, EventArgs e) } } + private void RecursivelyAddMod(Dictionary mods, string filename) + { + string path = Path.GetDirectoryName(filename).Substring(modDir.Length + 1); + var ini = IniFile.Load(filename); + mods.Add(path,IniFile.Deserialize(ini)); + if (ini.ContainsKey("Submods")) + { + foreach (var kv in ini["Submods"]) + { + var dirInfo = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(filename), kv.Value)); + if (!dirInfo.Exists) + { + MessageBox.Show("Submod " + kv.Value + " doesn't exist in mod " + path); + continue; + } + foreach (string filename2 in GetModFiles(new DirectoryInfo[] { dirInfo })) + RecursivelyAddMod(mods, filename2); + } + } + } + private void LoadModList() { modListView.Items.Clear(); mods = new Dictionary(); codes = new List(mainCodes.Codes); - string modDir = Path.Combine(Environment.CurrentDirectory, "mods"); - foreach (string filename in GetModFiles(new DirectoryInfo(modDir).GetDirectories())) - mods.Add(Path.GetDirectoryName(filename).Substring(modDir.Length + 1), IniFile.Deserialize(filename)); + foreach (string filename in GetModFiles(new DirectoryInfo(modDir).GetDirectories())) + RecursivelyAddMod(mods, filename); modListView.BeginUpdate(); foreach (string mod in new List(loaderini.Mods)) { @@ -511,7 +533,6 @@ private void modListView_ItemCheck(object sender, ItemCheckEventArgs e) { if (suppressEvent) return; codes = new List(mainCodes.Codes); - string modDir = Path.Combine(Environment.CurrentDirectory, "mods"); List modlist = new List(); foreach (ListViewItem item in modListView.CheckedItems) modlist.Add((string)item.Tag); @@ -524,7 +545,7 @@ private void modListView_ItemCheck(object sender, ItemCheckEventArgs e) { ModInfo inf = mods[mod]; if (!string.IsNullOrEmpty(inf.Codes)) - codes.AddRange(CodeList.Load(Path.Combine(Path.Combine(modDir, mod), inf.Codes)).Codes); + codes.AddRange(CodeList.Load(Path.Combine(modDir, mod, inf.Codes)).Codes); } loaderini.EnabledCodes = new List(loaderini.EnabledCodes.Where(a => codes.Any(c => c.Name == a))); foreach (Code item in codes.Where(a => a.Required && !loaderini.EnabledCodes.Contains(a.Name)))