@name E2 ChipDup Browser
@inputs
@outputs [List Path]:array Select:string
@persist [List Path Kind]:array Type B Root:string
@trigger 

if(first()){
    B=1
    Root="http://www1.dd-tech.com:9000/Dups/users/CaptainMaim/Morthotos/"
    Kind=array()
    Kind[1,string]=">dupeshared/"
    Kind[2,string]=">e2shared/"
    Type=1
    httpRequest(Root) #This should be a simple file dump, not something fancy with graphics, just a simple file directory page.
}
runOnHTTP(1)
runOnChat(1)



O=owner()
Chat=O:lastSaid()

Sl="/"
Com="CDB"
Brk="<"
Back="back"
Forward="for"

COM=Chat:find(Com)
BRK=Chat:find(Brk)
BACK=Chat:find(Back)
FORWARD=Chat:find(Forward)

if(chatClk()&COM){
    if(BRK){
        Select=List[Chat:explode(Brk)[2,string]:toNumber(),string]
        if(Select=="../"){Path:popString()}
        elseif(Select:find("/")){Type=1 Path:pushString(Select)}
        elseif(Select:find(".txt")){Type=2 Path:pushString(Select)}
        httpRequest(Root+Path:concat(Sl))
        B=1
    }
}


if(httpClk()|clk("continue")){
    Data=httpData()
    if(Type==1){
        List=array() #let's start with a blank slate
        List=Data:explode("HREF=") #pass1, find all directory entries
        if(B<List:count()){timer("continue",20)}
        while(B<=List:count()&perf()){
            Item=httpUrlDecode(List[B,string]:explode(">")[1,string]) #crop the string to the end of the entry
            Item=Item:replace("&#39;","'") #repair any undecoded representations of apostrophy
            IL=Item:length() #get the length so we can crop off the extra quotes
            Item=Item:sub(2,IL-1) #crop the quotes off the first and last characters 
            List[B,string]=Item #resubmit the processed item to the list. 
            B++
            
        }
        if(B>List:count()){
            stoptimer("continue")
            List:remove(1) #just erase all the useless header crap and put a back directory entry instead.
            printTable(List)
        }
    }
    if(Type==2){
        if(Path:concat(Sl):find("adv_duplicator")){
            fileWrite(Kind[1,string]+Path[Path:count(),string],Data)
        }
        if(Path:concat(Sl):find("Expression2")){
            fileWrite(Kind[2,string]+Path:concat(Sl),Data)
        }
    }
}
