fix(app): a portable copy in a OneDrive folder keeps its index outside it
BRIEF §6.2 forbids a SQLite index in a synchronised folder. AppEnvironment.Detect now resolves the data folder through Core.Windows' AppPaths and OneDriveFolders: a portable copy whose .\data would lie under a OneDrive sync root (a OneDrive folder, or a Desktop or Documents folder backed up into one) keeps its data in %LOCALAPPDATA%\Titano and stays portable otherwise; AppEnvironment.SyncedFolder names the OneDrive folder so the user can be told. The pure choice lives in Core/IO/DataLocation (tested on Linux); reading the OneDrive accounts key no longer fails start-up when it cannot be read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
12 files changed
+279
-53
No files matched your search
@@ -1,22 +1,28 @@
|
||||
using Titano.Core.IO;
|
||||
|
||||
namespace Titano.Core.Windows.Shell;
|
||||
|
||||
/// <summary>
|
||||
/// Where the desktop programs keep their data (BRIEF §6.2): <c>%LOCALAPPDATA%\Titano</c>, or <c>.\data</c> next to the
|
||||
/// executable in portable mode. SQLite corrupts inside synchronised folders, so a data root under OneDrive is
|
||||
/// reported by <see cref="SyncedFolder"/> and refused by <see cref="CreateDirectories"/>.
|
||||
/// 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"/>.
|
||||
/// </summary>
|
||||
public sealed class AppPaths
|
||||
{
|
||||
public const string ProductFolderName = "Titano";
|
||||
public const string ProductFolderName = DataLocation.ProductFolderName;
|
||||
public const string DatabaseFileName = "titano.db";
|
||||
|
||||
private AppPaths(string dataRoot, bool isPortable, string? syncedFolder)
|
||||
private AppPaths(DataLocation location)
|
||||
{
|
||||
DataRoot = dataRoot;
|
||||
IsPortable = isPortable;
|
||||
SyncedFolder = syncedFolder;
|
||||
DataRoot = location.Root;
|
||||
IsPortable = location.IsPortable;
|
||||
SyncedFolder = location.SyncedFolder;
|
||||
PortableSyncRoot = location.PortableSyncRoot;
|
||||
}
|
||||
|
||||
/// <summary>A portable copy, also when its data had to go to <c>%LOCALAPPDATA%\Titano</c>.</summary>
|
||||
public bool IsPortable { get; }
|
||||
|
||||
public string DataRoot { get; }
|
||||
@@ -34,6 +40,9 @@ public sealed class AppPaths
|
||||
|
||||
public bool IsInSyncedFolder => SyncedFolder is not null;
|
||||
|
||||
/// <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>Paths for this process: the executable's folder decides portable mode.</summary>
|
||||
public static AppPaths Resolve() => Resolve(AppContext.BaseDirectory, KnownFolders.LocalAppData);
|
||||
|
||||
@@ -41,14 +50,9 @@ public sealed class AppPaths
|
||||
public static AppPaths Resolve(string applicationDirectory, string localAppData) =>
|
||||
Resolve(applicationDirectory, localAppData, OneDriveFolders.SyncRoots());
|
||||
|
||||
internal static AppPaths Resolve(string applicationDirectory, string localAppData, IReadOnlyList<string> syncRoots)
|
||||
{
|
||||
var portable = PortableMode.IsEnabled(applicationDirectory);
|
||||
var root = Path.GetFullPath(portable
|
||||
? Path.Combine(applicationDirectory, PortableMode.DataFolderName)
|
||||
: Path.Combine(localAppData, ProductFolderName));
|
||||
return new AppPaths(root, portable, OneDriveFolders.Containing(root, 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));
|
||||
|
||||
/// <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