#runtime "hsp3cl"
dirlist tmplist,"flash0",5
if stat=0{mkdir "flash0"}
sdim filelists4pack,64
sdim flash0img,10240*1024*4
sdim fname,256
dim cntofdir,256,2
flash0path="flash0"
dirname="/"
cntoftree=0:statue=0
noteunsel
repeat
//dialog dirname
dirlist tmplist,flash0path+dirname+"*.*",5
statue=stat
if statue!0{
if cntofdir(cntoftree,0)=0{
cntofdir(cntoftree,0)=statue
cntofdir(cntoftree,1)=0
}
}else{
if cntoftree>0{
repeat cntoftree-1
cntofdir(cnt+1,0)=0
cntofdir(cnt+1,1)=0
loop
cntoftree=0
dirname="/"
continue cnt+1
}
}
*fetchfiles
notesel tmplist
noteget dirtmp,cntofdir(cntoftree,1)
cntofdir(cntoftree,1)++
dirname+=dirtmp+"/"
if dirtmp=""{dirname="/"}
dirlist dirtmps,flash0path+dirname+"*.*",1
statue2=stat
noteunsel
cntoftree++
if statue2=0 & statue!0{continue cnt+1}
await
notesel dirtmps
repeat statue2
noteget dirtmp,cnt
if dirname="/"{
filelists4pack+=dirtmp+"\n"
}else{
filelists4pack+=dirname+dirtmp+"\n"
}
loop
noteunsel
if dirname="/"{
	break
}
if cntoftree>0{
dirlist tmplist,flash0path+dirname+"*.*",5
if stat!0{continue cnt+1}
if cntofdir(cntoftree-1,0)>cntofdir(cntoftree-1,1){
cntoftree--
posofslsh=0:posofslshold=-1
repeat strlen(dirname):if strmid(dirname,cnt,1)="/"{posofslshold=posofslsh:posofslsh=cnt}:loop
if posofslshold!-1{dirname=strmid(dirname,0,posofslshold+1):cntofdir(cntoftree+1,0)=0:cntofdir(cntoftree+1,1)=0}
continue cnt+1
goto *fetchfiles
}
}
loop
delta=0x8b000000
deltaoffnamesx=0
notesel filelists4pack
howmanydatas=notemax
repeat howmanydatas
noteget filelists4pack1l,cnt
memcpy flash0img,filelists4pack1l,strlen(filelists4pack1l),((howmanydatas+1)*12)+deltaoffnamesx,0
lpoke flash0img,(12*cnt)+(4*0),(((howmanydatas+1)*12)+deltaoffnamesx)+delta
deltaoffnamesx+=strlen(filelists4pack1l)+1
loop
deltaoffnamesx2=0
repeat howmanydatas
noteget filelists4pack1l,cnt
if strmid(filelists4pack1l,0,1)!="/"{filelists4pack1l="/"+filelists4pack1l}
exist flash0path+filelists4pack1l
strsize2=strsize
if strsize2!-1{
sdim filedata,strsize2
bload flash0path+filelists4pack1l,filedata
memcpy flash0img,filedata,strsize2,((howmanydatas+1)*12)+deltaoffnamesx+deltaoffnamesx2,0
lpoke flash0img,(12*cnt)+(4*1),(((howmanydatas+1)*12)+deltaoffnamesx+deltaoffnamesx2)+delta
lpoke flash0img,(12*cnt)+(4*2),strsize2
deltaoffnamesx2+=strsize2
}
loop
sdim flash0img2,(((howmanydatas+1)*12)+deltaoffnamesx+deltaoffnamesx2)
memcpy flash0img2,flash0img,(((howmanydatas+1)*12)+deltaoffnamesx+deltaoffnamesx2),0,0
sdim flash0img,0

bsave "flash0_pcff.bin",flash0img2

end
