home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / software / varie / gdtrash1.1rev.2 / modules / gdtrash.dopus5
Text File  |  2000-01-14  |  36KB  |  934 lines

  1. /* Global Trashcan for Dopus by Nils-Erik R. Skilnand Version 2.1 public version 1.1 11-aug-99 13:50 */
  2. options results
  3. options failat 11
  4. Address value DOPUS.1
  5. signal on syntax
  6. signal on break_c
  7. signal on halt
  8. dopus front
  9.  
  10. if ~show("L", 'rexxsupport.library') then do
  11.   if ~addlib('rexxsupport.library', 0, -30, 0) then do
  12.     dopus request '"rexxsupport.library is not available. Exiting..." OK'
  13.     exit
  14.   end
  15. end
  16.  
  17. if ~show("L", 'rexxtricks.library') then do
  18.   if ~addlib('rexxtricks.library', 0, -30, 0) then do
  19.     dopus request '"rexxtricks.library is not available. Exiting..." OK'
  20.     exit
  21.   end
  22. end
  23.  
  24. remlib('rexxtricks.library')
  25.  
  26. Call Forbid()
  27.     If Show("P",'trash-handler') then do
  28.         Call Permit()
  29.         dopus request '"Global Trash error:"'|| '0a'x ||'" multiple handlers!" OK'
  30.         Exit
  31.         End
  32.     If ~openport('trash-handler') then do
  33.         Call Permit()
  34.         dopus request '"Global Trash error:"'|| '0a'x ||'" could not open port" OK'
  35.         Exit
  36.         End
  37. Call Permit()
  38.  
  39. /*- Open Prefs File -----------------------------------------------------------------*/
  40.  
  41. if open(1,'Env:trash.prefs','R') then do
  42.     do i=1 to 6
  43.         prefs.i = readln(1)
  44.     end
  45.         
  46.     if prefs.1 ~="" then AskAtBeginning=prefs.1
  47.     if prefs.2 ~="" then FileDate=prefs.2
  48.     if prefs.3 ~="" then iconname=prefs.3
  49.     if prefs.4 ~="" then trashpath=prefs.4
  50.     if prefs.5 ~="" then trashname=prefs.5
  51.     if prefs.6 ~="" then coolbar=prefs.6
  52.     Call close(1)
  53.     
  54.         parse var iconname iconname'.info'
  55. end     
  56. else do
  57.     if exists('ENVARC:trash.prefs') then do
  58.         address command 'Copy ENVARC:trash.prefs ENV:'
  59.         Dopus request '"Please Start me Again!!!" OK'
  60.         exit
  61.         end
  62.     else
  63.         address command 'Execute SYS:prefs/DTrashConfig/DTrashConfig'
  64.         Dopus request '"Please Start me Again!!!" OK'
  65.         exit
  66.     end
  67.  
  68.  
  69. if (showdir(trashpath,'All'))~="" then do
  70.     if AskAtBeginning = 'YES' | AskAtBeginning = 'Yes' then do
  71.         dopus request '"All Files in TrashDir"'|| '0a'x ||'"Will Be Deleted"'|| '0a'x ||'"Even If You Have Set The Date Control" OK|Cancel'
  72.         if RC=1 then Address Command 'Delete 'trashpath'#? all'
  73.         dopus front
  74.     end
  75.  
  76. end     
  77.  
  78. Call DiskSpace
  79.  
  80. if freespace1 < 5120 then do
  81.     if (showdir(trashpath,'All'))~="" then do
  82.         dopus request '"WARNING!!!!!!! WARNING!!!!!!!"'|| '0a'x ||'"Global Trash Needs Alot Of Free"'|| '0a'x ||'"Harddisk space to work"'|| '0a'x ||'"Your selected Device have less than 5 Meg Free"'|| '0a'x ||'" I could Flush it for you???"'|| '0a'x ||'"It Will Delete all Files in Trashdir!"'|| '0a'x ||'"Free Disk Space= 'freespace'" OK|Cancel'
  83.         if RC=1 then Address Command 'Delete 'trashpath'#? all'
  84.     end
  85.     else
  86.         dopus request '"WARNING!!!!!!! WARNING!!!!!!!"'|| '0a'x ||'"Global Trash Needs Alot Of Free"'|| '0a'x ||'"Harddisk space to work"'|| '0a'x ||'"Your selected Device have less than 5 Meg Free"'|| '0a'x ||'"You should consider to select another device!!!!!!!"'|| '0a'x ||'"Free Disk Space= 'freespace'" OK'
  87. end
  88.  
  89. /*- Delete files older than x Days ---------------------------------------------------*/
  90.     newd=date('e',date('i')-FileDate)
  91.     parse var newd day'/'month'/'year
  92.  
  93.     /* uses the command list upto to get old files */
  94.     address command 'List 'trashpath' UPTO 'day'-'month'-'year' DATES LFORMAT="%n" >T:trashlist'
  95.     CALL Open('a1','t:trashlist','r')
  96.     do until eof('a1')
  97.      ln=Readln('a1')
  98.      Name=substr(ln,1,length(ln))
  99.      if Name~="" then do 
  100.       Address Command 'Delete "'trashpath''Name'" ALL'
  101.       Address Command 'Delete "'trashpath''Name||.PATH'"'   
  102.      end
  103.     end
  104.     Close('a1')
  105. /*- Do some toolbar stuff ------------------------------------------------------------*/
  106.  
  107. if coolbar~="" then do
  108.     coolbar = "toolbar" coolbar
  109.     end
  110. else
  111.     coolbar = ""
  112.  
  113. /*- See if there is any snapshot info in the icon's filecomment ----------------------*/
  114.  
  115. address command "list >PIPE:trash-handler "iconname".info LFORMAT %c"
  116. if open(comfile,'PIPE:trash-handler',"R") then do
  117.     comment = readln(comfile)
  118.     close(comfile)
  119.     end
  120.  
  121. If Word(comment,1) = "TSnap:" Then do
  122.     comment =   word(comment,2)
  123.     comcom  =  index(comment,",")
  124.     comx    =   left(comment,comcom-1)
  125.     comy    =  right(comment,length(comment) - comcom)
  126.     comment = "POS" comx comy
  127.     End
  128. Else
  129.     comment = ""
  130.  
  131. /*- Set up menu items ---------------------------------------------------------------*/
  132.  
  133. iconmenu.count=3
  134. iconmenu.0='Empty Trash'
  135. iconmenu.1='Configuration'
  136. iconmenu.2='About'
  137.  
  138. /*- add an icon ---------------------------------------------------------------------*/
  139.  
  140. dopus addappicon 'trash-handler' '"'trashname'"' comment icon iconname quotes info snap close local menu iconmenu. 
  141. myicon=result
  142.  
  143. /*- loop around ---------------------------------------------------------------------*/
  144.  
  145. flag = 0
  146. do while flag = 0
  147.     call waitpkt('trash-handler')
  148.  
  149.     packet=getpkt('trash-handler')
  150.     arg0=getarg(packet,0)
  151.     arg1=getarg(packet,1)
  152.     arg2=getarg(packet,2)
  153.     arg3=getarg(packet,3)
  154.     arg4=getarg(packet,4)
  155.  
  156.     call reply(packet,0)
  157.  
  158.     if arg0 = 'dropfrom' then do
  159.     dopus setappicon myicon busy on
  160.         allents = arg2
  161.         If arg3 = 0 then call getall_alien
  162.         Else do
  163.             lister query arg3 path
  164.             printpath = strip(result,"B",'"')
  165.             call getall
  166.             end
  167.         LISTER SET arg3 newprogress name info bar
  168.         Lister set arg3 newprogress title "Trashing Files ..."
  169.         LISTER SET arg3 NEWPROGRESS INFO "Number of files: "entries
  170.         do i = 1 to entries
  171.             if type.i = 0 then do
  172.                 Call DeviceEject
  173.             end
  174.             if type.i < 0 then do
  175.                 /* Only Files */
  176.                 address command 'Move 'name.i' to 'trashpath''
  177.                 address command 'Echo >'trashpath||strip(name1.i,B,'"')||.path' 'printpath''
  178.                 Address Command 'SetDate 'trashpath||strip(name1.i,B,'"')''
  179.             end
  180.             LISTER SET arg3 NEWPROGRESS INFO entries "/" entries-i Name1.i
  181.             LISTER SET arg3 NEWPROGRESS bar entries i
  182.             if type.i > 0 then do
  183.                 /* Dirs */
  184.                 address command 'Move 'name.i' to 'trashpath||strip(name1.i,B,'"')''    
  185.                 address command 'Echo >'trashpath||strip(name1.i,B,'"')||.path' 'printpath''
  186.                 Address Command 'SetDate 'trashpath||strip(name1.i,B,'"')''
  187.             end
  188.         end
  189.             LISTER CLEAR arg3 progress
  190.             Lister refresh arg3 full
  191.             dopus getdesktop
  192.             dest=result
  193.             dopus checkdesktop dest
  194.         dopus setappicon myicon busy off
  195.         end
  196.     if arg0 = 'close' then flag = 1
  197.     if arg0 = 'info'  then do
  198.         files=0;dirs=0
  199.         address command 'list 'trashpath'~(#?.PATH) files lformat %n >PIPE:fl'
  200.         address command 'list 'trashpath'~(#?.PATH) dirs lformat %n >PIPE:fl1'
  201.  
  202.         call open('1','PIPE:fl','r')
  203.         do until eof('1')
  204.             files=files+1 
  205.             readln('1')
  206.         end
  207.         close('1')
  208.  
  209.         Call Open('2','PIPE:fl1','r')
  210.         do until eof('2')
  211.             dirs=dirs+1 
  212.             readln('2')
  213.         end
  214.         close('2')
  215.  
  216.         Call DiskSpace
  217.  
  218.         dopus setappicon myicon busy on
  219.         dopus request '"Days Before Deleting= 'FileDate'"'|| '0a'x ||'"Files= 'files-1'"'|| '0a'x ||'"Directories= 'dirs-1'"'|| '0a'x ||'"Free Disk Space= 'freespace'" OK' 
  220.         dopus setappicon myicon busy off                
  221.         end
  222.     if arg0 = 'doubleclick' then do
  223.         Call Forbid()
  224.            If Show("P",'Trash_lister') then do
  225.                Call Permit()
  226.                dopus request '"Global Trash error:"'|| '0a'x ||'" multiple handlers!" OK'
  227.                Call halt
  228.            End
  229.            If ~openport('Trash_lister') then do
  230.                Call Permit()
  231.                dopus request '"Global Trash error:"'|| '0a'x ||'" could not open port" OK'
  232.                call halt
  233.            End
  234.         Call Permit()
  235.  
  236.         dopus setappicon myicon busy on
  237.     addlib('rexxtricks.library', 0, -30, 0)
  238.         lister new coolbar 
  239.         handle=result
  240.         Newpath=Trashpath
  241.         Setenv('NewPath',Newpath)
  242.         lister Clear handle
  243.         call CheckFiles                 
  244.         /*- Do some lister stuff ---------------------------------------------------------*/
  245.         lister set handle handler 'Trash_lister' quotes nopopups
  246.         traps = 'Delete Parent Copy CopyAs Comment Rename'
  247.         do while traps ~= ''
  248.             parse var traps trapcommand traps
  249.             dopus addtrap trapcommand 'Trash_lister'
  250.         end
  251.  
  252.         /*- loop around ------------------------------------------------------------------*/
  253.                 
  254.         do forever
  255.             call waitpkt('Trash_lister')
  256.                 packet=getpkt('Trash_lister')
  257.                 arg0=getarg(packet,0)
  258.                 arg1=getarg(packet,1)
  259.                 arg2=getarg(packet,2)
  260.                 arg3=getarg(packet,3)
  261.                 arg4=getarg(packet,4)
  262.                 arg5=getarg(packet,5)
  263.                 arg6=getarg(packet,6)
  264.                 arg7=getarg(packet,7)
  265.  
  266.                 call reply(packet,0)
  267.         
  268.                 if arg0 = 'inactive' then do
  269.                     closeport('Trash_lister')
  270.                     lister close handle
  271.                     lister Clear handle
  272.                     traps = 'Delete Parent Copy CopyAs Comment Rename'
  273.                     do while traps ~= ''
  274.                         parse var traps trapcommand traps
  275.                         dopus remtrap trapcommand 'Trash_lister'
  276.                     end
  277.                     leave
  278.                     end 
  279.                 if arg0 = 'dropfrom' then do
  280.                     if arg5 = 'desktop' then do
  281.                     dopus getdesktop
  282.                         arg5=result
  283.                     end
  284.                     allents = arg2
  285.                     entries=0
  286.                     do while allents~=''
  287.                         entries=entries+1
  288.                         parse var allents '"' name.entries '"' allents
  289.                         lister query handle entry '"'name.entries'"' stem fileinfo.
  290.                         type.entries=fileinfo.type
  291.                         name1.entries=name.entries
  292.                     end
  293.                     
  294.                     do i = 1 to entries
  295.                         if type.i < 0 then do
  296.                             /* Only Files */
  297.                             address command 'Move 'newpath||strip(name1.i,B,'"')' 'arg5''
  298.                             if NewPath==TrashPath then do
  299.                                 address command 'Delete 'trashpath||strip(name1.i,B,'"').PATH''
  300.                             end     
  301.                             lister remove handle strip(name1.i,B,'"')
  302.                         end
  303.                         if type.i > 0 then do
  304.                             /* Dirs */
  305.                             address command 'Move 'newpath||strip(name1.i,B,'"')' 'arg5||strip(name1.i,B,'"')''
  306.                             if NewPath==TrasPath then do
  307.                                 address command 'Delete 'trashpath||strip(name1.i,B,'"').PATH''
  308.                             end
  309.                             lister remove handle strip(name1.i,B,'"')
  310.                         end
  311.                     end
  312.                     
  313.                     lister refresh handle full
  314.                     dopus checkdesktop arg5
  315.                 end
  316.                 
  317.                 if arg0 = 'drop' then do        
  318.                     allents = arg2
  319.                     If arg3 = 0 then call getall_alien
  320.                 Else do
  321.                     lister query arg3 path
  322.                     printpath = strip(result,"B",'"')
  323.                     call getall
  324.                 end
  325.                     LISTER SET arg3 newprogress name info bar
  326.                     Lister set arg3 newprogress title "Trashing Files ..."
  327.                     LISTER SET arg3 NEWPROGRESS INFO "Number of files: "entries
  328.                     do i = 1 to entries
  329.                         if type.i = 0 then do
  330.                             Call DeviceEject
  331.                         end
  332.                         if type.i < 0 then do
  333.                             /* Only Files */
  334.                             address command 'Move 'name.i' to 'trashpath''
  335.                             address command 'Echo >'trashpath||strip(name1.i,B,'"')||.path' 'printpath''
  336.                             Address Command 'SetDate 'trashpath||strip(name1.i,B,'"')''
  337.                             if newpath==TrashPath then
  338.                             lister add handle '"'strip(name1.i,B,'"')'" "'FSize.i'" -1 r '"* "FileDate' '"-"' 'printpath''
  339.                         end
  340.                         LISTER SET arg3 NEWPROGRESS INFO entries "/" entries-i Name1.i
  341.                         LISTER SET arg3 NEWPROGRESS bar entries i
  342.                         if type.i > 0 then do
  343.                             /* Dirs */
  344.                             address command 'Move 'name.i' to 'trashpath||strip(name1.i,B,'"')''    
  345.                             address command 'Echo >'trashpath||strip(name1.i,B,'"')||.path' 'printpath''
  346.                             Address Command 'SetDate 'trashpath||strip(name1.i,B,'"')''
  347.                             If newpath==TrashPath then
  348.                             lister add handle '"'strip(name1.i,B,'"')'" "Dir" 1 r '"* "FileDate' '"-"' 'printpath''
  349.                         end
  350.                     end
  351.                     LISTER CLEAR arg3 progress
  352.                     Lister refresh arg3 full
  353.                     lister refresh handle full       
  354.                     dopus getdesktop
  355.                     dest=result
  356.                     dopus checkdesktop dest
  357.                 end
  358.                 if arg0 = 'doubleclick' then do
  359.                     lister query handle entry '"'arg2'"' stem fileinfo.
  360.                     if fileinfo.type > 0 then do
  361.                         NewPath=NewPath||arg2'/'
  362.                         days=''
  363.                         Com=''
  364.                         Com1=''
  365.                         Setenv('NewPath',NewPath)
  366.                         Call CheckFiles
  367.                     end
  368.                     else command doubleclick newpath||arg2
  369.                 end
  370.                 if arg0 = 'Parent' then do
  371.                     if NewPath==TrashPath then 
  372.                         Nop
  373.                     else do
  374.                         newpos=lastpos('/',newpath,lastpos('/',newpath)-1)
  375.                         newpath=left(newpath,newpos)
  376.                         Setenv('NewPath',NewPath)
  377.                         Call CheckFiles
  378.                     End
  379.                 end
  380.                 if arg0 = 'Delete' then do
  381.                     allents = arg2
  382.                     entries=0
  383.                     do while allents~=''
  384.                         entries=entries+1
  385.                         parse var allents '"' name.entries '"' allents
  386.                         lister query handle entry '"'name.entries'"' stem fileinfo.
  387.                         type.entries=fileinfo.type
  388.                         name1.entries=name.entries
  389.                     end
  390.                     lister request handle '"Warning: You cannot get back"'|| '0a'x ||'"What you delete! OK to delete"'|| '0a'x ||'""'|| '0a'x ||'"Entries to delete:'entries'" Proceed|DeleteAll|Cancel'
  391.                     if RC~=0 then do
  392.                     LISTER SET arg1 newprogress name info bar
  393.                     Lister set arg1 newprogress title "Deleting Files ..."
  394.                     LISTER SET arg1 NEWPROGRESS INFO "Number of files: "entries
  395.                     do i = 1 to entries
  396.                         if type.i < 0 then do
  397.                             /* Only Files */
  398.                             address command 'Delete 'newpath||strip(name1.i,B,'"')''
  399.                             if NewPath==TrashPath then do
  400.                                 address command 'Delete 'trashpath||strip(name1.i,B,'"').PATH''
  401.                             end     
  402.                             lister remove handle strip(name1.i,B,'"')
  403.                         end
  404.                         LISTER SET arg1 NEWPROGRESS INFO entries "/" entries-i Name1.i
  405.                         LISTER SET arg1 NEWPROGRESS bar entries i
  406.                         if type.i > 0 then do
  407.                             /* Dirs */
  408.                             address command 'Delete all 'newpath||strip(name1.i,B,'"')''
  409.                             if NewPath==TrashPath then do
  410.                                 address command 'Delete 'trashpath||strip(name1.i,B,'"').PATH''
  411.                             end
  412.                             lister remove handle strip(name1.i,B,'"')
  413.                         end
  414.                     end
  415.                     LISTER CLEAR arg1 progress
  416.                     lister refresh handle all       
  417.                     end
  418.                 end
  419.                         
  420.                 if arg0='path' then do 
  421.                     call CheckFiles
  422.                 end
  423.  
  424. /* This Will add a comment to the file. A popup would have been better, but then I will need to */
  425. /* rewrite the 'CheckFiles' routine and thats out of the question for now. That will not */
  426. /* happen until the global version is ready */
  427.  
  428.                 if arg0 = 'Comment' then do
  429.             lf = '0a'x
  430.                     allents=arg2
  431.                     entries=0
  432.                     do while allents~=''
  433.                         entries=entries+1
  434.                         parse var allents '"' name.entries '"' allents
  435.                         address command 'list 'newpath||name.entries' LFORMAT %c >PIPE:comment'
  436.                         if open(comfile,'PIPE:comment',"R") then do
  437.                             comment = readln(comfile)
  438.                             close(comfile)
  439.                             if comment='' then do
  440.                                 lister getstring handle '"Please enter description"'lf'"for 'name.entries'" 80 "" Ok|Cancel'
  441.                                 if dopusrc=0 then nop
  442.                                 if dopusrc=1|dopusrc=-1 then do
  443.                                     address command 'filenote file 'newpath||name.entries' "'result'"'
  444.                                 end
  445.                             end
  446.                             else do
  447.                                 antwords=comment
  448.                                 text='';i=1;l=0;lf = '0a'x;break=0
  449.                                 do i=i to length(antwords)
  450.                                     l=l+1
  451.                                     word=substr(antwords,i,1)
  452.                                     if word=' '|word='?'|word='.'|word=','|word='_'|word='-' then break=1
  453.                                     text=text||word
  454.  
  455.                                     if l=25 then do
  456.                                         if break=1 then do
  457.                                             if word=' '|word='?'|word='.'|word=','|word='_'|word='-' then do
  458.                                                 text=text''lf''
  459.                                             end
  460.                                             else do
  461.                                                 do until word=' '|word='?'|word='.'|word=','|word='_'|word='-'
  462.                                                     text=strip(text,'T',word)
  463.                                                     i=i-1
  464.                                                     word=substr(antwords,i,1)
  465.                                                 end
  466.                                             text=text''lf''
  467.                                             end
  468.                                         end
  469.                                         Else text=text''lf''
  470.                                         l=0;break=0
  471.                                     end
  472.                                 end
  473.                                 lister request handle '"'text'" Ok|Edit|Cancel'
  474.                                 if rc=0 then nop
  475.                                 if rc=1 then nop
  476.                                 if rc=2 then do
  477.  
  478.                     lister getstring handle '"Please enter description"'lf'"for 'name.entries'" 80 "'comment'" Ok|Cancel'
  479.                     if dopusrc=0 then nop
  480.                     if dopusrc=1|dopusrc=-1 then do
  481.                     address command 'filenote file 'newpath||name.entries' "'result'"'
  482.                     end
  483.                                 end
  484.                             end
  485.                         end
  486.                     end     
  487.                 end
  488.  
  489.         if arg0 = 'Rename' then do
  490.             allents=arg2
  491.                     entries=0
  492.                     do while allents~=''
  493.                         entries=entries+1
  494.                         parse var allents '"' name.entries '"' allents
  495.                         lister query handle entry '"'name.entries'"' stem fileinfo.
  496.                         type.entries=fileinfo.type
  497.                         name1.entries=name.entries
  498.                         name.entries = newpath || name.entries
  499.             lister getstring handle '"Please enter new name"'|| '0a'x ||'"for 'name1.entries'" 31"'name1.entries'" Ok|Cancel'
  500.                     if dopusrc=0 then newname.entries=name1.entries
  501.                     if dopusrc=1|dopusrc=-1 then newname.entries=result
  502.                     end
  503.             
  504.             if newpath=trashpath then do
  505.             do i = 1 to entries
  506.                 address command 'Rename QUIET "'name.i'" as "'trashpath||newname.i'"'
  507.                 address command 'Rename QUIET "'name.i||.PATH'" as "'trashpath||newname.i||.PATH'"'
  508.             end
  509.             end
  510.             Else do
  511.             do i = 1 to entries
  512.                 address command 'Rename QUIET "'name.i'" as "'newpath||newname.i'"'
  513.             end
  514.             end
  515.             call CheckFiles
  516.         end
  517.  
  518.         if arg0 = 'CopyAs' then do
  519.                     if arg3 ~=0 then do
  520.                         lister query arg3 path
  521.                         dest=result
  522.                     end
  523.                     else do
  524.                         parse var arg7 arg7':'rest
  525.                         if arg7="Ram Disk" then arg7='Ram:'||rest
  526.                         dest = arg7
  527.                     end
  528.                     allents=arg2
  529.                     entries=0
  530.                     do while allents~=''
  531.                         entries=entries+1
  532.                         parse var allents '"' name.entries '"' allents
  533.                         lister query handle entry '"'name.entries'"' stem fileinfo.
  534.                         type.entries=fileinfo.type
  535.                         name1.entries=name.entries
  536.                         name.entries = newpath || name.entries
  537.             lister getstring handle '"Please enter new name"'|| '0a'x ||'"for 'name1.entries'" 31"'name1.entries'" Ok|Cancel'
  538.                     if dopusrc=0 then newname.entries=name1.entries
  539.                     if dopusrc=1|dopusrc=-1 then newname.entries=result
  540.                     end
  541.                                     
  542.                     LISTER SET arg1 newprogress name info bar
  543.                     Lister set arg1 newprogress title "Copying Files ..."
  544.                     LISTER SET arg1 NEWPROGRESS INFO "Number of files: "entries
  545.  
  546.                     do i = 1 to entries
  547.                         if type.i < 0 then do
  548.                             Address command 'Copy 'name.i' "'dest||newname.i'"'
  549.                         end
  550.                         LISTER SET arg1 NEWPROGRESS INFO entries "/" entries-i Name1.i
  551.                         LISTER SET arg1 NEWPROGRESS bar entries i
  552.                         if type.i > 0 then do
  553.                             Address command 'Copy all 'name.i' "'dest||strip(newname.i,B,'"')'"'
  554.                         end
  555.                     end
  556.                     LISTER CLEAR arg1 progress
  557.                 end           
  558.  
  559.                 if arg0 = 'Copy' then do
  560.                     if arg3 ~=0 then do
  561.                         lister query arg3 path
  562.                         dest=result
  563.                     end
  564.                     else do
  565.                         parse var arg7 arg7':'rest
  566.                         if arg7="Ram Disk" then arg7='Ram:'||rest
  567.                         dest = arg7
  568.                     end
  569.                     allents=arg2
  570.                     entries=0
  571.                     do while allents~=''
  572.                         entries=entries+1
  573.                         parse var allents '"' name.entries '"' allents
  574.                         lister query handle entry '"'name.entries'"' stem fileinfo.
  575.                         type.entries=fileinfo.type
  576.                         name1.entries=name.entries
  577.                         name.entries = newpath || name.entries
  578.                     end
  579.                                     
  580.                     LISTER SET arg1 newprogress name info bar
  581.                     Lister set arg1 newprogress title "Copying Files ..."
  582.                     LISTER SET arg1 NEWPROGRESS INFO "Number of files: "entries
  583.  
  584.                     do i = 1 to entries
  585.                         if type.i < 0 then do
  586.                             Address command 'Copy 'name.i' "'dest'"'
  587.                         end
  588.                         LISTER SET arg1 NEWPROGRESS INFO entries "/" entries-i Name1.i
  589.                         LISTER SET arg1 NEWPROGRESS bar entries i
  590.                         if type.i > 0 then do
  591.                             Address command 'Copy all 'name.i' "'dest||strip(name1.i,B,'"')'"'
  592.                         end
  593.                     end
  594.                     LISTER CLEAR arg1 progress
  595.                 end                                  
  596.  
  597.         end
  598.         dopus setappicon myicon busy off
  599.         end
  600.     if arg0 = 'snapshot' then
  601.         address command 'filenote 'iconname'.info "TSnap:' arg2'"'
  602.     if arg0 = 'unsnapshot' then
  603.         address command 'filenote 'iconname'.info'
  604.     if (arg0 = 'menu' & arg2 = 0) then do
  605.     dopus setappicon myicon busy on
  606.         dopus request '"Warning: You can not get back"'|| '0a'x ||'"What you Delete!. OK to empty Trash?" Proceed|Cancel'
  607.         if RC~=0 then  Address command 'Delete 'trashpath'#? all'
  608.     dopus setappicon myicon busy off
  609.         end
  610.     if (arg0 = 'menu' & arg2 = 1) then do
  611.         if exists('SYS:prefs/DTrashConfig/DTrashConfig') then do
  612.             dopus setappicon myicon busy on
  613.             address command 'Execute SYS:prefs/DTrashConfig/DTrashConfig'
  614.             end
  615.         else
  616.             Dopus request '"No Config Found!!!!"'||' OK'
  617.             Dopus setappicon myicon busy off
  618.         end
  619.     if (arg0 = 'menu' & arg2 = 2) then do
  620.         dopus setappicon myicon busy on
  621.         dopus request '"Global Trashcan for Directory Opus'|| '0a'x ||"by Nils-Erik Reklev Skilnand"|| '0a'x ||"Skilnand@online.no"||'" OK'
  622.         dopus setappicon myicon busy off
  623.         end
  624. end
  625.  
  626. /*- Remove icon ---------------------------------------------------------------------*/
  627.  
  628. if flag ~= 2 then dopus remappicon myicon
  629.     remlib('rexxsupport.library')
  630.     remlib('rexxtricks.library')
  631.     Exit
  632.  
  633. /*- Get functions -------------------------------------------------------------------*/
  634.  
  635. getall:
  636. entries=0
  637. do while allents~=''
  638.     entries=entries+1
  639.     parse var allents '"' name.entries '"' allents
  640.     if name.entries='' then
  641.         type.entries=0
  642.     else do
  643.         lister query arg3 entry '"'name.entries'"' stem fileinfo.
  644.         type.entries=fileinfo.type
  645.         name1.entries=name.entries
  646.         name.entries = printpath || name.entries
  647.         FSize.entries=fileinfo.size
  648.         end
  649.     end
  650. return
  651.  
  652. /* Awfull spaghetti code!!! I'am sure I could do this on 5 lines----------------------*/
  653.  
  654. getall_alien:
  655. entries=0
  656. do while allents~=''
  657.     entries=entries+1
  658.     parse var allents '"' name.entries '"' allents
  659.     if lastpos(":",name.entries)=length(name.entries) then
  660.         type.entries= 0
  661.     else do
  662.         if pos(":",Name.entries)~=0 then do
  663.             parse var Name.entries ':'name1.entries
  664.             if lastpos("/",name1.entries)=length(name1.entries) then do
  665.                 type.entries = 1
  666.                 name1.entries=delstr(name1.entries,lastpos("/",name1.entries),length(name1.entries))
  667.                 if pos("/",name1.entries)~=0 then do
  668.                     do until pos("/",name1.entries)=0
  669.                         parse var name1.entries '/'name1.entries
  670.                     end
  671.                 end
  672.             end
  673.         else do
  674.             if pos("/",name1.entries)~=0 then do
  675.                 do until pos("/",name1.entries)=0
  676.                     parse var name1.entries '/'name1.entries
  677.                 end
  678.             end
  679.  
  680.         address command 'list 'Name.entries' files lformat= "%l" >pipe:fl'
  681.         open('1','PIPE:fl','r')
  682.             FSize.entries=Readln('1')
  683.         Close('1')
  684.         type.entries = -1
  685.         end
  686.         printpath=delstr(Name.entries,pos(name1.entries,Name.entries),length(Name.entries))
  687.         end
  688.         else type.entries = 0
  689.  
  690.                         
  691.     end     
  692. end
  693. return
  694.  
  695. /* Note!!! Drive names should be on the top between 'Select' and 'End' like ZIP0. Device drivers could be */
  696. /* placed anywhere between 'Select' and 'End'. If you have problems give me a note...*/
  697.  
  698. DeviceEject:
  699. if lastpos(":",name.i)=length(name.i) then do
  700.     address command 'diskinfo 'name.i' >Pipe:dev1'
  701.     open('1','Pipe:dev1','r')
  702.     do until device~="" | eof('1')
  703.         rdev=readln('1')
  704.         parse var rdev 'Device'" "'='" "Device
  705.     end
  706.             
  707.     open('1','Pipe:dev1','r')
  708.     do until Unit~="" | eof('1')
  709.         rdev=readln('1')
  710.         parse var rdev 'Unit'" "'='" "Unit
  711.     end
  712.  
  713.     Select
  714.         When Name.i="ZIP0:" then do
  715.             Address Command 'Park scsi 'name.i' Eject NoCheck EJECTDELAY=50 FLUSHDELAY=50'
  716.         End
  717.  
  718.         When Device="ramdrive.device" then do
  719.             Address Command 'Execute S:RemoveDevice 'name.i' 1'
  720.         End
  721.  
  722.         When Device="atapi.device"|Device="asim_atapi.device"|Device="cd.device" then do
  723.             Address Command 'Park scsi 'name.i' Eject NoCheck EJECTDELAY=0 FLUSHDELAY=0'
  724.         End
  725.  
  726.         When Device="trackdisk.device" then do
  727.             Address Command 'Park >NIL: scsi 'name.i' Eject NoCheck'
  728.         End
  729.  
  730.         When Device="mfm.device" then do
  731.             Address Command 'Park >NIL: scsi 'name.i' Eject NoCheck'
  732.         End
  733.  
  734.         When Device="scsi.device" then do
  735.             Address Command 'Execute S:RemoveDevice 'name.i''
  736.         End
  737.  
  738.         When Device="SCSI-Apollo.device" then do
  739.             Address Command 'Execute S:RemoveDevice 'name.i''
  740.         End
  741.  
  742.         Otherwise dopus request '"Global Trash error:"'|| '0a'x ||'"Device not supported!!!"'|| '0a'x ||'"See doc for suported devices and other"'|| '0a'x ||'" usefull information!" OK'
  743.     End
  744. End
  745. Else dopus request '"Global Trash error:"'|| '0a'x ||'"Drop is not a Device!!!" OK'
  746. Close('1')
  747. return
  748.  
  749. DiskSpace:
  750. String=trashpath
  751. parse var String String':'
  752. if upper(string)="SYS" then do
  753.     address command 'ResolveDeviceName SYS: >PIPE:d'
  754.     Open('1','PIPE:d','r')
  755.     String=ReadLn('1')
  756.     Close('1')
  757. end
  758. address command 'info 'String' >PIPE:d'
  759. open('1','PIPE:d','r')
  760. do i=1 to 4 
  761.     devl=readln('1')
  762. end
  763. Close('1')
  764. freespace=trunc((word(devl,4)*512)/1024,2)
  765. freespace1=trunc((word(devl,4)*512)/1024,2)
  766. Select
  767.  
  768.     When freespace > 5000 then do
  769.         freespace=trunc(freespace/1024,2)
  770.         freespace=freespace"MB"
  771.     End
  772.  
  773.     When freespace > 5000000 then do
  774.         freespace=trunc(freespace/1024**2,2)
  775.         freespace=freespace"GB"
  776.     End
  777.  
  778.     Otherwise freespace=freespace"KB"
  779. End
  780. return
  781.  
  782. CheckFiles:
  783.     lister clear handle 
  784.     lister set handle namelength 64
  785.     lister set handle title "TrashList"
  786.     lister set handle source
  787.     lister set handle busy on
  788.         
  789.     address command 'list 'NewPath'~(#?.PATH) files dates lformat= "Name:%nSize:%lDate:%d" >ram:t/l'
  790.     address command 'list 'NewPath'~(#?.PATH) dirs dates lformat= "Name:%nDate:%d" >ram:t/l1'
  791.  
  792.     Call open('d','ram:t/l1','r')
  793.  
  794.     dnr=0
  795.     do until eof('d')
  796.         dnr=dnr+1
  797.         Dir=readln('d')
  798.         parse var Dir 'Name:'DName.Dnr'Date:'Date.Dnr
  799.     end
  800.     Close('d')              
  801.     
  802.     Call open('f1','ram:t/l','r')
  803.  
  804.     fnr=0
  805.     do until eof('f1')
  806.         fnr=fnr+1
  807.         Fil=readln('f1')
  808.         parse var Fil 'Name:'FName.fnr'Size:'Size.fnr'Date:'Date1.fnr
  809.     end
  810.     Close('f1')
  811.         
  812.     Tot=((dnr-1)+(fnr-1))
  813.  
  814.     LISTER SET Handle newprogress name info bar
  815.     lister set handle newprogress title "Checking Files ..."
  816.     LISTER SET Handle NEWPROGRESS INFO "Number of files: "tot
  817.     
  818.     lister Clear handle
  819.  
  820.     do d=1 to dnr-1
  821.         if Open('1',NewPath||Dname.d||.PATH,'r') then do
  822.             Com=Readln('1')
  823.             Close('1')
  824.             
  825.         parse var Date.d day'-'month'-'year
  826.         if year<78 then 
  827.             century=20
  828.         else 
  829.             century=19
  830.         month=pos(month,'  JanFebMarAprMayJunJulAugSepOctNovDec')/3
  831.         month=right(month,2,'0')
  832.         if month='00' then
  833.             month='01'
  834.         days=(date('i',century||year||month||day,s)+FileDate)-date('i')
  835.         end
  836.         lister add handle '"'DName.d'" "Dir" 1 r '"* "days' '"-"' 'Com''
  837.         LISTER SET Handle NEWPROGRESS INFO tot "/" tot-d DName.d
  838.         LISTER SET Handle NEWPROGRESS bar tot d
  839.     end
  840.  
  841.     do f=1 to fnr-1
  842.         if Open('2',NewPath||FName.f||'.PATH','r') then do
  843.             Com1=Readln('2')
  844.             Close('2')
  845.             
  846.         parse var Date1.f day'-'month'-'year
  847.         if year<78 then 
  848.             century=20
  849.         else 
  850.             century=19
  851.         month=pos(month,'  JanFebMarAprMayJunJulAugSepOctNovDec')/3
  852.         month=right(month,2,'0')
  853.         if month='00' then
  854.             month='01'
  855.         days=(date('i',century||year||month||day,s)+FileDate)-date('i')
  856.         end
  857.         lister add handle '"'FName.f'" "'Size.f'" -1 r '"* "days' '"-"' 'Com1''
  858.         LISTER SET Handle NEWPROGRESS INFO tot "/" tot-f FName.f
  859.         LISTER SET Handle NEWPROGRESS bar tot f
  860.     end
  861.  
  862.     LISTER CLEAR Handle progress
  863.     lister set handle busy off
  864.     lister set handle display 'name' 'size' 'comment'
  865.     lister set handle field 4 'Days-SourcePath'
  866.     lister refresh handle full
  867. return
  868.  
  869. /*- For debugging -------------------------------------------------------------------*/
  870.  
  871. Halt:
  872. Syntax:
  873. lf = '0a'x
  874. LISTER CLEAR Handle progress
  875. lister close handle
  876. traps = 'Delete Parent Copy CopyAs Comment Rename'
  877. do while traps ~= ''
  878.     parse var traps trapcommand traps
  879.     dopus remtrap trapcommand 'Trash_lister'
  880. end
  881. dopus remappicon myicon
  882. signal=sigl
  883. comline=strip(sourceline(sigl),"B")
  884. err=Errortext(rc)
  885. dopus request '"Syntax Error!!!"'lf'"---------------------"'lf'"line nr. 'signall'"'lf'"'comline'"'lf'"'err'"'lf'""'lf'"Waht will you do??" Save Log and Restart|Save Log Only|Restart Only|Cancel'
  886. if rc=1 then do
  887.     call Open('log','Ram:ErrorReport','w')
  888.     writeln('log','Line nr. 'signal)
  889.     writeln('log',comline)
  890.     writeln('log',err)
  891.     close(log)
  892.     dopus request '"Report saved to Ram"'lf'"Will restart GDTrash" OK'
  893.     closeport('Trash_lister')
  894.     closeport('trash-handler')
  895.     remlib('rexxsupport.library')
  896.     Address command 'Rx Dopus5:Modules/GDtrash.dopus5'
  897.     exit
  898. end
  899. if rc=2 then do
  900.     call Open('log','Ram:ErrorReport','w')
  901.     writeln('log','Line nr. 'signal)
  902.     writeln('log',comline)
  903.     writeln('log',err)
  904.     close(log)
  905.     dopus request '"Report saved to Ram" OK'
  906.     closeport('Trash_lister')
  907.     remlib('rexxsupport.library')
  908.     exit
  909. End
  910. if rc=3 then do
  911.     dopus request '"Will Restart GDTrash" OK'
  912.     closeport('Trash_lister')
  913.     closeport('trash-handler')
  914.     remlib('rexxsupport.library')
  915.     Address command 'Rx Dopus5:Modules/GDtrash.dopus5'
  916.     exit
  917. end
  918. if rc=0 then exit
  919.  
  920. Break_c:
  921. LISTER CLEAR Handle progress
  922. lister close handle
  923. traps = 'Delete Parent Copy CopyAs Comment Rename'
  924. do while traps ~= ''
  925.     parse var traps trapcommand traps
  926.     dopus remtrap trapcommand 'Trash_lister'
  927. end
  928. dopus remappicon myicon
  929. closeport('Trash_lister')
  930. remlib('rexxsupport.library')
  931. Exit
  932.  
  933. /*- End of Line ---------------------------------------------------------------------*/
  934.