System.currentDirectory("ms0:/")
CD = Image.load("ms0:/PSP/GAME/LUA-Tool by Shaplayer/1background.jpg")
drive = 0
mode1 = Font.load("ms0:/PSP/GAME/LUA-Tool by Shaplayer/Geek a byte 2.ttf")
mode1:setPixelSizes(15,15)

weiss = Color.new(255,255,255)
rot = Color.new(0,255,0)
fbrowser = {s = 1, fl = System.listDirectory("ms0:/"),ls = 1, sp = 20}
fbrowser.nf = table.getn(fbrowser.fl)
oldpad = Controls.read()

function runfbrowser()
for i = ((fbrowser.ls-1)*fbrowser.sp)+1, fbrowser.ls*fbrowser.sp do
if fbrowser.nf >= i then
screen:print(10,((i-((fbrowser.ls-1)*fbrowser.sp))*10)-10,
fbrowser.fl[i].name,weiss)
elseif fbrowser.nf < i then break end
end

screen:print(10,((fbrowser.s-((fbrowser.ls-1)*fbrowser.sp))*10)-10,
fbrowser.fl[fbrowser.s].name,rot)

if pad:down() and not oldpad:down() then fbrowser.s = fbrowser.s + 1 end
if pad:up() and not oldpad:up() then fbrowser.s = fbrowser.s - 1 end
if pad:right() and not oldpad:down() then fbrowser.s = fbrowser.s + 3 end
if pad:left() and not oldpad:up() then fbrowser.s = fbrowser.s - 3 end

if fbrowser.s > fbrowser.nf then fbrowser.s = fbrowser.nf elseif fbrowser.s < 1 then fbrowser.s = 1 end
if fbrowser.s > fbrowser.sp*fbrowser.ls then fbrowser.ls = fbrowser.ls + 1
elseif fbrowser.s < ((fbrowser.ls-1) * fbrowser.sp)+1 then fbrowser.ls = fbrowser.ls - 1 fbrowser.s = (fbrowser.ls)*fbrowser.sp end

if pad:circle() and not oldpad:circle() then
ms = System.currentDirectory()
rename = System.startOSK(ms.."/"..fbrowser.fl[fbrowser.s].name,"PRESS START!")
System.rename(ms.."/"..fbrowser.fl[fbrowser.s].name,rename)
fbrowser.s = 1
fbrowser.fl=System.listDirectory()
fbrowser.nf=table.getn(fbrowser.fl)
fbrowser.ls = 1
end

if pad:square() and not oldpad:square() then
ms = System.currentDirectory()
x = System.removeDirectory(ms.."/"..fbrowser.fl[fbrowser.s].name)
System.removeFile(ms.."/"..fbrowser.fl[fbrowser.s].name,x)
System.message("Deleted!",0)
fbrowser.s = 1
fbrowser.fl=System.listDirectory()
fbrowser.nf=table.getn(fbrowser.fl)
fbrowser.ls = 1
end

if pad:select() and not oldpad:select() then
ms = System.currentDirectory()
copy = System.startOSK(ms.."/"..fbrowser.fl[fbrowser.s].name,"Kopieren:")
System.copyFile(ms.."/"..fbrowser.fl[fbrowser.s].name,copy..fbrowser.fl[fbrowser.s].name,1)
end

if pad:cross() and not oldpad:cross() then
if not fbrowser.fl[fbrowser.s].directory then
if string.lower(string.sub(fbrowser.fl[fbrowser.s].name, -4)) == ".pbp" or string.lower(string.sub(fbrowser.fl[fbrowser.s].name, -4)) == ".PBP" then
psx = System.currentDirectory()
System.runeboot(psx.."/"..fbrowser.fl[fbrowser.s].name)

elseif string.lower(string.sub(fbrowser.fl[fbrowser.s].name, -4)) == ".elf" or string.lower(string.sub(fbrowser.fl[fbrowser.s].name, -4)) == ".ELF" then
elf = System.currentDirectory()
System.loadElf(elf.."/"..fbrowser.fl[fbrowser.s].name)

elseif string.lower(string.sub(fbrowser.fl[fbrowser.s].name, -4)) == ".prx" or string.lower(string.sub(fbrowser.fl[fbrowser.s].name, -4)) == ".PRX" then
prx = System.currentDirectory()
System.loadPrxKernel(prx.."/"..fbrowser.fl[fbrowser.s].name)

