603af17e56
The repo carried two parallel UIs (WPF + WinUI) sharing Models/Services via
cross-directory Link includes. Now that WinUI is the only frontend, collapse
the structure so the WinUI project IS the repo root instead of a nested
sibling folder:
- Delete the WPF project entirely (App.xaml, MainWindow.xaml, csproj) and its
bin/obj output
- Move AmiReel.WinUI/* up to the repo root (App, MainWindow, MainPage,
DialogHelper, Assets, Package.appxmanifest, app.manifest, Properties,
.github/instructions, AGENTS.md) via git mv, preserving history
- Rename AmiReel.WinUI.csproj -> AmiReel.csproj; regenerate the solution as
AmiReel.slnx (the newer XML solution format) with a single project
- Rename namespace AmigaDB.VideoRenderer.{Models,Services} -> AmiReel.{...}
and AmiReel_WinUI -> AmiReel across all files, including the embedded
ffmpeg/ffprobe resource logical names in the csproj and ToolExtractor
- Models/ and Services/ no longer need the Link-based cross-directory
<Compile Include>; they're picked up by the SDK's default globbing now
that they live under the project directory
- Rename assets/ -> branding/ (source icon art) to avoid a case-insensitive
collision with Assets/ (packaged tile art) once both sit at repo root
- Merge the two .gitignore files into one; track the PublishProfiles pubxml
files instead of ignoring them (no secrets, and they keep publish
reproducible across machines) as branding, gitignore, etc.
- Simplify publish-win-x64.ps1 (drop the -Target Wpf/WinUI switch, there's
only one target now) and rewrite README.md to describe the single-project
layout, build/run/publish commands, and file structure
Verified: dotnet build succeeds for both AmiReel.csproj and AmiReel.slnx, and
the built exe launches and renders identically to before the move.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
107 lines
3.8 KiB
C#
107 lines
3.8 KiB
C#
using System.IO;
|
|
using System.Reflection;
|
|
using System.Security.Cryptography;
|
|
|
|
namespace AmiReel.Services;
|
|
|
|
public sealed record ToolPaths(string Ffmpeg, string Ffprobe);
|
|
|
|
public static class ToolExtractor
|
|
{
|
|
public static async Task<ToolPaths> ResolveAsync(string ffmpegPath, string ffprobePath, CancellationToken cancellationToken = default)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(ffmpegPath) || !string.IsNullOrWhiteSpace(ffprobePath))
|
|
{
|
|
if (string.IsNullOrWhiteSpace(ffmpegPath) || !File.Exists(ffmpegPath))
|
|
throw new FileNotFoundException("Configured ffmpeg.exe was not found.");
|
|
if (string.IsNullOrWhiteSpace(ffprobePath) || !File.Exists(ffprobePath))
|
|
throw new FileNotFoundException("Configured ffprobe.exe was not found.");
|
|
return new ToolPaths(ffmpegPath, ffprobePath);
|
|
}
|
|
|
|
if (TryResolveFromSystemPath(out ToolPaths? systemTools) && systemTools is not null)
|
|
return systemTools;
|
|
|
|
return await ExtractAsync(cancellationToken);
|
|
}
|
|
|
|
public static bool TryResolveFromSystemPath(out ToolPaths? tools)
|
|
{
|
|
tools = null;
|
|
string? ffmpeg = FindOnPath("ffmpeg.exe");
|
|
string? ffprobe = FindOnPath("ffprobe.exe");
|
|
if (ffmpeg is null || ffprobe is null)
|
|
return false;
|
|
|
|
tools = new ToolPaths(ffmpeg, ffprobe);
|
|
return true;
|
|
}
|
|
|
|
private static async Task<ToolPaths> ExtractAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
string toolDir = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
|
"AmiReel", "tools", "0.1.0");
|
|
Directory.CreateDirectory(toolDir);
|
|
|
|
string ffmpeg = await ExtractOneAsync("ffmpeg.exe", toolDir, cancellationToken);
|
|
string ffprobe = await ExtractOneAsync("ffprobe.exe", toolDir, cancellationToken);
|
|
return new ToolPaths(ffmpeg, ffprobe);
|
|
}
|
|
|
|
private static async Task<string> ExtractOneAsync(string fileName, string destination, CancellationToken token)
|
|
{
|
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
string resourceName = $"AmiReel.Tools.{fileName}";
|
|
await using Stream source = assembly.GetManifestResourceStream(resourceName)
|
|
?? throw new InvalidOperationException(
|
|
$"Embedded {fileName} was not found. Add it to ThirdParty and publish the application again.");
|
|
|
|
string target = Path.Combine(destination, fileName);
|
|
string temporary = target + ".new";
|
|
await using (FileStream output = File.Create(temporary))
|
|
await source.CopyToAsync(output, token);
|
|
|
|
if (File.Exists(target) && FilesMatch(target, temporary))
|
|
{
|
|
File.Delete(temporary);
|
|
return target;
|
|
}
|
|
|
|
File.Move(temporary, target, true);
|
|
return target;
|
|
}
|
|
|
|
private static bool FilesMatch(string first, string second)
|
|
{
|
|
using SHA256 sha = SHA256.Create();
|
|
using FileStream a = File.OpenRead(first);
|
|
byte[] aHash = sha.ComputeHash(a);
|
|
using FileStream b = File.OpenRead(second);
|
|
byte[] bHash = sha.ComputeHash(b);
|
|
return aHash.AsSpan().SequenceEqual(bHash);
|
|
}
|
|
|
|
private static string? FindOnPath(string fileName)
|
|
{
|
|
string? path = Environment.GetEnvironmentVariable("PATH");
|
|
if (string.IsNullOrWhiteSpace(path))
|
|
return null;
|
|
|
|
foreach (string directory in path.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
|
|
{
|
|
try
|
|
{
|
|
string candidate = Path.Combine(directory, fileName);
|
|
if (File.Exists(candidate))
|
|
return candidate;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|