home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / wuz131.zip / WUZ.Tpl < prev    next >
Text File  |  1994-05-21  |  7KB  |  288 lines

  1. /* unzip/arj/pac etc and open folder */
  2. /* (c) Copyright 1994 Scott Maxwell. */
  3.  
  4. Drive    = 'E:'
  5. DestPath = 'E:\DOWNLOAD\TEMP\'
  6. IconPath = 'E:\MY_OS2\'
  7.  
  8. KeepCommandLineWindow = 1
  9. WaitForUnzip = 1
  10. UnzipInCommandLineWindow = 1    /* KeepCommandLineWindow must be 1 for this */
  11. UsePKZip = 1
  12.  
  13. parse arg args
  14.  
  15. if args = '' then signal showUsage
  16. if Left(args,1) = '"' then
  17.   parse var args '"' Name '"' ExtractHere
  18. else
  19.   parse var args Name ExtractHere
  20.  
  21. ExtractHere = Strip( TransLate( ExtractHere ) )
  22.  
  23. CALL RxFuncAdd 'SysFileDelete','RexxUtil','SysFileDelete'
  24. CALL RxFuncAdd 'SysFileTree','RexxUtil','SysFileTree'
  25.  
  26. if Name = '' then SIGNAL ShowUsage
  27. CurrentDir = Directory()
  28. DeferToPostWuz = 0
  29.  
  30. if KeepCommandLineWindow = 1 & UnzipInCommandLineWindow = 1 & ExtractHere \= "HERE" then
  31.   stub="preparing to extract"
  32. else
  33.   stub="extracting"
  34. Say '0a'x"WPS Unzip -" stub Name
  35. Say "(c) Copyright 1994 Scott Maxwell"'0a'x
  36.  
  37. Yes    = 1
  38. No     = 0
  39.  
  40. Extractor.    = ''
  41. CopyTo.       = No
  42. Update.          = ''
  43. UpdateP.      = ''
  44. Fresh.        = ''
  45.  
  46. Extractor.ARC = '@arc xo'
  47. Fresh.ARC     = '@arc f'
  48. Extractor.ARJ = '@unarj x'
  49. Extractor.LZH = '@lh x /s /o'
  50. Extractor.Z   = '@compress -d'
  51. CopyTo.Z      = Yes
  52. Extractor.TAR = '@tar xf'
  53. CopyTo.TAR    = Yes
  54. Extractor.EXE = '@'
  55. CopyTo.EXE    = Yes
  56. Extractor.COM = '@'
  57. CopyTo.COM    = Yes
  58. Extractor.CMD = '@'
  59. CopyTo.CMD    = Yes
  60. Extractor.BAT = '@'
  61. CopyTo.BAT    = Yes
  62. if UsePKZip = 1 then do
  63.     Extractor.ZIF = '@pkunzip -d -o -n'
  64.     Extractor.ZIP = '@pkunzip -d -o'
  65.     Update.ZIP    = '@pkzip -p -r -u -whs'
  66.     UpdateP.ZIP   = '-xzclr.cmd -xzupdate.cmd -xzfresh.cmd'
  67.     Fresh.ZIP     = '@pkzip -p -r -f -whs'
  68. end
  69. else do
  70.     Extractor.ZIF = '@unzip -o -u'
  71.     Extractor.ZIP = '@unzip -o'
  72.     Update.ZIP    = '@zip -r -u'
  73.     UpdateP.ZIP   = '-x zclr.cmd zupdate.cmd zfresh.cmd'
  74.     Fresh.ZIP     = '@zip -r -f'
  75. end
  76. Extractor.ZOO = '@zoo x'
  77. CopyTo.ZOO    = No
  78.  
  79. call GetDriveSpec Name
  80. Ext = Translate(Ext)
  81. if Ext="" then do
  82.   Name=Name'\'NameOnly'.Zif'
  83.   call GetDriveSpec Name
  84. end
  85.  
  86. if Stream(Name, 'C', 'QUERY EXISTS') = '' then do
  87.    say Name 'not found.'"0a"x
  88.    '@pause'
  89.    exit(1)
  90.    END
  91.  
  92. if NameOnly="" | Ext="" then SIGNAL ShowUsage
  93.  
  94. if Extractor.Ext = '' then Ext="ZIP"
  95.  
  96. if ExtractHere = "HERE" then do
  97.   Call ExtractArchive
  98.   exit(0)
  99. end
  100.  
  101. call RxFuncAdd 'SysSetObjectData','RexxUtil','SysSetObjectData'
  102.  
  103. if Translate(Ext)="ZIF" then do
  104.   dir.1 = directory()
  105.   dir.2 = directory(Left(FullPath,2))
  106.   FullPath = Left(FullPath,Length(FullPath)-Length(FullName)-1)
  107.   Call Directory FullPath
  108.   Extractor.Ext '"'FullName'"'
  109.   Call SysSetObjectData FullPath,"ICONFILE="IconPath"FldUnZip.Ico"
  110.   Call Directory dir.2
  111.   Call Directory dir.1
  112.   exit(0)
  113. end
  114.  
  115. Dest=DestPath||NameOnly
  116.  
  117. CALL RxFuncAdd 'SysMkDir','RexxUtil','SysMkDir'
  118. CALL SysMkDir Dest
  119.  
  120. holdDir = DIRECTORY(Drive)
  121. Call directory Dest
  122.  
  123. Call SysFileDelete 'zclr.cmd'
  124.  
  125. if KeepCommandLineWindow = 1 then do
  126.   Call CHAROUT 'zclr.cmd',"@cd .."'0d0a'x
  127.   if Check4OS2()=1 then do
  128.     Call CHAROUT 'zclr.cmd',"@detach Kill-Dir """Dest""" > nul"'0d0a'x
  129.     Call CHAROUT 'zclr.cmd',"@if '%1'=='-x' exit"'0d0a'x
  130.     Call CHAROUT 'zclr.cmd'
  131.     '@attrib +h zclr.cmd > nul'
  132.   end
  133.   else do
  134.     Call CHAROUT 'zclr.cmd','@detach Kill-Dir "'Dest'"'"0d0a"x
  135.     Call CHAROUT 'zclr.cmd',"@if '%1'=='-x' exit"'0d0a'x
  136.     Call CHAROUT 'zclr.cmd'
  137.   end
  138. end
  139.  
  140. if Update.Ext \= '' then do
  141.   Call SysFileDelete 'zupdate.cmd'
  142.   Call CHAROUT 'zupdate.cmd','@call zipstrip "'FullPath'"'"0d0a"x
  143.   Call CHAROUT 'zupdate.cmd',Update.Ext' "'FullPath'" *' UpdateP.Ext
  144.   Call CHAROUT 'zupdate.cmd'
  145.   if Check4OS2()=1 then
  146.     '@attrib +h zupdate.cmd > nul'
  147.   Call SysSetObjectData Dest,"menuitem=Update,"Dest"\zupdate.cmd"
  148. end
  149.  
  150. if Fresh.Ext \= '' then do
  151.   Call SysFileDelete 'zfresh.cmd'
  152.   Call CHAROUT 'zfresh.cmd',Fresh.Ext' "'FullPath'" *'
  153.   Call CHAROUT 'zfresh.cmd'
  154.   if Check4OS2()=1 then
  155.     '@attrib +h zfresh.cmd > nul'
  156.   Call SysSetObjectData Dest,"menuitem=Refresh,"Dest"\zfresh.cmd"
  157. end
  158.  
  159. if WaitForUnzip = 0 then do
  160.   if KeepCommandLineWindow = 0 | UnzipInCommandLineWindow = 1 then
  161.     Call 'Open-Dir'
  162.   else
  163.     if Check4OS2()=1 then
  164.       '@start "'NameOnly'.'Ext'" /l /fg post-wuz.cmd "'DeferToPostWuz'"' Left(Fresh.Ext,1) Left(Update.Ext,1)
  165.     else
  166.       '@start "'NameOnly'.'Ext'" /f post-wuz.cmd "'DeferToPostWuz'"' Left(Fresh.Ext,1) Left(Update.Ext,1)
  167. end
  168.  
  169. if KeepCommandLineWindow = 0 | UnzipInCommandLineWindow = 0 then
  170.   Call ExtractArchive
  171.  
  172. if WaitForUnzip = 1 | UnzipInCommandLineWindow = 1 then do
  173.   if KeepCommandLineWindow = 0 then
  174.     Call 'Open-Dir'
  175.   else do
  176.     if UnzipInCommandLineWindow = 1 then
  177.       DeferToPostWuz = FullPath
  178.     if Check4OS2()=1 then
  179.       '@start "'NameOnly'.'Ext'" /l /fg post-wuz.cmd "'DeferToPostWuz'"' Left(Fresh.Ext,1) Left(Update.Ext,1)
  180.     else
  181.       '@start "'NameOnly'.'Ext'" /f post-wuz.cmd "'DeferToPostWuz'"' Left(Fresh.Ext,1) Left(Update.Ext,1)
  182.   end
  183. end
  184.  
  185. Call Directory holdDir
  186. Call Directory CurrentDir
  187. exit(0)
  188.  
  189.  
  190. ExtractArchive:
  191.   if CopyTo.Ext = Yes then do
  192.     '@copy "'FullPath'" "'FullName'" > nul'
  193.     '@attrib -r -h -s "'FullName'" > nul'
  194.     Param1 = FullName
  195.   end
  196.   else
  197.     Param1 = FullPath
  198.   Extractor.Ext '"'Param1'"'
  199.   if CopyTo.Ext = Yes then do
  200.     hold = FullPath
  201.     call GetDriveSpec FullName
  202.     if FullPath \= hold then
  203.       Call SysFileDelete Param1
  204.     FullPath = hold
  205.     if Ext == 'Z' & Translate(Right(FullPath,6)) == ".TAR.Z" then do
  206.     Ext = 'TAR'
  207.     Param1 = NameOnly
  208.     Extractor.Ext '"'Param1'"'
  209.     Call SysFileDelete Param1
  210.     end
  211.   end
  212. return
  213.  
  214. GetDriveSpec: procedure expose FullPath FullName NameOnly Ext
  215. parse arg Name
  216. Call SysFileTree Name, files, 'FO'
  217. if files.0 > 0 then do
  218.   FullPath = files.1
  219.   fDrive = Left( FullPath, 2 )
  220.   fPath = SubStr( FullPath, 3, LastPos( '\', FullPath) -2 )
  221.   FullName  = SubStr( FullPath, Length(fPath)+3 )
  222.  
  223.   ExtPos = LASTPOS(".",FullName)
  224.   if ExtPos=0 then do
  225.     Ext = ''
  226.     NameOnly = FullName
  227.   end
  228.   else do
  229.     Ext = SUBSTR(FullName,ExtPos+1)
  230.     NameOnly = LEFT(FullName,ExtPos-1)
  231.   end
  232. end
  233. else do
  234.   p = Pos( ':', Name )
  235.   if p > 0 then do
  236.     fDrive = Left( Name, p )
  237.     Name = SubStr( Name, p+1 )
  238.   end
  239.   else
  240.     fDrive = ''
  241.  
  242.   p = LastPos( '\', Name )
  243.   if p > 0 then do
  244.     fPath = Left( Name, p )
  245.     Name = SubStr( Name, p+1 )
  246.   end
  247.   else
  248.     fPath = ''
  249.  
  250.   FullName = Name
  251.   p = LastPos( '.', Name )
  252.   if p > 0 then do
  253.     Ext = SubStr( Name, p+1 )
  254.     NameOnly = Left( Name, p-1 )
  255.   end
  256.   else do
  257.     Ext = ''
  258.     NameOnly = Name
  259.   end
  260.  
  261.   FullPath = fDrive||fPath||FullName
  262. end
  263.  
  264. return
  265.  
  266.  
  267. Directory: procedure
  268.   arg Name
  269.   if Length(Name) > 3 then
  270.     if Right(Name,1) = '\' then
  271.       Name = Left(Name,LENGTH(Name)-1)
  272.   n = 'DIRECTORY'(Name)
  273.   if Right(n,1) \= '\' then
  274.     n = n'\'
  275.   return n
  276.  
  277.  
  278. Check4OS2: procedure
  279.   '@set is4os2=%_4ver'
  280.   return DATATYPE(VALUE(is4os2,,OS2ENVIRONMENT),'N')
  281.  
  282.  
  283. ShowUsage:
  284.   say "USAGE: wuz filename.[ARJ|LZH|TAR|Z|ZIP|ZOO] here"
  285.   say "If you add 'here' after the filename, the archive will be expanded in place."'0a'x
  286.   '@pause'
  287.   exit
  288.