Files

103 lines
3.5 KiB
C#
Raw Permalink Normal View History

using System.Diagnostics;
2024-01-01 15:17:11 +00:00
using Velopack;
public static class PathHelper
{
2024-12-03 07:16:59 +00:00
public static bool IsCI => Environment.GetEnvironmentVariable("CI") != null;
2023-12-30 15:39:45 +00:00
public static string GetFixturesDir()
=> Path.Combine(GetTestRoot(), "fixtures");
2023-12-30 15:39:45 +00:00
public static string GetProjectDir()
=> Path.Combine(GetTestRoot(), "..");
2024-01-25 15:17:37 +00:00
public static string GetAvaloniaSample()
=> Path.Combine(GetProjectDir(), "samples", "CSharpAvalonia");
2024-01-25 15:17:37 +00:00
public static string GetWpfSample()
=> Path.Combine(GetProjectDir(), "samples", "CSharpWpf");
2024-01-25 15:17:37 +00:00
2023-12-30 15:39:45 +00:00
public static string GetVendorLibDir()
=> Path.Combine(GetProjectDir(), "vendor");
2024-03-29 12:19:34 +00:00
public static string GetArtworkDir()
=> Path.Combine(GetProjectDir(), "artwork");
2023-12-30 15:39:45 +00:00
public static string GetFixture(params string[] names)
2024-11-02 15:13:37 -07:00
=> Path.Combine([GetTestRoot(), "fixtures", .. names]);
public static string GetTestRootPath(params string[] names)
2024-11-02 15:13:37 -07:00
=> Path.Combine([GetTestRoot(), .. names]);
2023-12-30 15:39:45 +00:00
#if DEBUG
public static string GetRustBuildOutputDir()
=> Path.Combine(GetProjectDir(), "target", "debug");
2023-12-30 15:39:45 +00:00
#else
public static string GetRustBuildOutputDir()
=> Path.Combine(GetProjectDir(), "target", "release");
2023-12-30 15:39:45 +00:00
#endif
public static string GetRustAsset(params string[] names)
2024-11-02 15:13:37 -07:00
=> Path.Combine([GetRustBuildOutputDir(), .. names]);
2023-12-30 15:39:45 +00:00
public static string CopyRustAssetTo(string assetName, string dir)
{
var path = GetRustAsset(assetName);
if (!File.Exists(path))
throw new FileNotFoundException($"File not found: {path}");
var newPath = Path.Combine(dir, assetName);
File.Copy(path, newPath);
return newPath;
}
public static string CopyFixtureTo(string fixtureName, string dir)
{
var path = GetFixture(fixtureName);
if (!File.Exists(path))
throw new FileNotFoundException($"File not found: {path}");
var newPath = Path.Combine(dir, fixtureName);
File.Copy(path, newPath);
return newPath;
}
2024-01-01 15:17:11 +00:00
public static string CopyUpdateTo(string dir)
{
2024-11-02 15:13:37 -07:00
static string GetUpdatePath()
{
if (VelopackRuntimeInfo.IsWindows && File.Exists(GetRustAsset("update.exe"))) {
return GetRustAsset("update.exe");
}
if (VelopackRuntimeInfo.IsLinux && File.Exists(GetRustAsset("UpdateNix"))) {
return GetRustAsset("UpdateNix");
}
if (VelopackRuntimeInfo.IsOSX && File.Exists(GetRustAsset("UpdateMac"))) {
return GetRustAsset("UpdateMac");
}
if (!VelopackRuntimeInfo.IsWindows && File.Exists(GetRustAsset("update"))) {
return GetRustAsset("update");
}
throw new FileNotFoundException("update.exe not found");
}
var path = GetUpdatePath();
var newPath = Path.Combine(dir, Path.GetFileName(path));
2024-01-01 15:17:11 +00:00
File.Copy(path, newPath);
return newPath;
}
public static string GetTestRoot()
{
// XXX: This is an evil hack, but it's okay for a unit test
// We can't use Assembly.Location because unit test runners love
// to move stuff to temp directories
var st = new StackFrame(true);
#pragma warning disable CS8604 // Possible null reference argument.
var di = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(st.GetFileName())));
#pragma warning restore CS8604 // Possible null reference argument.
return di.FullName;
}
}