elseif string.lower(string.sub(fbrowser.fl[fbrowser.s].name, -4)) == ".zip" or string.lower(string.sub(fbrowser.fl[fbrowser.s].name, -4)) == ".ZIP" then
zip = System.currentDirectory()
ZIP.extract(zip.."/"..fbrowser.fl[fbrowser.s].name, "ms0:/","")

elseif string.lower(string.sub(fbrowser.fl[fbrowser.s].name, -4)) == ".lua" or string.lower(string.sub(fbrowser.fl[fbrowser.s].name, -4)) == ".LUA" then
lua = System.currentDirectory()
dofile(lua.."/"..fbrowser.fl[fbrowser.s].name)
end

elseif fbrowser.fl[fbrowser.s].directory then
System.currentDirectory(fbrowser.fl[fbrowser.s].name)
fbrowser.s = 1
fbrowser.fl=System.listDirectory()
fbrowser.nf=table.getn(fbrowser.fl)
fbrowser.ls = 1
end

elseif pad:triangle() and not oldpad:triangle() then
if System.currentDirectory ~= "ms0:/" then
System.currentDirectory("./..")
fbrowser.s = 1
fbrowser.fl=System.listDirectory()
fbrowser.nf=table.getn(fbrowser.fl)
fbrowser.ls = 1
directorio = System.currentDirectory()
end
end
end

oldpad = Controls.read()

while true do
pad = Controls.read()
screen:clear()
screen:blit(0,0,CD)
screen:fontPrint(mode1,280,30,"Change Driver: L oder R",weiss)
screen:fontPrint(mode1,280,50,"Delete File/Folder: Square",weiss)
screen:fontPrint(mode1,280,70,"Rename File/Folder: Circle",weiss)
screen:fontPrint(mode1,280,90,"Copy File/Folder: Select",weiss)
screen:fontPrint(mode1,280,110,"LUA-Tool: Start",weiss)
runfbrowser()
screen.waitVblankStart()
screen.flip()
if pad:r() and not oldpad:r() then
drive = drive + 1
if drive == 1 then
    System.currentDirectory("flash0:/")
    fbrowser = {s = 1, fl = System.listDirectory("flash0:/"),ls = 1, sp = 20}
    fbrowser.nf = table.getn(fbrowser.fl)
    runfbrowser()
end
if drive == 2 then
    System.currentDirectory("flash1:/")
    fbrowser = {s = 1, fl = System.listDirectory("flash1:/"),ls = 1, sp = 20}
    fbrowser.nf = table.getn(fbrowser.fl)
    runfbrowser()
end
if drive == 3 then
isok = UMD.checkDisk()
    if isok == 1 then
        UMD.init()
        System.currentDirectory("disc0:/")
        fbrowser = {s = 1, fl = System.listDirectory("disc0:/"),ls = 1, sp = 20}
        fbrowser.nf = table.getn(fbrowser.fl)
        runfbrowser()
    end
end
if drive == 4 then
    System.currentDirectory("ms0:/")
    fbrowser = {s = 1, fl = System.listDirectory("ms0:/"),ls = 1, sp = 20}
    fbrowser.nf = table.getn(fbrowser.fl)
    runfbrowser()
    drive = 0
end
end
if pad:l() and not oldpad:l() then
drive = drive - 1
if drive == -1 then
    System.currentDirectory("flash0:/")
    fbrowser = {s = 1, fl = System.listDirectory("flash0:/"),ls = 1, sp = 20}
    fbrowser.nf = table.getn(fbrowser.fl)
    runfbrowser()
end
if drive == -2 then
    System.currentDirectory("flash1:/")
    fbrowser = {s = 1, fl = System.listDirectory("flash1:/"),ls = 1, sp = 20}
    fbrowser.nf = table.getn(fbrowser.fl)
    runfbrowser()
end
if drive == -3 then
isok = UMD.checkDisk()
    if isok == 1 then
        UMD.init()
        System.currentDirectory("disc0:/")
        fbrowser = {s = 1, fl = System.listDirectory("disc0:/"),ls = 1, sp = 20}
        fbrowser.nf = table.getn(fbrowser.fl)
        runfbrowser()
    end
end
if drive == -4 then
    System.currentDirectory("ms0:/")
    fbrowser = {s = 1, fl = System.listDirectory("ms0:/"),ls = 1, sp = 20}
    fbrowser.nf = table.getn(fbrowser.fl)
    runfbrowser()
    drive = 0
end
end
oldpad = pad
if pad:start() then
System.currentDirectory("ms0:/PSP/GAME/LUA-Tool by Shaplayer/")
dofile("./LUATool.lua")
end

end
