forked from shadowsocks/shadowsocks-gui
-
Notifications
You must be signed in to change notification settings - Fork 22
/
args.js
163 lines (138 loc) · 3.56 KB
/
args.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Generated by CoffeeScript 1.7.1
(function() {
var allConfigs, defaultConfig, deleteConfig, fs, guiconfigFilename, loadConfig, loadConfigs, loadFromJSON, loadIndex, localStorage, publicConfig, saveConfig, saveConfigs, saveIndex, saveToJSON, util;
localStorage = window.localStorage;
util = require('util');
fs = require('fs');
guiconfigFilename = fs.realpathSync(process.execPath + '/..') + '/gui-config.json';
loadFromJSON = function() {
var data, e, temp;
if (process.platform === 'win32') {
try {
data = fs.readFileSync(guiconfigFilename);
temp = JSON.parse(data.toString('utf-8'));
if (temp.configs) {
temp.configs = JSON.stringify(temp.configs);
}
localStorage = temp;
return util.log('reading config file');
} catch (_error) {
e = _error;
return console.log(e);
}
}
};
loadFromJSON();
saveToJSON = function() {
var data, e, temp;
if (process.platform === 'win32') {
util.log('saving config file');
temp = JSON.parse(JSON.stringify(localStorage));
if (temp.configs) {
temp.configs = JSON.parse(temp.configs);
}
data = JSON.stringify(temp, null, 2);
try {
return fs.writeFileSync(guiconfigFilename, data, {
'encoding': 'utf-8'
});
} catch (_error) {
e = _error;
return util.log(e);
}
}
};
publicConfig = {
server: '209.141.36.62',
server_port: 8348,
local_port: 1080,
password: '$#HAL9000!',
method: 'aes-256-cfb',
timeout: 600
};
defaultConfig = {
server_port: 8388,
local_port: 1080,
method: 'aes-256-cfb',
timeout: 600
};
loadConfigs = function() {
var e;
try {
return JSON.parse(localStorage['configs'] || '[]');
} catch (_error) {
e = _error;
util.log(e);
return [];
}
};
allConfigs = function() {
var c, configs, e, i, result;
if (localStorage['configs']) {
result = [];
try {
configs = loadConfigs();
for (i in configs) {
c = configs[i];
result.push("" + c.server + ":" + c.server_port);
}
return result;
} catch (_error) {
e = _error;
}
}
return [];
};
saveIndex = function(index) {
localStorage['index'] = index;
return saveToJSON();
};
loadIndex = function() {
return +localStorage['index'];
};
saveConfigs = function(configs) {
localStorage['configs'] = JSON.stringify(configs);
return saveToJSON();
};
saveConfig = function(index, config) {
var configs;
if (index === -1) {
index = NaN;
}
configs = loadConfigs();
if (isNaN(index)) {
configs.push(config);
index = configs.length - 1;
} else {
configs[index] = config;
}
saveConfigs(configs);
return index;
};
loadConfig = function(index) {
var configs;
if (isNaN(index)) {
return defaultConfig;
}
if (index === -1) {
return publicConfig;
}
configs = loadConfigs();
return configs[index] || defaultConfig;
};
deleteConfig = function(index) {
var configs;
if ((!isNaN(index)) && !(index === -1)) {
configs = loadConfigs();
configs.splice(index, 1);
return saveConfigs(configs);
}
};
exports.allConfigs = allConfigs;
exports.saveConfig = saveConfig;
exports.loadConfig = loadConfig;
exports.deleteConfig = deleteConfig;
exports.loadIndex = loadIndex;
exports.saveIndex = saveIndex;
exports.publicConfig = publicConfig;
}).call(this);