Skip to content

Commit

Permalink
Backend changes + thcrap compatibility
Browse files Browse the repository at this point in the history
Changed: Updated thcrap interaction to be compatible with the 2019-10-05 update. You may need to set your thcrap_loader path again.
Changed: The profile editor will now fill in missing game profiles with paths that you have already filled automatically when launching it.
Changed: You can now set arbitrary names for game profile IDs as long as they don't start with "th".
  • Loading branch information
David-JonesDVN committed Mar 10, 2020
1 parent 335154d commit e063158
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 50 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Added: Tray icon for Touhou 17.
Changed: The backwards compatibility code has been rewritten. Unfortunately this breaks compatibility with older versions. An intermediary version called pre3.5 is provided for conversion of settings.json to the new format.
Changed: The browser will no longer start on a webpage.
Changed: replays.gensokyo.org was changed to maribelhearn.com/gensokyo as the former is no longer accessible.
Changed: Updated thcrap interaction to be compatible with the 2019-10-05 update. You may need to set your thcrap_loader path again.
Changed: The profile editor will now fill in missing game profiles with paths that you have already filled automatically when launching it.
Changed: You can now set arbitrary names for game profile IDs as long as they don't start with "th".
Fixed: The tray icon's Main Games menu not working (no idea when that broke).

1.0-pre3 (13/08/2019)
Expand Down
55 changes: 17 additions & 38 deletions Touhou Launcher/ConfigForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ public void Refreshcrap()
crapGame.Items.Add("None");
if (MainForm.curCfg.crapDir != "")
{
if (File.Exists(Path.GetDirectoryName(MainForm.curCfg.crapDir) + "\\games.js"))
if (File.Exists(MainForm.curCfg.crapDir + "\\config\\games.js"))
{
crap = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(Path.GetDirectoryName(MainForm.curCfg.crapDir) + "\\games.js"));
crap = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(MainForm.curCfg.crapDir + "\\config\\games.js"));
foreach (KeyValuePair<string, string> line in crap)
{
int number = Int32.TryParse(new String(line.Key.Where(Char.IsDigit).ToArray()), out number) ? number : 0;
if (number == MainForm.idToNumber[game])
if (number == MainForm.idToNumber[game] || !line.Key.StartsWith("th"))
{
crapGame.Items.Add(line.Key);
}
}
}
foreach (string file in Directory.GetFiles(Path.GetDirectoryName(MainForm.curCfg.crapDir), "*.js").Where(n => !n.Contains("games.js") && !n.Contains("config.js")))
foreach (string file in Directory.GetFiles(MainForm.curCfg.crapDir + "\\config", "*.js").Where(n => !n.Contains("games.js") && !n.Contains("config.js")))
{
crapCfg.Items.Add(Path.GetFileName(file));
}
Expand Down Expand Up @@ -185,41 +185,20 @@ private void browse_Click(object sender, EventArgs e)
string enPath = Path.GetDirectoryName(path) + "\\th" + (MainForm.idToNumber[game]).ToString("00") + "e.exe";
string customPath = Path.GetDirectoryName(path);
customPath += MainForm.idToNumber[game] == 75 ? "\\Config.exe" : "\\custom.exe";
switch (type)
if (type != 0 && File.Exists(jpPath) && MainForm.curCfg.gameCFG[game].GameDir[0] == "")
{
case 0: if (File.Exists(enPath) && MainForm.curCfg.gameCFG[game].GameDir[1] == "")
{
enDir.Text = enPath;
MainForm.curCfg.gameCFG[game].GameDir[1] = enPath;
}
if (File.Exists(customPath) && MainForm.curCfg.gameCFG[game].GameDir[2] == "")
{
customDir.Text = customPath;
MainForm.curCfg.gameCFG[game].GameDir[2] = customPath;
}
break;
case 1: if (File.Exists(jpPath) && MainForm.curCfg.gameCFG[game].GameDir[0] == "")
{
jpDir.Text = jpPath;
MainForm.curCfg.gameCFG[game].GameDir[0] = jpPath;
}
if (File.Exists(customPath) && MainForm.curCfg.gameCFG[game].GameDir[2] == "")
{
customDir.Text = customPath;
MainForm.curCfg.gameCFG[game].GameDir[2] = customPath;
}
break;
case 2: if (File.Exists(jpPath) && MainForm.curCfg.gameCFG[game].GameDir[0] == "")
{
jpDir.Text = jpPath;
MainForm.curCfg.gameCFG[game].GameDir[0] = jpPath;
}
if (File.Exists(enPath) && MainForm.curCfg.gameCFG[game].GameDir[1] == "")
{
enDir.Text = enPath;
MainForm.curCfg.gameCFG[game].GameDir[1] = enPath;
}
break;
jpDir.Text = jpPath;
MainForm.curCfg.gameCFG[game].GameDir[0] = jpPath;
}
if (type != 1 && File.Exists(enPath) && MainForm.curCfg.gameCFG[game].GameDir[1] == "")
{
enDir.Text = enPath;
MainForm.curCfg.gameCFG[game].GameDir[1] = enPath;
}
if (type != 2 && File.Exists(customPath) && MainForm.curCfg.gameCFG[game].GameDir[2] == "")
{
customDir.Text = customPath;
MainForm.curCfg.gameCFG[game].GameDir[2] = customPath;
}
break;
}
Expand Down
12 changes: 6 additions & 6 deletions Touhou Launcher/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@ public static void launchGame(int game, int dir, bool applocale)

