mirror of
https://github.com/par274/sharpemu.git
synced 2026-08-09 19:25:39 +08:00
2b6bd5a532
* [audio] added sdl audio backend and in-tree atrac9 decoder * [input] replaced per-platform pad readers with sdl gamepad input * [video] added sdl window and host display plumbing * [gui] added host display options and per-game render settings * [bink] synced host movie playback to the guest audio clock * [cpu] hooked windows write faults into guest image tracking * [perf] added guest and render profiling, reserved host cpu lanes * [kernel] fixed stale pthread mutex handle alias * [host] wired the sdl session, save-data paths and project references * [audio] hoisted ajm trace stackalloc out of its loop * [video] Add guest image sync setting * [build] Strip native symbols * reuse
97 lines
2.8 KiB
C#
97 lines
2.8 KiB
C#
// Copyright (C) 2026 SharpEmu Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
namespace SharpEmu.Libs.VideoOut;
|
|
|
|
internal static class VulkanPipelineCacheStorage
|
|
{
|
|
private const string CacheFileName = "vulkan-pipeline-cache.bin";
|
|
|
|
internal static string ResolvePath(string? titleId, string? configuredPath)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(configuredPath))
|
|
{
|
|
return Path.GetFullPath(
|
|
Environment.ExpandEnvironmentVariables(configuredPath));
|
|
}
|
|
|
|
return Path.GetFullPath(Path.Combine(
|
|
AppContext.BaseDirectory,
|
|
"user",
|
|
"pipeline_cache",
|
|
SanitizeTitleId(titleId),
|
|
CacheFileName));
|
|
}
|
|
|
|
internal static string GetLegacyPath()
|
|
{
|
|
var root = OperatingSystem.IsMacOS()
|
|
? Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
|
"Library",
|
|
"Caches")
|
|
: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
return Path.Combine(root, "SharpEmu", CacheFileName);
|
|
}
|
|
|
|
internal static bool ImportLegacyCache(string legacyPath, string destinationPath)
|
|
{
|
|
if (File.Exists(destinationPath) || !File.Exists(legacyPath))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var directory = Path.GetDirectoryName(destinationPath);
|
|
if (!string.IsNullOrWhiteSpace(directory))
|
|
{
|
|
Directory.CreateDirectory(directory);
|
|
}
|
|
|
|
try
|
|
{
|
|
File.Copy(legacyPath, destinationPath, overwrite: false);
|
|
try
|
|
{
|
|
File.Delete(legacyPath);
|
|
}
|
|
catch (IOException)
|
|
{
|
|
// The destination is valid; a locked legacy cache can remain
|
|
// as an unused artifact without affecting future writes.
|
|
}
|
|
catch (UnauthorizedAccessException)
|
|
{
|
|
// See above. Cache migration must not block game startup.
|
|
}
|
|
|
|
return true;
|
|
}
|
|
catch (IOException) when (File.Exists(destinationPath))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private static string SanitizeTitleId(string? titleId)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(titleId))
|
|
{
|
|
return "UNKNOWN";
|
|
}
|
|
|
|
var source = titleId.Trim();
|
|
Span<char> sanitized = source.Length <= 128
|
|
? stackalloc char[source.Length]
|
|
: new char[source.Length];
|
|
for (var index = 0; index < source.Length; index++)
|
|
{
|
|
var value = source[index];
|
|
sanitized[index] = char.IsAsciiLetterOrDigit(value) || value is '-' or '_'
|
|
? char.ToUpperInvariant(value)
|
|
: '_';
|
|
}
|
|
|
|
return new string(sanitized);
|
|
}
|
|
}
|