-
Notifications
You must be signed in to change notification settings - Fork 148
/
extregister.lua
67 lines (57 loc) · 1.87 KB
/
extregister.lua
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
-- Copyright 2014 Paul Kulchenko, ZeroBrane LLC; All rights reserved
local winapi
local function setvalue(key, name, val)
local k, err = winapi.create_reg_key(key)
k, err = winapi.open_reg_key(key, true)
if not k then
ide:Print(("Failed to create key %s: %s"):format(key, err))
return
end
if not k:set_value(name, val, winapi.REG_SZ) then
ide:Print(("Failed to update key %s"):format(key))
return
end
ide:Print(("Registered '%s'"):format(key))
return true
end
local function register()
local exts = ide:GetKnownExtensions()
if #exts == 0 then
ide:Print("No known extensions to register.")
return
end
local extensions = table.concat(exts, ", ")
extensions = wx.wxGetTextFromUser("Enter extensions to associate with the IDE",
"Register extensions", extensions)
if #extensions == 0 then return end
ide:Print(("Registering extensions '%s' for the current user.")
:format(extensions))
if not setvalue([[HKEY_CURRENT_USER\Software\Classes\ZeroBrane.Studio\shell\edit\command]],
"", ide:GetRootPath('zbstudio.exe')..[[ "%1"]]) then
return
end
for ext in extensions:gmatch("(%w+)") do
if not setvalue(([[HKEY_CURRENT_USER\Software\Classes\.%s]]):format(ext),
"", [[ZeroBrane.Studio]])
or not setvalue(([[HKEY_CURRENT_USER\Software\Classes\.%s\OpenWithProgids]]):format(ext),
[[ZeroBrane.Studio]], "") then
return
end
end
end
return {
name = "Extension register",
description = "Registers known extensions to launch the IDE on Windows.",
author = "Paul Kulchenko",
version = 0.2,
dependencies = {"1.30", osname = "Windows"},
onRegister = function(self)
local ok
ok, winapi = pcall(require, 'winapi')
if not ok then return false end
ide:AddTool("Register Known Extensions", register)
end,
onUnRegister = function(self)
ide:RemoveTool("Register Known Extensions")
end,
}