mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
* Rename avalonia & wpf samples * Rename rest of samples * fix sample readme * Fix compat util tests * rename / move all src projects * remove package lock files and move libC# again * Add rust lib and cargo workspace * Replace locksmith lib with new filelocksmith-rs library * Deprecated type * fix setup compile * Use thiserror for error handling * Rename some enums and formatting * Add missing SHA256 * wip c++ library * cpp wip * alphabetize readme * Try to get build working again * Fix some conditionally compiled bits * cross config should be in workspace root * Fix PathHelper for new rust target dir * Missed one old path to velopack.csproj * remove obsolete coverage code * testawareapp.exe no longer exists
101 lines
3.5 KiB
C#
101 lines
3.5 KiB
C#
using System.Diagnostics;
|
|
using Velopack;
|
|
|
|
public static class PathHelper
|
|
{
|
|
public static string GetFixturesDir()
|
|
=> Path.Combine(GetTestRoot(), "fixtures");
|
|
|
|
public static string GetProjectDir()
|
|
=> Path.Combine(GetTestRoot(), "..");
|
|
|
|
public static string GetAvaloniaSample()
|
|
=> Path.Combine(GetProjectDir(), "samples", "CSharpAvalonia");
|
|
|
|
public static string GetWpfSample()
|
|
=> Path.Combine(GetProjectDir(), "samples", "CSharpWpf");
|
|
|
|
public static string GetVendorLibDir()
|
|
=> Path.Combine(GetProjectDir(), "vendor");
|
|
|
|
public static string GetArtworkDir()
|
|
=> Path.Combine(GetProjectDir(), "artwork");
|
|
|
|
public static string GetFixture(params string[] names)
|
|
=> Path.Combine(new string[] { GetTestRoot(), "fixtures" }.Concat(names).ToArray());
|
|
|
|
public static string GetTestRootPath(params string[] names)
|
|
=> Path.Combine(new string[] { GetTestRoot() }.Concat(names).ToArray());
|
|
|
|
#if DEBUG
|
|
public static string GetRustBuildOutputDir()
|
|
=> Path.Combine(GetProjectDir(), "target", "debug");
|
|
#else
|
|
public static string GetRustBuildOutputDir()
|
|
=> Path.Combine(GetProjectDir(), "target", "release");
|
|
#endif
|
|
|
|
public static string GetRustAsset(params string[] names)
|
|
=> Path.Combine(new string[] { GetRustBuildOutputDir() }.Concat(names).ToArray());
|
|
|
|
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;
|
|
}
|
|
|
|
public static string CopyUpdateTo(string dir)
|
|
{
|
|
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));
|
|
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;
|
|
}
|
|
} |