public static void launchcrap(int game)
{
if (!File.Exists(curCfg.crapDir))
if (!File.Exists(curCfg.crapDir + "\\bin\\thcrap_loader.exe"))
MessageBox.Show(rm.GetString("errorcrapNotFound"));
else if (curCfg.gameCFG[game].crapCFG[0] == "None" || curCfg.gameCFG[game].crapCFG[1] == "None")
MessageBox.Show(rm.GetString("errorcrapConfigNotSet"));
else
{
startProcess(curCfg.crapDir, "\"" + Path.GetDirectoryName(curCfg.crapDir) + "\\" + curCfg.gameCFG[game].crapCFG[1] + "\" " + curCfg.gameCFG[game].crapCFG[0]);
startProcess(curCfg.crapDir + "\\bin\\thcrap_loader.exe", "\"" + curCfg.crapDir + "\\config\\" + curCfg.gameCFG[game].crapCFG[1] + "\" " + curCfg.gameCFG[game].crapCFG[0]);
}
}

Expand Down Expand Up @@ -346,7 +346,7 @@ private void LoadSettings()
minimizeToTray.Checked = curCfg.minimizeToTray;
showTray.Checked = curCfg.showTray;
np2Dir.Text = curCfg.np2Dir;
crapDir.Text = curCfg.crapDir;
crapDir.Text = curCfg.crapDir + "\\bin\\thcrap_loader.exe";
crapStartingRepo.Text = curCfg.StartingRepo;
foreach (CheckBox chk in GetAll(randomSettings, typeof(CheckBox)))
{
Expand Down Expand Up @@ -984,7 +984,7 @@ private void browse_Click(object sender, EventArgs e)
txtbox.BackColor = SystemColors.Window;
txtbox.Text = file;
curCfg.np2Dir = np2Dir.Text;
curCfg.crapDir = crapDir.Text;
curCfg.crapDir = Path.GetDirectoryName(crapDir.Text).TrimEnd("\\bin".ToCharArray());
}
}

