diff --git a/i18n/en/Settings.resx b/i18n/en/Settings.resx index 4df33790..d183a3f6 100644 --- a/i18n/en/Settings.resx +++ b/i18n/en/Settings.resx @@ -8,10 +8,12 @@ Index backed up Back up now Data folder + Data inside OneDrive Data kept outside OneDrivelong Diagnostics Diagnostics bundle saved Save the diagnostics bundle to + Earlier data unused Export bundle Logs No backups yet diff --git a/i18n/en/Tooltips.resx b/i18n/en/Tooltips.resx index 65d67fdd..ffd83e9b 100644 --- a/i18n/en/Tooltips.resx +++ b/i18n/en/Tooltips.resx @@ -528,10 +528,12 @@ Delete the cache contents now Delete spilled frames and cached thumbnails; asks first Database, settings, logs and caches of this PC + Open the data folder in Explorer. OneDrive synchronises it, which can damage the index: exclude it from syncing New cards and folders queue a deep analysis of what they import, in the background; each card can change it Sequences a scan finds (adopted folders, new sidecars) also get a deep analysis, in the background Server Titano connects to at start; changing it signs out · Enter applies, Esc reverts Zip the logs, a system and codec report, settings and recent failed jobs into a folder you choose; passwords, tokens and photos are left out + Open the data this portable copy kept beside it before it ran from OneDrive. Titano no longer uses it and leaves it as it is Save every setting as JSON, without the session token File name of each frame, for example {date}_{time}_{n:0000}; the extension is added · Enter applies, Esc reverts Archive folders, for example {year}/{date} {camera}; a slash starts a subfolder · Enter applies, Esc reverts diff --git a/i18n/it/Settings.it.resx b/i18n/it/Settings.it.resx index f61c0972..f171f9e0 100644 --- a/i18n/it/Settings.it.resx +++ b/i18n/it/Settings.it.resx @@ -8,10 +8,12 @@ Copia dell'indice salvata Salva una copia Cartella dati + Dati dentro OneDrive Dati tenuti fuori da OneDrive Diagnostica Pacchetto diagnostico salvato Salva il pacchetto in + Dati precedenti inutilizzati Esporta pacchetto Log Ancora nessuna copia diff --git a/i18n/it/Tooltips.it.resx b/i18n/it/Tooltips.it.resx index 91f31e25..78e9ea04 100644 --- a/i18n/it/Tooltips.it.resx +++ b/i18n/it/Tooltips.it.resx @@ -528,10 +528,12 @@ Elimina adesso il contenuto della cache Elimina fotogrammi temporanei e miniature in cache; prima chiede conferma Database, impostazioni, log e cache di questo PC + Apri la cartella dati in Esplora file. OneDrive la sincronizza e così può danneggiare l'indice: escludila dalla sincronizzazione Schede e cartelle nuove accodano l'analisi profonda di ciò che importano, in background; ogni scheda può cambiarlo Anche le sequenze trovate da una scansione (cartelle adottate, nuovi sidecar) ricevono l'analisi profonda, in background Server a cui Titano si connette all'avvio; cambiarlo chiude l'accesso · Invio applica, Esc annulla Comprime log, rapporto su sistema e codec, impostazioni e attività fallite di recente in una cartella a tua scelta; password, token e foto restano fuori + Apri i dati che questa copia portatile teneva accanto a sé prima di trovarsi in OneDrive. Titano non li usa più e li lascia com'erano Salva tutte le impostazioni in JSON, senza il token di sessione Nome del file di ogni fotogramma, ad esempio {date}_{time}_{n:0000}; l'estensione viene aggiunta · Invio applica, Esc annulla Cartelle dell'archivio, ad esempio {year}/{date} {camera}; la barra crea una sottocartella · Invio applica, Esc annulla diff --git a/src/Titano.App/App.xaml.cs b/src/Titano.App/App.xaml.cs index 9da130e6..2125e10f 100644 --- a/src/Titano.App/App.xaml.cs +++ b/src/Titano.App/App.xaml.cs @@ -46,7 +46,9 @@ public partial class App : Application Log.SetSink(capture ? new TeeLogSink(_log, new StderrLogSink()) : _log); Log.Info("app", $"Titano {AppServices.VersionText} starting; data at {Environment.DataDirectory}"); // Settings tells the user once the window is up. - if (Environment.SyncedFolder is { } synced) Log.Warning("app", $"This portable copy runs in the OneDrive folder {synced}: its data is kept outside it"); + if (Environment.PortableSyncRoot is { } portableIn) Log.Warning("app", $"This portable copy runs in the OneDrive folder {portableIn}: its data is kept outside it"); + if (Environment.EarlierPortableData is { } earlier) Log.Warning("app", $"The data this portable copy kept in {earlier} before is left there and no longer used"); + if (Environment.SyncedFolder is { } synced) Log.Warning("app", $"The data folder lies in the OneDrive folder {synced}: synchronisation may damage the index"); var projectFile = capture ? null : ProjectFileArgument(e.Args); if (!capture) diff --git a/src/Titano.App/Infrastructure/AppEnvironment.cs b/src/Titano.App/Infrastructure/AppEnvironment.cs index 06c60555..83a2cbc1 100644 --- a/src/Titano.App/Infrastructure/AppEnvironment.cs +++ b/src/Titano.App/Infrastructure/AppEnvironment.cs @@ -7,16 +7,20 @@ namespace Titano.App.Infrastructure; /// Where the client keeps its data (BRIEF §6.2, ): %LOCALAPPDATA%\Titano, or .\data /// next to the executable when portable.txt exists. Never inside a folder OneDrive synchronises (SQLite corrupts /// there): a portable copy in one keeps its data in %LOCALAPPDATA%\Titano, and Settings tells the user so -/// (). +/// (, ). When that folder itself lies in one, nowhere +/// is safe: Titano starts all the same and Settings warns (). /// public sealed class AppEnvironment { - private AppEnvironment(string dataDirectory, bool portable, bool isCapture, string? syncedFolder = null) + private AppEnvironment(string dataDirectory, bool portable, bool isCapture, string? syncedFolder = null, string? portableSyncRoot = null, + string? earlierPortableData = null) { DataDirectory = dataDirectory; IsPortable = portable; IsCapture = isCapture; SyncedFolder = syncedFolder; + PortableSyncRoot = portableSyncRoot; + EarlierPortableData = earlierPortableData; Directory.CreateDirectory(DataDirectory); Directory.CreateDirectory(LogDirectory); Directory.CreateDirectory(CacheDirectory); @@ -28,20 +32,30 @@ public sealed class AppEnvironment /// A throw-away environment for --capture: nothing of the user's data is read or written. public bool IsCapture { get; } - /// The OneDrive folder this portable copy runs from; its data is in %LOCALAPPDATA%\Titano instead of .\data. Null otherwise. + /// The OneDrive folder itself lies in, where the index may be damaged; null when it is safe. public string? SyncedFolder { get; } + /// The OneDrive folder this portable copy runs from; its data is in %LOCALAPPDATA%\Titano instead of .\data. Null otherwise. + public string? PortableSyncRoot { get; } + + /// The .\data folder this portable copy used before it ran from OneDrive, left as it was; null when there is none. + public string? EarlierPortableData { get; } + public string LogDirectory => Path.Combine(DataDirectory, "logs"); public string CacheDirectory => Path.Combine(DataDirectory, "cache"); public string BackupDirectory => Path.Combine(DataDirectory, "backups"); - public string DatabasePath => Path.Combine(DataDirectory, "titano.db"); - public string SettingsPath => Path.Combine(DataDirectory, "settings.json"); + public string DatabasePath => Path.Combine(DataDirectory, AppPaths.DatabaseFileName); + public string SettingsPath => Path.Combine(DataDirectory, AppPaths.SettingsFileName); /// The environment of this process: its executable's folder and the user's OneDrive folders decide. public static AppEnvironment Detect() => From(AppPaths.Resolve()); /// The environment at (its folders are created). - public static AppEnvironment From(AppPaths paths) => new(paths.DataRoot, paths.IsPortable, isCapture: false, paths.PortableSyncRoot); + public static AppEnvironment From(AppPaths paths) + { + ArgumentNullException.ThrowIfNull(paths); + return new(paths.DataRoot, paths.IsPortable, isCapture: false, paths.SyncedFolder, paths.PortableSyncRoot, paths.EarlierPortableData); + } /// A fresh temporary data folder for screenshots and smoke tests; delete it with . public static AppEnvironment ForCapture() => diff --git a/src/Titano.App/Sections/SettingsViewModel.cs b/src/Titano.App/Sections/SettingsViewModel.cs index b041255d..72fbc458 100644 --- a/src/Titano.App/Sections/SettingsViewModel.cs +++ b/src/Titano.App/Sections/SettingsViewModel.cs @@ -808,10 +808,18 @@ public sealed class SettingsViewModel : SectionViewModel Shell.Notify(Loc.L("Settings.Advanced.RestoreFailed"), Loc.L("Errors.Backup.Deferred"), isError: true); break; } - // BRIEF §6.2: a portable copy in a folder OneDrive synchronises keeps its data in this user's folder instead. - if (Shell.Services.Environment.SyncedFolder is not null) + // BRIEF §6.2: a portable copy in a folder OneDrive synchronises keeps its data in this user's folder instead, and + // leaves the data it kept beside it before where it is. Only a user folder that is itself synchronised is unsafe. + var environment = Shell.Services.Environment; + if (environment.SyncedFolder is not null) + Shell.Notify(Loc.L("Settings.Advanced.DataInOneDrive"), Formatting.LeftToRight(DataFolder), Loc.L("Common.Open"), + Loc.L("Tooltips.Settings.DataInOneDrive"), () => ShellActions.Reveal(DataFolder), isError: true); + else if (environment.PortableSyncRoot is not null) Shell.Notify(Loc.L("Settings.Advanced.DataOutsideOneDrive"), Formatting.LeftToRight(DataFolder), Loc.L("Common.Open"), Loc.L("Tooltips.Settings.OpenDataFolder"), () => ShellActions.Reveal(DataFolder)); + if (environment.EarlierPortableData is { } earlier) + Shell.Notify(Loc.L("Settings.Advanced.EarlierData"), Formatting.LeftToRight(earlier), Loc.L("Common.Open"), + Loc.L("Tooltips.Settings.EarlierData"), () => ShellActions.Reveal(earlier)); Startup.Refresh(); } diff --git a/src/Titano.Core.Windows/Shell/AppPaths.cs b/src/Titano.Core.Windows/Shell/AppPaths.cs index 7bd02b74..91279f78 100644 --- a/src/Titano.Core.Windows/Shell/AppPaths.cs +++ b/src/Titano.Core.Windows/Shell/AppPaths.cs @@ -6,20 +6,22 @@ namespace Titano.Core.Windows.Shell; /// Where the desktop programs keep their data (BRIEF §6.2, ): %LOCALAPPDATA%\Titano, or /// .\data next to the executable in portable mode. SQLite corrupts inside synchronised folders, so a portable /// copy in a OneDrive folder keeps its data in %LOCALAPPDATA%\Titano instead ( -/// names that folder to tell the user), and a data root still under OneDrive is reported by -/// and refused by . +/// names that folder to tell the user, the data it kept there before), and a data +/// root still under OneDrive is reported by and refused by . /// public sealed class AppPaths { public const string ProductFolderName = DataLocation.ProductFolderName; public const string DatabaseFileName = "titano.db"; + public const string SettingsFileName = "settings.json"; - private AppPaths(DataLocation location) + private AppPaths(DataLocation location, string? earlierPortableData) { DataRoot = location.Root; IsPortable = location.IsPortable; SyncedFolder = location.SyncedFolder; PortableSyncRoot = location.PortableSyncRoot; + EarlierPortableData = earlierPortableData; } /// A portable copy, also when its data had to go to %LOCALAPPDATA%\Titano. @@ -43,6 +45,12 @@ public sealed class AppPaths /// The OneDrive sync root a portable copy runs from, whose data is in %LOCALAPPDATA%\Titano instead; null otherwise. public string? PortableSyncRoot { get; } + /// + /// The .\data folder of a portable copy now in a OneDrive folder when it still holds the index or the settings + /// of an earlier start: nothing moves or deletes it, and the user is told where it is. Null otherwise. + /// + public string? EarlierPortableData { get; } + /// Paths for this process: the executable's folder decides portable mode. public static AppPaths Resolve() => Resolve(AppContext.BaseDirectory, KnownFolders.LocalAppData); @@ -51,8 +59,16 @@ public sealed class AppPaths Resolve(applicationDirectory, localAppData, OneDriveFolders.SyncRoots()); /// Paths for an executable in , checked against . - public static AppPaths Resolve(string applicationDirectory, string localAppData, IReadOnlyCollection syncRoots) => - new(DataLocation.Choose(applicationDirectory, PortableMode.IsEnabled(applicationDirectory), localAppData, syncRoots)); + public static AppPaths Resolve(string applicationDirectory, string localAppData, IReadOnlyCollection syncRoots) + { + var location = DataLocation.Choose(applicationDirectory, PortableMode.IsEnabled(applicationDirectory), localAppData, syncRoots); + var beside = Path.GetFullPath(Path.Combine(applicationDirectory, PortableMode.DataFolderName)); + var earlier = location.PortableSyncRoot is not null + && (File.Exists(Path.Combine(beside, DatabaseFileName)) || File.Exists(Path.Combine(beside, SettingsFileName))) + ? beside + : null; + return new AppPaths(location, earlier); + } /// Creates the data, logs, cache and thumbnails folders. /// The data root lies inside a OneDrive-synced folder. diff --git a/tests/Titano.App.Tests/Infrastructure/AppEnvironmentTests.cs b/tests/Titano.App.Tests/Infrastructure/AppEnvironmentTests.cs index 771e2d94..a50b4cf6 100644 --- a/tests/Titano.App.Tests/Infrastructure/AppEnvironmentTests.cs +++ b/tests/Titano.App.Tests/Infrastructure/AppEnvironmentTests.cs @@ -20,7 +20,9 @@ public sealed class AppEnvironmentTests(TestContext context) Assert.Equal(Path.Combine(local, "Titano", "titano.db"), environment.DatabasePath); Assert.True(environment.IsPortable, "still a portable copy: updates fetch the portable zip, no sign-in entry"); - Assert.Equal(oneDrive, environment.SyncedFolder); + Assert.Equal(oneDrive, environment.PortableSyncRoot); + Assert.Null(environment.SyncedFolder); + Assert.Null(environment.EarlierPortableData); Assert.True(Directory.Exists(environment.LogDirectory)); Assert.False(Directory.Exists(Path.Combine(app, "data")), "nothing is written into the synchronised folder"); @@ -29,6 +31,52 @@ public sealed class AppEnvironmentTests(TestContext context) File.WriteAllText(Path.Combine(stick, PortableMode.MarkerFileName), ""); var beside = AppEnvironment.From(AppPaths.Resolve(stick, local, [oneDrive])); Assert.Equal(Path.Combine(stick, "data"), beside.DataDirectory); + Assert.Null(beside.PortableSyncRoot); Assert.Null(beside.SyncedFolder); } + + [Test] + public void TheDataAPortableCopyKeptInOneDriveBeforeIsNamedAndLeftAlone() + { + var oneDrive = context.CreateTempDirectory("onedrive"); + var app = Directory.CreateDirectory(Path.Combine(oneDrive, "Documents", "Titano")).FullName; + File.WriteAllText(Path.Combine(app, PortableMode.MarkerFileName), ""); + // An earlier version kept its index and settings beside the program. + var earlier = Directory.CreateDirectory(Path.Combine(app, "data")).FullName; + File.WriteAllText(Path.Combine(earlier, "settings.json"), "{}"); + File.WriteAllBytes(Path.Combine(earlier, "titano.db"), [1, 2, 3]); + var local = context.CreateTempDirectory("local"); + + var environment = AppEnvironment.From(AppPaths.Resolve(app, local, [oneDrive])); + + Assert.Equal(earlier, environment.EarlierPortableData); + Assert.Equal(Path.Combine(local, "Titano"), environment.DataDirectory); + Assert.SequenceEqual(new byte[] { 1, 2, 3 }, File.ReadAllBytes(Path.Combine(earlier, "titano.db"))); + Assert.Equal("{}", File.ReadAllText(Path.Combine(earlier, "settings.json"))); + + // A data folder with neither (logs only) holds nothing the user would miss. + File.Delete(Path.Combine(earlier, "settings.json")); + File.Delete(Path.Combine(earlier, "titano.db")); + Directory.CreateDirectory(Path.Combine(earlier, "logs")); + Assert.Null(AppEnvironment.From(AppPaths.Resolve(app, local, [oneDrive])).EarlierPortableData); + } + + [Test] + public void AUserFolderOneDriveSynchronisesIsReportedNotHidden() + { + // Nowhere is safe: Titano starts all the same, and the folder that is synchronised is named for the warning. + var oneDrive = context.CreateTempDirectory("onedrive"); + var local = Directory.CreateDirectory(Path.Combine(oneDrive, "AppData", "Local")).FullName; + + var installed = AppEnvironment.From(AppPaths.Resolve(context.CreateTempDirectory("app"), local, [oneDrive])); + Assert.Equal(oneDrive, installed.SyncedFolder); + Assert.Null(installed.PortableSyncRoot); + Assert.True(Directory.Exists(installed.LogDirectory)); + + // A portable copy in that OneDrive has nowhere safe either: its data is not said to be kept outside it. + var app = Directory.CreateDirectory(Path.Combine(oneDrive, "Desktop", "Titano")).FullName; + File.WriteAllText(Path.Combine(app, PortableMode.MarkerFileName), ""); + var portable = AppEnvironment.From(AppPaths.Resolve(app, local, [oneDrive])); + Assert.Equal<(string?, string?)>((oneDrive, oneDrive), (portable.SyncedFolder, portable.PortableSyncRoot)); + } }