[host] wired the sdl session, save-data paths and project references

This commit is contained in:
ParantezTech
2026-07-28 01:05:55 +03:00
parent 12432f8fa2
commit c32ba52ca6
14 changed files with 542 additions and 153 deletions
@@ -0,0 +1,96 @@
// Copyright (C) 2026 SharpEmu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
using SharpEmu.Libs.Kernel;
using Xunit;
namespace SharpEmu.Libs.Tests.Kernel;
[Collection(KernelMemoryCompatStateCollection.Name)]
public sealed class KernelGameLogPathTests : IDisposable
{
private readonly string? _previousHostappRoot =
Environment.GetEnvironmentVariable("SHARPEMU_HOSTAPP_DIR");
private readonly string? _previousDevlogRoot =
Environment.GetEnvironmentVariable("SHARPEMU_DEVLOG_APP_DIR");
public KernelGameLogPathTests()
{
Environment.SetEnvironmentVariable("SHARPEMU_HOSTAPP_DIR", null);
Environment.SetEnvironmentVariable("SHARPEMU_DEVLOG_APP_DIR", null);
KernelMemoryCompatExports.ConfigureApplicationInfo("ppsa/01:342");
}
public void Dispose()
{
Environment.SetEnvironmentVariable("SHARPEMU_HOSTAPP_DIR", _previousHostappRoot);
Environment.SetEnvironmentVariable("SHARPEMU_DEVLOG_APP_DIR", _previousDevlogRoot);
KernelMemoryCompatExports.ConfigureApplicationInfo(null);
var testRoot = Path.Combine(
AppContext.BaseDirectory,
"user",
"game_logs",
"PPSA_01_342");
if (Directory.Exists(testRoot))
{
Directory.Delete(testRoot, recursive: true);
}
}
[Fact]
public void HostappUsesPerTitleGameLogDirectory()
{
var path = KernelMemoryCompatExports.ResolveGuestPath("/hostapp/logs/game.log");
Assert.Equal(
Path.GetFullPath(Path.Combine(
AppContext.BaseDirectory,
"user",
"game_logs",
"PPSA_01_342",
"hostapp",
"logs",
"game.log")),
path);
}
[Fact]
public void DevlogUsesPerTitleGameLogDirectory()
{
var path = KernelMemoryCompatExports.ResolveGuestPath("/devlog/app/debug.log");
Assert.Equal(
Path.GetFullPath(Path.Combine(
AppContext.BaseDirectory,
"user",
"game_logs",
"PPSA_01_342",
"devlog",
"app",
"debug.log")),
path);
}
[Fact]
public void ExplicitHostappOverrideIsPreserved()
{
var root = Path.Combine(Path.GetTempPath(), "SharpEmuTests", Guid.NewGuid().ToString("N"));
try
{
Environment.SetEnvironmentVariable("SHARPEMU_HOSTAPP_DIR", root);
Assert.Equal(
Path.Combine(Path.GetFullPath(root), "logs", "game.log"),
KernelMemoryCompatExports.ResolveGuestPath("/hostapp/logs/game.log"));
}
finally
{
Environment.SetEnvironmentVariable("SHARPEMU_HOSTAPP_DIR", null);
if (Directory.Exists(root))
{
Directory.Delete(root, recursive: true);
}
}
}
}
@@ -8,19 +8,20 @@ using Xunit;
namespace SharpEmu.Libs.Tests;
/// <summary>
/// Save data lives under ~/SharpEmu/Saves/&lt;titleId&gt;/&lt;dirName&gt;/ with UI
/// Save data lives under user/savedata/&lt;titleId&gt;/&lt;dirName&gt;/ with UI
/// metadata in &lt;slot&gt;/sce_sys/param.json. These guard the pure path and
/// metadata logic that the SaveData HLE exports build on.
/// </summary>
public sealed class SaveDataStorageTests
{
[Fact]
public void RootHonorsOverrideAndFallsBackToUserProfile()
public void RootHonorsOverrideAndFallsBackToPortableDirectory()
{
Assert.Equal(Path.GetFullPath("/tmp/custom-saves"), SaveDataStorage.Root("/tmp/custom-saves"));
var home = System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile);
Assert.Equal(Path.Combine(home, "SharpEmu", "Saves"), SaveDataStorage.Root());
Assert.Equal(
Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "user", "savedata")),
SaveDataStorage.Root());
}
[Fact]
@@ -112,4 +113,36 @@ public sealed class SaveDataStorageTests
}
}
}
[Fact]
public void LegacyMigrationKeepsTheNewestSaveAndFlattensNumericUsers()
{
var testRoot = Path.Combine(Path.GetTempPath(), "sharpemu-savemigrate-" + Path.GetRandomFileName());
var destination = Path.Combine(testRoot, "portable");
var profile = Path.Combine(testRoot, "profile");
try
{
var stale = Path.Combine(destination, "268435456", "PPSA02929", "SAVEDATA00", "save.dat");
Directory.CreateDirectory(Path.GetDirectoryName(stale)!);
File.WriteAllText(stale, "stale");
File.SetLastWriteTimeUtc(stale, DateTime.UtcNow.AddMinutes(-2));
var current = Path.Combine(profile, "PPSA02929", "SAVEDATA00", "save.dat");
Directory.CreateDirectory(Path.GetDirectoryName(current)!);
File.WriteAllText(current, "current");
SaveDataStorage.MigrateLegacyLayout(destination, profile);
Assert.Equal(
"current",
File.ReadAllText(Path.Combine(destination, "PPSA02929", "SAVEDATA00", "save.dat")));
}
finally
{
if (Directory.Exists(testRoot))
{
Directory.Delete(testRoot, recursive: true);
}
}
}
}