Expand All @@ -994,7 +994,7 @@ private void Dir_LostFocus(object sender, EventArgs e)
{
((TextBox)sender).BackColor = SystemColors.Window;
curCfg.np2Dir = np2Dir.Text;
curCfg.crapDir = crapDir.Text;
curCfg.crapDir = Path.GetDirectoryName(crapDir.Text).TrimEnd("\\bin".ToCharArray());
curCfg.StartingRepo = crapStartingRepo.Text;
}
else
Expand All @@ -1011,7 +1011,7 @@ private void crapConfigure_Click(object sender, EventArgs e)
{
if (curCfg.crapDir != "")
{
string procDir = Path.GetDirectoryName(curCfg.crapDir) + "\\thcrap_configure.exe";
string procDir = curCfg.crapDir + "\\bin\\thcrap_configure.exe";
if (File.Exists(procDir))
startProcess(procDir);
}
Expand Down
20 changes: 14 additions & 6 deletions Touhou Launcher/thcrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void RefreshProfiles()
public thcrap(ConfigForm cfg)
{
cfgForm = cfg;
gamejs = Path.GetDirectoryName(MainForm.curCfg.crapDir) + "\\launcher" + MainForm.idToNumber[cfg.game] + ".js";
gamejs = MainForm.curCfg.crapDir + "\\config\\launcher" + MainForm.idToNumber[cfg.game] + ".js";
InitializeComponent();
InitializeLanguage();
}
Expand All @@ -95,12 +95,20 @@ private void thcrap_Load(object sender, EventArgs e)
patchStates.Add(patch["archive"]);
}
}
foreach (string localRepo in Directory.GetFiles(Path.GetDirectoryName(MainForm.curCfg.crapDir), "repo.js", SearchOption.AllDirectories))
foreach (string localRepo in Directory.GetFiles(MainForm.curCfg.crapDir + "\\repos", "repo.js", SearchOption.AllDirectories))
{
addRepo(File.ReadAllText(localRepo), true);
}
searchRepo(MainForm.curCfg.StartingRepo);
games = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(Path.GetDirectoryName(MainForm.curCfg.crapDir) + "\\games.js"));
games = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(MainForm.curCfg.crapDir + "\\config\\games.js"));
for (int i = 0; i < 3; i += 2)
{
if (MainForm.curCfg.gameCFG[cfgForm.game].GameDir[i] != "" && !games.ContainsValue(MainForm.curCfg.gameCFG[cfgForm.game].GameDir[i].Replace("\\", "/")))
{
string augment = i == 2 ? "_custom" : "";
games.Add("th" + (MainForm.idToNumber[cfgForm.game]).ToString("00") + augment, MainForm.curCfg.gameCFG[cfgForm.game].GameDir[i].Replace("\\", "/"));
}
}
RefreshProfiles();
}

Expand All @@ -113,7 +121,7 @@ private void searchRepo(string address, bool child = false)

private void onJsonGet(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
if (e.Error == null && !e.Cancelled)
{
string json = e.Result;
string[] args = (string[])e.UserState;
Expand Down Expand Up @@ -180,7 +188,7 @@ private void onPatchGet(object sender, DownloadStringCompletedEventArgs e)
if (e.Error == null)
{
patchData patch = JsonConvert.DeserializeObject<patchData>(e.Result);
string jsPath = Path.GetDirectoryName(MainForm.curCfg.crapDir) + "\\" + (string)e.UserState + "\\" + patch.id + "\\patch.js";
string jsPath = MainForm.curCfg.crapDir + "\\repos\\" + (string)e.UserState + "\\" + patch.id + "\\patch.js";
if (!File.Exists(jsPath))
File.WriteAllText(jsPath, e.Result);
foreach (string dependency in patch.dependencies)
Expand Down Expand Up @@ -229,7 +237,7 @@ private void thcrap_Closing(object sender, FormClosingEventArgs e)
{
games[game.Text] = game.SubItems[1].Text;
}
File.WriteAllText(Path.GetDirectoryName(MainForm.curCfg.crapDir) + "\\games.js", JsonConvert.SerializeObject(games, Formatting.Indented));
File.WriteAllText(MainForm.curCfg.crapDir + "\\config\\games.js", JsonConvert.SerializeObject(games, Formatting.Indented));
cfgForm.Refreshcrap();
}

Expand Down

0 comments on commit e063158

Please sign in to comment.