merge: desktop settings fixes (V-4, V-6, V-7, V-30, V-31, V-32, V-34, ENG-08)
Merge branch fix2/desktop-settings into the verification branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
34 files changed
+1132
-171
No files matched your search
@@ -0,0 +1,52 @@
|
||||
namespace Titano.Core.IO;
|
||||
|
||||
/// <summary>
|
||||
/// Where the desktop client keeps its data (BRIEF §6.2): the per-user folder (<c>%LOCALAPPDATA%\Titano</c>), or
|
||||
/// <c>.\data</c> next to the executable of a portable copy (a <c>portable.txt</c> beside it). SQLite corrupts inside
|
||||
/// synchronised folders, so a portable copy in a folder OneDrive synchronises (a OneDrive folder, or a Desktop or
|
||||
/// Documents folder moved into one) keeps its data in the per-user folder instead, and <see cref="PortableSyncRoot"/>
|
||||
/// says so, to tell the user. Paths are full paths; a folder lies in a sync root when its whole leading segments are
|
||||
/// that root's, ignoring case as Windows does.
|
||||
/// </summary>
|
||||
/// <param name="Root">The data folder.</param>
|
||||
/// <param name="IsPortable">The copy is portable, also when its data had to go to the per-user folder.</param>
|
||||
/// <param name="SyncedFolder">The sync root that contains <paramref name="Root"/> itself; null when the data is safe there.</param>
|
||||
/// <param name="PortableSyncRoot">The sync root a portable copy runs from, whose data went to the per-user folder instead; null otherwise.</param>
|
||||
public sealed record DataLocation(string Root, bool IsPortable, string? SyncedFolder, string? PortableSyncRoot)
|
||||
{
|
||||
/// <summary>The data folder's name under the user's local application data.</summary>
|
||||
public const string ProductFolderName = "Titano";
|
||||
|
||||
/// <summary>The data folder's name next to a portable copy's executable.</summary>
|
||||
public const string PortableFolderName = "data";
|
||||
|
||||
/// <summary>
|
||||
/// The data folder of a copy in <paramref name="applicationDirectory"/> (<paramref name="portable"/> when it has a
|
||||
/// <c>portable.txt</c>), given the user's local application data and the OneDrive sync roots.
|
||||
/// </summary>
|
||||
public static DataLocation Choose(string applicationDirectory, bool portable, string localAppData, IReadOnlyCollection<string> syncRoots)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(applicationDirectory);
|
||||
ArgumentNullException.ThrowIfNull(localAppData);
|
||||
ArgumentNullException.ThrowIfNull(syncRoots);
|
||||
var perUser = Path.GetFullPath(Path.Combine(localAppData, ProductFolderName));
|
||||
if (!portable) return new DataLocation(perUser, false, SyncRootOf(perUser, syncRoots), null);
|
||||
var beside = Path.GetFullPath(Path.Combine(applicationDirectory, PortableFolderName));
|
||||
return SyncRootOf(beside, syncRoots) is { } synced
|
||||
? new DataLocation(perUser, true, SyncRootOf(perUser, syncRoots), synced)
|
||||
: new DataLocation(beside, true, null, null);
|
||||
}
|
||||
|
||||
/// <summary>The sync root that contains <paramref name="path"/>, or null.</summary>
|
||||
public static string? SyncRootOf(string path, IEnumerable<string> syncRoots) => syncRoots.FirstOrDefault(root => IsUnder(path, root));
|
||||
|
||||
/// <summary>True when <paramref name="path"/> equals <paramref name="root"/> or lies below it (whole path segments, case-insensitive).</summary>
|
||||
public static bool IsUnder(string path, string root)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(path);
|
||||
ArgumentNullException.ThrowIfNull(root);
|
||||
var trimmedRoot = root.TrimEnd('\\', '/');
|
||||
if (trimmedRoot.Length == 0 || !path.StartsWith(trimmedRoot, StringComparison.OrdinalIgnoreCase)) return false;
|
||||
return path.Length == trimmedRoot.Length || path[trimmedRoot.Length] is '\\' or '/';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace Titano.Core.IO;
|
||||
|
||||
/// <summary>
|
||||
/// Whether Windows runs a sign-in entry (<see cref="StartupCommand"/>). Task Manager's Startup tab and Settings › Apps ›
|
||||
/// Startup turn an entry off without touching its Run value: they write a binary value of the same name under
|
||||
/// <see cref="RunKey"/> whose first byte is odd while the entry is off (0x03) and even once it is on again (0x02). An
|
||||
/// entry without that value is on. Rewriting the Run value leaves it as it is, so turning an entry back on means
|
||||
/// removing it.
|
||||
/// </summary>
|
||||
public static class StartupApproval
|
||||
{
|
||||
public const string RunKey = @"Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run";
|
||||
|
||||
/// <summary>The entry is turned off according to its StartupApproved <paramref name="state"/> (null when it has none).</summary>
|
||||
public static bool IsTurnedOff(byte[]? state) => state is { Length: > 0 } && (state[0] & 1) != 0;
|
||||
}
|
||||
Reference in new issue
Block a user