using System; using System.IO; using ClaudeDo.Data; namespace ClaudeDo.Ui.Services; /// /// Temp PNGs written for clipboard-image paste into the interactive terminal (see /// ) — dropped into the composer as a path, /// the same way a file drop is, then read by Claude like any other file. /// public static class ClipboardImageTempStore { public static string Directory => Path.Combine(Paths.AppDataRoot(), "tmp"); /// A fresh, collision-free path for one pasted image. public static string NewPngPath(DateTime utcNow) => NewPngPath(Directory, utcNow); /// Deletes files older than under the tmp dir — called once at /// app startup, not a running cleanup service. public static void DeleteOlderThan(TimeSpan maxAge, DateTime utcNow) => DeleteOlderThan(Directory, maxAge, utcNow); /// Test seam for — takes the target dir explicitly /// instead of the real app data root. internal static string NewPngPath(string dir, DateTime utcNow) => Path.Combine(dir, $"paste-{utcNow:yyyyMMdd-HHmmssfff}-{Guid.NewGuid():N}.png"); /// Test seam for — takes the target dir /// explicitly instead of the real app data root. internal static void DeleteOlderThan(string dir, TimeSpan maxAge, DateTime utcNow) { if (!System.IO.Directory.Exists(dir)) return; foreach (var file in System.IO.Directory.EnumerateFiles(dir)) { try { if (utcNow - File.GetLastWriteTimeUtc(file) > maxAge) File.Delete(file); } catch (IOException) { /* best effort */ } catch (UnauthorizedAccessException) { /* best effort */ } } } }