--copytoms.lua

System.memclean()

System.setHigh()

cfw = System.cfwVersion()
mac = Adhoc.getMac()

------------------------------------------------------------------

----Incrémentation nom DUMP---->
file = io.open("ms0:/PSP/GAME/F1Dumper & Manager/script/dumpnametext.txt" ,"r")
number = file:read("*n")
file:close()

number=number+1

file = io.open("ms0:/PSP/GAME/F1Dumper & Manager/script/dumpnametext.txt" ,"w")
file:write(number)
file:close()

dumpname = ("DUMP No ("..number..")")
--<--Incrémentation nom DUMP----


while true do

screen:clear()
screen.flip()
screen:clear()
screen.flip()
screen:clear()

screen:fontPrint(sanssherif,20,20,"Checking folders",blanc)
screen.flip()
screen:fontPrint(sanssherif,20,20,"Checking folders",blanc)
screen.flip()

check = System.doesDirExist("ms0:/DUMPF1/"..dumpname) 
if check == 1 then 
System.message("Be carefull there is a problem !\n\nThe homebrew going to restart\n\nPlease retry the operation.",0) 

dofile("ms0:/PSP/GAME/F1Dumper & Manager/script.lua")

end

screen:fontPrint(sanssherif,20,35,"Creating folders",blanc)
screen.flip()
screen:fontPrint(sanssherif,20,35,"Creating folders",blanc)
screen.flip()

System.createDirectory("ms0:/DUMPF1/"..dumpname)


check = System.doesDirExist("flash1:/dic") 
if check == 1 then 

System.createDirectory("ms0:/DUMPF1/"..dumpname.."/dic")
end


check = System.doesDirExist("flash1:/gps") 
if check == 1 then 

System.createDirectory("ms0:/DUMPF1/"..dumpname.."/gps")
end


check = System.doesDirExist("flash1:/net") 
if check == 1 then 

System.createDirectory("ms0:/DUMPF1/"..dumpname.."/net")
end

check = System.doesDirExist("flash1:/net/http") 
if check == 1 then 

System.createDirectory("ms0:/DUMPF1/"..dumpname.."/net/http")
end

check = System.doesDirExist("flash1:/registry") 
if check == 1 then 

System.createDirectory("ms0:/DUMPF1/"..dumpname.."/registry")
end

check = System.doesDirExist("flash1:/updater") 
if check == 1 then 

System.createDirectory("ms0:/DUMPF1/"..dumpname.."/updater")
end

check = System.doesDirExist("flash1:/vsh") 
if check == 1 then 

System.createDirectory("ms0:/DUMPF1/"..dumpname.."/vsh")
end

check = System.doesDirExist("flash1:/vsh/theme") 
if check == 1 then 

System.createDirectory("ms0:/DUMPF1/"..dumpname.."/vsh/theme")
end

screen:fontPrint(sanssherif,20,50,"Copying flash1:/ files to ms0:/DUMPF1 directory",blanc)
screen.flip()
screen:fontPrint(sanssherif,20,50,"Copying flash1:/ files to ms0:/DUMPF1 directory",blanc)
screen.flip()


--racine

check = System.doesFileExist("flash1:/config.se") 
if check == 1 then 

System.copyFile("flash1:/config.se", "ms0:/DUMPF1/"..dumpname.."/config.se", 0)

end

check = System.doesFileExist("flash1:/squirrel.red") 
if check == 1 then 

System.copyFile("flash1:/squirrel.red", "ms0:/DUMPF1/"..dumpname.."/squirrel.red", 0)

end



--dic
check = System.doesDirExist("flash1:/dic") 
if check == 1 then 

System.currentDirectory("flash1:/dic") 
fichiers = System.listDirectory() 
nombre_fichiers = table.getn(fichiers) 

for z = 1, nombre_fichiers do -- Pour tout les fichiers
if fichiers[z].directory == false then
System.copyFile(fichiers[z].name,"ms0:/DUMPF1/"..dumpname.."/dic/" ..fichiers[z].name,0)
end
end
end


--gps

check = System.doesDirExist("flash1:/gps") 
if check == 1 then 
System.currentDirectory("flash1:/gps") 
fichiers = System.listDirectory() 
nombre_fichiers = table.getn(fichiers) 

for z = 1, nombre_fichiers do -- Pour tout les fichiers
if fichiers[z].directory == false then
System.copyFile(fichiers[z].name,"ms0:/DUMPF1/"..dumpname.."/gps/" ..fichiers[z].name,0)
end
end
end


