From de8e67393532dfa68fbfc5921f68dccc50a51760 Mon Sep 17 00:00:00 2001 From: chinseng85 Date: Sat, 21 Mar 2020 21:29:42 +0800 Subject: [PATCH] Add files via upload Fix an issue where icon0 and game title id cannot be found after the game is deleted. --- app/index.lua | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/index.lua b/app/index.lua index cdf4720..a9db86e 100644 --- a/app/index.lua +++ b/app/index.lua @@ -51,7 +51,7 @@ end -- Recover title from homebrew database function recoverTitle(tid) - local file = System.openFile("ux0:/data/TrackPlugArchive/" .. tid .. ".txt", FREAD) + local file = System.openFile("ux0:/data/TrackPlugArchive/" .. tid .. "/title.txt", FREAD) fsize = System.sizeFile(file) local title = System.readFile(file, fsize) System.closeFile(file) @@ -61,15 +61,23 @@ end -- Extracts title name from an SFO file 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") + if System.doesFileExist("ux0:/data/TrackPlugArchive/" .. tid .. "/title.txt") then + System.deleteFile("ux0:/data/TrackPlugArchive/" .. tid .. "/title.txt") end - local file = System.openFile("ux0:/data/TrackPlugArchive/" .. tid .. ".txt", FCREATE) + local file = System.openFile("ux0:/data/TrackPlugArchive/" .. tid .. "/title.txt", FCREATE) System.writeFile(file, data.title, string.len(data.title)) System.closeFile(file) return data.title end +function copyIcon(titleid) + newFile = System.openFile("ux0:/data/TrackPlugArchive/" .. titleid .. "/icon0.png", FCREATE) + oldFile = System.openFile("ur0:/appmeta/" .. titleid .. "/icon0.png", FREAD) + fileSize = System.sizeFile(oldFile) + icon = System.readFile(oldFile, fileSize) + System.writeFile(newFile, icon, fileSize) +end + function getRegion(titleid) local regioncode = string.sub(titleid,1,4) local prefix = string.sub(regioncode,1,2) @@ -145,12 +153,18 @@ for i, file in pairs(tbl) do local titleid = string.sub(file.name,1,-5) file.region = getRegion(titleid) - if System.doesFileExist("ur0:/appmeta/" .. titleid .. "/icon0.png") then + if System.doesFileExist("ux0:/data/TrackPlugArchive/" .. titleid .. "/icon0.png") then + file.icon = Graphics.loadImage("ux0:/data/TrackPlugArchive/" .. titleid .. "/icon0.png") + elseif System.doesFileExist("ur0:/appmeta/" .. titleid .. "/icon0.png") then file.icon = Graphics.loadImage("ur0:/appmeta/" .. titleid .. "/icon0.png") + System.createDirectory("ux0:/data/TrackPlugArchive/" .. titleid .. "") + copyIcon(titleid) else file.icon = unk end - if System.doesFileExist("ux0:/data/TrackPlugArchive/" .. titleid .. ".txt") then + + + if System.doesFileExist("ux0:/data/TrackPlugArchive/" .. titleid .. "/title.txt") then file.title = recoverTitle(titleid) elseif System.doesFileExist("ux0:/app/" .. titleid .. "/sce_sys/param.sfo") then file.title = extractTitle("ux0:/app/" .. titleid .. "/sce_sys/param.sfo", titleid)