-
-
Notifications
You must be signed in to change notification settings - Fork 697
Expand file tree
/
Copy pathConfig.cs
More file actions
2333 lines (1855 loc) Β· 80.5 KB
/
Config.cs
File metadata and controls
2333 lines (1855 loc) Β· 80.5 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
ImageGlass Project - Image viewer for Windows
Copyright (C) 2010 - 2026 DUONG DIEU PHAP
Project homepage: https://imageglass.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using Cysharp.Text;
using DirectN;
using ImageGlass.Base;
using ImageGlass.Base.Actions;
using ImageGlass.Base.PhotoBox;
using ImageGlass.Base.Photoing.Codecs;
using ImageGlass.Base.WinApi;
using ImageGlass.UI;
using Microsoft.Extensions.Configuration;
using Microsoft.Win32;
using System.Collections.Frozen;
using System.Diagnostics;
using System.Dynamic;
using System.Reflection;
namespace ImageGlass.Settings;
/// <summary>
/// Provides app configuration
/// </summary>
public static class Config
{
#region Internal properties
private static CancellationTokenSource _requestUpdatingColorModeCancelToken = new();
private static bool _isDarkMode = WinColorsApi.IsDarkMode;
private static float Version = 9;
/// <summary>
/// The default image info tags
/// </summary>
public static List<string> DefaultImageInfoTags => [
nameof(ImageInfo.Name),
nameof(ImageInfo.ListCount),
nameof(ImageInfo.FrameCount),
nameof(ImageInfo.Zoom),
nameof(ImageInfo.Dimension),
nameof(ImageInfo.FileSize),
nameof(ImageInfo.ColorSpace),
nameof(ImageInfo.ExifRating),
nameof(ImageInfo.DateTimeAuto),
nameof(ImageInfo.AppName),
];
/// <summary>
/// Gets, sets current theme.
/// </summary>
public static IgTheme Theme { get; set; } = new();
/// <summary>
/// Occurs when the system app color is changed and does not match the current <see cref="Theme"/>'s dark mode.
/// </summary>
public static event RequestUpdatingColorModeHandler? RequestUpdatingColorMode;
public delegate void RequestUpdatingColorModeHandler(SystemColorModeChangedEventArgs e);
/// <summary>
/// Occurs when the <see cref="Config.Theme"/> is requested to change.
/// </summary>
public static event RequestUpdatingThemeHandler? RequestUpdatingTheme;
public delegate void RequestUpdatingThemeHandler(RequestUpdatingThemeEventArgs e);
/// <summary>
/// Occurs when the <see cref="Config.Language"/> is requested to change.
/// </summary>
public static event RequestUpdatingLanguageHandler? RequestUpdatingLanguage;
public delegate void RequestUpdatingLanguageHandler();
#endregion
#region Setting items
/// <summary>
/// Gets, sets the config section of tool settings.
/// </summary>
public static ExpandoObject ToolSettings { get; set; } = new();
#region Boolean items
/// <summary>
/// Gets, sets value indicating whether the slideshow mode is enabled or not.
/// </summary>
public static bool EnableSlideshow { get; set; } = false;
/// <summary>
/// Gets, sets value indicating whether the FrmMain should be hidden when <see cref="EnableSlideshow"/> is on.
/// </summary>
public static bool HideMainWindowInSlideshow { get; set; } = true;
/// <summary>
/// Gets, sets value if the countdown timer is shown or not.
/// </summary>
public static bool ShowSlideshowCountdown { get; set; } = true;
/// <summary>
/// Gets, sets value indicates whether the slide show interval is random.
/// </summary>
public static bool UseRandomIntervalForSlideshow { get; set; } = false;
/// <summary>
/// Gets, sets value indicates that slideshow will loop back to the first image when reaching the end of list.
/// </summary>
public static bool EnableLoopSlideshow { get; set; } = true;
/// <summary>
/// Gets, sets value indicates that slideshow is played in full screen, not window mode.
/// </summary>
public static bool EnableFullscreenSlideshow { get; set; } = true;
/// <summary>
/// Gets, sets value of FrmMain's frameless mode.
/// </summary>
public static bool EnableFrameless { get; set; } = false;
/// <summary>
/// Gets, sets value indicating whether the full screen mode is enabled or not.
/// </summary>
public static bool EnableFullScreen { get; set; } = false;
/// <summary>
/// Gets, sets value indicates that the toolbar should be hidden in Full screen mode
/// </summary>
public static bool HideToolbarInFullscreen { get; set; } = false;
/// <summary>
/// Gets, sets value indicates that the gallery should be hidden in Full screen mode
/// </summary>
public static bool HideGalleryInFullscreen { get; set; } = false;
/// <summary>
/// Gets, sets value of gallery visibility
/// </summary>
public static bool ShowGallery { get; set; } = true;
/// <summary>
/// Gets, sets value whether gallery scrollbars visible
/// </summary>
public static bool ShowGalleryScrollbars { get; set; } = false;
/// <summary>
/// Gets, sets value indicates that showing image file name on gallery
/// </summary>
public static bool ShowGalleryFileName { get; set; } = true;
/// <summary>
/// Gets, sets welcome picture value
/// </summary>
public static bool ShowWelcomeImage { get; set; } = true;
/// <summary>
/// Gets, sets value of visibility of toolbar on start up
/// </summary>
public static bool ShowToolbar { get; set; } = true;
/// <summary>
/// Gets, sets value of visibility of Frame Navigation tool on startup
/// </summary>
public static bool ShowFrameNavTool { get; set; } = false;
/// <summary>
/// Gets, sets value of visibility of app icon
/// </summary>
public static bool ShowAppIcon { get; set; } = true;
/// <summary>
/// Gets, sets value indicating that ImageGlass will loop back viewer to the first image when reaching the end of the list.
/// </summary>
public static bool EnableLoopBackNavigation { get; set; } = true;
/// <summary>
/// Gets, sets value indicating that ImageGlass will automatically switch
/// to the next or previous sibling directory when reaching the boundary
/// of the current image list.
/// </summary>
public static bool EnableAutoSwitchSiblingDir { get; set; } = false;
/// <summary>
/// Gets, sets value indicating that checker board is shown or not
/// </summary>
public static bool ShowCheckerboard { get; set; } = false;
/// <summary>
/// Gets, sets the value indicates whether to show checkerboard in the image region only
/// </summary>
public static bool ShowCheckerboardOnlyImageRegion { get; set; } = false;
/// <summary>
/// Gets, sets value indicating that multi instances is allowed or not
/// </summary>
public static bool EnableMultiInstances { get; set; } = true;
/// <summary>
/// Gets, sets value indicating that FrmMain is always on top or not.
/// </summary>
public static bool EnableWindowTopMost { get; set; } = false;
/// <summary>
/// Gets, sets value indicates that Confirmation dialog is displayed when deleting image
/// </summary>
public static bool ShowDeleteConfirmation { get; set; } = true;
/// <summary>
/// Gets, sets value indicates that Confirmation dialog is displayed when overriding the viewing image
/// </summary>
public static bool ShowSaveOverrideConfirmation { get; set; } = true;
/// <summary>
/// Gets, sets the setting to control whether the image's original modified date value is preserved on save
/// </summary>
public static bool ShouldPreserveModifiedDate { get; set; } = false;
/// <summary>
/// Gets, sets value indicates that Save dialog should use the current image folder as initial directory
/// </summary>
public static bool OpenSaveAsDialogInTheCurrentImageDir { get; set; } = true;
/// <summary>
/// Gets, sets the value indicates that there is a new version
/// </summary>
public static bool ShowNewVersionIndicator { get; set; } = false;
/// <summary>
/// Gets, sets the value indicates that to toolbar buttons to be centered horizontally
/// </summary>
public static bool EnableCenterToolbar { get; set; } = true;
/// <summary>
/// Gets, sets the value indicates that to show last seen image on startup
/// </summary>
public static bool ShouldOpenLastSeenImage { get; set; } = true;
/// <summary>
/// Gets, sets the value indicates that the ColorProfile will be applied for all or only the images with embedded profile
/// </summary>
public static bool ShouldUseColorProfileForAll { get; set; } = false;
/// <summary>
/// Gets, sets the value indicates whether to show or hide the Navigation Buttons on viewer
/// </summary>
public static bool EnableNavigationButtons { get; set; } = true;
/// <summary>
/// Gets, sets recursive value
/// </summary>
public static bool EnableRecursiveLoading { get; set; } = false;
/// <summary>
/// Gets, sets the value indicates that Windows File Explorer sort order is used if possible
/// </summary>
public static bool ShouldUseExplorerSortOrder { get; set; } = true;
/// <summary>
/// Gets, sets the value indicates that images order should be grouped by directory
/// </summary>
public static bool ShouldGroupImagesByDirectory { get; set; } = false;
/// <summary>
/// Gets, sets showing/loading hidden images
/// </summary>
public static bool ShouldLoadHiddenImages { get; set; } = false;
/// <summary>
/// Gets, sets value specifying that Window Fit mode is on
/// </summary>
public static bool EnableWindowFit { get; set; } = false;
/// <summary>
/// Gets, sets value indicates the window should be always center in Window Fit mode
/// </summary>
public static bool CenterWindowFit { get; set; } = true;
/// <summary>
/// Displays the embedded thumbnail for RAW formats if found.
/// </summary>
public static bool UseEmbeddedThumbnailRawFormats { get; set; } = false;
/// <summary>
/// Displays the embedded thumbnail for other formats if found.
/// </summary>
public static bool UseEmbeddedThumbnailOtherFormats { get; set; } = false;
/// <summary>
/// Gets, sets value indicates that image preview is shown while the image is being loaded.
/// </summary>
public static bool ShowImagePreview { get; set; } = true;
/// <summary>
/// Gets, sets value indicates that images should be loaded asynchronously.
/// </summary>
public static bool EnableImageAsyncLoading { get; set; } = true;
/// <summary>
/// Enables / Disables copy multiple files.
/// </summary>
public static bool EnableCopyMultipleFiles { get; set; } = true;
/// <summary>
/// Enables / Disables cut multiple files.
/// </summary>
public static bool EnableCutMultipleFiles { get; set; } = true;
/// <summary>
/// Enables / Disables the file system watcher.
/// </summary>
public static bool EnableRealTimeFileUpdate { get; set; } = true;
/// <summary>
/// Gets, sets value indicates that ImageGlass should open the new image file added in the viewing folder.
/// </summary>
public static bool ShouldAutoOpenNewAddedImage { get; set; } = false;
/// <summary>
/// Uses Webview2 for viewing SVG format.
/// </summary>
public static bool UseWebview2ForSvg { get; set; } = true;
/// <summary>
/// Enables, disables debug mode.
/// </summary>
public static bool EnableDebug { get; set; } = false;
#endregion // Boolean items
#region Number items
/// <summary>
/// Gets, sets the version that requires to open Quick setup ImageGlass dialog.
/// </summary>
public static float QuickSetupVersion { get; set; } = 0f;
/// <summary>
/// Gets, sets 'Left' position of main window
/// </summary>
public static int FrmMainPositionX { get; set; } = 200;
/// <summary>
/// Gets, sets 'Top' position of main window
/// </summary>
public static int FrmMainPositionY { get; set; } = 200;
/// <summary>
/// Gets, sets width of main window
/// </summary>
public static int FrmMainWidth { get; set; } = 1300;
/// <summary>
/// Gets, sets height of main window
/// </summary>
public static int FrmMainHeight { get; set; } = 800;
/// <summary>
/// Gets, sets 'Left' position of settings window
/// </summary>
public static int FrmSettingsPositionX { get; set; } = 200;
/// <summary>
/// Gets, sets 'Top' position of settings window
/// </summary>
public static int FrmSettingsPositionY { get; set; } = 200;
/// <summary>
/// Gets, sets width of settings window
/// </summary>
public static int FrmSettingsWidth { get; set; } = 1300;
/// <summary>
/// Gets, sets height of settings window
/// </summary>
public static int FrmSettingsHeight { get; set; } = 800;
/// <summary>
/// Gets, sets the panning speed.
/// Value range is from 0 to 100.
/// </summary>
public static float PanSpeed { get; set; } = 20f;
/// <summary>
/// Gets, sets the zooming speed.
/// Value range is from -500 to 500.
/// </summary>
public static float ZoomSpeed { get; set; } = 0;
/// <summary>
/// Gets, sets slide show interval (minimum value if it's random)
/// </summary>
public static float SlideshowInterval { get; set; } = 5f;
/// <summary>
/// Gets, sets the maximum slide show interval value
/// </summary>
public static float SlideshowIntervalTo { get; set; } = 5f;
/// <summary>
/// Gets, sets the number of image changes to notify <see cref="SlideshowNotificationSound"/> sound in slideshow mode.
/// </summary>
public static int SlideshowImagesToNotifySound { get; set; } = 0;
/// <summary>
/// Gets, sets value of thumbnail dimension in pixel
/// </summary>
public static int ThumbnailSize { get; set; } = 50;
/// <summary>
/// Gets, sets the maximum size in MB of thumbnail persistent cache.
/// </summary>
public static int GalleryCacheSizeInMb { get; set; } = 400;
/// <summary>
/// Gets, sets number of thumbnail columns displayed in vertical gallery.
/// </summary>
public static int GalleryColumns { get; set; } = 3;
/// <summary>
/// Gets, sets the minimum image dimension to use WIC decoder if the format is supported.
/// </summary>
public static int MinDimensionToUseWIC { get; set; } = 16_000;
/// <summary>
/// Gets, sets the number of images cached by <see cref="Base.Services.ImageBooster"/>.
/// </summary>
public static int ImageBoosterCacheCount { get; set; } = 1;
/// <summary>
/// Gets, sets the maximum image dimension when caching by <see cref="Base.Services.ImageBooster"/>.
/// If this value is <c>less than or equals 0</c>, the option will be ignored.
/// </summary>
public static int ImageBoosterCacheMaxDimension { get; set; } = 8_000;
/// <summary>
/// Gets, sets the maximum image file size (in MB) when caching by <see cref="Base.Services.ImageBooster"/>.
/// If this value is <c>less than or equals 0</c>, the option will be ignored.
/// </summary>
public static float ImageBoosterCacheMaxFileSizeInMb { get; set; } = 100f;
/// <summary>
/// Gets, sets fixed width on zooming
/// </summary>
public static float ZoomLockValue { get; set; } = 100f;
/// <summary>
/// Gets, sets toolbar icon height
/// </summary>
public static uint ToolbarIconHeight { get; set; } = Const.TOOLBAR_ICON_HEIGHT;
/// <summary>
/// Gets, sets value of image quality for editting
/// </summary>
public static uint ImageEditQuality { get; set; } = 80;
/// <summary>
/// Gets, sets value of duration to display the in-app message
/// </summary>
public static int InAppMessageDuration { get; set; } = 2000;
/// <summary>
/// Gets, sets the minimum width of the embedded thumbnail to use for displaying
/// image when the setting <see cref="UseEmbeddedThumbnailRawFormats"/> or <see cref="UseEmbeddedThumbnailOtherFormats"/> is <c>true</c>.
/// </summary>
public static int EmbeddedThumbnailMinWidth { get; set; } = 0;
/// <summary>
/// Gets, sets the minimum height of the embedded thumbnail to use for displaying
/// image when the setting <see cref="UseEmbeddedThumbnailRawFormats"/> or <see cref="UseEmbeddedThumbnailOtherFormats"/> is <c>true</c>.
/// </summary>
public static int EmbeddedThumbnailMinHeight { get; set; } = 0;
#endregion // Number items
#region String items
/// <summary>
/// Gets, sets color profile string. It can be a defined name or ICC/ICM file path
/// </summary>
public static string ColorProfile { get; set; } = nameof(ColorProfileOption.CurrentMonitorProfile);
/// <summary>
/// Gets, sets the last time to check for update. Set it to <c>0</c> to disable auto-update.
/// </summary>
public static string AutoUpdate { get; set; } = DateTime.UtcNow.Subtract(TimeSpan.FromDays(30)).ToISO8601String();
/// <summary>
/// Gets, sets the absolute file path of the last seen image
/// </summary>
public static string LastSeenImagePath { get; set; } = "";
/// <summary>
/// Gets, sets the last view of settings window.
/// </summary>
public static string LastOpenedSetting { get; set; } = string.Empty;
/// <summary>
/// Gets, sets the theme name for dark mode.
/// </summary>
public static string DarkTheme { get; set; } = Const.DEFAULT_THEME;
/// <summary>
/// Gets, sets the theme name for light mode.
/// </summary>
public static string LightTheme { get; set; } = "Kobe-Light";
#endregion
#region Array items
/// <summary>
/// Gets, sets zoom levels of the viewer
/// </summary>
public static float[] ZoomLevels { get; set; } = [];
/// <summary>
/// Gets, sets the list of apps for edit action.
/// </summary>
public static Dictionary<string, EditApp?> EditApps { get; set; } = [];
/// <summary>
/// Gets, sets the list of supported image formats
/// </summary>
public static HashSet<string> FileFormats { get; set; } = [];
/// <summary>
/// Gets, sets the list of formats that only load the first frame forcefully
/// </summary>
public static HashSet<string> SingleFrameFormats { get; set; } = [".avif", ".heic", ".heif", ".psd", ".jxl"];
/// <summary>
/// Gets, sets the list of toolbar buttons
/// </summary>
public static List<ToolbarItemModel> ToolbarButtons { get; set; } = [];
/// <summary>
/// Gets, sets the tags for displaying image info
/// </summary>
public static List<string> ImageInfoTags { get; set; } = DefaultImageInfoTags;
/// <summary>
/// Gets, sets hotkeys list of menu
/// </summary>
public static Dictionary<string, List<Hotkey>> MenuHotkeys { get; set; } = [];
/// <summary>
/// Gets, sets mouse click actions
/// </summary>
public static Dictionary<MouseClickEvent, ToggleAction> MouseClickActions { get; set; } = [];
/// <summary>
/// Gets, sets mouse wheel actions
/// </summary>
public static Dictionary<MouseWheelEvent, MouseWheelAction> MouseWheelActions { get; set; } = [];
/// <summary>
/// Gets, sets layout for FrmMain. Syntax:
/// <c>Dictionary["ControlName", "DockStyle;order"]</c>
/// </summary>
public static Dictionary<string, string?> Layout { get; set; } = [];
/// <summary>
/// Gets, sets tools.
/// </summary>
public static List<IgTool?> Tools { get; set; } = [
new IgTool()
{
ToolId = Const.IGTOOL_EXIFTOOL,
ToolName = "ExifGlass - EXIF metadata viewer",
Executable = "exifglass",
Argument = Const.FILE_MACRO,
IsIntegrated = true,
Hotkeys = [new Hotkey(Keys.X)],
},
];
/// <summary>
/// Gets, sets the list of disabled menus
/// </summary>
public static FrozenSet<string> DisabledMenus { get; set; } = FrozenSet<string>.Empty;
#endregion // Array items
#region Enum items
/// <summary>
/// Gets, sets state of main window
/// </summary>
public static FormWindowState FrmMainState { get; set; } = FormWindowState.Normal;
/// <summary>
/// Gets, sets state of settings window
/// </summary>
public static FormWindowState FrmSettingsState { get; set; } = FormWindowState.Normal;
/// <summary>
/// Gets, sets image loading order
/// </summary>
public static ImageOrderBy ImageLoadingOrder { get; set; } = ImageOrderBy.Name;
/// <summary>
/// Gets, sets image loading order type
/// </summary>
public static ImageOrderType ImageLoadingOrderType { get; set; } = ImageOrderType.Asc;
/// <summary>
/// Gets, sets zoom mode value
/// </summary>
public static ZoomMode ZoomMode { get; set; } = ZoomMode.AutoZoom;
/// <summary>
/// Gets, sets the interpolation mode to render the viewing image when the zoom factor is <c>less than or equals 100%</c>.
/// </summary>
public static ImageInterpolation ImageInterpolationScaleDown { get; set; } = ImageInterpolation.MultiSampleLinear;
/// <summary>
/// Gets, sets the interpolation mode to render the viewing image when the zoom factor is <c>greater than 100%</c>.
/// </summary>
public static ImageInterpolation ImageInterpolationScaleUp { get; set; } = ImageInterpolation.NearestNeighbor;
/// <summary>
/// Gets, sets value indicates what happens after clicking Edit menu
/// </summary>
public static AfterEditAppAction AfterEditingAction { get; set; } = AfterEditAppAction.Nothing;
/// <summary>
/// Gets, sets the interpolation mode to render the viewing image when the zoom factor is <c>greater than 100%</c>.
/// </summary>
public static BackdropStyle WindowBackdrop { get; set; } = BackdropStyle.Mica;
#endregion // Enum items
#region Other types items
/// <summary>
/// Gets, sets background color of of the main window
/// </summary>
public static Color BackgroundColor { get; set; } = Color.Empty;
/// <summary>
/// Gets, sets background color of slideshow
/// </summary>
public static Color SlideshowBackgroundColor { get; set; } = Color.Black;
/// <summary>
/// Gets, sets language pack
/// </summary>
public static IgLang Language { get; set; }
#endregion // Other types items
#endregion // Setting items
#region Public static functions
/// <summary>
/// Loads and parsse configs from file
/// </summary>
public static void Load(IConfigurationRoot? items = null)
{
#nullable disable
items ??= Source.LoadUserConfigs();
// get user config version
Version = items.GetValue<float>($"_Metadata:{nameof(Version)}");
// save the config for all tools
ToolSettings = items.GetValueObj(nameof(ToolSettings)).GetValue(nameof(ToolSettings), new ExpandoObject());
// Boolean values
#region Boolean items
EnableSlideshow = items.GetValueEx(nameof(EnableSlideshow), EnableSlideshow);
HideMainWindowInSlideshow = items.GetValueEx(nameof(HideMainWindowInSlideshow), HideMainWindowInSlideshow);
ShowSlideshowCountdown = items.GetValueEx(nameof(ShowSlideshowCountdown), ShowSlideshowCountdown);
UseRandomIntervalForSlideshow = items.GetValueEx(nameof(UseRandomIntervalForSlideshow), UseRandomIntervalForSlideshow);
EnableLoopSlideshow = items.GetValueEx(nameof(EnableLoopSlideshow), EnableLoopSlideshow);
EnableFullscreenSlideshow = items.GetValueEx(nameof(EnableFullscreenSlideshow), EnableFullscreenSlideshow);
EnableFrameless = items.GetValueEx(nameof(EnableFrameless), EnableFrameless);
EnableFullScreen = items.GetValueEx(nameof(EnableFullScreen), EnableFullScreen);
ShowGallery = items.GetValueEx(nameof(ShowGallery), ShowGallery);
ShowGalleryScrollbars = items.GetValueEx(nameof(ShowGalleryScrollbars), ShowGalleryScrollbars);
ShowGalleryFileName = items.GetValueEx(nameof(ShowGalleryFileName), ShowGalleryFileName);
ShowWelcomeImage = items.GetValueEx(nameof(ShowWelcomeImage), ShowWelcomeImage);
ShowToolbar = items.GetValueEx(nameof(ShowToolbar), ShowToolbar);
ShowFrameNavTool = items.GetValueEx(nameof(ShowFrameNavTool), ShowFrameNavTool);
ShowAppIcon = items.GetValueEx(nameof(ShowAppIcon), ShowAppIcon);
EnableLoopBackNavigation = items.GetValueEx(nameof(EnableLoopBackNavigation), EnableLoopBackNavigation);
EnableAutoSwitchSiblingDir = items.GetValueEx(nameof(EnableAutoSwitchSiblingDir), EnableAutoSwitchSiblingDir);
ShowCheckerboard = items.GetValueEx(nameof(ShowCheckerboard), ShowCheckerboard);
ShowCheckerboardOnlyImageRegion = items.GetValueEx(nameof(ShowCheckerboardOnlyImageRegion), ShowCheckerboardOnlyImageRegion);
EnableMultiInstances = items.GetValueEx(nameof(EnableMultiInstances), EnableMultiInstances);
EnableWindowTopMost = items.GetValueEx(nameof(EnableWindowTopMost), EnableWindowTopMost);
ShowDeleteConfirmation = items.GetValueEx(nameof(ShowDeleteConfirmation), ShowDeleteConfirmation);
ShowSaveOverrideConfirmation = items.GetValueEx(nameof(ShowSaveOverrideConfirmation), ShowSaveOverrideConfirmation);
ShouldPreserveModifiedDate = items.GetValueEx(nameof(ShouldPreserveModifiedDate), ShouldPreserveModifiedDate);
OpenSaveAsDialogInTheCurrentImageDir = items.GetValueEx(nameof(OpenSaveAsDialogInTheCurrentImageDir), OpenSaveAsDialogInTheCurrentImageDir);
ShowNewVersionIndicator = items.GetValueEx(nameof(ShowNewVersionIndicator), ShowNewVersionIndicator);
EnableCenterToolbar = items.GetValueEx(nameof(EnableCenterToolbar), EnableCenterToolbar);
ShouldOpenLastSeenImage = items.GetValueEx(nameof(ShouldOpenLastSeenImage), ShouldOpenLastSeenImage);
ShouldUseColorProfileForAll = items.GetValueEx(nameof(ShouldUseColorProfileForAll), ShouldUseColorProfileForAll);
EnableNavigationButtons = items.GetValueEx(nameof(EnableNavigationButtons), EnableNavigationButtons);
EnableRecursiveLoading = items.GetValueEx(nameof(EnableRecursiveLoading), EnableRecursiveLoading);
ShouldUseExplorerSortOrder = items.GetValueEx(nameof(ShouldUseExplorerSortOrder), ShouldUseExplorerSortOrder);
ShouldGroupImagesByDirectory = items.GetValueEx(nameof(ShouldGroupImagesByDirectory), ShouldGroupImagesByDirectory);
ShouldLoadHiddenImages = items.GetValueEx(nameof(ShouldLoadHiddenImages), ShouldLoadHiddenImages);
EnableWindowFit = items.GetValueEx(nameof(EnableWindowFit), EnableWindowFit);
CenterWindowFit = items.GetValueEx(nameof(CenterWindowFit), CenterWindowFit);
UseEmbeddedThumbnailRawFormats = items.GetValueEx(nameof(UseEmbeddedThumbnailRawFormats), UseEmbeddedThumbnailRawFormats);
UseEmbeddedThumbnailOtherFormats = items.GetValueEx(nameof(UseEmbeddedThumbnailOtherFormats), UseEmbeddedThumbnailOtherFormats);
ShowImagePreview = items.GetValueEx(nameof(ShowImagePreview), ShowImagePreview);
EnableImageAsyncLoading = items.GetValueEx(nameof(EnableImageAsyncLoading), EnableImageAsyncLoading);
EnableCopyMultipleFiles = items.GetValueEx(nameof(EnableCopyMultipleFiles), EnableCopyMultipleFiles);
EnableCutMultipleFiles = items.GetValueEx(nameof(EnableCutMultipleFiles), EnableCutMultipleFiles);
EnableRealTimeFileUpdate = items.GetValueEx(nameof(EnableRealTimeFileUpdate), EnableRealTimeFileUpdate);
ShouldAutoOpenNewAddedImage = items.GetValueEx(nameof(ShouldAutoOpenNewAddedImage), ShouldAutoOpenNewAddedImage);
UseWebview2ForSvg = items.GetValueEx(nameof(UseWebview2ForSvg), UseWebview2ForSvg);
EnableDebug = items.GetValueEx(nameof(EnableDebug), EnableDebug);
HideToolbarInFullscreen = items.GetValueEx(nameof(HideToolbarInFullscreen), HideToolbarInFullscreen);
HideGalleryInFullscreen = items.GetValueEx(nameof(HideGalleryInFullscreen), HideGalleryInFullscreen);
#endregion
// Number values
#region Number items
QuickSetupVersion = items.GetValueEx(nameof(QuickSetupVersion), QuickSetupVersion);
// FrmMain
FrmMainPositionX = items.GetValueEx(nameof(FrmMainPositionX), FrmMainPositionX);
FrmMainPositionY = items.GetValueEx(nameof(FrmMainPositionY), FrmMainPositionY);
FrmMainWidth = items.GetValueEx(nameof(FrmMainWidth), FrmMainWidth);
FrmMainHeight = items.GetValueEx(nameof(FrmMainHeight), FrmMainHeight);
// FrmSettings
FrmSettingsPositionX = items.GetValueEx(nameof(FrmSettingsPositionX), FrmSettingsPositionX);
FrmSettingsPositionY = items.GetValueEx(nameof(FrmSettingsPositionY), FrmSettingsPositionY);
FrmSettingsWidth = items.GetValueEx(nameof(FrmSettingsWidth), FrmSettingsWidth);
FrmSettingsHeight = items.GetValueEx(nameof(FrmSettingsHeight), FrmSettingsHeight);
PanSpeed = items.GetValueEx(nameof(PanSpeed), PanSpeed);
ZoomSpeed = items.GetValueEx(nameof(ZoomSpeed), ZoomSpeed);
#region Slideshow
SlideshowInterval = items.GetValueEx(nameof(SlideshowInterval), SlideshowInterval);
if (SlideshowInterval <= 0) SlideshowInterval = 5f;
SlideshowIntervalTo = items.GetValueEx(nameof(SlideshowIntervalTo), SlideshowIntervalTo);
SlideshowIntervalTo = Math.Max(SlideshowIntervalTo, SlideshowInterval);
SlideshowImagesToNotifySound = items.GetValueEx(nameof(SlideshowImagesToNotifySound), SlideshowImagesToNotifySound);
#endregion
#region Load gallery thumbnail width & position
ThumbnailSize = items.GetValueEx(nameof(ThumbnailSize), ThumbnailSize);
ThumbnailSize = Math.Max(20, ThumbnailSize);
GalleryCacheSizeInMb = items.GetValueEx(nameof(GalleryCacheSizeInMb), GalleryCacheSizeInMb);
GalleryColumns = items.GetValueEx(nameof(GalleryColumns), GalleryColumns);
GalleryColumns = Math.Max(1, GalleryColumns);
#endregion
MinDimensionToUseWIC = items.GetValueEx(nameof(MinDimensionToUseWIC), MinDimensionToUseWIC);
MinDimensionToUseWIC = Math.Max(0, MinDimensionToUseWIC);
ImageBoosterCacheCount = items.GetValueEx(nameof(ImageBoosterCacheCount), ImageBoosterCacheCount);
ImageBoosterCacheCount = Math.Max(0, Math.Min(ImageBoosterCacheCount, 10));
ImageBoosterCacheMaxDimension = items.GetValueEx(nameof(ImageBoosterCacheMaxDimension), ImageBoosterCacheMaxDimension);
ImageBoosterCacheMaxFileSizeInMb = items.GetValueEx(nameof(ImageBoosterCacheMaxFileSizeInMb), ImageBoosterCacheMaxFileSizeInMb);
ZoomLockValue = items.GetValueEx(nameof(ZoomLockValue), ZoomLockValue);
if (ZoomLockValue < 0) ZoomLockValue = 100f;
ToolbarIconHeight = items.GetValueEx(nameof(ToolbarIconHeight), ToolbarIconHeight);
ImageEditQuality = items.GetValueEx(nameof(ImageEditQuality), ImageEditQuality);
InAppMessageDuration = items.GetValueEx(nameof(InAppMessageDuration), InAppMessageDuration);
EmbeddedThumbnailMinWidth = items.GetValueEx(nameof(EmbeddedThumbnailMinWidth), EmbeddedThumbnailMinWidth);
EmbeddedThumbnailMinHeight = items.GetValueEx(nameof(EmbeddedThumbnailMinHeight), EmbeddedThumbnailMinHeight);
#endregion
// Enum values
#region Enum items
FrmMainState = items.GetValueEx(nameof(FrmMainState), FrmMainState);
FrmSettingsState = items.GetValueEx(nameof(FrmSettingsState), FrmSettingsState);
ImageLoadingOrder = items.GetValueEx(nameof(ImageLoadingOrder), ImageLoadingOrder);
ImageLoadingOrderType = items.GetValueEx(nameof(ImageLoadingOrderType), ImageLoadingOrderType);
ZoomMode = items.GetValueEx(nameof(ZoomMode), ZoomMode);
ImageInterpolationScaleDown = items.GetValueEx(nameof(ImageInterpolationScaleDown), ImageInterpolationScaleDown);
ImageInterpolationScaleUp = items.GetValueEx(nameof(ImageInterpolationScaleUp), ImageInterpolationScaleUp);
AfterEditingAction = items.GetValueEx(nameof(AfterEditingAction), AfterEditingAction);
WindowBackdrop = items.GetValueEx(nameof(WindowBackdrop), WindowBackdrop);
#endregion
// String values
#region String items
ColorProfile = items.GetValueEx(nameof(ColorProfile), ColorProfile);
ColorProfile = BHelper.GetCorrectColorProfileName(ColorProfile);
AutoUpdate = items.GetValueEx(nameof(AutoUpdate), AutoUpdate);
LastSeenImagePath = items.GetValueEx(nameof(LastSeenImagePath), LastSeenImagePath);
LastOpenedSetting = items.GetValueEx(nameof(LastOpenedSetting), LastOpenedSetting);
DarkTheme = items.GetValueEx(nameof(DarkTheme), DarkTheme);
LightTheme = items.GetValueEx(nameof(LightTheme), LightTheme);
#endregion
// Array values
#region Array items
// ZoomLevels
ZoomLevels = items.GetSection(nameof(ZoomLevels))
.GetChildren()
.Select(i =>
{
// convert % to float
try { return i.Get<float>() / 100f; } catch { }
return -1;
})
.OrderBy(i => i)
.Where(i => i > 0)
.Distinct()
.ToArray();
#region EditApps
EditApps = items.GetSection(nameof(EditApps))
.GetChildren()
.ToDictionary(
i => i.Key.ToLowerInvariant(),
i => i.Get<EditApp>()
);
#endregion
#region ImageFormats
var formats = items.GetValueEx(nameof(FileFormats), Const.IMAGE_FORMATS);
if (string.IsNullOrWhiteSpace(formats)) formats = Const.IMAGE_FORMATS;
FileFormats = GetImageFormats(formats);
formats = items.GetValueEx(nameof(SingleFrameFormats), ZString.Join(';', SingleFrameFormats));
SingleFrameFormats = GetImageFormats(formats);
#endregion
// toolbar buttons
var toolbarItems = items.GetSection(nameof(ToolbarButtons))
.GetChildren()
.Select(i =>
{
var item = i.Get<ToolbarItemModel>();
var hotkeysArr = i.GetChildren()
.FirstOrDefault(i => i.Key == nameof(ToolbarItemModel.Hotkeys))
?.Get<string[]>() ?? [];
item.Hotkeys = hotkeysArr.Distinct()
.Where(i => !string.IsNullOrEmpty(i))
.Select(i => new Hotkey(i))
.ToList();
return item;
})
.Where(i => i != null);
ToolbarButtons = toolbarItems.ToList();
// info items
var infoTagsHasValue = items.GetValueObj(nameof(ImageInfoTags)) is not null;
if (infoTagsHasValue)
{
ImageInfoTags = items.GetSection(nameof(ImageInfoTags))
.GetChildren()
.Select(i => i.Get<string>())
.ToList();
}
// hotkeys for menu
var stringArrDict = items.GetSection(nameof(MenuHotkeys))
.GetChildren()
.ToDictionary(
i => i.Key,
i => i.GetChildren().Select(i => i.Value).ToArray()
);
MenuHotkeys = ParseHotkeys(stringArrDict);
// MouseClickActions
MouseClickActions = items.GetSection(nameof(MouseClickActions))
.GetChildren()
.ToDictionary(
i => BHelper.ParseEnum<MouseClickEvent>(i.Key),
i => ParseToggleAction(i));
// MouseWheelActions
MouseWheelActions = items.GetSection(nameof(MouseWheelActions))
.GetChildren()
.ToDictionary(
i => BHelper.ParseEnum<MouseWheelEvent>(i.Key),
i => BHelper.ParseEnum<MouseWheelAction>(i.Value));
// Layout
Layout = items.GetSection(nameof(Layout))
.GetChildren()
.ToDictionary(
i => i.Key,
i => i.Get<string>()
);
// Tools
var toolList = items.GetSection(nameof(Tools))
.GetChildren()
.Select(i =>
{
var tool = i.Get<IgTool>();
var hotkeysArr = i.GetChildren()
.FirstOrDefault(i => i.Key == "Hotkeys")
?.Get<string[]>() ?? [];
tool.Hotkeys = hotkeysArr.Distinct()
.Where(i => !string.IsNullOrEmpty(i))
.Select(i => new Hotkey(i))
.ToList();
return tool;
})
.Where(i => i != null && !i.IsEmpty);
if (toolList != null && toolList.Any())
{
Tools.Clear();
Tools = toolList.ToList();
}
// DisabledMenus
DisabledMenus = items.GetSection(nameof(DisabledMenus))
.GetChildren()
.Select(i => i.Get<string>())
.ToFrozenSet();
#endregion // Array items
// Other types values
#region Other types items
#region Language
var langPath = items.GetValueEx(nameof(Language), "English");
Language = new IgLang(langPath, App.StartUpDir(Dir.Language));
#endregion
// must load before Theme
#region BackgroundColor
var bgValue = items.GetValueEx(nameof(BackgroundColor), string.Empty);
if (string.IsNullOrEmpty(bgValue))