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
@@ -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