Skip to content

Commit c71bde4

Browse files
committed
Fix identification of Cryptomator drives
1 parent fd5cec8 commit c71bde4

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/SimpleAccounting/Infrastructure/ProjectFileLoader.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace lg2de.SimpleAccounting.Infrastructure;
66

77
using System;
8+
using System.Diagnostics.CodeAnalysis;
89
using System.Globalization;
910
using System.Linq;
1011
using System.Threading.Tasks;
@@ -15,9 +16,8 @@ namespace lg2de.SimpleAccounting.Infrastructure;
1516

1617
internal class ProjectFileLoader
1718
{
18-
private readonly IFileSystem fileSystem;
19-
2019
private readonly IDialogs dialogs;
20+
private readonly IFileSystem fileSystem;
2121
private readonly IProcess processApi;
2222
private readonly Settings settings;
2323

@@ -155,14 +155,19 @@ private bool LoadFile(string projectFileName, out bool autoSaveFileLoaded)
155155
return true;
156156
}
157157

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

162166
var info = this.fileSystem.GetDrives().SingleOrDefault(
163167
x => projectFileName.StartsWith(x.RootPath, StringComparison.InvariantCultureIgnoreCase));
164168
string format = info.GetFormat?.Invoke() ?? string.Empty;
165-
if (format.Contains("cryptomator", StringComparison.InvariantCultureIgnoreCase)
169+
var identifiers = new[] { "cryptomator", "cryptoFs" };
170+
if (identifiers.Any(x => format.Contains(x, StringComparison.InvariantCultureIgnoreCase))
166171
&& !this.settings.SecuredDrives.Contains(info.RootPath))
167172
{
168173
this.settings.SecuredDrives.Add(info.RootPath);

tests/SimpleAccounting.UnitTests/Presentation/ShellViewModelTests.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,10 @@ public async Task LoadProjectFromFileAsync_UserDoesNotWantAutoSaveFileExists_Aut
490490
fileSystem.Received(1).FileDelete("the.fileName~");
491491
}
492492

493-
[Fact]
494-
public async Task LoadProjectFromFileAsync_NewFileOnSecureDrive_StoreOpenedAndFileLoaded()
493+
[Theory]
494+
[InlineData("Cryptomator File System")]
495+
[InlineData("cryptoFs")]
496+
public async Task LoadProjectFromFileAsync_NewFileOnSecureDrive_StoreOpenedAndFileLoaded(string cryptoDriveIdentifier)
495497
{
496498
var sut = CreateSut(out var dialogs, out IFileSystem fileSystem);
497499
fileSystem.FileExists(Arg.Is("K:\\the.fileName")).Returns(true);
@@ -500,8 +502,11 @@ public async Task LoadProjectFromFileAsync_NewFileOnSecureDrive_StoreOpenedAndFi
500502
_ =>
501503
{
502504
var func1 = new Func<string>(() => "Normal");
503-
var func2 = new Func<string>(() => "Cryptomator File System");
504-
return new[] { (FilePath: "C:\\", GetFormat: func1), (FilePath: "K:\\", GetFormat: func2) };
505+
var func2 = new Func<string>(() => cryptoDriveIdentifier);
506+
return new[]
507+
{
508+
(FilePath: "C:\\", GetFormat: func1), (FilePath: "K:\\", GetFormat: func2)
509+
};
505510
});
506511

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

0 commit comments

Comments
 (0)