-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.js
114 lines (96 loc) · 3.06 KB
/
main.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
'use strict';
var fs = require('fs');
var os = require('os');
var path = require('path');
var mkdirp = require('mkdirp');
function getFlashPlayerFolder() {
switch (process.platform) {
case 'win32':
var version = os.release().split('.');
if (version[0] === '5') {
// xp
return process.env.USERPROFILE + '\\Application Data\\Macromedia\\Flash Player';
} else {
// vista, 7, 8
return process.env.USERPROFILE + '\\AppData\\Roaming\\Macromedia\\Flash Player';
}
case 'darwin':
// osx
return process.env.HOME + '/Library/Preferences/Macromedia/Flash Player';
case 'linux':
return process.env.HOME + '/.macromedia/Flash_Player';
}
return null;
}
function getFlashPlayerConfigFolder(customFolder) {
if (customFolder) {
return path.join(customFolder, '#Security', 'FlashPlayerTrust');
}
return path.join(getFlashPlayerFolder(), '#Security', 'FlashPlayerTrust');
}
module.exports.initSync = function (appName, customFolder) {
var trusted = [];
var cfgPath, cfgFolder;
function save() {
var data = trusted.join(os.EOL);
fs.writeFileSync(cfgPath, data, { encoding: 'utf8' });
}
function add(path) {
if (!isTrusted(path)) {
trusted.push(path);
}
save();
}
function remove(path) {
var index = trusted.indexOf(path);
if (index !== -1) {
trusted.splice(index, 1);
}
save();
}
function isTrusted(path) {
return trusted.indexOf(path) !== -1;
}
function list() {
return trusted.concat();
}
function empty() {
trusted = [];
save();
}
// Init
// ----------------------
if (typeof appName !== 'string' || appName === '' || !appName.match(/^[a-zA-Z0-9-_\.]*$/)) {
throw new Error('Provide valid appName.');
}
cfgFolder = getFlashPlayerConfigFolder(customFolder);
// Find out if Flash Config Folder exists
if (!fs.existsSync(cfgFolder)) {
// if this folder is not present then try to create it
try {
mkdirp.sync(cfgFolder);
} catch(err) {
throw new Error('Could not create Flash Player config folder.');
}
}
cfgPath = path.join(cfgFolder, appName + '.cfg');
if (fs.existsSync(cfgPath)) {
// load and parse file if exists
var data = fs.readFileSync(cfgPath, { encoding: 'utf8' });
trusted = data.split(os.EOL);
// on the end of file could be empty line which means nothing
var emptyStringIndex = trusted.indexOf('');
if (emptyStringIndex !== -1) {
trusted.splice(emptyStringIndex, 1);
}
}
// API
// ----------------------
return {
add: add,
list: list,
isTrusted: isTrusted,
remove: remove,
empty: empty,
};
};