Skip to content

Commit 8d2e990

Browse files
author
Yatao Li
committed
improve win32 uninstall
1 parent d3d3a5b commit 8d2e990

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

shell.fs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ open System.IO
1111
open System.Reflection
1212
open System.Diagnostics
1313
open System.Runtime.InteropServices
14+
open System.Linq
1415
open Microsoft.Win32
1516
open UACHelper
1617

@@ -110,17 +111,56 @@ let private win32RegisterFileAssociation() =
110111

111112
let private win32UnregisterFileAssociation() =
112113
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
115117

116118
HKLM.DeleteSubKeyTree(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\FVim.exe", false)
117119
HKCR.DeleteSubKeyTree(@"Applications\FVim.exe", false)
118120
HKLM.DeleteSubKeyTree(@"SOFTWARE\Classes\Applications\FVim.exe", false)
119121

120-
for (ico,ext) in FVimIcons do
122+
for (_,ext) in FVimIcons do
121123
let progId = "FVim" + ext
124+
trace "Deleting %s" progId
122125
HKCR.DeleteSubKeyTree(progId, false)
123126

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+
124164
let setup() =
125165
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
126166
if win32CheckUAC() then

0 commit comments

Comments
 (0)