Skip to content

Commit

Permalink
Fix identification of Cryptomator drives
Browse files Browse the repository at this point in the history
  • Loading branch information
lg2de committed Jan 3, 2024
1 parent fd5cec8 commit c71bde4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/SimpleAccounting/Infrastructure/ProjectFileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace lg2de.SimpleAccounting.Infrastructure;

using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -15,9 +16,8 @@ namespace lg2de.SimpleAccounting.Infrastructure;

internal class ProjectFileLoader
{
private readonly IFileSystem fileSystem;

private readonly IDialogs dialogs;
private readonly IFileSystem fileSystem;
private readonly IProcess processApi;
private readonly Settings settings;

Expand Down Expand Up @@ -155,14 +155,19 @@ private bool LoadFile(string projectFileName, out bool autoSaveFileLoaded)
return true;
}

[SuppressMessage(
"Minor Code Smell",
"S6605:Collection-specific \"Exists\" method should be used instead of the \"Any\" extension",
Justification = "FP")]
private void UpdateSettings(string projectFileName)
{
this.settings.RecentProject = projectFileName;

var info = this.fileSystem.GetDrives().SingleOrDefault(
x => projectFileName.StartsWith(x.RootPath, StringComparison.InvariantCultureIgnoreCase));
string format = info.GetFormat?.Invoke() ?? string.Empty;
if (format.Contains("cryptomator", StringComparison.InvariantCultureIgnoreCase)
var identifiers = new[] { "cryptomator", "cryptoFs" };
if (identifiers.Any(x => format.Contains(x, StringComparison.InvariantCultureIgnoreCase))
&& !this.settings.SecuredDrives.Contains(info.RootPath))
{
this.settings.SecuredDrives.Add(info.RootPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,10 @@ public async Task LoadProjectFromFileAsync_UserDoesNotWantAutoSaveFileExists_Aut
fileSystem.Received(1).FileDelete("the.fileName~");
}

[Fact]
public async Task LoadProjectFromFileAsync_NewFileOnSecureDrive_StoreOpenedAndFileLoaded()
[Theory]
[InlineData("Cryptomator File System")]
[InlineData("cryptoFs")]
public async Task LoadProjectFromFileAsync_NewFileOnSecureDrive_StoreOpenedAndFileLoaded(string cryptoDriveIdentifier)
{
var sut = CreateSut(out var dialogs, out IFileSystem fileSystem);
fileSystem.FileExists(Arg.Is("K:\\the.fileName")).Returns(true);
Expand All @@ -500,8 +502,11 @@ public async Task LoadProjectFromFileAsync_NewFileOnSecureDrive_StoreOpenedAndFi
_ =>
{
var func1 = new Func<string>(() => "Normal");
var func2 = new Func<string>(() => "Cryptomator File System");
return new[] { (FilePath: "C:\\", GetFormat: func1), (FilePath: "K:\\", GetFormat: func2) };
var func2 = new Func<string>(() => cryptoDriveIdentifier);
return new[]
{
(FilePath: "C:\\", GetFormat: func1), (FilePath: "K:\\", GetFormat: func2)
};
});

(await sut.Awaiting(x => x.ProjectData.LoadFromFileAsync("K:\\the.fileName")).Should()
Expand Down

0 comments on commit c71bde4

Please sign in to comment.