-
Notifications
You must be signed in to change notification settings - Fork 0
/
PushbulletProtocol.go
80 lines (65 loc) · 1.93 KB
/
PushbulletProtocol.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"bytes"
"errors"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"
"text/template"
"golang.org/x/sys/windows/registry"
)
func pushbulletProtocolCheck(filename string) error {
key, err := registry.OpenKey(registry.CLASSES_ROOT, `pushbulletapi\shell\open\command`, registry.QUERY_VALUE)
if err != nil {
return err
}
defer key.Close()
s, _, err := key.GetStringValue("")
if err != nil {
return err
}
if strings.HasPrefix(s, "\""+filename+"\" \"%1\"") {
return nil // korrekter Pfad
}
// log.Println("in der Registry gefunden:", s)
// log.Println("cmd /c start \"PushbulletAPI\" /Min \"" + filename + " \"%1\"")
return errors.New("Pfad in der Registry ist falsch hinterlegt")
}
func pushbulletProtocolCreateReg(filename string) { // https://www.robvanderwoude.com/ntstart.php
templatePropertyData := `Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\PushbulletApi]
@="URL:PushbulletApi"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\PushbulletApi\shell]
[HKEY_CLASSES_ROOT\PushbulletApi\shell\open]
[HKEY_CLASSES_ROOT\PushbulletApi\shell\open\command]
@="{{ .}} \"%1\""`
tmplProperty := template.Must(template.New("template").Parse(string(templatePropertyData))) // erstellt aus den Daten das Template
var buf bytes.Buffer
err := tmplProperty.Execute(&buf, filename) // schreibt das Template mit den Daten in die Application.ini
if err != nil {
log.Fatal(err)
}
readBuf, err := ioutil.ReadAll(&buf)
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile("./PushbulletApi.reg", readBuf, 0644)
if err != nil {
log.Fatal(err)
}
cmd := exec.Command("REG", "IMPORT", "PushbulletApi.reg")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
log.Printf("REG IMPORT PushbulletApi.reg\nfailed with %s\n", err)
} else {
err = os.Remove("./PushbulletApi.reg")
if err != nil {
log.Fatal(err)
}
}
}