From b3230f7427a79a59abc267b74f366afa0afe3aa3 Mon Sep 17 00:00:00 2001 From: David_JonesDVN Date: Wed, 25 Mar 2020 17:05:01 +0430 Subject: [PATCH] Fixes for thcrap out of the box + dependency order. Changed: Dependencies will now appear only above the patches that depend on them. Changed: Required thcrap directories will now be created automatically if they do not exist. --- CHANGELOG.txt | 2 ++ Touhou Launcher/ConfigForm.cs | 10 +++++----- Touhou Launcher/MainForm.cs | 6 ++++-- Touhou Launcher/thcrap.cs | 12 +++++++----- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 3bff22d..be044da 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -8,6 +8,8 @@ Changed: The profile editor will now fill in missing game profiles with paths th Changed: You can now set arbitrary names for game profile IDs as long as they don't start with "th". Changed: Enlarged the custom games list. Changed: Upgraded to Visual Studio 2017 from 2012. Hopefully shouldn't change anything. +Changed: Dependencies will now appear only above the patches that depend on them. +Changed: Required thcrap directories will now be created automatically if they do not exist. Fixed: The tray icon's Main Games menu not working (no idea when that broke). Fixed: thcrap's encoding for patches not using UTF-8. Fixed: Error if patch directory does not exist. diff --git a/Touhou Launcher/ConfigForm.cs b/Touhou Launcher/ConfigForm.cs index 5019854..7a72f8c 100644 --- a/Touhou Launcher/ConfigForm.cs +++ b/Touhou Launcher/ConfigForm.cs @@ -77,9 +77,9 @@ public void Refreshcrap() } } } - foreach (string file in Directory.GetFiles(MainForm.curCfg.crapDir + "\\config", "*.js").Where(n => !n.Contains("games.js") && !n.Contains("config.js"))) + foreach (FileInfo file in new DirectoryInfo(MainForm.curCfg.crapDir).CreateSubdirectory("config").GetFiles("*.js").Where(n => n.Name != "games.js" && n.Name != "config.js")) { - crapCfg.Items.Add(Path.GetFileName(file)); + crapCfg.Items.Add(file.Name); } } if (MainForm.curCfg.crapDir != "") @@ -373,12 +373,12 @@ private void openAppdata_Click(object sender, EventArgs e) private void openReplays_Click(object sender, EventArgs e) { string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.DoNotVerify) + "\\ShanghaiAlice\\th"; - if (Directory.Exists(path + (MainForm.idToNumber[game]).ToString("00") + "\\replay")) + if (Directory.Exists(path + MainForm.idToNumber[game].ToString("00") + "\\replay")) { - Process.Start(path + (MainForm.idToNumber[game]).ToString("00") + "\\replay"); + Process.Start(path + MainForm.idToNumber[game].ToString("00") + "\\replay"); return; } - else if (Directory.Exists(path + (MainForm.idToNumber[game]).ToString("00") + "tr\\replay")) + else if (Directory.Exists(path + MainForm.idToNumber[game].ToString("00") + "tr\\replay")) { Process.Start(path + MainForm.idToNumber[game].ToString("00") + "tr\\replay"); return; diff --git a/Touhou Launcher/MainForm.cs b/Touhou Launcher/MainForm.cs index 9dc89c0..1157038 100644 --- a/Touhou Launcher/MainForm.cs +++ b/Touhou Launcher/MainForm.cs @@ -347,7 +347,8 @@ private void LoadSettings() minimizeToTray.Checked = curCfg.minimizeToTray; showTray.Checked = curCfg.showTray; np2Dir.Text = curCfg.np2Dir; - crapDir.Text = curCfg.crapDir + "\\bin\\thcrap_loader.exe"; + if (curCfg.crapDir != "") + crapDir.Text = curCfg.crapDir + "\\bin\\thcrap_loader.exe"; crapStartingRepo.Text = curCfg.StartingRepo; foreach (CheckBox chk in GetAll(randomSettings, typeof(CheckBox))) { @@ -995,7 +996,8 @@ private void Dir_LostFocus(object sender, EventArgs e) { ((TextBox)sender).BackColor = SystemColors.Window; curCfg.np2Dir = np2Dir.Text; - curCfg.crapDir = Path.GetDirectoryName(crapDir.Text).TrimEnd("\\bin".ToCharArray()); + string crapPath = Path.GetDirectoryName(crapDir.Text); + curCfg.crapDir = Directory.Exists(crapPath + "\\bin") ? crapPath : crapPath.TrimEnd("\\bin".ToCharArray()); curCfg.StartingRepo = crapStartingRepo.Text; } else diff --git a/Touhou Launcher/thcrap.cs b/Touhou Launcher/thcrap.cs index 170b841..d98d3dc 100644 --- a/Touhou Launcher/thcrap.cs +++ b/Touhou Launcher/thcrap.cs @@ -95,9 +95,9 @@ private void thcrap_Load(object sender, EventArgs e) patchStates.Add(patch["archive"].Substring(6)); } } - foreach (string localRepo in Directory.GetFiles(MainForm.curCfg.crapDir + "\\repos", "repo.js", SearchOption.AllDirectories)) + foreach (FileInfo localRepo in new DirectoryInfo(MainForm.curCfg.crapDir).CreateSubdirectory("repos").GetFiles("repo.js", SearchOption.AllDirectories)) { - addRepo(File.ReadAllText(localRepo), true); + addRepo(File.ReadAllText(localRepo.FullName), true); } searchRepo(MainForm.curCfg.StartingRepo); games = JsonConvert.DeserializeObject>(File.ReadAllText(MainForm.curCfg.crapDir + "\\config\\games.js")); @@ -211,16 +211,18 @@ private void onPatchGet(object sender, DownloadStringCompletedEventArgs e) } else repository = dependencySet[0]; - addPatch(repository, dependencySet[dependencySet.Length - 1], true); + addPatch(repository, dependencySet[dependencySet.Length - 1], (string)e.UserState + "/" + patch.id + "/"); } } } - private void addPatch(string repo, string patch, bool dependency = false) + private void addPatch(string repo, string patch, string dependent = "") { if (!patchStates.Contains(repo + "/" + patch + "/")) { - patchStates.Insert(dependency ? 0 : patchStates.Count, repo + "/" + patch + "/"); + int depIndex = patchStates.IndexOf(dependent); + depIndex = depIndex == -1 || dependent == "" ? patchStates.Count : depIndex; + patchStates.Insert(depIndex, repo + "/" + patch + "/"); repoList_SelectedIndexChanged(this, new EventArgs()); } WebClient wc = new WebClient();