mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-19 16:20:01 -04:00
Triforce v0.3.7
Setup's Convert saves page finds NX2navi saves by itself. Nothing else changed since v0.3.6's main.
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
// Saves of this game (Ocarina of Time, 0400486024DEC000), wherever they are: Triforce keeps them in <game>\user\save\<uid>, emulators
|
||||
// in their NAND (Eden, yuzu, suyu, sudachi, citron, torzu, EvilOOT: nand\user\save\0000000000000000\<user>\0400486024DEC000) or
|
||||
// Ryujinx's bis\user\save\<index>\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\<index>\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
|
||||
/// <game>\profile\save\<account> (32 hex digits) and commits through <game>\profile\save-tx: a finished commit there
|
||||
/// (ready-<n>, 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 (<launcher>\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<string, object>;
|
||||
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, <drive>:\Games\NX2navi, and beside a shortcut's program)
|
||||
public static List<SaveSet> FindEmulatorSaves()
|
||||
{
|
||||
var found = new List<SaveSet>();
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user