Skip to content

Commit

Permalink
Code Quality: Moving registry database to Files.App (#15357)
Browse files Browse the repository at this point in the history
  • Loading branch information
hez2010 committed May 12, 2024
1 parent 4929d98 commit a69c57b
Show file tree
Hide file tree
Showing 54 changed files with 62 additions and 285 deletions.
7 changes: 0 additions & 7 deletions src/Files.App (Package)/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,6 @@
<Path>Files.App.Server\Files.App.Server.exe</Path>
<Instancing>singleInstance</Instancing>
<ActivatableClass ActivatableClassId="Files.App.Server.AppInstanceMonitor" />
<ActivatableClass ActivatableClassId="Files.App.Server.Database.FileTagsDatabase" />
<ActivatableClass ActivatableClassId="Files.App.Server.Database.LayoutPreferencesDatabase" />
<ActivatableClass ActivatableClassId="Files.App.Server.Data.ColumnPreferences" />
<ActivatableClass ActivatableClassId="Files.App.Server.Data.ColumnPreferencesItem" />
<ActivatableClass ActivatableClassId="Files.App.Server.Data.TaggedFile" />
<ActivatableClass ActivatableClassId="Files.App.Server.Data.LayoutPreferences" />
<ActivatableClass ActivatableClassId="Files.App.Server.Data.LayoutPreferencesItem" />
</OutOfProcessServer>
</Extension>
</Extensions>
Expand Down
24 changes: 0 additions & 24 deletions src/Files.App.Server/Data/ColumnPreferences.cs

This file was deleted.

12 changes: 0 additions & 12 deletions src/Files.App.Server/Data/ColumnPreferencesItem.cs

This file was deleted.

16 changes: 0 additions & 16 deletions src/Files.App.Server/Data/LayoutPreferences.cs

This file was deleted.

25 changes: 0 additions & 25 deletions src/Files.App.Server/Data/LayoutPreferencesItem.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/Files.App.Server/Files.App.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<ItemGroup>
<Manifest Include="app.manifest" />
<TrimmerRootAssembly Include="Files.App.Server" />
<PackageReference Include="LiteDB" Version="5.0.19" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.7" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.1.647-beta" PrivateAssets="all" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions src/Files.App/Actions/Display/GroupAction.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Server.Data.Enums;

namespace Files.App.Actions
{
internal sealed class GroupByNoneAction : GroupByAction
Expand Down
2 changes: 0 additions & 2 deletions src/Files.App/Actions/Display/SortAction.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Server.Data.Enums;

namespace Files.App.Actions
{
internal sealed class SortByNameAction : SortByAction
Expand Down
3 changes: 0 additions & 3 deletions src/Files.App/Data/Contexts/DisplayPage/DisplayPageContext.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Server.Data.Enums;
using static Files.App.Constants;

namespace Files.App.Data.Contexts
{
internal sealed class DisplayPageContext : ObservableObject, IDisplayPageContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Server.Data.Enums;

namespace Files.App.Data.Contexts
{
public interface IDisplayPageContext : INotifyPropertyChanging, INotifyPropertyChanged
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Server.Data.Enums
namespace Files.App.Data.Enums
{
public enum FolderLayoutModes
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Server.Data.Enums
namespace Files.App.Data.Enums
{
public enum GroupByDateUnit
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Server.Data.Enums
namespace Files.App.Data.Enums
{
public enum GroupOption
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Server.Data.Enums
namespace Files.App.Data.Enums
{
/// <summary>
/// SortDirection is used instead of the CommunityToolkit equivalent because it is tied to the model
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Server.Data.Enums
namespace Files.App.Data.Enums
{
public enum SortOption
{
Expand Down
2 changes: 0 additions & 2 deletions src/Files.App/Data/EventArguments/LayoutModeEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Server.Data.Enums;

namespace Files.App.Data.EventArguments
{
public sealed class LayoutModeEventArgs
Expand Down
5 changes: 5 additions & 0 deletions src/Files.App/Data/Items/DetailsLayoutColumnItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public double UserLengthPixels
}

private double _NormalMaxLength = 800;

[RegistryIgnore]
public double NormalMaxLength
{
get => _NormalMaxLength;
Expand All @@ -36,6 +38,7 @@ public bool UserCollapsed
}
}

[RegistryIgnore]
public bool IsResizable { get; set; } = true;

public double MinLength
Expand Down Expand Up @@ -65,6 +68,7 @@ public bool IsHidden

private double _NormalMinLength = 50;

[RegistryIgnore]
public double NormalMinLength
{
get => _NormalMinLength;
Expand All @@ -77,6 +81,7 @@ public double NormalMinLength

private GridLength _UserLength = new(200, GridUnitType.Pixel);

[RegistryIgnore]
public GridLength UserLength
{
get => _UserLength;
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Data/Models/ColumnsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public sealed class ColumnsViewModel : ObservableObject
IsResizable = false,
};

[RegistryIgnore]
public DetailsLayoutColumnItem IconColumn
{
get => iconColumn;
Expand Down
2 changes: 0 additions & 2 deletions src/Files.App/Data/Models/CurrentInstanceViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Server.Data.Enums;

namespace Files.App.Data.Models
{
public sealed class CurrentInstanceViewModel : ObservableObject
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/Data/Models/ItemViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Server.Data.Enums;
using Files.App.Services.SizeProvider;
using Files.Shared.Helpers;
using LibGit2Sharp;
Expand Down
2 changes: 0 additions & 2 deletions src/Files.App/Extensions/GroupOptionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Server.Data.Enums;

namespace Files.App.Extensions
{
public static class GroupOptionExtensions
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Files.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<PackageReference Include="FluentFTP" Version="43.0.1" />
<PackageReference Include="ini-parser-netstandard" Version="2.5.2" />
<PackageReference Include="LibGit2Sharp" Version="0.30.0" />
<PackageReference Include="LiteDB" Version="5.0.19" />
<PackageReference Include="LiveChartsCore.SkiaSharpView.WinUI" Version="2.0.0-rc1.2" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.3" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.3" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Server.Data;
using LiteDB;
using Microsoft.Win32;
using System.IO;
using System.Runtime.CompilerServices;
using Windows.ApplicationModel;
using Windows.Storage;
using static Files.App.Server.Data.LayoutPreferencesRegistry;
using static Files.App.Server.Utils.RegistryUtils;
using static Files.App.Helpers.LayoutPreferencesDatabaseItemRegistry;
using static Files.App.Helpers.RegistryHelpers;
using JsonSerializer = System.Text.Json.JsonSerializer;

namespace Files.App.Server.Database
namespace Files.App.Helpers
{
public sealed class LayoutPreferencesDatabase
{
Expand All @@ -30,7 +30,7 @@ static LayoutPreferencesDatabase()
Upgrade = true
}))
{
ImportCore(database.GetCollection<LayoutPreferences>(LayoutSettingsCollectionName).FindAll().ToArray());
ImportCore(database.GetCollection<LayoutPreferencesDatabaseItem>(LayoutSettingsCollectionName).FindAll().ToArray());
}

File.Delete(LayoutSettingsDbPath);
Expand All @@ -51,7 +51,7 @@ public void SetPreferences(string filePath, ulong? frn, LayoutPreferencesItem? p
if (preferencesItem is not null)
{
// Insert new tagged file (Id will be auto-incremented)
var newPref = new LayoutPreferences()
var newPref = new LayoutPreferencesDatabaseItem()
{
FilePath = filePath,
Frn = frn,
Expand All @@ -77,7 +77,7 @@ public void SetPreferences(string filePath, ulong? frn, LayoutPreferencesItem? p
}
}

void UpdateValues(LayoutPreferences? preferences)
void UpdateValues(LayoutPreferencesDatabaseItem? preferences)
{
if (filePath is not null)
{
Expand All @@ -100,12 +100,12 @@ public void ResetAll()

public void Import(string json)
{
var preferences = JsonSerializer.Deserialize<LayoutPreferences[]>(json);
var preferences = JsonSerializer.Deserialize<LayoutPreferencesDatabaseItem[]>(json);
ImportCore(preferences);
}


private static void ImportCore(LayoutPreferences[]? preferences)
private static void ImportCore(LayoutPreferencesDatabaseItem[]? preferences)
{
Registry.CurrentUser.DeleteSubKeyTree(LayoutSettingsKey, false);
if (preferences is null)
Expand All @@ -126,12 +126,12 @@ private static void ImportCore(LayoutPreferences[]? preferences)

public string Export()
{
var list = new List<LayoutPreferences>();
var list = new List<LayoutPreferencesDatabaseItem>();
IterateKeys(list, LayoutSettingsKey, 0);
return JsonSerializer.Serialize(list);
}

private void IterateKeys(List<LayoutPreferences> list, string path, int depth)
private void IterateKeys(List<LayoutPreferencesDatabaseItem> list, string path, int depth)
{
using var key = Registry.CurrentUser.OpenSubKey(path);
if (key is null)
Expand All @@ -141,7 +141,7 @@ private void IterateKeys(List<LayoutPreferences> list, string path, int depth)

if (key.ValueCount > 0)
{
var preference = new LayoutPreferences();
var preference = new LayoutPreferencesDatabaseItem();
BindValues(key, preference);
list.Add(preference);
}
Expand All @@ -158,21 +158,21 @@ private void IterateKeys(List<LayoutPreferences> list, string path, int depth)
}
}

private LayoutPreferences? FindPreferences(string filePath, ulong? frn)
private LayoutPreferencesDatabaseItem? FindPreferences(string filePath, ulong? frn)
{
if (filePath is not null)
{
using var filePathKey = Registry.CurrentUser.CreateSubKey(CombineKeys(LayoutSettingsKey, filePath));
if (filePathKey.ValueCount > 0)
{
var preference = new LayoutPreferences();
var preference = new LayoutPreferencesDatabaseItem();
BindValues(filePathKey, preference);
if (frn is not null)
{
// Keep entry updated
preference.Frn = frn;
var value = frn.Value;
filePathKey.SetValue(nameof(LayoutPreferences.Frn), Unsafe.As<ulong, long>(ref value), RegistryValueKind.QWord);
filePathKey.SetValue(nameof(LayoutPreferencesDatabaseItem.Frn), Unsafe.As<ulong, long>(ref value), RegistryValueKind.QWord);
}
return preference;
}
Expand All @@ -183,13 +183,13 @@ private void IterateKeys(List<LayoutPreferences> list, string path, int depth)
using var frnKey = Registry.CurrentUser.CreateSubKey(CombineKeys(LayoutSettingsKey, "FRN", frn.Value.ToString()));
if (frnKey.ValueCount > 0)
{
var preference = new LayoutPreferences();
var preference = new LayoutPreferencesDatabaseItem();
BindValues(frnKey, preference);
if (filePath is not null)
{
// Keep entry updated
preference.FilePath = filePath;
frnKey.SetValue(nameof(LayoutPreferences.FilePath), filePath, RegistryValueKind.String);
frnKey.SetValue(nameof(LayoutPreferencesDatabaseItem.FilePath), filePath, RegistryValueKind.String);
}
return preference;
}
Expand Down

0 comments on commit a69c57b

Please sign in to comment.