git ssb

1+

mixmix / scuttle-shell



Tree: 851531c0e3ba49e7d6301e1941f7cf92e8f91628

Files: 851531c0e3ba49e7d6301e1941f7cf92e8f91628 / scripts / setup-win.js

1845 bytesRaw
1
2var path = require('path')
3var regedit = require('regedit')
4var fs = require("fs")
5var appPath = path.resolve(".\\app.bat")
6var appManifestFile = path.resolve(".\\scuttleshell.json")
7
8function setup() {
9
10 if (process.platform !== "win32") {
11 console.log("This script works only on windows, try npm run setup")
12 return 1
13 }
14
15 if (!fs.existsSync(appPath)) {
16 console.log("[ERROR] Application not found at: ", appPath)
17 return 1
18 }
19
20 if (!fs.existsSync(appManifestFile)) {
21 console.log("[ERROR] App manifest not found at: ", appManifestFile)
22 return 1
23 }
24
25 let manifest = JSON.parse(fs.readFileSync(appManifestFile))
26
27 let applicationLauncherPath = manifest.path
28
29 if (!fs.existsSync(applicationLauncherPath)) {
30 console.log("[ERROR] App not found at declared location", applicationLauncherPath)
31 console.log("FIXING...")
32 manifest.path = appPath
33 fs.writeFileSync(appManifestFile, JSON.stringify(manifest))
34 } else {
35 console.log("[OK] Application found at the correct location", applicationLauncherPath)
36 }
37
38 // This now involves writing to the registry, I am a bit scared of that...
39
40 var valuesToPut = {
41 'HKCU\\Software\\Mozilla\\NativeMessagingHosts\\scuttleshell': {
42 'scuttleshell': {
43 value: appManifestFile,
44 type: 'REG_DEFAULT'
45 }
46 }
47 }
48
49 regedit.createKey('HKCU\\Software\\Mozilla\\NativeMessagingHosts\\scuttleshell', function (a, b) {
50 regedit.putValue(valuesToPut, function (err) {
51 if (err) {
52 console.log("[ERROR] Problem writing to registry.", err)
53 return 1
54 } else {
55 console.log("[OK] Wrote manifest path to registry.\n[INFO] Try: npm run check-win")
56 return 0
57 }
58 })
59 })
60 return 0
61}
62
63module.exports = setup
64
65if (require.main === module) {
66 var errorLevel = setup()
67 process.exit(errorLevel)
68}
69
70

Built with git-ssb-web