Skip to content

Commit 8cf5b04

Browse files
committed
Copyed to new github folder.
1 parent f43f9d2 commit 8cf5b04

40 files changed

+19885
-0
lines changed

icon.ico

2.35 KB
Binary file not shown.

icon.pdn

26.7 KB
Binary file not shown.

lua54.dll

509 KB
Binary file not shown.

main.wlua

+334
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,334 @@
1+
local file = nil
2+
local log = sys.File("log")
3+
local outputfolder = nil
4+
local probar = nil
5+
local ui = require("ui")
6+
local sys = require("sys")
7+
local net = require("net")
8+
local console = require("console")
9+
log:open("write")
10+
local function betterprint(text)
11+
print(text)
12+
log:writeln(text)
13+
end
14+
betterprint("Setting up...")
15+
local gameId = nil
16+
local tempfolder = nil
17+
-- Important Variables
18+
local win = ui.Window("MPGT: AutoPSX","fixed",300,150)
19+
local menu = ui.Menu("File","About")
20+
local filetext = ui.Entry(win,"No file selected...",9,27,251,20)
21+
local outputtext = ui.Entry(win,"No output folder selected...",9,56,224,20)
22+
local selectfileButton = ui.Button(win,"...",264,27,28,20)
23+
local outputfileButton = ui.Button(win,"...",237,56,57,20)
24+
local convertbutton = ui.Button(win,"Convert",180,85,111,40)
25+
filetext.enabled = false
26+
filetext.textlimit = 40
27+
outputtext.enabled = false
28+
outputtext.textlimit = 40
29+
win:show()
30+
win.menu = menu
31+
32+
win:show()
33+
betterprint("Done")
34+
console:clear(console.bgcolor)
35+
betterprint("░▒▓██████▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓████████▓▒░▒▓██████▓▒░░▒▓███████▓▒░ ░▒▓███████▓▒░▒▓█▓▒░░▒▓█▓▒░ \n░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ \n░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ \n░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓███████▓▒░ ░▒▓██████▓▒░ ░▒▓██████▓▒░ \n░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ \n░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ \n░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░ ░▒▓█▓▒░ ░▒▓██████▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░\nMade by _FN10_")
36+
betterprint("Convert PSX games to eboots without the hassle!\n\n")
37+
-- Functions
38+
local function SetupConversionWindow ()
39+
local prowin = ui.Window("Converting...","fixed",200,100)
40+
probar = ui.Progressbar(prowin,9,60,182,31)
41+
local cancelbutton = ui.Button(prowin,"Cancel",9,36,182,20)
42+
local label = ui.Label(prowin,"Converting...",9,10)
43+
win:showmodal(prowin)
44+
if probar ~= nil then probar:advance(2) end
45+
end
46+
47+
local function magiclines( str )
48+
local pos = 1;
49+
return function()
50+
if not pos then return nil end
51+
local p1, p2 = string.find( str, "\r?\n", pos )
52+
local line
53+
if p1 then
54+
line = str:sub( pos, p1 - 1 )
55+
pos = p2 + 1
56+
else
57+
line = str:sub( pos )
58+
pos = nil
59+
end
60+
return line
61+
end
62+
end
63+
local function get_line(filename, line_number)
64+
local i = 0
65+
for line in magiclines(filename) do
66+
i = i + 1
67+
if i == line_number then
68+
return line
69+
end
70+
end
71+
return nil -- line not found
72+
end
73+
local function GetGameID (file)
74+
file:open("read","utf8")
75+
local s = file:read()
76+
local finsd,end1 = string.find(s, "%a%a%a%a_%d%d%d%d%d")
77+
if probar ~= nil then probar:advance(2) end
78+
if finsd == nil then
79+
return false
80+
end
81+
betterprint(finsd)
82+
local id = string.sub(s, finsd,end1)
83+
betterprint("Game id is ",id)
84+
if probar ~= nil then probar:advance(10) end
85+
return id
86+
end
87+
local function GetGameCover (gameid,dest)
88+
local des = nil
89+
betterprint("Getting ","https://username:[email protected]".."/xlenore/psx-covers/refs/heads/main/covers/default/"..gameid:gsub("_","-")..".jpg")
90+
local http = net.Http("https://username:[email protected]")
91+
local puthttp, output = await(http:download("/xlenore/psx-covers/refs/heads/main/covers/default/"..gameid:gsub("_","-")..".jpg"))
92+
if probar ~= nil then probar:advance(2) end
93+
if dest == "dia" then
94+
des = ui.savedialog("Save Cover to...",false,"JPEG Image (*.jpg)|*.jpg|All files (*.*)|*.*")
95+
if probar ~= nil then probar:advance(2) end
96+
else
97+
des = sys.File(dest.fullpath.."/cover.jpg")
98+
if probar ~= nil then probar:advance(2) end
99+
-- des:open():move()
100+
end
101+
output["file"]:open("read","binary")
102+
des:open("write","binary")
103+
des:write(output["file"]:read())
104+
http:close()
105+
if probar ~= nil then probar:advance(2) end
106+
des:close()
107+
if probar ~= nil then probar:advance(2) end
108+
return des.fullpath
109+
end
110+
local function CreateIcon (tempfolderfullpath)
111+
local icon0 = sys.File(tempfolderfullpath.."/icon0.png")
112+
sys.File(sys.currentdir.."/programs/imagemag/ICON0.PNG"):copy(icon0.fullpath)
113+
betterprint(sys.currentdir.."/programs/imagemag/magick.exe")
114+
if probar ~= nil then probar:advance(1) end
115+
sys.cmd(sys.currentdir.."/programs/imagemag/magick.exe".." mogrify -resize 70x70 "..tempfolderfullpath.."/cover.jpg")
116+
if probar ~= nil then probar:advance(1) end
117+
sys.cmd(sys.currentdir.."/programs/imagemag/magick.exe".." "..tempfolderfullpath.."/cover.jpg "..tempfolderfullpath.."/cover.png") --Convert to PNG
118+
if probar ~= nil then probar:advance(1) end
119+
sys.cmd(sys.currentdir.."/programs/imagemag/magick.exe "..tempfolderfullpath.."/cover.png"..' -gravity center -background transparent -extent 80x80 '..tempfolderfullpath.."/cover.png")
120+
if probar ~= nil then probar:advance(1) end
121+
betterprint("canvas size ",sys.currentdir.."/programs/imagemag/magick.exe"..tempfolderfullpath.."/cover.png".." -gravity center -extent -background rgba(255, 0, 0, 1.0) 80x80 "..tempfolderfullpath.."/cover.png")
122+
sys.cmd(sys.currentdir.."/programs/imagemag/magick.exe".." composite -gravity center "..icon0.fullpath.." "..tempfolderfullpath.."/cover.png "..tempfolderfullpath.."/finshed.png")
123+
if probar ~= nil then probar:advance(1) end
124+
return sys.File(tempfolderfullpath.."/finshed.png")
125+
end
126+
local function GetTrackFileFromCue(cue,track)
127+
if not cue.exists then ui.error("Fatal Error\nCue doesn't exist. (ERR3)") win:hide() return false end
128+
local function processstring(l)
129+
local s = l:gsub('" BINARY',"")
130+
return s:gsub('FILE "',"")
131+
end
132+
local cuefile = cue
133+
local tracks = 0
134+
cuefile:open("read","utf8")
135+
local i = 1
136+
local tracklines = {}
137+
local cueread = cuefile:read()
138+
for l in magiclines(cueread) do
139+
i = i+1
140+
--if l:find("FILE ") ~= nil then
141+
--
142+
if l:find("TRACK %d%d") ~= nil then
143+
local ss = string.sub(l,l:find("%d%d"))
144+
tracklines[ss] = processstring(get_line(cueread,i-2))
145+
tracks = tracks+1
146+
end
147+
end
148+
149+
local cuedir = cue.directory
150+
if not cuedir.exists then ui.error("Fatal Error\nCue DIR doesn't exist. (ERR4)") win:hide() return false end
151+
if tracklines[track] == nil then betterprint("Cue dont done exist!") return false end
152+
153+
local binfile = sys.File(cuedir.fullpath.."/"..tracklines[track])
154+
if binfile.exists then
155+
cuefile:close()
156+
betterprint("Got Track file name, ",binfile.name," with track amount ",tracks)
157+
if probar ~= nil then probar:advance(3) end
158+
return binfile,tracks
159+
else
160+
ui.error("Fatal Error\nFiles Cue reported dont exist. (ERR1)")
161+
win:hide()
162+
end
163+
end
164+
local function FinalStep (tempfolderfullpath,cue)
165+
local function lastfinalstep (eboot)
166+
if eboot:copy(outputfolder.fullpath.."/EBOOT.PBP") == nil then ui.error("Fatal Error\nFailed EBOOT copy. (ERR6)") win:hide() return false end
167+
if probar ~= nil then probar:advance(10000) end
168+
ui.msg("EBOOT.PBP built to "..outputfolder.fullpath.."/EBOOT.PBP"..".")
169+
return true
170+
end
171+
local mainfolderfullpath = tempfolderfullpath.."/mainfolder"
172+
local program = sys.File(sys.currentdir.."/programs/psxpack/psxpackager.exe")
173+
local newprogram = program:copy(tempfolderfullpath.."/mainfolder/psxpack.exe")
174+
local resourcefolder = sys.Directory(sys.currentdir.."/programs/psxpack/Resources/")
175+
local newresourcefolder = sys.Directory(tempfolderfullpath.."/mainfolder/Resources/")
176+
betterprint("Cue name",cue.name)
177+
--local command = mainfolderfullpath..'/psxpack.exe -i\\"'..mainfolderfullpath.."/"..cue.name..'\\" --import --resource-format \\"'..mainfolderfullpath..'\\"/%R`ESOURCE%.%EXT%'
178+
newresourcefolder:make()
179+
for file in each(resourcefolder:list("*.*")) do
180+
print(type(file))
181+
if type(file) == "table" or type(file) == "file" then
182+
betterprint("Copying",file.name,tempfolderfullpath.."/mainfolder/Resources/"..file.name)
183+
file:copy(tempfolderfullpath.."/mainfolder/Resources/"..file.name)
184+
end
185+
end
186+
if probar ~= nil then probar:advance(3) end
187+
if newprogram == nil then ui.error("Fatal Error\nFailed Copy. (ERR5)") win:hide() return false end
188+
-- betterprint(mainfolderfullpath..'/psxpack.exe -i"'..mainfolderfullpath.."/"..cue.name..'" --import --resource-format "'..mainfolderfullpath..'"\\%RESOURCE\\%.\\%EXT\\%')
189+
local command = mainfolderfullpath..'/psxpack.exe -i"'..mainfolderfullpath.."/"..cue.name..'" --import --resource-format "'..mainfolderfullpath..'"%RESOURCE%.%EXT%'
190+
if not sys.cmd(command) then betterprint("Error! Retrying CMDS...") if not sys.cmd(mainfolderfullpath..'/psxpack.exe -i"'..mainfolderfullpath.."/"..cue.name..'" --import --resource-format "'..mainfolderfullpath..'"%RESOURCE%.%EXT%') then ui.error("Fatal Error\nFailed CMD. (ERR7)") win:hide() return false end end
191+
if probar ~= nil then probar:advance(3) end
192+
for file in each(resourcefolder:list("*.pbp")) do
193+
lastfinalstep(file)
194+
break
195+
end
196+
end
197+
local function SetupConversionFolder (tempfolderfullpath,cue,gameid,coverfile)
198+
betterprint("Setting up folder.")
199+
local function step3 (newfolderpath,cue,gamid)
200+
betterprint("step3")
201+
local gtftc,trackamount = GetTrackFileFromCue(cue,"01")
202+
for i = 0,trackamount,1 do
203+
if tostring(i):len() == 1 then
204+
local gtffcc = GetTrackFileFromCue(cue,"0"..tostring(i))
205+
if gtffcc then gtffcc:copy(newfolderpath.."/"..gtffcc.name) end
206+
elseif tostring(i):len() == 2 then
207+
local gtffcc = GetTrackFileFromCue(cue,""..tostring(i))
208+
if gtffcc then gtffcc:copy(newfolderpath.."/"..gtffcc.name) end
209+
end
210+
end
211+
cue:copy(newfolderpath.."/"..cue.name)
212+
if probar ~= nil then probar:advance(1) end
213+
coverfile:copy(newfolderpath.."/".."ICON0.png")
214+
if probar ~= nil then probar:advance(1) end
215+
FinalStep(tempfolderfullpath,cue)
216+
if probar ~= nil then probar:advance(1) end
217+
end
218+
local function step2 (newfolderpath)
219+
betterprint("step2")
220+
local pic0 = sys.File(newfolderpath.."/PIC0.png")
221+
local couldtherealpic0pleasestandup = sys.File(sys.currentdir.."/programs/psxpack/PIC0.png")
222+
betterprint(sys.currentdir.."/programs/psxpack/PIC0.png")
223+
if couldtherealpic0pleasestandup.exists then
224+
couldtherealpic0pleasestandup:copy(pic0.fullpath)
225+
step3(newfolderpath,cue,gameid)
226+
else
227+
return false
228+
end
229+
end
230+
local newfolder = sys.Directory(tempfolderfullpath.."/mainfolder")
231+
local newfolderpath = newfolder.fullpath
232+
if newfolder:make() then
233+
step2(newfolderpath)
234+
elseif newfolder.exists then
235+
step2(newfolderpath)
236+
else
237+
ui.error("Fatal Error\nCouldnt create folder. (ERR2)")
238+
win:hide()
239+
return false
240+
end
241+
end
242+
local function Convert (Cue)
243+
local function convert2(gameid)
244+
betterprint("Verifyed GameID ",gameid)
245+
local gamecoverpath = GetGameCover(gameid,tempfolder)
246+
local icon = CreateIcon(tempfolder.fullpath)
247+
SetupConversionFolder(tempfolder.fullpath,Cue,gameId,icon)
248+
end
249+
SetupConversionWindow()
250+
-- local binfile =
251+
tempfolder = sys.tempdir("mgt")
252+
sys.cmd("explorer "..tempfolder.fullpath)
253+
local track1,trackamount = GetTrackFileFromCue(Cue,"01")
254+
local ggi = GetGameID(track1)
255+
if ggi then
256+
gameId = ggi
257+
convert2(gameId)
258+
else
259+
ui.error("Failed to find GameID from track 1!\nPlease Type it Manually")
260+
local window = ui.Window("MPGT: Manual GameID","fixed",200,100)
261+
local textbox = ui.Entry(window,"XXXX_XXXXX",63,18,128,20)
262+
local text1 = ui.Label(window,"Game ID",9,18,54,20)
263+
local text2 = ui.Label(window,"Please include the underscore. (e.g. SLUS_00072)",9,47,182)
264+
local submitbutton = ui.Button(window,"Submit",9,65,182)
265+
local done = false
266+
text2.fontsize = 6
267+
text1.textalign = "center"
268+
text2.textalign = "center"
269+
win:showmodal(window)
270+
for i = 0,20,1 do
271+
window:tofront()
272+
end
273+
function submitbutton.onClick()
274+
local s = textbox.text
275+
local patern = string.find(s,"%a%a%a%a_%d%d%d%d%d")
276+
if patern == nil then
277+
ui.error("ID Format incorrect.")
278+
else
279+
gameId = s
280+
convert2(gameId)
281+
end
282+
end
283+
end
284+
end
285+
286+
287+
local function UpdateChoosenFile(efile,ftype)
288+
if ftype == "cue" then
289+
file = efile
290+
filetext.text = efile.fullpath
291+
return true
292+
else
293+
return false
294+
end
295+
end
296+
local function UpdateOutputFolder(folder)
297+
outputfolder = folder
298+
outputtext.text = folder.fullpath
299+
return true
300+
end
301+
--Non-local functions
302+
--function filebutton.onClick()
303+
-- file = ui.opendialog("Open CUE",false,"PS1 CUE files (*.cue)|*.cue|All Files (*.*)|*.*")
304+
-- Convert(file)
305+
--end
306+
function selectfileButton.onClick()
307+
local choosenfile = ui.opendialog("Open CUE",false,"PS1 CUE files (*.cue)|*.cue|All Files (*.*)|*.*")
308+
if choosenfile then
309+
local update = UpdateChoosenFile(choosenfile,"cue")
310+
if not update then ui.error("Not Supported") return false end
311+
else
312+
return false
313+
end
314+
end
315+
function outputfileButton.onClick()
316+
UpdateOutputFolder(ui.dirdialog("Choose output folder..."))
317+
end
318+
function convertbutton.onClick()
319+
if file == nil then
320+
ui.error("No File selected")
321+
return false
322+
elseif outputfolder ~= nil then
323+
Convert(file)
324+
elseif outputfolder == nil then
325+
ui.error("No Output folder selected.")
326+
return false
327+
end
328+
end
329+
330+
331+
while win.visible do
332+
ui.update()
333+
end
334+
tempfolder:removeall()

net.dll

72.5 KB
Binary file not shown.

programs/imagemag/ICON0.PNG

3.88 KB
Loading

0 commit comments

Comments
 (0)