@@ -11,6 +11,7 @@ open System.IO
11
11
open System.Reflection
12
12
open System.Diagnostics
13
13
open System.Runtime .InteropServices
14
+ open System.Linq
14
15
open Microsoft.Win32
15
16
open UACHelper
16
17
@@ -110,17 +111,56 @@ let private win32RegisterFileAssociation() =
110
111
111
112
let private win32UnregisterFileAssociation () =
112
113
trace " unregistering file associations..."
113
- let HKCR = Registry.ClassesRoot
114
- let HKLM = Registry.LocalMachine
114
+ use HKCR = Registry.ClassesRoot
115
+ use HKLM = Registry.LocalMachine
116
+ use HKCU = Registry.CurrentUser
115
117
116
118
HKLM.DeleteSubKeyTree( @" SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\FVim.exe" , false )
117
119
HKCR.DeleteSubKeyTree( @" Applications\FVim.exe" , false )
118
120
HKLM.DeleteSubKeyTree( @" SOFTWARE\Classes\Applications\FVim.exe" , false )
119
121
120
- for ( ico , ext) in FVimIcons do
122
+ for (_ , ext) in FVimIcons do
121
123
let progId = " FVim" + ext
124
+ trace " Deleting %s " progId
122
125
HKCR.DeleteSubKeyTree( progId, false )
123
126
127
+ let tryCreateSubKey subKeyName ( rootKey : RegistryKey ) =
128
+ try Some( rootKey.CreateSubKey( subKeyName))
129
+ with _ -> None
130
+
131
+ let tryOpenSubKey subKeyName ( rootKey : RegistryKey ) =
132
+ if rootKey.GetSubKeyNames() .Contains( subKeyName) then Some( rootKey.CreateSubKey subKeyName)
133
+ else None
134
+
135
+ let tryDeleteFVimShellKey ( rootKey : RegistryKey ) ( subkey : RegistryKey ) =
136
+ let name = subkey.Name
137
+ match subkey.GetValue( " " ) with
138
+ | :? string as v when v.Contains( " FVim" ) ->
139
+ trace " Deleting %O " subkey
140
+ let path = name.Substring( rootKey.Name.Length + 1 )
141
+ subkey.Dispose()
142
+ rootKey.DeleteSubKeyTree path
143
+ Some()
144
+ | _ -> None
145
+
146
+ let removeExtShellCommands ( rootKey : RegistryKey ) subKeyName =
147
+ let shell = rootKey
148
+ |> tryCreateSubKey subKeyName
149
+ >>= tryOpenSubKey " shell"
150
+ shell >>= ( fun shell -> tryOpenSubKey " new" shell >>= tryDeleteFVimShellKey shell) |> ignore
151
+ shell >>= ( fun shell -> tryOpenSubKey " open" shell >>= tryDeleteFVimShellKey shell) |> ignore
152
+ shell >>= ( fun shell -> Some <| shell.Dispose()) |> ignore
153
+
154
+ let removeFVimShellCommands ( rootKey : RegistryKey ) =
155
+ rootKey.GetSubKeyNames()
156
+ |> Seq.where( fun x -> x.StartsWith( " ." ))
157
+ |> Seq.iter( removeExtShellCommands rootKey)
158
+
159
+ use hkcu_classes = HKCU.CreateSubKey( @" SOFTWARE\Classes" )
160
+ removeFVimShellCommands HKCR
161
+ removeFVimShellCommands hkcu_ classes
162
+
163
+
124
164
let setup () =
125
165
if RuntimeInformation.IsOSPlatform( OSPlatform.Windows) then
126
166
if win32CheckUAC() then
0 commit comments