-
Notifications
You must be signed in to change notification settings - Fork 6
/
defaults.ts
90 lines (78 loc) · 2.52 KB
/
defaults.ts
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
81
82
83
84
85
86
87
88
89
90
import { GetStringRegKey } from '@vscode/windows-registry'
import * as fs from 'fs'
import {
homedir,
platform
} from 'os'
import * as path from 'path'
import { env } from 'process'
const ApplicationName = 'SuperCollider'
const Home = homedir();
const sclangConfYaml = 'sclang_conf.yaml'
export function sclangExecutable() {
switch (platform()) {
case 'win32': return 'sclang.exe'
default: return 'sclang'
}
}
export function userConfigPath() {
switch (platform()) {
case 'win32': {
const localAppData = env.LOCALAPPDATA || path.join(Home, 'AppData', 'Local');
return path.join(localAppData, ApplicationName);
}
case 'darwin': {
const localAppData = (env.XDG_CONFIG_HOME || env.XDG_DATA_HOME) || path.join(Home, 'Library', 'Application Support')
return path.join(localAppData, ApplicationName)
}
case 'linux':
case 'freebsd':
case 'openbsd': {
const localAppData = env.XDG_CONFIG_HOME || path.join(Home, '.config')
return path.join(localAppData, ApplicationName)
}
}
}
export function sclangConfYamlPath() {
return path.join(userConfigPath(), sclangConfYaml)
}
function getInstallPathWin() {
const MAX_MAJOR_VERSION = 20
const MAX_MINOR_VERSION = 6
const minorVersions = new Array(MAX_MAJOR_VERSION + 1)
.fill(null)
.map((_, i) => i)
.reverse();
const patchVersions = new Array(MAX_MINOR_VERSION + 1)
.fill(null)
.map((_, i) => i)
.reverse();
try {
return GetStringRegKey('HKEY_CURRENT_USER', `SOFTWARE\\${ApplicationName}\\CurrentVersion`, '')
} catch { }
for (const minor of minorVersions) {
for (const patch of patchVersions) {
const versionString = `3.${minor}.${patch}`;
try {
return GetStringRegKey('HKEY_CURRENT_USER', `SOFTWARE\\${ApplicationName}\\${versionString}`, '')
} catch { }
}
}
return 'c:\\Program Files\\SuperCollider';
}
getInstallPathWin()
export function sclangPath() {
switch (platform()) {
case 'win32': {
return path.join(getInstallPathWin(), sclangExecutable());
}
case 'darwin': {
return path.join('/Applications', ApplicationName + '.app', 'Contents', 'MacOS', sclangExecutable())
}
case 'linux':
case 'freebsd':
case 'openbsd': {
return path.join('usr', 'bin', sclangExecutable())
}
}
}