/* UnInstaller v1.0 by Panokostas Dimitris */

Options Results
addlib("libs:rexxsupport.library", 0, -30, 34)
addlib("libs:rexxreqtools.library", 0, -30, 0)
NL='0a'x
rtezrequest("Welcome to UnInstaller v1.0." || NL ||,
             "Created by Panokostas Dimitris in 1997","Proceed")
rtezrequest("You have to specify an Installer logfile","Pick a logfile | Never Mind")
if rtresult=0 then call Finished
logfile=rtfilerequest(, , "Pick an Installer logfile", ,)
if logfile="" then call Finished
open(1,logfile,"R")
i=0;d=0
do until eof(1)
  OneLine=ReadLN(1)
  If Index(OneLine,"Copy")>0 then do
    i=i+1
    InstFileTmp=substr(OneLine,pos('"',OneLine),(pos('"',OneLine,(pos('"',OneLine)+1)))-(pos('"',OneLine)-1))
    InstPath=Strip(substr(OneLine,pos("to",OneLine)+3),,".")
    If LastPos("/",InstFileTmp)>0 then InstFile=SubStr(InstFileTmp,LastPos("/",InstFileTmp)+1)
    If LastPos(":",InstFileTmp)>0 then InstFile=SubStr(InstFileTmp,LastPos(":",InstFileTmp)+1)
    If LastPos(":",InstFileTmp)=0 then InstFile=InstFileTmp
    If Right(InstPath,2)~='/"' & Right(InstPath,2)~=':"' then InstPath=Strip(InstPath,,'"')||"/"
    InstFull.I=strip(InstPath,,'"')||strip(InstFile,,'"')
  end
  If Index(OneLine,"User made a new drawer:")>0 then do
    d=d+1
    InstDrawer.d=strip(substr(OneLine,pos('"',OneLine),(pos('"',OneLine,(pos('"',OneLine)+1)))-(pos('"',OneLine)-1)),,'"')
  end
end

If I>0 then
  do j=1 to i
        rtezrequest("Delete this file?" || NL ||,
                    InstFull.j,"Abort | Yes | No | Delete All")

  if rtresult=1 then call Finished
  if rtresult=0 then rtezrequest("Are you sure about that?","Yes | No")
        if rtresult=1 then do
          j=i
          call DeleteAll
          call Finished
        end
  if rtresult=2 then do
        if exists(InstFull.j) then delete(InstFull.j)
  end
  if rtresult=3 then noop
end
Call DrawerCleanUp

DrawerCleanUp:
If D>0 then
  do j=1 to d
        rtezrequest("Delete this drawer?" || NL ||,
                    InstDrawer.j,"Abort | Yes | No | Delete All")

  if rtresult=1 then call Finished
  if rtresult=0 then rtezrequest("Are you sure about that?","Yes | No")
        if rtresult=1 then do
          j=d
          call DeleteAllDrawers
          call DrawerCleanUp
        end
  if rtresult=2 then do
        if exists(InstDrawer.j) then delete(InstDrawer.j)
        if exists(InstDrawer.j||".info") then delete(InstDrawer.j||".info")
  end
  if rtresult=3 then noop
end
Call Finished

Finished:
rtezrequest("Finished!")
exit

DeleteAll:
do j=1 to i
        if exists(InstFull.j) then delete(InstFull.j)
end

DeleteAllDrawers:
do j=1 to d
        if exists(InstDrawer.j) then delete(InstDrawer.j)
        if exists(InstDrawer.j||".info") then delete(InstDrawer.j||".info")
end
