diff --git a/src/Titano.Uploader/App.xaml.cs b/src/Titano.Uploader/App.xaml.cs index 8fe2c3da..f737a506 100644 --- a/src/Titano.Uploader/App.xaml.cs +++ b/src/Titano.Uploader/App.xaml.cs @@ -64,7 +64,7 @@ public partial class App : Application _instance = SingleInstance.TryAcquire(); if (_instance is null) { - SingleInstance.TrySend([.. command.Paths.Select(Absolute).OfType()]); + SingleInstance.HandOver([.. command.Paths.Select(Absolute).OfType()]); Log.Info("app", "Another uploader runs in this session; arguments handed over"); Shutdown(); return; diff --git a/src/Titano.Uploader/Infrastructure/SingleInstance.cs b/src/Titano.Uploader/Infrastructure/SingleInstance.cs index cc39c03c..1c3c89cf 100644 --- a/src/Titano.Uploader/Infrastructure/SingleInstance.cs +++ b/src/Titano.Uploader/Infrastructure/SingleInstance.cs @@ -33,7 +33,7 @@ public sealed class SingleInstance : IDisposable } /// Sends (absolute paths; empty = just show the window) to the running instance. - public static bool TrySend(IReadOnlyList args) + public static void HandOver(IReadOnlyList args) { try { @@ -41,12 +41,10 @@ public sealed class SingleInstance : IDisposable pipe.Connect(3000); pipe.Write(Encode(args)); pipe.Flush(); - return true; } catch (Exception ex) when (ex is IOException or TimeoutException or UnauthorizedAccessException) { Log.Warning("instance", "Could not reach the running uploader", ex); - return false; } } diff --git a/src/Titano.Uploader/Server/DiscoveryListener.cs b/src/Titano.Uploader/Server/DiscoveryListener.cs index 18286c83..1796ed3d 100644 --- a/src/Titano.Uploader/Server/DiscoveryListener.cs +++ b/src/Titano.Uploader/Server/DiscoveryListener.cs @@ -6,10 +6,7 @@ using Titano.Protocol; namespace Titano.Uploader.Server; /// A Titano Server announced on the LAN. -public sealed record DiscoveredServer(string Name, string Address) -{ - public override string ToString() => Name + " · " + Address; -} +public sealed record DiscoveredServer(string Name, string Address); /// /// Listens for the server's UDP beacon () while the connect form is open and reports @@ -31,17 +28,15 @@ public sealed class DiscoveryListener : IDisposable _ = Task.Run(() => ListenAsync(context, _cts.Token)); } - public void Stop() + public void Dispose() { _cts?.Cancel(); _cts?.Dispose(); _cts = null; } - public void Dispose() => Stop(); - /// The address the client should use for sent from . - public static string AddressOf(DiscoveryBeacon beacon, IPAddress sender) + private static string AddressOf(DiscoveryBeacon beacon, IPAddress sender) { var host = sender.AddressFamily == AddressFamily.InterNetworkV6 ? "[" + sender + "]" : sender.ToString(); return beacon.HttpsPort > 0 ? $"https://{host}:{beacon.HttpsPort}" : $"http://{host}:{beacon.HttpPort}"; diff --git a/src/Titano.Uploader/Uploads/QueueStore.cs b/src/Titano.Uploader/Uploads/QueueStore.cs index edf30ac1..3b70be25 100644 --- a/src/Titano.Uploader/Uploads/QueueStore.cs +++ b/src/Titano.Uploader/Uploads/QueueStore.cs @@ -2,7 +2,6 @@ using System.IO; using System.Text.Json.Serialization; using System.Text.Json; using Titano.Core.Diagnostics; -using Titano.Core.IO; namespace Titano.Uploader.Uploads; @@ -73,9 +72,6 @@ public static class QueueStore file.Paused); } - /// Commits serialized bytes with temp → fsync → rename. - public static void Write(string path, byte[] content) => AtomicFile.WriteAllBytes(path, content); - internal sealed class QueueFile { public int Version { get; set; } diff --git a/src/Titano.Uploader/Watching/ProcessedFileMemory.cs b/src/Titano.Uploader/Watching/ProcessedFileMemory.cs index 9277ca00..9669fbd4 100644 --- a/src/Titano.Uploader/Watching/ProcessedFileMemory.cs +++ b/src/Titano.Uploader/Watching/ProcessedFileMemory.cs @@ -2,7 +2,6 @@ using System.IO; using System.Text.Json.Serialization; using System.Text.Json; using Titano.Core.Diagnostics; -using Titano.Core.IO; using Titano.Uploader.Sources; namespace Titano.Uploader.Watching; @@ -106,8 +105,6 @@ public sealed class ProcessedFileMemory } } - public void Save(string path) => AtomicFile.WriteAllBytes(path, Serialize()); - /// Loads ; a missing or corrupt file gives an empty memory. public static ProcessedFileMemory Load(string path) { diff --git a/src/Titano.Uploader/Watching/StableFileTracker.cs b/src/Titano.Uploader/Watching/StableFileTracker.cs index b1958744..4758cbb8 100644 --- a/src/Titano.Uploader/Watching/StableFileTracker.cs +++ b/src/Titano.Uploader/Watching/StableFileTracker.cs @@ -44,6 +44,4 @@ public sealed class StableFileTracker _seen[o.Path] = (o.Size, o.ModifiedUtc, count); return false; } - - public void Clear() => _seen.Clear(); } diff --git a/tests/Titano.App.Tests/Uploader/ProcessedFileMemoryTests.cs b/tests/Titano.App.Tests/Uploader/ProcessedFileMemoryTests.cs index 9cb80990..203c771a 100644 --- a/tests/Titano.App.Tests/Uploader/ProcessedFileMemoryTests.cs +++ b/tests/Titano.App.Tests/Uploader/ProcessedFileMemoryTests.cs @@ -51,7 +51,7 @@ public sealed class ProcessedFileMemoryTests(TestContext context) memory.SetSession(root, new SessionContinuation("1a2b3c4d-20260928-180000", new DateTime(2026, 9, 28, 18, 40, 0))); var path = Path.Combine(dir, "uploader-watch.json"); - memory.Save(path); + File.WriteAllBytes(path, memory.Serialize()); Assert.False(memory.IsDirty); var restored = ProcessedFileMemory.Load(path); diff --git a/tests/Titano.App.Tests/Uploader/UploadQueueTests.cs b/tests/Titano.App.Tests/Uploader/UploadQueueTests.cs index e390ed76..6d1841bb 100644 --- a/tests/Titano.App.Tests/Uploader/UploadQueueTests.cs +++ b/tests/Titano.App.Tests/Uploader/UploadQueueTests.cs @@ -26,7 +26,7 @@ public sealed class UploadQueueTests(TestContext context) queue.IsPaused = true; var path = Path.Combine(context.CreateTempDirectory(), "uploader-queue.json"); - QueueStore.Write(path, QueueStore.Serialize(queue)); + File.WriteAllBytes(path, QueueStore.Serialize(queue)); var restored = new UploadQueue(); QueueStore.Load(path, restored); @@ -67,7 +67,7 @@ public sealed class UploadQueueTests(TestContext context) queue.Items[1].State = UploadItemState.Hashing; var path = Path.Combine(context.CreateTempDirectory(), "q.json"); - QueueStore.Write(path, QueueStore.Serialize(queue)); + File.WriteAllBytes(path, QueueStore.Serialize(queue)); var restored = new UploadQueue(); QueueStore.Load(path, restored);