diff --git a/setup/Main.xaml b/setup/Main.xaml
index f2bac68..8edc698 100644
--- a/setup/Main.xaml
+++ b/setup/Main.xaml
@@ -650,7 +650,7 @@
+ Text="Bring your saves from NX2navi or an emulator into Triforce, or take Triforce's back out. Whatever gets replaced is backed up first."/>
diff --git a/setup/Saves.cs b/setup/Saves.cs
index 936cc41..24d6fe2 100644
--- a/setup/Saves.cs
+++ b/setup/Saves.cs
@@ -1,12 +1,13 @@
// Saves of this game (Ocarina of Time, 0400486024DEC000), wherever they are: Triforce keeps them in \user\save\, emulators
// in their NAND (Eden, yuzu, suyu, sudachi, citron, torzu, EvilOOT: nand\user\save\0000000000000000\\0400486024DEC000) or
-// Ryujinx's bis\user\save\\0. The files are the same everywhere (account.sav, option.sav, slot_00..05\caption.sav +
-// progress.sav), so converting is a copy, with what gets replaced backed up first.
+// Ryujinx's bis\user\save\\0, NX2navi in its game folder's profile (NaviSave). The files are the same everywhere
+// (account.sav, option.sav, slot_00..05\caption.sav + progress.sav), so converting is a copy, with what gets replaced backed up first.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
+using System.Text.RegularExpressions;
namespace TriforceSetup;
@@ -45,8 +46,56 @@ static class Saves
return s;
}
+ /// The save an NX2navi game would load, given its game folder or that folder's profile folder. NX2navi keeps the save in
+ /// \profile\save\ (32 hex digits) and commits through \profile\save-tx: a finished commit there
+ /// (ready-, the highest n) is newer than the account folder until the game's next start swaps it in. Null when the folder is
+ /// no NX2navi game or holds no save
+ public static string? NaviSave(string dir)
+ {
+ try
+ {
+ foreach (var profile in new[] { Path.Combine(dir, "profile"), dir })
+ {
+ var saves = Path.Combine(profile, "save");
+ if (!Directory.Exists(saves)) continue;
+ var tx = Path.Combine(profile, "save-tx");
+ if (Directory.Exists(tx))
+ {
+ // (the game names them with ten digits, ready-0000000001: its runtime/fs_host.c "ready-%010u", an unsigned 32-bit n)
+ var ready = Directory.GetDirectories(tx, "ready-*")
+ .Select(d => (Dir: d, M: Regex.Match(Path.GetFileName(d), @"^ready-(\d{1,10})$")))
+ .Where(r => r.M.Success && IsSaveSet(r.Dir))
+ .OrderByDescending(r => long.Parse(r.M.Groups[1].Value)).FirstOrDefault();
+ if (ready.Dir != null) return ready.Dir;
+ }
+ var account = Directory.GetDirectories(saves)
+ .Where(d => Regex.IsMatch(Path.GetFileName(d), "^[0-9a-fA-F]{32}$") && IsSaveSet(d))
+ .OrderByDescending(d => Describe("", d).Last).FirstOrDefault();
+ if (account != null) return account;
+ }
+ }
+ catch (Exception) { }
+ return null;
+ }
+
+ /// The game folder NX2navi's launcher built into, from its settings (\data\launcher.json, "game_dir"); null when
+ /// the launcher is not there or never built a game
+ static string? NaviGameDir(string launcher)
+ {
+ try
+ {
+ var file = Path.Combine(launcher, "data", "launcher.json");
+ if (!File.Exists(file)) return null;
+ var json = File.ReadAllText(file).TrimStart('\uFEFF');
+ var parsed = new System.Web.Script.Serialization.JavaScriptSerializer().DeserializeObject(json) as Dictionary;
+ return parsed != null && parsed.TryGetValue("game_dir", out var g) && g is string { Length: > 0 } game ? game : null;
+ }
+ catch (Exception) { return null; }
+ }
+
/// Every save of this game found on the PC: the emulators' usual folders, the folders of programs the desktop and Start menu start
- /// (portable emulators keep a "user" folder beside them), and Ryujinx's numbered saves that hold this game's files
+ /// (portable emulators keep a "user" folder beside them), Ryujinx's numbered saves that hold this game's files, and NX2navi's
+ /// games (its launcher's own game folder and the one its settings name, :\Games\NX2navi, and beside a shortcut's program)
public static List FindEmulatorSaves()
{
var found = new List();
@@ -73,7 +122,24 @@ static class Saves
if (!Directory.Exists(saves)) return;
foreach (var s in SafeDirs(saves)) Add(name, Path.Combine(s, "0"));
}
+ void Navi(string game) // (an NX2navi game folder)
+ {
+ if (NaviSave(game) is { } save) Add("NX2navi", save);
+ }
+ void NaviLauncher(string launcher) // (the folder of NX2navi's launcher: its own game folder, and the one it was told to use)
+ {
+ Navi(Path.Combine(launcher, "game"));
+ if (NaviGameDir(launcher) is { } game) Navi(game);
+ }
var appData = Install.TestRoot != null ? Path.Combine(Install.TestRoot, "Roaming") : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
+ var local = Install.TestRoot != null ? Path.Combine(Install.TestRoot, "Local") : Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
+ NaviLauncher(Path.Combine(local, "Programs", "NX2navi"));
+ if (Install.TestRoot == null)
+ foreach (var drive in DriveInfo.GetDrives())
+ {
+ try { if (drive.DriveType == DriveType.Fixed && drive.IsReady) Navi(Path.Combine(drive.RootDirectory.FullName, "Games", "NX2navi")); }
+ catch (Exception) { }
+ }
foreach (var e in Emulators)
{
var root = Path.Combine(appData, e);
@@ -87,6 +153,8 @@ static class Saves
var name = Path.GetFileNameWithoutExtension(exe) + " (" + dir + ")";
Nand(name, Path.Combine(dir, "user"));
Ryujinx(name, Path.Combine(dir, "portable"));
+ Navi(dir); // (a shortcut to the game itself)
+ NaviLauncher(dir); // (a shortcut to NX2navi's launcher)
}
return found.OrderByDescending(s => s.Last).ToList();
}
@@ -143,6 +211,9 @@ static class Saves
public static string? FindIn(string dir)
{
if (IsSaveSet(dir)) return dir;
+ // (an NX2navi game folder or its profile: the save the game would load, which a search by depth would not pick when a
+ // finished commit waits beside the account folder)
+ if (NaviSave(dir) is { } navi) return navi;
var queue = new Queue<(string, int)>();
queue.Enqueue((dir, 0));
var looked = 0;
@@ -161,9 +232,10 @@ static class Saves
/// A game or emulator that has these saves open: it would write over the copy when it closes
public static string? RunningGame()
{
- foreach (var n in new[] { "Triforce", "hookshot", "EvilOOT", "eden", "yuzu", "suyu", "sudachi", "citron", "torzu", "Ryujinx" })
+ // ("ocarina" is the program NX2navi builds)
+ foreach (var n in new[] { "Triforce", "hookshot", "EvilOOT", "eden", "yuzu", "suyu", "sudachi", "citron", "torzu", "Ryujinx", "ocarina" })
foreach (var p in Process.GetProcessesByName(n))
- if (Install.TestRoot == null || InTestRoot(p)) return n;
+ if (Install.TestRoot == null || InTestRoot(p)) return n == "ocarina" ? "NX2navi" : n;
return null;
}
diff --git a/setup/Setup.cs b/setup/Setup.cs
index b2d72f2..dbcdf76 100644
--- a/setup/Setup.cs
+++ b/setup/Setup.cs
@@ -80,6 +80,22 @@ static class Program
Log("convert-saves " + args[cv + 1] + " -> " + args[cv + 2] + ", backup " + (b ?? "none"));
return 0;
}
+ // (testing: --find-saves writes every save of the game the Convert saves page would list to setup.log; --find-saves
+ // the save Choose a folder would take from that folder)
+ var fs = Array.IndexOf(args, "--find-saves");
+ if (fs >= 0)
+ {
+ if (fs + 1 < args.Length && !args[fs + 1].StartsWith("--"))
+ {
+ var set = Saves.FindIn(args[fs + 1]);
+ Log("find-saves " + args[fs + 1] + ": " + (set ?? "none"));
+ return set != null ? 0 : 1;
+ }
+ var sets = Saves.FindEmulatorSaves();
+ foreach (var set in sets) Log("find-saves: " + set.Name + ", " + set.Slots + " slot(s), " + set.Folder);
+ Log("find-saves: " + sets.Count + " found");
+ return 0;
+ }
// (testing: --check-game <.nup | exefs folder> writes the version check's answer to setup.log)
var cg = Array.IndexOf(args, "--check-game");
if (cg >= 0 && cg + 1 < args.Length)
diff --git a/setup/Shell.Saves.cs b/setup/Shell.Saves.cs
index 4c8e872..951aab5 100644
--- a/setup/Shell.Saves.cs
+++ b/setup/Shell.Saves.cs
@@ -1,4 +1,4 @@
-// The Convert saves page: an emulator's saves into Triforce, or Triforce's out to an emulator (Saves.cs).
+// The Convert saves page: an emulator's or NX2navi's saves into Triforce, or Triforce's out to one of them (Saves.cs).
using System;
using System.Collections.Generic;
using System.IO;
@@ -145,7 +145,7 @@ sealed partial class Shell
}
if (pick == null)
{
- SavesInfo.Text = (found.Count == 0 ? "No emulator saves of this game were found. " : "") +
+ SavesInfo.Text = (found.Count == 0 ? "No saves of this game from an emulator or NX2navi were found. " : "") +
(into ? "Use Choose a folder to point at the saves (the folder with option.sav and slot_00 to slot_05)."
: "Use Choose a folder to point at the emulator's save folder for this game (0400486024DEC000).");
return;