feat(windows): add shell launcher, taskbar progress and app paths
ShellLauncher opens only http(s) and ms-windows-store URLs and reveals files
(SHOpenFolderAndSelectItems) or folders ("explore") on an STA. TaskbarProgress
wraps ITaskbarList3 and returns false for null or stale windows. KnownFolders
reads LocalAppData/Pictures via SHGetKnownFolderPath. AppPaths resolves the
data root (%LOCALAPPDATA%\Titano or .\data in portable mode) and refuses to
create it inside a OneDrive sync root (environment variables and
HKCU\Software\Microsoft\OneDrive\Accounts\*\UserFolder).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
8 files changed
+508
No files matched your search
@@ -0,0 +1,64 @@
|
||||
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"/>.
|
||||
/// </summary>
|
||||
public sealed class AppPaths
|
||||
{
|
||||
public const string ProductFolderName = "Titano";
|
||||
public const string DatabaseFileName = "titano.db";
|
||||
|
||||
private AppPaths(string dataRoot, bool isPortable, string? syncedFolder)
|
||||
{
|
||||
DataRoot = dataRoot;
|
||||
IsPortable = isPortable;
|
||||
SyncedFolder = syncedFolder;
|
||||
}
|
||||
|
||||
public bool IsPortable { get; }
|
||||
|
||||
public string DataRoot { get; }
|
||||
|
||||
public string DatabasePath => Path.Combine(DataRoot, DatabaseFileName);
|
||||
|
||||
public string LogsDirectory => Path.Combine(DataRoot, "logs");
|
||||
|
||||
public string CacheDirectory => Path.Combine(DataRoot, "cache");
|
||||
|
||||
public string ThumbnailsDirectory => Path.Combine(DataRoot, "thumbnails");
|
||||
|
||||
/// <summary>The OneDrive sync root containing <see cref="DataRoot"/>, or null when the location is safe.</summary>
|
||||
public string? SyncedFolder { get; }
|
||||
|
||||
public bool IsInSyncedFolder => SyncedFolder is not null;
|
||||
|
||||
/// <summary>Paths for this process: the executable's folder decides portable mode.</summary>
|
||||
public static AppPaths Resolve() => Resolve(AppContext.BaseDirectory, KnownFolders.LocalAppData);
|
||||
|
||||
/// <summary>Paths for an executable in <paramref name="applicationDirectory"/>, checked against the user's OneDrive roots.</summary>
|
||||
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>Creates the data, logs, cache and thumbnails folders.</summary>
|
||||
/// <exception cref="InvalidOperationException">The data root lies inside a OneDrive-synced folder.</exception>
|
||||
public void CreateDirectories()
|
||||
{
|
||||
if (SyncedFolder is not null)
|
||||
throw new InvalidOperationException($"The data folder '{DataRoot}' is inside the OneDrive folder '{SyncedFolder}'; the database would be corrupted by synchronisation.");
|
||||
Directory.CreateDirectory(DataRoot);
|
||||
Directory.CreateDirectory(LogsDirectory);
|
||||
Directory.CreateDirectory(CacheDirectory);
|
||||
Directory.CreateDirectory(ThumbnailsDirectory);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user