This repository has been archived by the owner on Sep 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.wlua
431 lines (428 loc) · 15.7 KB
/
main.wlua
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
ui = require("ui")
sys = require("sys")
com = require("compression")
ini = require("ini")
net = require("net")
settings = sys.File("settings.ini")
window = ui.Window("PSP Game Tools: Main Menu","fixed",504,212)
window:loadicon(sys.currentdir.."/images/icon.ico")
pspimage = ui.Picture(window,sys.currentdir.."/images/psp.png")
pspimage:center()
ps1button = ui.Button(window,"PS1 Game Tool",131,23,116,33)
ps1button:tofront()
isoadderbutton = ui.Button(window,"ISO Adder",269,23,116,33)
isoadderbutton:show()
savelistbutton = ui.Button(window,"Savedata List",131,77,116,33)
savelistbutton:show()
gamelistbutton = ui.Button(window,"Game List",131,131,116,33)
gamelistbutton:show()
reselectdrivebutton = ui.Button(window,"Reselect Drive",300,185,110,22)
reselectdrivebutton:show()
window:show()
gamedatabase = sys.File(sys.currentdir.."/data/gamedatabase.txt")
ldl = ini.decode(settings:open("read","utf8"):read()).sets.drive
local function FTPDone ()
if ftpportcheck.checked then
ftp = net.Ftp("ftp://"..ftphostentry.text..":guest@"..ftphostentry.text..":"..ftpportentry.text)
else
ftp = net.Ftp(ftphostentry.text)
end
o = 0
for name, isdir in ftp:list("*.*") do
if isdir then
if name == ftpfolder.text then
o = 1
ui.info("Found /"..ftpfolder.text.." folder...")
ftp.currentdir = "/"..ftpfolder.text
for name, isdir in ftp:list("*.*") do
print(name)
if isdir then
print(name)
if name == "GAME" then
correctfolders = 1
end
end
end
if correctfolders == 1 then
ftp.currentdir = "/"..ftpfolder.text
local driveinini = ini.decode(settings:open("read","utf8"):read())
driveinini["ftp"]["lh"] = ftphostentry.text
driveinini["ftp"]["lp"] = ftpportentry.text
driveinini["ftp"]["port?"] = tostring(ftpportcheck.checked)
driveinini["ftp"]["lf"] = ftpfolder.text
driveinini["sets"]["drive"] = "ftp"
ini.save(settings,driveinini)
drivewindow:hide()
print(ldl)
print(ldl.."PSP/GAME")
else
ui.error("No GAME or SAVEDATA folder")
end
end
else
end
end
if o == 0 then
ui.error("Could not find folder.")
end
end
local function DriveSelect(OverideMessage)
if ldl == "none" and OverideMessage == nil then
ui.msg("Select Drive Letter", "First Time Setup")
elseif OverideMessage == nil then
ui.error("The selected drive doesn't have the PSP/ISO folder, or is not a PSP")
elseif OverideMessage ~= nil then
ui.msg(OverideMessage)
end
drivewindow = ui.Window("PSP Game Tools: Drive Selection","single",265,125)
drivemenu = ui.Tab(drivewindow,{"File","FTP"},0,0)
window:showmodal(drivewindow)
customdirbutton = ui.Button(drivemenu.items[1],"...",92,9,25,25)
driveselect = ui.Combobox(drivemenu.items[1],false,{"D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"},9,9,80)
driveshowbutton = ui.Button(drivemenu.items[1],"Show Connected Drives",120,9,140)
driveclosebutton = ui.Button(drivemenu.items[1],"Done",0,40,265,60)
ftphostentry = ui.Entry(drivemenu.items[2],"192.168.x.x",9,9)
ftpportentry = ui.Entry(drivemenu.items[2],"Port number",120,9)
ftpfolder = ui.Entry(drivemenu.items[2],"Folder",9,45)
ftpdonebutton = ui.Button(drivemenu.items[2],"Done",120,50,145,50)
ftpportcheck = ui.Checkbox(drivemenu.items[2],"Port?",120,32)
ftpportentry.enabled = false
function ftpportcheck.onClick()
ftpportentry.enabled = ftpportcheck.checked
end
function ftpdonebutton.onClick()
ui.msg("FTP Support coming soon!")
-- FTPDone()
end
function driveshowbutton.onClick()
sys.cmd("explorer file:\\")
end
function customdirbutton.onClick()
local dir = ui.dirdialog("Open Directory with PSP and ISO folders")
if not dir == false then
print(dir.fullpath)
if sys.Directory(dir.fullpath.."/".. "PSP").exists == true and sys.Directory(dir.fullpath.."/".. "ISO").exists == true then
ui.msg("Selected PSP at "..dir.fullpath.."/")
local driveinini = ini.decode(settings:open("read","utf8"):read())
driveinini["sets"]["drive"] = dir.fullpath.."/"
ini.save(settings,driveinini)
ldl = ini.decode(settings:open("read","utf8"):read()).sets.drive
drivewindow:hide()
print(ldl)
print(ldl.."PSP/GAME")
else
ui.error("Still not a psp...")
end
drivewindow:tofront()
end
end
function driveclosebutton.onClick()
if driveselect.selected == nil then
ui.error("Please Select a letter")
else
if sys.Directory(driveselect.selected.text..":/".. "PSP").exists == true and sys.Directory(driveselect.selected.text..":/".. "ISO").exists == true then
ui.msg("Selected PSP at "..driveselect.selected.text..":/")
local driveinini = ini.decode(settings:open("read","utf8"):read())
driveinini["sets"]["drive"] = driveselect.selected.text..":/"
ini.save(settings,driveinini)
ldl = ini.decode(settings:open("read","utf8"):read()).sets.drive
drivewindow:hide()
print(ldl)
print(ldl.."PSP/GAME")
else
ui.error("Still not a psp...")
end
drivewindow:tofront()
end
end
function drivewindow.onClose()
if ui.confirm("The only program you can use without a drive selected, is PSXTOPSP, would you like to open it?") == "yes" then
sys.cmd(sys.currentdir.."/psxtopsp/app.exe")
return false
else
if ui.confirm("Would you like to exit?") == "yes" then
window:hide()
else
return false
end
end
end
end
function reselectdrivebutton.onClick()
DriveSelect("Reselect Drive")
end
if ldl == "none" or sys.Directory(ldl.."PSP").exists == false then
if ldl == "ftp" then
ui.msg("Using FTP")
local driveinini = ini.decode(settings:open("read","utf8"):read())
if driveinini["ftp"]['port?'] == "true" then
ftp = net.Ftp("ftp://"..driveinini["ftp"]["lh"]..":guest@"..driveinini["ftp"]["lh"]..":"..driveinini["ftp"]["lp"])
else
ftp = net.Ftp(driveinini["ftp"]["lh"])
end
o = 0
for name, isdir in ftp:list("*.*") do
if isdir then
print("\t"..name)
if name == driveinini["ftp"]["lf"] then
o = 1
ui.info("Connected")
ftp.currentdir = "/"..driveinini["ftp"]["lf"]
ini.save(settings,driveinini)
print(ldl)
print(ldl.."PSP/GAME")
end
else
print("\t/"..name)
end
end
if o == 0 then
ui.error("Could not find folder.")
end
else
DriveSelect()
end
else
ui.msg("Selected PSP at "..ldl)
end
ldl = ini.decode(settings:open("read","utf8"):read()).sets.drive
function ps1button.onClick()
if ui.confirm("This will open PSXTOPSP, Do you wish to continue?","Open Other App") == "yes" then
print(sys.cmd(sys.currentdir.."/psxtopsp/app.exe",false,true))
end
end
function isoadderbutton.onClick()
ui.msg("You can add ISO or ZIP files with ISOs in them! (7z support coming soon!)")
local file = ui.opendialog("Open ISO or ZIP with ISO",false,"ISO Archives(*.iso,*.ISO)|*.iso|ZIP Archives|*.zip")
print(file.extension)
if file.extension == ".iso" or file.extension == ".ISO" then
local copy = ui.confirm('Do you wish to copy the file?')
if copy == "cancel" then
return false
end
local progress = ui.Progressbar(window,0,200,504,20)
progress:show()
progress.toback(pspimage)
progress:advance(1)
if copy == "yes" then
local existingfile = sys.File(ldl.."ISO/"..file.name)
if existingfile.exists then
ui.msg("File "..ldl.."ISO/"..file.name.." already exists.\nReplacing the file.")
if existingfile:remove() == false then
ui.error("Failed to remove existing file.")
progress:hide()
else
progress:advance(10)
end
end
progress:advance(1)
print(ldl.."ISO/"..file.name)
sleep(1000)
local copyedfile = file:copy(ldl.."ISO/"..file.name)
progress:advance(99999)
sleep(1000)
if copyedfile == nil then
ui.error("Can't Move File")
progress:hide()
else
sleep(1000)
ui.msg("Moved File to "..copyedfile.fullpath)
progress:hide()
end
else
local existingfile = sys.File(ldl.."ISO/"..file.name)
if existingfile.exists then
ui.msg("File "..ldl.."ISO/"..file.name.." already exists.\nReplacing the file.")
if existingfile:remove() == false then
ui.error("Failed to remove existing file.")
progress:hide()
else
progress:advance(10)
end
end
progress:advance(1)
if file:move(ldl.."ISO/"..file.name) then
progress:advance(199999999999999)
sleep(1000)
ui.msg("Moved File to "..ldl.."ISO/"..file.name)
progress:hide()
else
ui.error("Couldn't move file.")
progress:hide()
end
end
else
ui.msg("Sadly, LuaRT does not support 7z files, so you can not use them.")
local tempdir = sys.tempdir("pgt")
local zip = com.Zip(file,"read")
local progress = ui.Progressbar(window,0,200,504,20)
progress:show()
progress.toback(pspimage)
progress:advance(1)
sleep(1000)
ui.msg("Extracting ZIPS does take a while, so dont think the app crashed or anything!")
print(tempdir.fullpath)
if zip:extractall(tempdir) == false then
ui.error("Extracting failed with error: "..zip.error)
progress:hide()
tempdir:removeall()
return false
end
progress:advance(50)
for entry in each(tempdir) do
print(entry.name)
if entry.extension == ".iso" then
progress:advance(10)
sleep(2000)
local existingfile = sys.File(ldl.."ISO/"..entry.name)
if existingfile.exists then
ui.msg("File "..ldl.."ISO/"..entry.name.." already exists.\nReplacing the file.")
if existingfile:remove() == false then
ui.error("Failed to remove existing file.")
progress:hide()
else
progress:advance(10)
end
end
if entry:move(ldl.."ISO/"..entry.name) then
sleep(4000)
ui.msg("Extracted "..entry.name.." to "..ldl.."ISO/"..entry.name)
progress:advance(59999999999999990)
progress:hide()
tempdir:removeall()
else
ui.error("Failed to move ISO")
progress:advance(59999999999999990)
progress:hide()
tempdir:removeall()
end
end
end
end
end
function savelistbutton.onClick()
local list = { }
for entry in each(sys.Directory(ldl.."PSP/SAVEDATA")) do
list[#list+1] = entry.name
end
print(ldl)
ui.msg("You can look at the saves on your PSP!")
local listwindow = ui.Window("PSP Game Tools: Save List","fixed",500,300)
window:showmodal(listwindow)
local isolist = ui.List(listwindow,list,0,0,150,300)
gameimage = ui.Picture(listwindow,sys.currentdir.."/images/noneselected.png",160,50,288,160)
gameimage:show()
gamedes = ui.Label(listwindow,"No Save Selected",160,210,260,90)
local gametitle = ui.Label(listwindow,"No Save Selected",160,10,1000000,20)
local savetitle = ui.Label(listwindow,"No Save Selected",160,30)
gametitle.textalign = "left"
gametitle.fgcolor = 0xc0c0c0
savetitle.textalign = "left"
gamedes.textalign = "left"
local deletebutton = ui.Button(listwindow,"Delete Save",420,270,70)
deletebutton.enabled = false
function deletebutton.onClick()
item = isolist.selected
if ui.confirm("Are you sure you want to delete this save?") == "yes" then
if sys.Directory(ldl.."PSP/SAVEDATA/"..item.text).exists then
sys.Directory(ldl.."PSP/SAVEDATA/"..item.text):removeall()
item:remove()
else
sys.File(ldl.."ISO/"..item.text):remove()
item:remove()
end
end
end
function isolist:onSelect(item)
if sys.Directory(ldl.."PSP/SAVEDATA/"..item.text).exists then
gameimage:hide()
gameimage:load(ldl.."PSP/SAVEDATA/"..item.text.."/ICON0.PNG")
gameimage.width = 288
gameimage.height = 160
gameimage:show()
local des = string.sub(sys.File(ldl.."PSP/SAVEDATA/"..item.text.."/PARAM.SFO"):open("read"):read():encode(),273)
local title = string.sub(sys.File(ldl.."PSP/SAVEDATA/"..item.text.."/PARAM.SFO"):open("read"):read():encode(),4657 )
gametitle.text = "Unknown Game"
gamedes.text = des
savetitle.text = title
--ui.msg(des)
deletebutton.enabled = true
for line in gamedatabase:open("read").lines do
if string.sub(line,0,9) == string.sub(item.text,0,9) then
gametitle.text = string.sub(line,11)
end
end
else
gameimage:load(sys.currentdir.."/images/isoselected.png")
gameimage.width = 288
gameimage.height = 160
gametitle.text = item.text
end
end
end
function gamelistbutton.onClick()
local gamelistwindow = ui.Window("PSP Game Tools: Game List","fixed",520,300)
window:showmodal(gamelistwindow)
local openbutton = ui.Button(gamelistwindow,"Open Game",250,150)
local delbutton = ui.Button(gamelistwindow,"Delete Game",360,150)
local copybutton = ui.Button(gamelistwindow,"Copy Game",305,180)
local gametitle = ui.Label(gamelistwindow,"No Game Selected",210,120,300,40)
openbutton.enabled = false
delbutton.enabled = false
copybutton.enabled = false
gametitle.fontsize = 15
local list = { }
for entry in each(sys.Directory(ldl.."PSP/GAME")) do
list[#list+1] = entry.name
end
for entry in each(sys.Directory(ldl.."ISO")) do
list[#list+1] = entry.name
end
gamelist = ui.List(gamelistwindow,list,0,0,200,300)
function openbutton.onClick()
local selected = gamelist.selected
if sys.Directory(ldl.."PSP/GAME/"..selected.text).exists then
sys.cmd("explorer file://"..ldl.."PSP/GAME/"..selected.text,false,true)
elseif sys.File(ldl.."ISO/"..selected.text).exists then
sys.cmd("explorer file://"..ldl.."ISO/",false,true)
end
end
function copybutton.onClick()
local selected = gamelist.selected
local game = sys.File(ldl.."ISO/"..selected.text)
local moveto = ui.savedialog("Copy game to...",false,"ISO Archive (*.iso*)|*.iso|")
if game:copy(moveto.fullpath) == nil then
ui.error("Failed to copy file.")
else
ui.info("Copyed game "..selected.text.." to "..moveto.fullpath)
end
end
function gamelist.onSelect()
gametitle.text = gamelist.selected.text
delbutton.enabled = true
copybutton.enabled = true
openbutton.enabled = true
end
function delbutton.onClick()
local selected = gamelist.selected
print(ldl.."ISO/"..selected.text)
print(ldl.."ISO/"..selected.text)
local confim = ui.confirm("Do you really want to delete the game?")
if confim == "yes" then
if sys.Directory(ldl.."PSP/GAME/"..selected.text).exists then
print("folder")
sys.Directory(ldl.."PSP/GAME/"..selected.text):removeall()
elseif sys.File(ldl.."ISO/"..selected.text).exists then
print("iso")
if sys.File(ldl.."ISO/"..selected.text):remove() == false then
ui.error("Unable to delete file! It may be open.")
else
ui.info("Deleted Game "..ldl.."ISO/"..selected.text)
end
end
end
end
end
while window.visible do
ui.update()
end