--net
check = System.doesDirExist("flash1:/net") 
if check == 1 then 

System.currentDirectory("flash1:/net") 
fichiers = System.listDirectory() 
nombre_fichiers = table.getn(fichiers) 

for z = 1, nombre_fichiers do -- Pour tout les fichiers
if fichiers[z].directory == false then
System.copyFile(fichiers[z].name,"ms0:/DUMPF1/"..dumpname.."/net/" ..fichiers[z].name,0)
end
end
end


--net/http
check = System.doesDirExist("flash1:/net/http") 
if check == 1 then 

System.currentDirectory("flash1:/net/http") 
fichiers = System.listDirectory() 
nombre_fichiers = table.getn(fichiers) 

for z = 1, nombre_fichiers do -- Pour tout les fichiers
if fichiers[z].directory == false then
System.copyFile(fichiers[z].name,"ms0:/DUMPF1/"..dumpname.."/net/http/" ..fichiers[z].name,0)
end
end
end


--registry
check = System.doesDirExist("flash1:/registry") 
if check == 1 then 

System.currentDirectory("flash1:/registry") 
fichiers = System.listDirectory() 
nombre_fichiers = table.getn(fichiers) 

for z = 1, nombre_fichiers do -- Pour tout les fichiers
if fichiers[z].directory == false then
System.copyFile(fichiers[z].name,"ms0:/DUMPF1/"..dumpname.."/registry/" ..fichiers[z].name,0)
end
end
end


--updater
check = System.doesDirExist("flash1:/updater") 
if check == 1 then

System.currentDirectory("flash1:/updater") 
fichiers = System.listDirectory() 
nombre_fichiers = table.getn(fichiers) 

for z = 1, nombre_fichiers do -- Pour tout les fichiers
if fichiers[z].directory == false then
System.copyFile(fichiers[z].name,"ms0:/DUMPF1/"..dumpname.."/updater/" ..fichiers[z].name,0)
end
end
end

--vsh
check = System.doesDirExist("flash1:/vsh") 
if check == 1 then 

System.currentDirectory("flash1:/vsh") 
fichiers = System.listDirectory() 
nombre_fichiers = table.getn(fichiers) 

for z = 1, nombre_fichiers do -- Pour tout les fichiers
if fichiers[z].directory == false then
System.copyFile(fichiers[z].name,"ms0:/DUMPF1/"..dumpname.."/vsh/" ..fichiers[z].name,0)
end
end
end

--vsh/theme
check = System.doesDirExist("flash1:/vsh/theme") 
if check == 1 then 

System.currentDirectory("flash1:/vsh/theme") 
fichiers = System.listDirectory() 
nombre_fichiers = table.getn(fichiers) 

for z = 1, nombre_fichiers do -- Pour tout les fichiers
if fichiers[z].directory == false then
System.copyFile(fichiers[z].name,"ms0:/DUMPF1/"..dumpname.."/vsh/theme/" ..fichiers[z].name,0)
end
end
end

screen:fontPrint(sanssherif,20,65,"Creating file About this dump.txt",blanc)
screen.flip()
screen:fontPrint(sanssherif,20,65,"Creating file About this dump.txt",blanc)
screen.flip()


System.copyFile("ms0:/PSP/GAME/F1Dumper & Manager/script/About this dump.txt","ms0:/DUMPF1/"..dumpname.."/About this dump.txt",0)


file = io.open("ms0:/DUMPF1/"..dumpname.."/About this dump.txt" ,"w")
file:write("This dump has be realised with : F1Dumper & Manager V 2.5\n\n\n")
file:write("Fiwmware : \n"..cfw.." \n\n")
file:write("Mac address : \n"..mac.." \n\n")
file:write("Nickname : "..System.nickName().." \n")
file:write("Date : "..System.getDate(2).." of the "..System.getDate(3).." at "..System.getTime(1).."."..System.getTime(2))
file:close()


screen:fontPrint(sanssherif,20,80,"Done !",blanc)
screen:fontPrint(sanssherif,20,110,"Ruturn to the main menu in 2 sec...",rouge)
screen.flip()
screen:fontPrint(sanssherif,20,80,"Done !",blanc)
screen:fontPrint(sanssherif,20,110,"Ruturn to the main menu in 2 sec...",rouge)
screen.flip()

System.sleep(2000)

dofile("ms0:/PSP/GAME/F1Dumper & Manager/script/mainmenu.lua")


screen.flip()
screen.waitVblankStart()
end
