1
1
// Copyright (c) 2024 Files Community
2
2
// Licensed under the MIT License. See the LICENSE.
3
3
4
- using Files . App . Services ;
4
+ using Microsoft . Win32 ;
5
+ using System . IO ;
5
6
using System . Runtime . InteropServices ;
6
7
using Vanara . PInvoke ;
7
8
@@ -34,6 +35,14 @@ public async Task TogglePreviewPopupAsync(string path)
34
35
35
36
public async Task SwitchPreviewAsync ( string path )
36
37
{
38
+ // Close preview window is track selection setting is disabled
39
+ if ( ! IsTrackSelectionSettingEnabled && ! string . IsNullOrEmpty ( CurrentPath ) )
40
+ {
41
+ await TogglePreviewPopupAsync ( CurrentPath ) ;
42
+ return ;
43
+ }
44
+
45
+ // Update the preview window if the path changed
37
46
if ( CurrentPath is not null && path != CurrentPath )
38
47
await TogglePreviewPopupAsync ( path ) ;
39
48
}
@@ -43,5 +52,64 @@ public async Task<bool> DetectAvailability()
43
52
var handle = User32 . FindWindow ( "SeerWindowClass" , null ) . DangerousGetHandle ( ) ;
44
53
return handle != IntPtr . Zero && handle . ToInt64 ( ) != - 1 ;
45
54
}
55
+
56
+ private bool ? _IsTrackSelectionSettingEnabledCache ;
57
+ private bool IsTrackSelectionSettingEnabled
58
+ {
59
+ get
60
+ {
61
+ if ( _IsTrackSelectionSettingEnabledCache is null )
62
+ _IsTrackSelectionSettingEnabledCache = DetectTrackSelectionSetting ( ) . Result ;
63
+
64
+ return _IsTrackSelectionSettingEnabledCache . Value ;
65
+ }
66
+ }
67
+
68
+ private Task < bool > DetectTrackSelectionSetting ( )
69
+ {
70
+ bool trackSelectedFile = true ;
71
+
72
+ var keyName = @"HKEY_CURRENT_USER\Software\Corey\Seer" ;
73
+ var value = Registry . GetValue ( keyName , "tracking_file" , null ) ;
74
+
75
+ if ( value ? . ToString ( ) == "false" )
76
+ return Task . FromResult ( false ) ;
77
+
78
+ // List of possible paths for the Seer Pro settings file
79
+ string [ ] paths =
80
+ {
81
+ Environment . ExpandEnvironmentVariables ( "%USERPROFILE%\\ Documents\\ Seer\\ uwp.ini" ) ,
82
+ Environment . ExpandEnvironmentVariables ( "%USERPROFILE%\\ appdata\\ Local\\ Packages\\ CNABA5E861-AC2A-4523-B3C1.Seer-AWindowsQuickLookTo_p7t0z30wh4868\\ LocalCache\\ Local\\ Corey\\ Seer\\ uwp.ini" ) ,
83
+ Environment . ExpandEnvironmentVariables ( "%USERPROFILE%\\ appdata\\ Local\\ Corey\\ Seer\\ uwp.ini" ) ,
84
+ Environment . ExpandEnvironmentVariables ( "%USERPROFILE%\\ Documents\\ Seer\\ config.ini" )
85
+ } ;
86
+
87
+ // Find the first existing path
88
+ foreach ( var path in paths )
89
+ {
90
+ if ( File . Exists ( path ) )
91
+ {
92
+ // Read the settings file and look for the tracking_file setting
93
+ string [ ] lines = File . ReadAllLines ( path ) ;
94
+
95
+ foreach ( var line in lines )
96
+ {
97
+ if ( line . StartsWith ( "tracking_file" , StringComparison . OrdinalIgnoreCase ) )
98
+ {
99
+ string [ ] keyValue = line . Split ( '=' ) ;
100
+ if ( keyValue . Length == 2 && bool . TryParse ( keyValue [ 1 ] . Trim ( ) , out bool isTrackingFile ) )
101
+ {
102
+ trackSelectedFile = isTrackingFile ;
103
+ break ;
104
+ }
105
+ }
106
+ }
107
+
108
+ break ;
109
+ }
110
+ }
111
+
112
+ return Task . FromResult ( trackSelectedFile ) ;
113
+ }
46
114
}
47
115
}
0 commit comments