forked from nuzzyfutts/GameDrawer-Launcher-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Origin.lua
97 lines (86 loc) · 2.82 KB
/
Origin.lua
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
function main(TEMP_DIR)
function parseFileData()
os.execute("REG QUERY \"HKLM\\SOFTWARE\\EA Games\" /s > "..TEMP_DIR.."msg.txt")
local dataFile = io.open(TEMP_DIR.."msg.txt")
local inEntry = false
local allFound = false
local currGame = {}
local games = {}
if dataFile then
for line in dataFile:lines() do
local key, type, val = string.match(line,"^%s%s+([%a%s]*)%s%s+([%a%p]*)%s*(.*)")
if key ~= nil and string.match(key, "DisplayName") then
currGame["name"] = val
end
if key ~= nil and string.match(key, "Product GUID") then
os.execute("REG QUERY \"HKLM\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"..val.."\" /v DisplayIcon > "..TEMP_DIR.."msg2.txt")
currGame["guid"] = val
end
if key ~= nil and string.match(key, "Install Dir") then
currGame["path"] = getExePath(val)
allFound = true
end
if allFound then
allFound = false
table.insert(games, currGame)
currGame = {}
end
end
dataFile:close()
os.execute("del "..TEMP_DIR.."msg.txt")
else
--game family file not found file not found
debug("Error: Could not open the file created by running the REG command")
return nil
end
return games
end
function getExePath(gameGUID)
local dataFile = io.open(TEMP_DIR.."msg2.txt")
local inEntry = false
local allFound = false
local actualPath = nil
if dataFile then
for line in dataFile:lines() do
local key, type, val = string.match(line,"^%s%s+([%a%s]*)%s%s+([%a%p]*)%s*(.*)")
if key ~= nil and string.match(key, "DisplayIcon") then
actualPath = val:sub(2,-2)
end
end
dataFile:close()
else
--game family file not found file not found
debug("Error: Could not open the file created by running the REG command")
return nil
end
os.execute("del "..TEMP_DIR.."msg2.txt")
return actualPath
end
local function finalizeGames(games)
local resultTable = {}
local currTable = {}
if games ~= nil then
for i=1, table.getn(games) do
currTable["appID"]= games[i].guid
currTable["appName"] = games[i].name
currTable["installed"] = true
currTable["hidden"] = false
currTable["lastPlayed"] = nil
currTable["appPath"] = games[i].path
currTable["bannerURL"] = nil --TODO
currTable["bannerName"] = games[i].name..".png" --TODO
currTable["launcher"] = Origin
table.insert(resultTable, currTable)
currTable = {}
end
end
return resultTable
end
local gameData = parseFileData()
local final = finalizeGames(gameData)
for a = 1, table.getn(final) do
debug("App Name: "..final[a].appName.."","App Path: "..final[a].appPath.."","App ID: "..final[a].appID.."","")
end
debug("Total number of games found: ",table.getn(final))
return final
end