-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathUserSettingsService.cs
More file actions
115 lines (94 loc) · 3.6 KB
/
Copy pathUserSettingsService.cs
File metadata and controls
115 lines (94 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright (c) Files Community
// Licensed under the MIT License.
using Files.App.Utils.Serialization.Implementation;
using System.IO;
using Windows.Storage;
namespace Files.App.Services.Settings
{
internal sealed class UserSettingsService : BaseJsonSettings, IUserSettingsService
{
private IGeneralSettingsService _GeneralSettingsService;
public IGeneralSettingsService GeneralSettingsService
{
get => GetSettingsService(ref _GeneralSettingsService);
}
private IFoldersSettingsService _FoldersSettingsService;
public IFoldersSettingsService FoldersSettingsService
{
get => GetSettingsService(ref _FoldersSettingsService);
}
private IAppearanceSettingsService _AppearanceSettingsService;
public IAppearanceSettingsService AppearanceSettingsService
{
get => GetSettingsService(ref _AppearanceSettingsService);
}
private IInfoPaneSettingsService _InfoPaneSettingsService;
public IInfoPaneSettingsService InfoPaneSettingsService
{
get => GetSettingsService(ref _InfoPaneSettingsService);
}
private ILayoutSettingsService _LayoutSettingsService;
public ILayoutSettingsService LayoutSettingsService
{
get => GetSettingsService(ref _LayoutSettingsService);
}
private IApplicationSettingsService _ApplicationSettingsService;
public IApplicationSettingsService ApplicationSettingsService
{
get => GetSettingsService(ref _ApplicationSettingsService);
}
private IAppSettingsService _AppSettingsService;
public IAppSettingsService AppSettingsService
{
get => GetSettingsService(ref _AppSettingsService);
}
private IDevToolsSettingsService _DevToolsSettingsService;
public IDevToolsSettingsService DevToolsSettingsService
{
get => GetSettingsService(ref _DevToolsSettingsService);
}
public UserSettingsService()
{
SettingsSerializer = new DefaultSettingsSerializer();
Initialize(Path.Combine(ApplicationData.Current.LocalFolder.Path, Constants.LocalSettings.SettingsFolderName, Constants.LocalSettings.UserSettingsFileName));
JsonSettingsSerializer = new DefaultJsonSettingsSerializer();
JsonSettingsDatabase = new CachingJsonSettingsDatabase(SettingsSerializer, JsonSettingsSerializer);
}
public override object ExportSettings()
{
var export = (IDictionary<string, object>)base.ExportSettings();
// Remove session settings
export.Remove(nameof(GeneralSettingsService.LastSessionTabList));
export.Remove(nameof(GeneralSettingsService.LastSessionSelectedTabIndex));
export.Remove(nameof(GeneralSettingsService.LastCrashedTabList));
export.Remove(nameof(GeneralSettingsService.PathHistoryList));
export.Remove(nameof(GeneralSettingsService.PreviousSearchQueriesList));
export.Remove(nameof(GeneralSettingsService.PreviousArchiveExtractionLocations));
return JsonSettingsSerializer.SerializeToJson(export);
}
public override bool ImportSettings(object import)
{
Dictionary<string, object> settingsImport = import switch
{
string s => JsonSettingsSerializer?.DeserializeFromJson<Dictionary<string, object>>(s) ?? [],
Dictionary<string, object> d => d,
_ => [],
};
if (!settingsImport.IsEmpty() && base.ImportSettings(settingsImport))
{
foreach (var item in settingsImport)
{
RaiseOnSettingChangedEvent(this, new SettingChangedEventArgs(item.Key, item.Value));
}
return true;
}
return false;
}
private TSettingsService GetSettingsService<TSettingsService>(ref TSettingsService settingsServiceMember)
where TSettingsService : class, IBaseSettingsService
{
settingsServiceMember ??= Ioc.Default.GetService<TSettingsService>()!;
return settingsServiceMember;
}
}
}