Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7af21aab09
|
||
|
|
e5f2835229 | ||
|
|
76b27e86ed
|
No files matched your search
@@ -19,6 +19,13 @@ dotnet test OmniDeck.slnx
|
||||
dotnet run --project src/OmniDeck.App
|
||||
```
|
||||
|
||||
To run a development build beside an installed OmniDeck, give it a data root of its own. Only Debug builds read the variable, so the installed copy keeps its settings, sign-ins and database, and the two run side by side:
|
||||
|
||||
```powershell
|
||||
$env:OMNIDECK_DATA_ROOT = "$env:TEMP\OmniDeck.Dev"
|
||||
dotnet run --project src/OmniDeck.App
|
||||
```
|
||||
|
||||
## Code style & quality gates (enforced in CI)
|
||||
|
||||
- `.editorconfig` is authoritative. `dotnet format OmniDeck.slnx --verify-no-changes` must pass.
|
||||
|
||||
@@ -35,11 +35,13 @@ namespace OmniDeck.App;
|
||||
public partial class OdApp
|
||||
{
|
||||
private readonly OdSingleInstanceGuard _guard;
|
||||
private readonly OdDataRoot _dataRoot;
|
||||
private ServiceProvider? _services;
|
||||
|
||||
internal OdApp(OdSingleInstanceGuard guard)
|
||||
internal OdApp(OdSingleInstanceGuard guard, OdDataRoot dataRoot)
|
||||
{
|
||||
_guard = guard;
|
||||
_dataRoot = dataRoot;
|
||||
}
|
||||
|
||||
/// <summary>The legal documents that ship next to the executable.</summary>
|
||||
@@ -76,10 +78,14 @@ public partial class OdApp
|
||||
private void Start(string[] args)
|
||||
{
|
||||
var startMinimized = args.Contains(OdRunKeyStartup.MinimizedArgument, StringComparer.OrdinalIgnoreCase);
|
||||
var dataRoot = OdDataRoot.Default;
|
||||
var dataRoot = _dataRoot;
|
||||
dataRoot.EnsureCreated();
|
||||
Log.Logger = OdLogging.CreateLogger(dataRoot);
|
||||
Log.ForContext<OdApp>().Information("OmniDeck {Version} starting", OdVersionInfo.FromAssembly(typeof(OdApp).Assembly).DisplayText);
|
||||
if (!dataRoot.IsDefault)
|
||||
{
|
||||
Log.ForContext<OdApp>().Warning("Development data root in use: {DataRoot}", dataRoot.Root);
|
||||
}
|
||||
|
||||
// The catalog decides which web-app modules exist, so it loads before the container is built.
|
||||
var catalog = OdCatalogService.LoadInstalled(dataRoot, TimeProvider.System, Log.Logger);
|
||||
|
||||
@@ -19,15 +19,30 @@ internal static class Program
|
||||
.OnBeforeUninstallFastCallback(_ => OdDataRoot.Default.TryDelete())
|
||||
.Run();
|
||||
|
||||
using var guard = new OdSingleInstanceGuard();
|
||||
var dataRoot = DataRoot();
|
||||
using var guard = new OdSingleInstanceGuard(dataRoot.InstanceSuffix);
|
||||
if (!guard.IsPrimaryInstance)
|
||||
{
|
||||
guard.SignalPrimaryInstance();
|
||||
return 0;
|
||||
}
|
||||
|
||||
var app = new OdApp(guard);
|
||||
var app = new OdApp(guard, dataRoot);
|
||||
app.InitializeComponent();
|
||||
return app.Run();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The signed-in user's data root. A Debug build can be pointed elsewhere with
|
||||
/// <see cref="OdDataRoot.OverrideVariable"/>, so it runs beside an installed OmniDeck without
|
||||
/// touching its data; a Release build never reads the variable.
|
||||
/// </summary>
|
||||
private static OdDataRoot DataRoot()
|
||||
{
|
||||
#if DEBUG
|
||||
return OdDataRoot.Choose(Environment.GetEnvironmentVariable(OdDataRoot.OverrideVariable));
|
||||
#else
|
||||
return OdDataRoot.Default;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace OmniDeck.Core.Storage;
|
||||
|
||||
/// <summary>
|
||||
@@ -11,6 +14,13 @@ public sealed class OdDataRoot
|
||||
/// <summary>The data root's folder name under <c>%LocalAppData%</c>.</summary>
|
||||
public const string FolderName = "OmniDeck.Data";
|
||||
|
||||
/// <summary>
|
||||
/// The environment variable a Debug build reads to use a data root of its own, so a development
|
||||
/// copy runs beside an installed OmniDeck without touching its data (CONTRIBUTING.md). Release
|
||||
/// builds never read it.
|
||||
/// </summary>
|
||||
public const string OverrideVariable = "OMNIDECK_DATA_ROOT";
|
||||
|
||||
/// <summary>Velopack's install folder name, which the data root must never be.</summary>
|
||||
private const string InstallFolderName = "OmniDeck";
|
||||
|
||||
@@ -28,8 +38,25 @@ public sealed class OdDataRoot
|
||||
public static OdDataRoot Default { get; } = new(Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), FolderName));
|
||||
|
||||
/// <summary><paramref name="overridePath"/> when it is set, otherwise <see cref="Default"/>.</summary>
|
||||
public static OdDataRoot Choose(string? overridePath) =>
|
||||
string.IsNullOrWhiteSpace(overridePath) ? Default : new OdDataRoot(overridePath);
|
||||
|
||||
public string Root { get; }
|
||||
|
||||
/// <summary>Whether this is the signed-in user's real data root.</summary>
|
||||
public bool IsDefault => string.Equals(
|
||||
Path.TrimEndingDirectorySeparator(Root), Path.TrimEndingDirectorySeparator(Default.Root), StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// Tells single-instance guards apart per data root: <see langword="null"/> for the real one and a
|
||||
/// short hash of the path otherwise, so a development build with a root of its own does not hand
|
||||
/// off to the installed OmniDeck.
|
||||
/// </summary>
|
||||
public string? InstanceSuffix => IsDefault
|
||||
? null
|
||||
: "." + Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(Path.TrimEndingDirectorySeparator(Root).ToUpperInvariant())), 0, 4);
|
||||
|
||||
public string SettingsFile => Path.Combine(Root, "settings.json");
|
||||
|
||||
public string DatabaseFile => Path.Combine(Root, "omnideck.db");
|
||||
|
||||
@@ -34,6 +34,51 @@ public sealed class OdDataRootTests
|
||||
Assert.Throws<ArgumentException>(() => new OdDataRoot(temp.Combine(name)));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public void Choose_WithoutAnOverride_IsTheRealRoot(string? overridePath)
|
||||
{
|
||||
var root = OdDataRoot.Choose(overridePath);
|
||||
|
||||
Assert.Same(OdDataRoot.Default, root);
|
||||
Assert.True(root.IsDefault);
|
||||
Assert.Null(root.InstanceSuffix);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Choose_WithAnOverride_UsesIt_AndGetsAnInstanceOfItsOwn()
|
||||
{
|
||||
using var temp = new OdTempDirectory();
|
||||
var path = temp.Combine("OmniDeck.Dev");
|
||||
|
||||
var root = OdDataRoot.Choose(path);
|
||||
|
||||
Assert.Equal(path, root.Root, StringComparer.OrdinalIgnoreCase);
|
||||
Assert.False(root.IsDefault);
|
||||
Assert.Matches("^\\.[0-9A-F]{8}$", root.InstanceSuffix);
|
||||
Assert.Equal(root.InstanceSuffix, OdDataRoot.Choose(path.ToUpperInvariant() + Path.DirectorySeparatorChar).InstanceSuffix, StringComparer.Ordinal);
|
||||
Assert.NotEqual(root.InstanceSuffix, OdDataRoot.Choose(temp.Combine("OmniDeck.Other")).InstanceSuffix, StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Choose_StillRejectsVelopacksInstallFolder()
|
||||
{
|
||||
using var temp = new OdTempDirectory();
|
||||
|
||||
Assert.Throws<ArgumentException>(() => OdDataRoot.Choose(temp.Combine("OmniDeck")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Choose_TheRealPathItself_CountsAsTheRealRoot()
|
||||
{
|
||||
var root = OdDataRoot.Choose(OdDataRoot.Default.Root + Path.DirectorySeparatorChar);
|
||||
|
||||
Assert.True(root.IsDefault);
|
||||
Assert.Null(root.InstanceSuffix);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsureCreated_ThenTryDelete_LeavesNothing()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user