Added archive for title app storing.

Added archive for title app storing.
This commit is contained in:
Rinnegatamante 2017-05-01 15:13:55 +02:00
parent c27ff9ea8c
commit cb38409eb3

View File

@ -1,3 +1,7 @@
-- Creating dirs in case they do not exist
System.createDirectory("ux0:/data/TrackPlug")
System.createDirectory("ux0:/data/TrackPlugArchive")
-- Scanning TrackPlug folder -- Scanning TrackPlug folder
local tbl = System.listDirectory("ux0:/data/TrackPlug") local tbl = System.listDirectory("ux0:/data/TrackPlug")
if tbl == nil then if tbl == nil then
@ -23,45 +27,36 @@ function FormatTime(val)
if minutes > 0 then if minutes > 0 then
res = res .. minutes .. "m " res = res .. minutes .. "m "
end end
if seconds > 0 then
res = res .. seconds .. "s " res = res .. seconds .. "s "
end
return res return res
end end
-- Extracts title name from an SFO file descriptor -- Recover title from homebrew database
function extractTitle(handle) function recoverTitle(tid)
io.seek(handle, 0x0C, SET) local file = System.openFile("ux0:/data/TrackPlugArchive/" .. tid .. ".txt", FREAD)
local data_offs = bin2int(io.read(handle, 4)) fsize = System.sizeFile(file)
local title_idx = bin2int(io.read(handle, 4)) - 3 -- STITLE seems to be always the MAX-3 entry local title = System.readFile(file, fsize)
io.seek(handle, (title_idx << 4) + 0x04, CUR) System.closeFile(file)
local len = bin2int(io.read(handle, 4)) return title
local dummy = io.read(handle, 4) end
local offs = bin2int(io.read(handle, 4))
io.seek(handle, data_offs + offs, SET) -- Extracts title name from an SFO file
return io.read(handle, len) function extractTitle(file, tid)
local data = System.extractSFO(file)
if System.doesFileExist("ux0:/data/TrackPlugArchive/" .. tid .. ".txt") then
System.deleteFile("ux0:/data/TrackPlugArchive/" .. tid .. ".txt")
end
local file = System.openFile("ux0:/data/TrackPlugArchive/" .. tid .. ".txt", FCREATE)
System.writeFile(file, data.title, string.len(data.title))
System.closeFile(file)
return data.title
end end
-- Loading unknown icon -- Loading unknown icon
local unk = Graphics.loadImage("app0:/unk.png") local unk = Graphics.loadImage("app0:/unk.png")
-- GekiHEN contest splashscreen -- Getting region, playtime, icon and title name for any game
local splash = Graphics.loadImage("app0:/splash.png") for i, file in pairs(tbl) do
local tmr = Timer.new()
local spl = 0
local setup_finished = false
while Timer.getTime(tmr) < 3000 do
Graphics.initBlend()
Graphics.drawImage(0, 0, splash)
Graphics.termBlend()
Screen.flip()
Screen.waitVblankStart()
spl = spl + 1
if not setup_finished and spl > 3 then
setup_finished = true
-- Getting region, playtime, icon and title name for any game
for i, file in pairs(tbl) do
if file.name == "config.lua" then if file.name == "config.lua" then
dofile("ux0:/data/TrackPlug/"..file.name) dofile("ux0:/data/TrackPlug/"..file.name)
cfg_idx = i cfg_idx = i
@ -86,28 +81,23 @@ while Timer.getTime(tmr) < 3000 do
else else
file.icon = unk file.icon = unk
end end
if System.doesFileExist("ux0:/app/" .. titleid .. "/sce_sys/param.sfo") then if System.doesFileExist("ux0:/data/TrackPlugArchive/" .. titleid .. ".txt") then
fd = io.open("ux0:/app/" .. titleid .. "/sce_sys/param.sfo", FREAD) file.title = recoverTitle(titleid)
file.title = extractTitle(fd) elseif System.doesFileExist("ux0:/app/" .. titleid .. "/sce_sys/param.sfo") then
io.close(fd) file.title = extractTitle("ux0:/app/" .. titleid .. "/sce_sys/param.sfo", titleid)
else else
file.title = "Unknown Title" file.title = "Unknown Title"
end end
file.id = titleid file.id = titleid
fd = io.open("ux0:/data/TrackPlug/" .. file.name, FREAD) fd = System.openFile("ux0:/data/TrackPlug/" .. file.name, FREAD)
file.rtime = bin2int(io.read(fd, 4)) file.rtime = bin2int(System.readFile(fd, 4))
file.ptime = FormatTime(file.rtime) file.ptime = FormatTime(file.rtime)
io.close(fd) System.closeFile(fd)
end
end
if cfg_idx ~= nil then
table.remove(tbl, cfg_ifx)
end
end end
end end
Timer.destroy(tmr) if cfg_idx ~= nil then
Graphics.freeImage(splash) table.remove(tbl, cfg_idx)
end
-- Background wave effect -- Background wave effect
local colors = { local colors = {
@ -368,9 +358,9 @@ while #tbl > 0 do
col_idx = 1 col_idx = 1
end end
wav:color(Color.getR(colors[col_idx][3]),Color.getG(colors[col_idx][3]),Color.getB(colors[col_idx][3])) wav:color(Color.getR(colors[col_idx][3]),Color.getG(colors[col_idx][3]),Color.getB(colors[col_idx][3]))
fd = io.open("ux0:/data/TrackPlug/config.lua", FCREATE) fd = System.openFile("ux0:/data/TrackPlug/config.lua", FCREATE)
io.write(fd, "col_idx="..col_idx, 9) System.writeFile(fd, "col_idx="..col_idx, 9)
io.close(fd) System.closeFile(fd)
end end
oldpad = pad oldpad = pad
end end