-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBNetSwitcher.lua
More file actions
57 lines (53 loc) · 1.3 KB
/
BNetSwitcher.lua
File metadata and controls
57 lines (53 loc) · 1.3 KB
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
local path = os.getenv("TEMP"):match([[.*\AppData]]) .. [[\Roaming\Battle.net\Battle.net.config]]
local function findNames()
for line in io.lines(path) do
line = line:match([[%s*"SavedAccountNames": "(.*)",]])
if line then
local names = {}
for name in line:gmatch([[([^,]*),?]]) do
table.insert(names, name)
end
return names
end
end
end
local function saveNames(names)
local output = ''
for line in io.lines(path) do
local tab = line:match([[(%s*)"SavedAccountNames": ".*",]])
if tab then
output = output .. string.format([[%s"SavedAccountNames": "%s",]], tab, names) .. '\n'
else
output = output .. line .. '\n'
end
end
local file = io.open(path, 'w+')
local result = file:write(output)
io.close(file)
return result
end
local function main()
-- 选择账号:
print("选择账号: ")
local names = findNames()
for i,name in ipairs(names) do
print(string.format("[%d] %s", i, name))
end
print("")
-- 用户输入:
print("输入数字:")
local i = io.read('*num') or 1
print("")
-- 账号置顶
local user = table.remove(names, i)
table.insert(names, 1, user)
names = table.concat(names, ',')
-- 完成
if saveNames(names) then
print(string.format("切换成功! (当前账号: %s)", user))
else
print("配置文件写入失败!")
end
print("")
end
main()