/
config.coffee
153 lines (138 loc) · 3.39 KB
/
config.coffee
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
###*
* @fileoverview 設定関係のメソッド
###
fs = require "fs-extra"
path = require "path"
{app} = require "electron"
denodeify = require "denodeify"
util = require "./util"
os = require "os"
###*
* 設定をおくフォルダ
* @const
###
CONFIG_FOLDER_PATH = path.join(app.getPath("userData"), "config")
GENERAL_CONFIG_PATH = path.join(CONFIG_FOLDER_PATH, "general.json")
LANG_LIST = [
"ja"
"en"
"ru"
"zh_TW"
"zh_CN"
]
PLATFORM_LIST = [
"w"
"m"
"a"
"i"
]
BLITZ_PATH =
WIN64: "C:\\Program Files (x86)\\Steam\\steamapps\\common\\World of Tanks Blitz"
WIN32: "C:\\Program Files\\Steam\\steamapps\\common\\World of Tanks Blitz"
MACSTEAM: path.join(os.homedir(), "Library/Application Support/Steam/SteamApps/common/World of Tanks Blitz/World of Tanks Blitz.app/Contents/Resources/")
MACSTORE: "/Applications/World of Tanks Blitz.app/Contents/Resources/"
ensureFile = denodeify(fs.ensureFile)
readJson = denodeify(fs.readJson)
###
* 設定のデータ
###
data = {}
###
* dataの初期値
* @const
###
DEFAULT_DATA =
repos: ["http://subdiox.com/repo"]
localRepos: []
debugRepo: ""
appliedMods: []
lang: "ja"
blitzPathType: "folder"
do ->
DEFAULT_DATA.platform = util.getPlatform()
switch DEFAULT_DATA.platform
when "w"
switch os.arch()
when "x64" then DEFAULT_DATA.blitzPath = BLITZ_PATH.WIN64
when "ia32" then DEFAULT_DATA.blitzPath = BLITZ_PATH.WIN32
DEFAULT_DATA.blitzPathRadio = "win"
when "m"
DEFAULT_DATA.blitzPath = BLITZ_PATH.MACSTEAM
DEFAULT_DATA.blitzPathRadio = "macsteam"
else
DEFAULT_DATA.blitzPath = "World of Tanks Blitz"
DEFAULT_DATA.blitzPathRadio = "other"
return
getDefaultWinBlitzPath = ->
switch os.arch()
when "x64" then return BLITZ_PATH.WIN64
when "ia32" then return BLITZ_PATH.WIN32
###
* エラー出力
* @private
###
_outputError = (err) ->
console.error("Error: #{err}") if err?
return
###
* 設定更新
* @private
###
_update = ->
fs.outputJson(GENERAL_CONFIG_PATH, data, _outputError)
return
###
* 設定をメモリに展開
* @constructor
###
init = ->
return ensureFile(GENERAL_CONFIG_PATH).then( ->
return readJson(GENERAL_CONFIG_PATH, throws: false)
).then( (content) ->
data = Object.assign({}, DEFAULT_DATA)
if content?
data = Object.assign(data, content)
else
machineLang = app.getLocale()
switch true
when machineLang is "ja" then data.lang = "ja"
when machineLang is "ru" then data.lang = "ru"
when machineLang is "zh-TW" then data.lang = "zh_TW"
when machineLang is "zh-CN" then data.lang = "zh_CN"
when machineLang.includes("en") then data.lang = "en"
when machineLang.includes("zh") then data.lang = "zh_CN"
else data.lang = "en"
_update()
)
get = (a) ->
return data[a]
set = (a, b) ->
data[a] = b
_update()
return
add = (a, b) ->
data[a].push(b)
_update()
return
remove = (a, b) ->
for v, i in data[a] when JSON.stringify(v) is JSON.stringify(b)
data[a].splice(i, 1)
_update()
return
reset = ->
data = Object.assign({}, DEFAULT_DATA)
_update()
return
module.exports =
GENERAL_CONFIG_PATH: GENERAL_CONFIG_PATH
LANG_LIST: LANG_LIST
PLATFORM_LIST: PLATFORM_LIST
BLITZ_PATH: BLITZ_PATH
getDefaultWinBlitzPath: getDefaultWinBlitzPath
data: data
init: init
get: get
set: set
add: add
remove: remove
reset: reset