Skip to content

Commit

Permalink
fix #68
Browse files Browse the repository at this point in the history
  • Loading branch information
yatli committed Nov 12, 2019
1 parent 2bd67b3 commit 4877e1e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions Program.fs
Expand Up @@ -84,6 +84,7 @@ let main(args: string[]) =
FVim.log.init opts
match opts.intent with
| Setup -> setup()
| Uninstall -> uninstall()
| Daemon(port, pipe) -> daemon port pipe opts
| Start ->

Expand Down
3 changes: 3 additions & 0 deletions getopt.fs
Expand Up @@ -12,6 +12,7 @@ type ServerOptions =
type Intent =
| Start
| Setup
| Uninstall
| Daemon of port: uint16 option * pipe: string option

type Options =
Expand Down Expand Up @@ -50,6 +51,7 @@ let parseOptions (args: string[]) =
let nvim = eat2 "--nvim" |> Option.defaultValue "nvim"
let connect = eat2 "--connect"
let setup = eat1 "--setup"
let uninstall = eat1 "--uninstall"
let tryDaemon = eat1 "--tryDaemon"
let runDaemon = eat1 "--daemon"
let port = eat2 "--daemonPort" >>= ParseUInt16
Expand Down Expand Up @@ -101,6 +103,7 @@ let parseOptions (args: string[]) =

let intent =
if setup then Setup
elif uninstall then Uninstall
elif runDaemon then Daemon(port, pipe)
else Start

Expand Down
39 changes: 30 additions & 9 deletions shell.fs
Expand Up @@ -73,21 +73,21 @@ let private win32RegisterFileAssociation() =

use shell = key.CreateSubKey("shell")

shell.SetValue("", "open")
shell.SetValue("", "edit")

let () =
use _open = shell.CreateSubKey("open")
_open.SetValue("", "Open with FVim")
_open.SetValue("Icon", fvicon)
use command = _open.CreateSubKey("command")
use _edit = shell.CreateSubKey("edit")
_edit.SetValue("", "Open with FVim")
_edit.SetValue("Icon", fvicon)
use command = _edit.CreateSubKey("command")
command.SetValue("", sprintf "\"%s\" --tryDaemon \"%%1\"" exe)
in ()

let () =
use _open = shell.CreateSubKey("new")
_open.SetValue("", "Open with new FVim")
_open.SetValue("Icon", fvicon)
use command = _open.CreateSubKey("command")
use _edit = shell.CreateSubKey("new")
_edit.SetValue("", "Open with new FVim")
_edit.SetValue("Icon", fvicon)
use command = _edit.CreateSubKey("command")
command.SetValue("", sprintf "\"%s\" \"%%1\"" exe)
in ()

Expand Down Expand Up @@ -115,6 +115,19 @@ let private win32RegisterFileAssociation() =
use extKey = HKCR.CreateSubKey(ext)
extKey.SetValue("", progId)

let private win32UnregisterFileAssociation() =
trace "unregistering file associations..."
let HKCR = Registry.ClassesRoot
let HKLM = Registry.LocalMachine

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

for (ico,ext) in FVimIcons do
let progId = "FVim" + ext
HKCR.DeleteSubKeyTree(progId, false)

let setup() =
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
if win32CheckUAC() then
Expand All @@ -123,6 +136,14 @@ let setup() =
// setup finished.
0

let uninstall() =
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
if win32CheckUAC() then
win32UnregisterFileAssociation()

// setup finished.
0

let daemon (port: uint16 option) (pipe: string option) {args=args; program=program; stderrenc = enc} =
trace "Running as daemon."
let pipe = pipe |> Option.defaultValue FVimServerAddress
Expand Down

0 comments on commit 4877e1e

Please sign in to comment.