fix(app): warn about a synced data folder and name a portable copy's earlier data
AppEnvironment now carries AppPaths.SyncedFolder: when the per-user data
folder itself lies in a OneDrive sync root, Titano still starts (nowhere
is safer), logs it and shows the error toast "Data inside OneDrive" with
Open, instead of the false "Data kept outside OneDrive". The latter now
needs PortableSyncRoot (renamed from the old SyncedFolder meaning).
A portable copy now in a OneDrive folder whose .\data still holds an
index or settings.json gets that folder named in the log and in a toast
("Earlier data unused", with Open). Nothing is moved or deleted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
9 files changed
+111
-15
No files matched your search
@@ -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)
|
||||
|
||||
@@ -7,16 +7,20 @@ namespace Titano.App.Infrastructure;
|
||||
/// Where the client keeps its data (BRIEF §6.2, <see cref="AppPaths"/>): <c>%LOCALAPPDATA%\Titano</c>, or <c>.\data</c>
|
||||
/// next to the executable when <c>portable.txt</c> exists. Never inside a folder OneDrive synchronises (SQLite corrupts
|
||||
/// there): a portable copy in one keeps its data in <c>%LOCALAPPDATA%\Titano</c>, and Settings tells the user so
|
||||
/// (<see cref="SyncedFolder"/>).
|
||||
/// (<see cref="PortableSyncRoot"/>, <see cref="EarlierPortableData"/>). When that folder itself lies in one, nowhere
|
||||
/// is safe: Titano starts all the same and Settings warns (<see cref="SyncedFolder"/>).
|
||||
/// </summary>
|
||||
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
|
||||
/// <summary>A throw-away environment for <c>--capture</c>: nothing of the user's data is read or written.</summary>
|
||||
public bool IsCapture { get; }
|
||||
|
||||
/// <summary>The OneDrive folder this portable copy runs from; its data is in <c>%LOCALAPPDATA%\Titano</c> instead of <c>.\data</c>. Null otherwise.</summary>
|
||||
/// <summary>The OneDrive folder <see cref="DataDirectory"/> itself lies in, where the index may be damaged; null when it is safe.</summary>
|
||||
public string? SyncedFolder { get; }
|
||||
|
||||
/// <summary>The OneDrive folder this portable copy runs from; its data is in <c>%LOCALAPPDATA%\Titano</c> instead of <c>.\data</c>. Null otherwise.</summary>
|
||||
public string? PortableSyncRoot { get; }
|
||||
|
||||
/// <summary>The <c>.\data</c> folder this portable copy used before it ran from OneDrive, left as it was; null when there is none.</summary>
|
||||
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);
|
||||
|
||||
/// <summary>The environment of this process: its executable's folder and the user's OneDrive folders decide.</summary>
|
||||
public static AppEnvironment Detect() => From(AppPaths.Resolve());
|
||||
|
||||
/// <summary>The environment at <paramref name="paths"/> (its folders are created).</summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>A fresh temporary data folder for screenshots and smoke tests; delete it with <see cref="DeleteCaptureData"/>.</summary>
|
||||
public static AppEnvironment ForCapture() =>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,20 +6,22 @@ namespace Titano.Core.Windows.Shell;
|
||||
/// Where the desktop programs keep their data (BRIEF §6.2, <see cref="DataLocation"/>): <c>%LOCALAPPDATA%\Titano</c>, or
|
||||
/// <c>.\data</c> next to the executable in portable mode. SQLite corrupts inside synchronised folders, so a portable
|
||||
/// copy in a OneDrive folder keeps its data in <c>%LOCALAPPDATA%\Titano</c> instead (<see cref="PortableSyncRoot"/>
|
||||
/// names that folder to tell the user), and a data root still under OneDrive is reported by <see cref="SyncedFolder"/>
|
||||
/// and refused by <see cref="CreateDirectories"/>.
|
||||
/// names that folder to tell the user, <see cref="EarlierPortableData"/> the data it kept there before), and a data
|
||||
/// root still under OneDrive is reported by <see cref="SyncedFolder"/> and refused by <see cref="CreateDirectories"/>.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>A portable copy, also when its data had to go to <c>%LOCALAPPDATA%\Titano</c>.</summary>
|
||||
@@ -43,6 +45,12 @@ public sealed class AppPaths
|
||||
/// <summary>The OneDrive sync root a portable copy runs from, whose data is in <c>%LOCALAPPDATA%\Titano</c> instead; null otherwise.</summary>
|
||||
public string? PortableSyncRoot { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The <c>.\data</c> 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.
|
||||
/// </summary>
|
||||
public string? EarlierPortableData { get; }
|
||||
|
||||
/// <summary>Paths for this process: the executable's folder decides portable mode.</summary>
|
||||
public static AppPaths Resolve() => Resolve(AppContext.BaseDirectory, KnownFolders.LocalAppData);
|
||||
|
||||
@@ -51,8 +59,16 @@ public sealed class AppPaths
|
||||
Resolve(applicationDirectory, localAppData, OneDriveFolders.SyncRoots());
|
||||
|
||||
/// <summary>Paths for an executable in <paramref name="applicationDirectory"/>, checked against <paramref name="syncRoots"/>.</summary>
|
||||
public static AppPaths Resolve(string applicationDirectory, string localAppData, IReadOnlyCollection<string> syncRoots) =>
|
||||
new(DataLocation.Choose(applicationDirectory, PortableMode.IsEnabled(applicationDirectory), localAppData, syncRoots));
|
||||
public static AppPaths Resolve(string applicationDirectory, string localAppData, IReadOnlyCollection<string> 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);
|
||||
}
|
||||
|
||||
/// <summary>Creates the data, logs, cache and thumbnails folders.</summary>
|
||||
/// <exception cref="InvalidOperationException">The data root lies inside a OneDrive-synced folder.</exception>
|
||||
|
||||
Reference in new issue
Block a user