9bb4f85802
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
60 lines
2.9 KiB
C#
60 lines
2.9 KiB
C#
using CVRManager.Models;
|
|
|
|
namespace CVRManager.Services;
|
|
|
|
public static class Paths
|
|
{
|
|
public const int AppId = 661130;
|
|
|
|
public static string ConfigDir => Environment.GetEnvironmentVariable("CVRMANAGER_CONFIG_DIR") is { Length: > 0 } custom
|
|
? custom
|
|
: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CVRManager");
|
|
public static string ConfigFile => Path.Combine(ConfigDir, "config.json");
|
|
|
|
public static string Root { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CVRManager");
|
|
|
|
public static string SharedCache => Path.Combine(Root, "cache");
|
|
public static string ModStore => Path.Combine(Root, "mods");
|
|
public static string BranchCache => Path.Combine(Root, "sources", "branches.json");
|
|
|
|
public static string InstallsRoot => Path.Combine(Root, "installs");
|
|
public static string InstallDir(InstallInfo i) => Path.Combine(InstallsRoot, i.Folder);
|
|
public static string GameDir(InstallInfo i) => InstallDir(i);
|
|
|
|
public static string SafeFolderName(string name)
|
|
{
|
|
var bad = Path.GetInvalidFileNameChars();
|
|
var cleaned = new string(name.Select(c => bad.Contains(c) ? ' ' : c).ToArray());
|
|
while (cleaned.Contains(" ")) cleaned = cleaned.Replace(" ", " ");
|
|
cleaned = cleaned.Trim().TrimEnd('.');
|
|
if (cleaned.Length > 60) cleaned = cleaned[..60].TrimEnd();
|
|
return cleaned.Length == 0 ? "Install" : cleaned;
|
|
}
|
|
public static string GameDataDir(string? gameDir = null)
|
|
{
|
|
string company = "ChilloutVR", product = "ChilloutVR";
|
|
try
|
|
{
|
|
var info = gameDir == null ? null : Path.Combine(gameDir, "ChilloutVR_Data", "app.info");
|
|
if (info != null && File.Exists(info) && File.ReadAllLines(info) is { Length: >= 2 } l && l[0].Trim().Length > 0 && l[1].Trim().Length > 0)
|
|
(company, product) = (l[0].Trim(), l[1].Trim());
|
|
}
|
|
catch (Exception e) when (e is IOException or UnauthorizedAccessException) { }
|
|
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "AppData", "LocalLow", company, product);
|
|
}
|
|
|
|
public static string CacheDir(InstallInfo i) => Path.Combine(GameDir(i), "ChilloutVR_Data", "Cache");
|
|
public static string GameExe(InstallInfo i) => Path.Combine(GameDir(i), "ChilloutVR.exe");
|
|
public static string Manifest(InstallInfo i) => Path.Combine(GameDir(i), "steamapps", $"appmanifest_{AppId}.acf");
|
|
|
|
public static string ModVersionDir(ModDef m, string tag) => Path.Combine(ModStore, m.Id, Safe(tag));
|
|
public static string ModFilesDir(ModDef m, string tag) => Path.Combine(ModVersionDir(m, tag), "files");
|
|
|
|
public static string Safe(string s)
|
|
{
|
|
var bad = Path.GetInvalidFileNameChars();
|
|
var r = new string(s.Select(c => bad.Contains(c) ? '_' : c).ToArray()).Trim().TrimEnd('.');
|
|
return r.Length == 0 ? "_" : r;
|
|
}
|
|
}
|