home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / awget169.zip / install.cmd < prev    next >
OS/2 REXX Batch file  |  2001-07-17  |  39KB  |  1,084 lines

  1. /* REXX installation script for Auto WGet Daemon
  2.  * Copyright (C) 1998-2001 Dmitry A.Steklenev
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  *
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  *
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in
  13.  *    the documentation and/or other materials provided with the
  14.  *    distribution.
  15.  *
  16.  * 3. All advertising materials mentioning features or use of this
  17.  *    software must display the following acknowledgment:
  18.  *    "This product includes software developed by Dmitry A.Steklenev".
  19.  *
  20.  * 4. Redistributions of any form whatsoever must retain the following
  21.  *    acknowledgment:
  22.  *    "This product includes software developed by Dmitry A.Steklenev".
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR OR CONTRIBUTORS "AS IS"
  25.  * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27.  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28.  * AUTHOR OR THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  30.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31.  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  33.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  35.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36.  *
  37.  * $Id: install.cms,v 1.48 2001/06/27 10:56:43 glass Exp $
  38.  */
  39.  
  40. globals = "cfg. local. msg. sys. color. dir. jobs. job. plugins."
  41.  
  42. if translate( value( "AWGET_TRACE",, "OS2ENVIRONMENT" )) == "YES" then do
  43.    call  value "AWGET_TRACE", "", "OS2ENVIRONMENT"
  44.    trace intermediate
  45.    trace results
  46. end
  47.  
  48. cls ; call AwInit
  49.  
  50. say color.bold  || "Auto WGet Daemon " || color.usual || "Version 1.6.9 Installation"
  51. say color.usual || "Copyright (C) 1998-2001 Dmitry A.Steklenev"
  52. say color.usual || ""
  53.  
  54. call MsgRead "awgmsg"
  55. call CfgRead
  56.  
  57. '@del install.log 1> nul 2> nul'
  58.  
  59. /* Customizing of installation process */
  60.  
  61. country  = MsgCountryID()
  62. instpath = cfg.home
  63.  
  64. if instpath == "." | \DirExist(cfg.home) then
  65.    instpath =  ""
  66.  
  67. do while instpath == ""
  68.    call charout, color.usual || ">>> "msg.install_dir": "
  69.    parse pull instpath
  70. end
  71.  
  72. instpath    = DirCanonical( instpath )
  73. found_count = 0
  74.  
  75. /* We search for all download utilities known to us */
  76.  
  77. do i = 1 to sys.utils.0
  78.    found = SysSearchPath( "PATH", sys.utils.i.prog )
  79.  
  80.    if found \= "" then do
  81.       found_count = found_count + 1
  82.       found_utils.found_count.name = sys.utils.i.name
  83.       found_utils.found_count.parm = sys.utils.i.parm
  84.       found_utils.found_count.prog = sys.utils.i.prog
  85.       found_utils.found_count.path = found
  86.    end
  87. end
  88.  
  89. /* It is necessary to check up contains the configuration file
  90.  * any unknown download utility
  91.  */
  92.  
  93. if cfg.downloads_utility \= "" &,
  94.    cfg.downloads_utility \= sys.utils.default.prog then do
  95.  
  96.    do i = 1 to found_count until,
  97.       translate(cfg.downloads_utility) == translate(found_utils.i.prog)
  98.    end
  99.    if i > found_count then do
  100.       found_utils.i.name = filespec( "name", cfg.downloads_utility )
  101.       found_utils.i.parm = cfg.downloads_parameters
  102.       found_utils.i.prog = translate(cfg.downloads_utility)
  103.       found_utils.i.path = translate(cfg.downloads_utility)
  104.       found_count = i
  105.    end
  106. end
  107.  
  108. if found_count == 0 then do
  109.    /* The download utility is necessary for us */
  110.    call LogDo err, msg.not_found_utils
  111.    call terminate
  112. end
  113.  
  114. if found_count == 1 then
  115.    select = 1
  116. else do
  117.    /* Let's enable the user to select the download utility */
  118.  
  119.    max_len = 0
  120.    do i = 1 to found_count
  121.       max_len = max( max_len, length( found_utils.i.name ))
  122.    end
  123.  
  124.    say color.usual || ">>> "msg.select_util ; say
  125.  
  126.    do i = 1 to found_count
  127.       say color.bold  || "    "i ||,
  128.           color.usual || " - "substr( found_utils.i.name, 1, max_len )"  ("found_utils.i.path")"
  129.    end
  130.  
  131.    say ; select = MsgGetNum( "    "msg.select_number, 0, found_count )
  132. end
  133.  
  134. if select == 0 then exit 0
  135.  
  136. if translate(cfg.downloads_utility) \= found_utils.select.prog then do
  137.    cfg.downloads_utility    = found_utils.select.prog
  138.    cfg.downloads_parameters = found_utils.select.parm
  139. end
  140.  
  141. if cfg.log_file == "nul"  | translate(cfg.log_file ),
  142.                 == translate(instpath"\ToDo\Info\awget.log") then
  143.    cfg.log_file  = instpath"\awget.log"
  144.  
  145. if cfg.error_log == "nul" | translate(cfg.error_log),
  146.                  == translate(instpath"\ToDo\Info\awget_error.log") then
  147.    cfg.error_log = instpath"\awget.err"
  148.  
  149. if cfg.download == "." | \DirExist(cfg.download) then do
  150.    call charout, color.usual || ">>> "msg.download": "
  151.    parse pull cfg.download
  152. end
  153.  
  154. cfg.use_desktop      = (MsgYesNo( ">>> "msg.use_desktop      ) == 1)
  155. cfg.check_connection = (MsgYesNo( ">>> "msg.check_connection ) == 1)
  156. cfg.home             = instpath
  157.  
  158. parse version version
  159. compile = left( version, 7 ) == "OBJREXX" &,
  160.           SysSearchPath( "path", "rexxc.exe" ) \= ""
  161.  
  162. /* The beginning of installation */
  163.  
  164. cls
  165. say color.bold  || "Auto WGet Daemon " || color.usual || "Version 1.6.9 Installation"
  166. say color.usual || "Copyright (C) 1998-2001 Dmitry A.Steklenev"
  167. say color.usual || ""
  168.  
  169. say CfgShow()
  170.  
  171. if MsgYesNo( color.usual">>> "msg.install ) == 0 then
  172.    exit 0
  173.  
  174. cls
  175. say color.bold  || "Auto WGet Daemon " || color.usual || "Version 1.6.9 Installation"
  176. say color.usual || "Copyright (C) 1998-2001 Dmitry A.Steklenev"
  177. say color.usual || ""
  178. say AwStop()
  179.  
  180. /* Create of installation directorys */
  181.  
  182. if \CreateDirectory( instpath           ) then call terminate
  183. if \CreateDirectory( instpath"\NLS"     ) then call terminate
  184. if \CreateDirectory( instpath"\Icons"   ) then call terminate
  185. if \CreateDirectory( instpath"\Plugins" ) then call terminate
  186. if \CreateDirectory( instpath"\Folders" ) then call terminate
  187. if \CreateDirectory( cfg.download       ) then call terminate
  188.  
  189. /* Updating the configuration file */
  190.  
  191. call CfgSave
  192. call LogDo inf, msg.config_updated": "sys.config_file
  193.  
  194. /* Copying files */
  195.  
  196. if \CopyFile( "Icons\awget.ico"  , instpath"\Icons" ) then call terminate
  197. if \CopyFile( "Icons\awgadd.ico" , instpath"\Icons" ) then call terminate
  198. if \CopyFile( "Icons\awghome.ico", instpath"\Icons" ) then call terminate
  199. if \CopyFile( "Icons\awgfold.ico", instpath"\Icons" ) then call terminate
  200. if \CopyFile( "Icons\awgactv.ico", instpath"\Icons" ) then call terminate
  201. if \CopyFile( "Icons\awgdone.ico", instpath"\Icons" ) then call terminate
  202. if \CopyFile( "Icons\awgfail.ico", instpath"\Icons" ) then call terminate
  203. if \CopyFile( "Icons\awgtodo.ico", instpath"\Icons" ) then call terminate
  204. if \CopyFile( "Icons\awglogs.ico", instpath"\Icons" ) then call terminate
  205. if \CopyFile( "Icons\awgstop.ico", instpath"\Icons" ) then call terminate
  206. if \CopyFile( "Icons\awgedit.ico", instpath"\Icons" ) then call terminate
  207. if \CopyFile( "Icons\uninstl.ico", instpath"\Icons" ) then call terminate
  208. if \CopyFile( "Icons\awgread.ico", instpath"\Icons" ) then call terminate
  209. if \CopyFile( "Icons\awgurls.ico", instpath"\Icons" ) then call terminate
  210.  
  211. if compile then do
  212.    if \CopyFile( "awgetd.cmd"    , instpath"\*.rex" ) then call terminate
  213.    if \CopyFile( "awgadd.cmd"    , instpath"\*.rex" ) then call terminate
  214.    if \CopyFile( "awgexec.cmd"   , instpath"\*.rex" ) then call terminate
  215.    if \CopyFile( "awgstop.cmd"   , instpath"\*.rex" ) then call terminate
  216.    if \CopyFile( "uninstl.cmd"   , instpath"\*.rex" ) then call terminate
  217.    end
  218. else do
  219.    if \CopyFile( "awgetd.cmd"    , instpath         ) then call terminate
  220.    if \CopyFile( "awgadd.cmd"    , instpath         ) then call terminate
  221.    if \CopyFile( "awgexec.cmd"   , instpath         ) then call terminate
  222.    if \CopyFile( "awgstop.cmd"   , instpath         ) then call terminate
  223.    if \CopyFile( "uninstl.cmd"   , instpath         ) then call terminate
  224. end
  225.  
  226. if \CopyFile( "traceit.cmd"      , instpath         ) then call terminate
  227. if \CopyFile( "changes"          , instpath         ) then call terminate
  228. if \CopyFile( "license"          , instpath         ) then call terminate
  229. if \CopyFile( "pmpopup2.eng"     , instpath         ) then call terminate
  230. if \CopyFile( "pmpopup2.ger"     , instpath         ) then call terminate
  231. if \CopyFile( "pmpopup2.exe"     , instpath         ) then call terminate
  232. if \CopyFile( "NLS\readme.001"   , instpath         ) then call terminate
  233.  
  234. if \CopyFile( "Plugins\awpglob.cmd", instpath"\Plugins" ) then call terminate
  235. if \CopyFile( "Plugins\awppriv.cmd", instpath"\Plugins" ) then call terminate
  236.  
  237. call SysFileTree "NLS\awgmsg.*", 'nls', 'FO'
  238. do i = 1 to nls.0
  239.    if \CopyFile( "NLS\"filespec( "name", nls.i ), instpath"\NLS" ) then
  240.       call terminate
  241. end
  242.  
  243. if stream( "NLS\readme."country, "c", "query exist" ) \= "" then
  244.    if \CopyFile( "NLS\readme."country, instpath ) then
  245.       call terminate
  246.  
  247. /* Wait for unlocking awget.dll */
  248.  
  249. if \RxFuncQuery('AwDropFuncs') then
  250.    call AwDropFuncs
  251. if \RxFuncQuery('AwLoadFuncs') then
  252.    call RxFuncDrop 'AwLoadFuncs'
  253.  
  254. do 10 until stream( instpath"\awget.dll", "c", "query exists" ) == ""
  255.    rc = stream( instpath"\awget.dll", "c", sys.open_write )
  256.    if rc == "READY:" then do
  257.       rc = stream( instpath"\awget.dll", "c", "close" )
  258.       leave
  259.    end
  260.    call SysSleep 1
  261. end
  262.  
  263. if \CopyFile( "awget.dll", instpath ) then call terminate
  264.  
  265. /* Remove of out-of-date files */
  266.  
  267. files = "vwin.eng  vwin.exe  awget.ico info.ico  awget.msg " ||,
  268.         "awget.001 awget.033 awget.039 awget.049 awget.950 " ||,
  269.         "awget.007 awget.046 awget.048 awget.eng awget.rus " ||,
  270.         "awget.tw  awget.pl  "                               ||,
  271.         "Icon\todo.ico   Icon\run.ico     Icon\done.ico    " ||,
  272.         "Icon\failed.ico Icon\info.ico    Icon\add.ico     " ||,
  273.         "Icon\awget.ico  Icon\uninstl.ico Icon\infoold.ico " ||,
  274.         "awgets.cmd install.cmd"
  275.  
  276. do i = 1 to words(files)
  277.    old_file = instpath"\"word(files,i)
  278.  
  279.    if stream( old_file, "c", "query exists" ) \= "" then do
  280.       '@del "'old_file'" 1> nul 2> nul'
  281.       call LogDo inf, msg.erase_done": "old_file
  282.    end
  283. end
  284.  
  285. /* Migration from pre 1.6.0 versions */
  286.  
  287. call SysDestroyObject "<AWG_LOCK>"
  288. call SysDestroyObject "<AWG_TODO>"
  289.  
  290. if DirExist( instpath"\Icon" ) then
  291.    call SysRmDir instpath"\Icon"
  292.  
  293. /* Migration from 1.6.0 version */
  294.  
  295. if DirExist( instpath"\ToDo" ) then do
  296.    if \CreateDirectory( instpath"\Folders" ) then call terminate
  297.  
  298.    call SysMoveObject "<AWG2_TODO>"   , instpath"\Folders"
  299.    call SysMoveObject "<AWG2_RUNNING>", instpath"\Folders"
  300.    call SysMoveObject "<AWG2_DONE>"   , instpath"\Folders"
  301.    call SysMoveObject "<AWG2_FAILED>" , instpath"\Folders"
  302.    call SysMoveObject "<AWG2_JOBS>"   , instpath"\Folders"
  303. end
  304.  
  305. /* Compile REXX files */
  306.  
  307. if compile then do
  308.    if \CompileFile( instpath"\awgetd.rex" , instpath"\awgetd.cmd"  ) then call terminate
  309.    if \CompileFile( instpath"\awgadd.rex" , instpath"\awgadd.cmd"  ) then call terminate
  310.    if \CompileFile( instpath"\awgexec.rex", instpath"\awgexec.cmd" ) then call terminate
  311.    if \CompileFile( instpath"\awgstop.rex", instpath"\awgstop.cmd" ) then call terminate
  312.    if \CompileFile( instpath"\uninstl.rex", instpath"\uninstl.cmd" ) then call terminate
  313. end
  314.  
  315. /* Create Folders and Objects */
  316.  
  317. if SysOs2Ver() > "2.30" then
  318.    fld_class = "WPUrlFolder"
  319. else
  320.    fld_class = "WPFolder"
  321.  
  322. call CreateObject "U", "WPFolder", msg.obj_home,,
  323.                   "<WP_DESKTOP>",,
  324.                   "OBJECTID=<AWG2_HOME>;"                     ||,
  325.                   "DEFAULTVIEW=TREE;"                         ||,
  326.                   "SHOWALLINTREEVIEW=YES;"                    ||,
  327.                   "ICONFILE="instpath"\Icons\awghome.ico;"
  328.  
  329. call CreateObject "U", "WPFolder", msg.obj_downloads,,
  330.                   "<AWG2_HOME>",,
  331.                   "OBJECTID=<AWG2_DOWNLOADS>;"                ||,
  332.                   "SHOWALLINTREEVIEW=YES;"                    ||,
  333.                   "DEFAULTVIEW=ICON;"                         ||,
  334.                   "ICONFILE="instpath"\Icons\awgfold.ico;"
  335.  
  336. call CreateObject "U", "WPFolder", msg.obj_tools,,
  337.                   "<AWG2_HOME>",,
  338.                   "OBJECTID=<AWG2_TOOLS>;"                    ||,
  339.                   "SHOWALLINTREEVIEW=YES;"                    ||,
  340.                   "DEFAULTVIEW=ICON;"                         ||,
  341.                   "ICONFILE="instpath"\Icons\awgfold.ico;"
  342.  
  343. call CreateObject "U", "WPFolder", msg.obj_info,,
  344.                   "<AWG2_HOME>",,
  345.                   "OBJECTID=<AWG2_INFO>;"                     ||,
  346.                   "SHOWALLINTREEVIEW=YES;"                    ||,
  347.                   "DEFAULTVIEW=ICON;"                         ||,
  348.                   "ICONFILE="instpath"\Icons\awgfold.ico;"
  349.  
  350. call CreateObject "U", "WPFolder", msg.obj_jobs,,
  351.                   instpath"\Folders",,
  352.                   "OBJECTID=<AWG2_JOBS>;"                     ||,
  353.                   "DEFAULTVIEW=DETAILS;"                      ||,
  354.                   "NOTVISIBLE=YES"
  355.  
  356. call CreateObject "U", fld_class, msg.obj_todo,,
  357.                   instpath"\Folders",,
  358.                   "OBJECTID=<AWG2_TODO>;"                     ||,
  359.                   "SHOWALLINTREEVIEW=YES;"                    ||,
  360.                   "DEFAULTVIEW=DETAILS;"                      ||,
  361.                   "DETAILSTODISPLAY=0,1,9,10,12;"             ||,
  362.                   "ALWAYSSORT=YES;"                           ||,
  363.                   "DEFAULTSORT=11;"                           ||,
  364.                   "ICONFILE="instpath"\Icons\awgtodo.ico;"
  365.  
  366. call CreateObject "U", fld_class, msg.obj_running,,
  367.                   instpath"\Folders",,
  368.                   "OBJECTID=<AWG2_RUNNING>;"                  ||,
  369.                   "SHOWALLINTREEVIEW=YES;"                    ||,
  370.                   "DEFAULTVIEW=DETAILS;"                      ||,
  371.                   "DETAILSTODISPLAY=0,1,9,10,12;"             ||,
  372.                   "ALWAYSSORT=YES;"                           ||,
  373.                   "DEFAULTSORT=11;"                           ||,
  374.                   "ICONFILE="instpath"\Icons\awgactv.ico;"
  375.  
  376. call CreateObject "U", fld_class, msg.obj_done,,
  377.                   instpath"\Folders",,
  378.                   "OBJECTID=<AWG2_DONE>;"                     ||,
  379.                   "SHOWALLINTREEVIEW=YES;"                    ||,
  380.                   "DEFAULTVIEW=DETAILS;"                      ||,
  381.                   "DETAILSTODISPLAY=0,1,9,10,12;"             ||,
  382.                   "ALWAYSSORT=YES;"                           ||,
  383.                   "DEFAULTSORT=11;"                           ||,
  384.                   "ICONFILE="instpath"\Icons\awgdone.ico;"
  385.  
  386. call CreateObject "U", fld_class, msg.obj_failed,,
  387.                   instpath"\Folders",,
  388.                   "OBJECTID=<AWG2_FAILED>;"                   ||,
  389.                   "SHOWALLINTREEVIEW=YES;"                    ||,
  390.                   "DEFAULTVIEW=DETAILS;"                      ||,
  391.                   "DETAILSTODISPLAY=0,1,9,10,12;"             ||,
  392.                   "ALWAYSSORT=YES;"                           ||,
  393.                   "DEFAULTSORT=11;"                           ||,
  394.                   "ICONFILE="instpath"\Icons\awgfail.ico;"
  395.  
  396. call CreateObject "R", "WPShadow", msg.obj_todo,,
  397.                   "<WP_DESKTOP>",,
  398.                   "SHADOWID=<AWG2_TODO>"
  399. call CreateObject "R", "WPShadow", msg.obj_todo,,
  400.                   "<AWG2_DOWNLOADS>",,
  401.                   "SHADOWID=<AWG2_TODO>"
  402. call CreateObject "R", "WPShadow", msg.obj_running,,
  403.                   "<AWG2_DOWNLOADS>",,
  404.                   "SHADOWID=<AWG2_RUNNING>"
  405. call CreateObject "R", "WPShadow", msg.obj_done,,
  406.                   "<AWG2_DOWNLOADS>",,
  407.                   "SHADOWID=<AWG2_DONE>"
  408. call CreateObject "R", "WPShadow", msg.obj_failed,,
  409.                   "<AWG2_DOWNLOADS>",,
  410.                   "SHADOWID=<AWG2_FAILED>"
  411.  
  412. call CreateObject "U", "WPProgram", msg.obj_daemon,,
  413.                   "<AWG2_TOOLS>",,
  414.                   "OBJECTID=<AWG2_DAEMON>;"                   ||,
  415.                   "EXENAME="instpath"\AWGETD.CMD;"            ||,
  416.                   "STARTUPDIR="instpath";"                    ||,
  417.                   "MINIMIZED=YES;"                            ||,
  418.                   "ICONFILE="instpath"\Icons\awget.ico;"
  419.  
  420. call CreateObject "R", "WPShadow", msg.obj_daemon,,
  421.                   "<WP_START>",,
  422.                   "SHADOWID=<AWG2_DAEMON>;"
  423.  
  424. call CreateObject "U", "WPProgram", msg.obj_uninstall,,
  425.                   "<AWG2_TOOLS>",,
  426.                   "OBJECTID=<AWG2_UNINSTALL>;"                ||,
  427.                   "EXENAME=*;"                                ||,
  428.                   "STARTUPDIR="instpath";"                    ||,
  429.                   "PROGTYPE=WINDOWABLEVIO;"                   ||,
  430.                   "ICONFILE="instpath"\Icons\uninstl.ico;"    ||,
  431.                   'PARAMETERS=/C start "Uninstall Auto WGet Daemon" /C/F 'instpath'\UNINSTL.CMD;'
  432.  
  433. call CreateObject "U", "WPProgram", msg.obj_editcfg,,
  434.                   "<AWG2_TOOLS>",,
  435.                   "OBJECTID=<AWG2_EDITCFG>;"                  ||,
  436.                   "EXENAME=E.EXE;"                            ||,
  437.                   "PROGTYPE=PM;"                              ||,
  438.                   "PARAMETERS="sys.config_file";"             ||,
  439.                   "ICONFILE="instpath"\Icons\awgedit.ico;"
  440.  
  441. call CreateObject "U", "WPProgram", msg.obj_stop,,
  442.                   "<AWG2_TOOLS>",,
  443.                   "OBJECTID=<AWG2_STOP>;"                     ||,
  444.                   "EXENAME="instpath"\AWGSTOP.CMD;"           ||,
  445.                   "STARTUPDIR="instpath";"                    ||,
  446.                   "ICONFILE="instpath"\Icons\awgstop.ico;"
  447.  
  448. call CreateObject "U", "WPProgram", msg.obj_evtlog,,
  449.                   "<AWG2_TOOLS>",,
  450.                   "OBJECTID=<AWG2_EVTLOG>;"                   ||,
  451.                   "EXENAME=E.EXE;"                            ||,
  452.                   "STARTUPDIR="instpath";"                    ||,
  453.                   "PARAMETERS="cfg.log_file";"                ||,
  454.                   "ICONFILE="instpath"\Icons\awglogs.ico;"
  455.  
  456. call CreateObject "U", "WPProgram", msg.obj_errlog,,
  457.                   "<AWG2_TOOLS>",,
  458.                   "OBJECTID=<AWG2_ERRLOG>;"                   ||,
  459.                   "EXENAME=E.EXE;"                            ||,
  460.                   "STARTUPDIR="instpath";"                    ||,
  461.                   "PARAMETERS="cfg.error_log";"               ||,
  462.                   "ICONFILE="instpath"\Icons\awglogs.ico;"
  463.  
  464. call CreateObject "U", "WPProgram", msg.obj_add,,
  465.                   "<AWG2_TOOLS>",,
  466.                   "OBJECTID=<AWG2_ADD>;"                      ||,
  467.                   "EXENAME=*;"                                ||,
  468.                   "STARTUPDIR="instpath";"                    ||,
  469.                   "PROGTYPE=PM;"                              ||,
  470.                   "ICONFILE="instpath"\Icons\awgadd.ico;"     ||,
  471.                   'PARAMETERS=/C awgadd.cmd'
  472.  
  473. call CreateObject "U", "WPProgram", msg.obj_readme_en,,
  474.                   "<AWG2_INFO>",,
  475.                   "EXENAME=E.EXE;"                            ||,
  476.                   "OBJECTID=<AWG2_README_EN>;"                ||,
  477.                   "STARTUPDIR="instpath";"                    ||,
  478.                   "PARAMETERS="instpath"\readme.001;"         ||,
  479.                   "ICONFILE="instpath"\Icons\awgread.ico;"
  480.  
  481. if stream( instpath"\readme."country, "c", "query exist" ) \= "" then do
  482.    call CreateObject "R", "WPProgram", msg.obj_readme,,
  483.                   "<AWG2_INFO>",,
  484.                   "EXENAME=E.EXE;"                            ||,
  485.                   "OBJECTID=<AWG2_README>;"                   ||,
  486.                   "STARTUPDIR="instpath";"                    ||,
  487.                   "PARAMETERS="instpath"\readme."country";"   ||,
  488.                   "ICONFILE="instpath"\Icons\awgread.ico;"
  489.    end
  490. else
  491.    call SysDestroyObject "<AWG2_README>"
  492.  
  493. call CreateObject "U", "WPProgram", msg.obj_changes_en,,
  494.                   "<AWG2_INFO>",,
  495.                   "EXENAME=E.EXE;"                            ||,
  496.                   "OBJECTID=<AWG2_CHANGES_EN>;"               ||,
  497.                   "STARTUPDIR="instpath";"                    ||,
  498.                   "PARAMETERS="instpath"\changes;"            ||,
  499.                   "ICONFILE="instpath"\Icons\awgread.ico;"
  500.  
  501. call CreateObject "U", "WPProgram", msg.obj_license_en,,
  502.                   "<AWG2_INFO>",,
  503.                   "EXENAME=E.EXE;"                            ||,
  504.                   "OBJECTID=<AWG2_LICENSE_EN>;"               ||,
  505.                   "STARTUPDIR="instpath";"                    ||,
  506.                   "PARAMETERS="instpath"\license;"            ||,
  507.                   "ICONFILE="instpath"\Icons\awgread.ico;"
  508.  
  509. if SysOs2Ver() > "2.30" then do
  510.    call CreateObject "U", "WPUrl", msg.obj_url_ru,,
  511.                   "<AWG2_INFO>",,
  512.                   "OBJECTID=<AWG2_URL_RU>;"                   ||,
  513.                   "ICONFILE="instpath"\Icons\awgurls.ico;"    ||,
  514.                   "URL=http://www.geocities.com/SiliconValley/Vista/7567/software/awget.html"
  515.  
  516.    call CreateObject "U", "WPUrl", msg.obj_url_en,,
  517.                   "<AWG2_INFO>",,
  518.                   "OBJECTID=<AWG2_URL_EN>;"                   ||,
  519.                   "ICONFILE="instpath"\Icons\awgurls.ico;"    ||,
  520.                   "URL=http://www.geocities.com/SiliconValley/Vista/7567/software/english/awget.html"
  521. end
  522.  
  523. call SysSetObjectData "<AWG2_DAEMON>", "OPEN=DEFAULT"
  524.  
  525. say color.info || "■■■ "msg.started
  526. say color.info || "■■■ Done!" || color.usual
  527. exit 0
  528.  
  529. /*------------------------------------------------------------------
  530.  * Create directory
  531.  *------------------------------------------------------------------*/
  532. CreateDirectory: procedure expose (globals)
  533.  
  534.  parse arg path
  535.  rc = 0
  536.  
  537.  if \DirExist( path ) then do
  538.     rc = DirCreate( path )
  539.  
  540.     if rc == 0 then
  541.        call LogDo inf, msg.dir_done  || ": "path
  542.     else
  543.        call LogDo err, msg.dir_error || ": "path", rc="rc
  544.  end
  545. return rc == 0
  546.  
  547. /*------------------------------------------------------------------
  548.  * Copy file
  549.  *------------------------------------------------------------------*/
  550. CopyFile: procedure expose (globals)
  551.  
  552.  parse arg from, to
  553.  "copy "from to" 1> nul 2>nul"
  554.  
  555.  if rc == 0 then
  556.     call LogDo inf, msg.copy_done  || ": "from
  557.  else
  558.     call LogDo err, msg.copy_error || ": "from", rc="rc
  559. return rc == 0
  560.  
  561. /*------------------------------------------------------------------
  562.  * Compile REXX file
  563.  *------------------------------------------------------------------*/
  564. CompileFile: procedure expose (globals)
  565.  
  566.  parse arg from, to
  567.  "rexxc "from to" 1> nul 2>nul"
  568.  
  569.  if rc == 0 then
  570.     call LogDo inf, msg.compile_done  || ": "from
  571.  else
  572.     call LogDo err, msg.compile_error || ": "from", rc="rc
  573. return rc == 0
  574.  
  575. /*------------------------------------------------------------------
  576.  * Create WPS object
  577.  *------------------------------------------------------------------*/
  578. CreateObject: procedure expose (globals)
  579.  
  580.    parse arg action, class, objname, folder, prmstr
  581.  
  582.    rc = SysCreateObject( class, replace( objname, "\n", "0D0A"x ),,
  583.                                          folder, prmstr, action )
  584.  
  585.    objname = replace( objname, "\n"   , " " )
  586.    objname = replace( objname, '0D0A'x, " " )
  587.  
  588.    if rc then
  589.       call LogDo inf, msg.object_done  || " "substr(class,1,12) || ": "objname
  590.    else
  591.       call LogDo err, msg.object_error || " "substr(class,1,12) || ": "objname
  592. return rc
  593.  
  594. /*------------------------------------------------------------------
  595.  * Terminate installation
  596.  *------------------------------------------------------------------*/
  597. terminate: procedure expose (globals)
  598.  
  599.   call beep 1000, 100
  600.   call LogDo err, msg.install_aborted
  601.   exit 1
  602. return
  603.  
  604. /*------------------------------------------------------------------
  605.  * Write Log Record
  606.  *------------------------------------------------------------------*/
  607. LogDo: procedure expose (globals)
  608.  
  609.   parse arg type, message
  610.   type = translate(type)
  611.  
  612.   if type == "INF" then type = "INFO"
  613.   if type == "ERR" then type = "ERROR"
  614.  
  615.   rc = stream( "install.log", "c", "open write" )
  616.   call lineout "install.log", replace( message, '0D0A'x, '0D0A'x || copies( ' ', 21 ))
  617.   rc = stream( "install.log", "c", "close" )
  618.  
  619.   say color.type"■■■ " ||,
  620.       replace( message, '0D0A'x, '0D0A'x || copies( ' ', 4 )) || color.usual
  621.  
  622. return ""
  623.  
  624. /* $Id: init.cms,v 1.26 2001/05/11 09:45:01 glass Exp $ */
  625.  
  626. /*------------------------------------------------------------------
  627.  * Initialization
  628.  *------------------------------------------------------------------*/
  629. AwInit: procedure expose (globals)
  630.  
  631.   if RxFuncQuery('SysLoadFuncs') then do
  632.      call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  633.      call SysLoadFuncs
  634.   end
  635.  
  636.   '@echo off'
  637.  
  638.   sys.config_file = value( "ETC",, "OS2ENVIRONMENT" )"\awget.cfg"
  639.   sys.connected   = 1
  640.   sys.active_time = 0
  641.  
  642.   /* enable ANSI extended screen and keyboard control */
  643.   '@ansi on > nul'
  644.  
  645.   color.brown   = "1B"x"[0;33m"
  646.   color.red     = "1B"x"[1;31m"
  647.   color.green   = "1B"x"[1;32m"
  648.   color.yellow  = "1B"x"[1;33m"
  649.   color.blue    = "1B"x"[1;34m"
  650.   color.magenta = "1B"x"[1;35m"
  651.   color.cyan    = "1B"x"[1;36m"
  652.   color.white   = "1B"x"[1;37m"
  653.   color.gray    = "1B"x"[0m"
  654.  
  655.   color.usual   = color.gray
  656.   color.bold    = color.white
  657.   color.error   = color.red
  658.   color.info    = color.green
  659.   color.debug   = color.brown
  660.  
  661.   /* known download utilites */
  662.  
  663.   sys.utils.0      = 2
  664.   sys.utils.1.prog = wget.exe
  665.   sys.utils.1.name = "GNU WGet"
  666.   sys.utils.1.parm = '-c -t 10 -w 30 -P "%p" "%u"'
  667.   sys.utils.2.prog = curl.exe
  668.   sys.utils.2.name = "cURL"
  669.   sys.utils.2.parm = '-y 300 -Y 1 -v -C - -o "%p/%f" "%u"'
  670.  
  671.   sys.utils.default.prog = sys.utils.1.prog
  672.   sys.utils.default.name = sys.utils.1.name
  673.   sys.utils.default.parm = sys.utils.1.parm
  674.  
  675.   /* service semaphores */
  676.  
  677.   sys.running = "$live$"
  678.   sys.killing = "$stop$"
  679.   sys.pushing = "$push$"
  680.   sys.tqueue  = "$term$"
  681.  
  682.   /* stream's open modes */
  683.  
  684.   parse version version .
  685.   if version = "OBJREXX" then do
  686.      sys.open_read  = "OPEN READ  SHAREREAD"
  687.      sys.open_write = "OPEN WRITE SHAREREAD"
  688.      end
  689.   else do
  690.      sys.open_read  = "OPEN READ"
  691.      sys.open_write = "OPEN WRITE"
  692.   end
  693. return
  694.  
  695. /* $Id: nls.cms,v 1.13 2001/05/11 08:54:34 glass Exp $ */
  696.  
  697. /*------------------------------------------------------------------
  698.  * Read messages
  699.  *------------------------------------------------------------------*/
  700. MsgRead: procedure expose (globals)
  701.  
  702.   parse arg msgfile
  703.   parse source OS2 what msgpath
  704.  
  705.   msgfile = filespec( "disk", msgpath ) ||,
  706.             filespec( "path", msgpath ) || "NLS\" || msgfile
  707.  
  708.   country = MsgCountryID()
  709.  
  710.   if stream( msgfile"."country, "c", "query exists" ) == "" then
  711.      country = "001"
  712.  
  713.   msgfile = msgfile"."country
  714.   rc = stream( msgfile, "C", sys.open_read )
  715.  
  716.   if rc \= "READY:" then do
  717.      say  color.error || "■■■ Error on open NLS file: "msgfile
  718.      exit 1
  719.   end
  720.  
  721.   do while lines(msgfile) > 0
  722.      line = strip(linein(msgfile))
  723.  
  724.      do while right(line,1) == "\"
  725.         line = left( line, length(line)-1 )
  726.         line = line || strip(linein(msgfile))
  727.      end
  728.  
  729.      if line \= "" & left(line,1) \= "#" then do
  730.         parse value line with id "=" msg
  731.  
  732.         id  = strip(id )
  733.         msg = strip(msg)
  734.  
  735.         i = pos( "\n", msg )
  736.         do while i > 0
  737.            msg = substr( msg, 1, i-1 ) || '0D0A'x || substr( msg, i+2 )
  738.            i = pos( "\n", msg )
  739.         end
  740.  
  741.         msg.id = msg
  742.      end
  743.   end
  744.  
  745.   rc = stream( msgfile, "C", "CLOSE" )
  746. return
  747.  
  748. /*------------------------------------------------------------------
  749.  * Returns Country Identifier
  750.  *------------------------------------------------------------------*/
  751. MsgCountryID: procedure expose (globals)
  752.  
  753.   country = strip( SysIni( "BOTH", "PM_National", "iCountry" ),, '0'x )
  754.  
  755.   if country == "ERROR:" then
  756.      country =  "001"
  757.   else
  758.      country =  right( country, 3, "0" )
  759.  
  760. return country
  761.  
  762. /*------------------------------------------------------------------
  763.  * Get Yes or No
  764.  *------------------------------------------------------------------*/
  765. MsgYesNo: procedure expose (globals)
  766.  
  767.   parse arg prompt
  768.   ok = 0
  769.  
  770.   do until ok
  771.      call charout, prompt"? "
  772.      pull reply
  773.      reply = left(reply,1)
  774.  
  775.      ok = (reply == "Y") |,
  776.           (reply == "N") |,
  777.           (pos( reply, msg.yes ) > 0 ) |,
  778.           (pos( reply, msg.no  ) > 0 )
  779.  
  780.      if \ok then do
  781.         say msg.bad_yesno
  782.      end
  783.   end
  784.  
  785. return (reply = "Y") | ( pos( reply, msg.yes ) > 0 )
  786.  
  787. /*------------------------------------------------------------------
  788.  * Get numeric value
  789.  *------------------------------------------------------------------*/
  790. MsgGetNum: procedure expose (globals)
  791.  
  792.   parse arg prompt, min, max
  793.   ok = 0
  794.  
  795.   do until ok
  796.      call charout, prompt"? "
  797.      pull reply
  798.  
  799.      ok = datatype( reply, "NUMBER" ) & reply >= min & reply <= max
  800.   end
  801.  
  802. return reply
  803.  
  804. /* $Id: config.cms,v 1.29 2001/05/11 08:54:34 glass Exp $ */
  805.  
  806. /*------------------------------------------------------------------
  807.  * Returns Confguration Keys
  808.  *------------------------------------------------------------------*/
  809. CfgKeys: procedure expose (globals)
  810.  
  811. return "HOME "                      ||,
  812.        "DOWNLOAD "                  ||,
  813.        "DOWNLOADS_SIMULTANEOUSLY "  ||,
  814.        "DOWNLOADS_ATTEMPTS "        ||,
  815.        "DOWNLOADS_UTILITY "         ||,
  816.        "DOWNLOADS_PARAMETERS "      ||,
  817.        "SCAN_INTERVAL "             ||,
  818.        "LOG_FILE "                  ||,
  819.        "ERROR_LOG "                 ||,
  820.        "LOG_KEEP "                  ||,
  821.        "MESSAGE_DONE "              ||,
  822.        "MESSAGE_ERROR "             ||,
  823.        "MESSAGES "                  ||,
  824.        "CHECK_CONNECTION "          ||,
  825.        "USE_DESKTOP "               ||,
  826.        "KEEP_FAILED_URL "           ||,
  827.        "KEEP_DONE_URL "
  828.  
  829. /*------------------------------------------------------------------
  830.  * Get Configuration
  831.  *------------------------------------------------------------------*/
  832. CfgRead: procedure expose (globals)
  833.  
  834.   cfg.home                     = "."
  835.   cfg.download                 = "."
  836.   cfg.downloads_simultaneously = 3
  837.   cfg.downloads_attempts       = 15
  838.   cfg.downloads_utility        = sys.utils.default.prog
  839.   cfg.downloads_parameters     = sys.utils.default.parm
  840.   cfg.scan_interval            = 30
  841.   cfg.log_file                 = "nul"
  842.   cfg.error_log                = "nul"
  843.   cfg.log_keep                 = 15
  844.   cfg.message_done             = 'start /n pmpopup2.exe "%m:~~%u" "Auto WGet Daemon" /BELL /B1:"OK" /T:900 /F:"8.Helv"'
  845.   cfg.message_error            = 'start /n pmpopup2.exe "%m:~~%u~%i" "Auto WGet Daemon" /BELL /B1:"OK" /T:900 /F:"8.Helv"'
  846.   cfg.messages                 = 1
  847.   cfg.check_connection         = 0
  848.   cfg.use_desktop              = 0
  849.   cfg.keep_failed_url          = 1
  850.   cfg.keep_done_url            = 0
  851.  
  852.   rc = stream( sys.config_file, "C", sys.open_read )
  853.  
  854.   do while lines(sys.config_file) > 0
  855.      parse value linein(sys.config_file) with command "=" argument
  856.  
  857.      command  = translate(strip(command))
  858.      argument = strip(argument)
  859.  
  860.      select
  861.         when command == "HOME",
  862.            | command == "DOWNLOAD",
  863.            | command == "DOWNLOADS_SIMULTANEOUSLY",
  864.            | command == "DOWNLOADS_ATTEMPTS",
  865.            | command == "DOWNLOADS_UTILITY",
  866.            | command == "DOWNLOADS_PARAMETERS",
  867.            | command == "SCAN_INTERVAL",
  868.            | command == "LOG_FILE",
  869.            | command == "ERROR_LOG",
  870.            | command == "LOG_KEEP",
  871.            | command == "MESSAGE_DONE",
  872.            | command == "MESSAGE_ERROR" then
  873.  
  874.              cfg.command = argument
  875.  
  876.         when command == "MESSAGES",
  877.            | command == "CHECK_CONNECTION",
  878.            | command == "USE_DESKTOP",
  879.            | command == "KEEP_FAILED_URL",
  880.            | command == "KEEP_DONE_URL" then
  881.  
  882.              cfg.command = (argument == "1")
  883.         otherwise
  884.      end
  885.   end
  886.  
  887.   rc = stream( sys.config_file, "C", "CLOSE" )
  888.   cfg.file_date = stream( sys.config_file, "C", "QUERY DATETIME" )
  889. return
  890.  
  891. /*------------------------------------------------------------------
  892.  * Show Configuration
  893.  *------------------------------------------------------------------*/
  894. CfgShow: procedure expose (globals)
  895.  
  896.   key_list = CfgKeys()
  897.   do i = 1 to words(key_list)
  898.  
  899.      key = word(key_list,i)
  900.  
  901.      if  key \= "LOG_FILE"      &,
  902.          key \= "ERROR_LOG"     &,
  903.          key \= "MESSAGE_DONE"  &,
  904.          key \= "MESSAGE_ERROR" &,
  905.          cfg.key \= ""          &,
  906.          cfg.key \= "nul" then do
  907.  
  908.          say color.usual || "*** "msg.key  || ": " || color.bold || cfg.key
  909.      end
  910.   end
  911.  
  912.   call charout , color.usual
  913. return ""
  914.  
  915. /*------------------------------------------------------------------
  916.  * Save Configuration
  917.  *------------------------------------------------------------------*/
  918. CfgSave: procedure expose (globals)
  919.  
  920.   rc = stream( sys.config_file, "C", sys.open_read )
  921.  
  922.   do i = 1 while lines(sys.config_file) > 0
  923.      body.i = linein(sys.config_file)
  924.   end
  925.   body.0 = i - 1
  926.   rc = stream( sys.config_file, "C", "CLOSE" )
  927.  
  928.   key_list = CfgKeys()
  929.  
  930.   do i = 1 to words(key_list)
  931.      key = word(key_list,i)
  932.  
  933.      do j = 1 to body.0
  934.         if left( strip( body.j ), 1 ) == "#" then
  935.            iterate
  936.  
  937.         parse value body.j with command "="
  938.         command = translate(strip(command))
  939.  
  940.         if key == command then
  941.            leave
  942.      end j
  943.  
  944.      if cfg.key \= "nul" then do
  945.         if j > body.0 then do
  946.            comment = "CFG_"  || key
  947.            body.j  = "# "replace( msg.comment, "0D0A"x, "0D0A"x || "# " ) ||,
  948.                      "0D0A"x || "0D0A"x || key "=" cfg.key || "0D0A"x
  949.            end
  950.         else
  951.            body.j = key "=" cfg.key
  952.  
  953.         if j > body.0 then
  954.           body.0 = j
  955.      end
  956.   end i
  957.  
  958.   if stream( sys.config_file, "C", "QUERY EXISTS" ) \= "" then
  959.      "@del " sys.config_file
  960.  
  961.   rc = stream( sys.config_file, "C", sys.open_write )
  962.  
  963.   do j = 1 to body.0
  964.      parse value body.j with command "="
  965.      command  = translate(strip(command))
  966.  
  967.      if command \= "MAXIMUM_DOWNLOADS_SIMULTANEOUSLY" &,
  968.         command \= "WGET_PARAMETERS" then
  969.         call lineout sys.config_file, body.j
  970.   end
  971.  
  972.   rc = stream( sys.config_file, "C", "CLOSE" )
  973. return
  974.  
  975.  
  976. /* $Id: replace.cms,v 1.5 2001/05/11 08:54:34 glass Exp $ */
  977.  
  978. /*------------------------------------------------------------------
  979.  * Search and replace string
  980.  *------------------------------------------------------------------*/
  981. replace: procedure expose (globals)
  982.  
  983.   parse arg source, string, substitute
  984.   string = translate(string)
  985.  
  986.   i = pos( string, translate(source))
  987.  
  988.   do while i \= 0
  989.      source = substr( source, 1, i-1 ) || substitute ||,
  990.               substr( source, i+length(string))
  991.  
  992.      i = pos( string, translate(source), i + length(substitute))
  993.   end
  994.  
  995. return source
  996.  
  997. /* $Id: dirs.cms,v 1.24 2001/05/11 08:54:34 glass Exp $ */
  998.  
  999. /*------------------------------------------------------------------
  1000.  * Converts directory to canonical form
  1001.  *------------------------------------------------------------------*/
  1002. DirCanonical: procedure expose (globals)
  1003.  
  1004.   parse arg path
  1005.   path = translate( path, "\", "/" )
  1006.  
  1007.   if right( path, 1 ) == "\" & pos( ":", path ) \= length(path)-1 then
  1008.      path = left( path, length(path)-1 )
  1009.  
  1010. return path
  1011.  
  1012. /*------------------------------------------------------------------
  1013.  * Returns path to file
  1014.  *------------------------------------------------------------------*/
  1015. DirPath: procedure expose (globals)
  1016.  
  1017.   parse arg pathname
  1018.  
  1019. return DirCanonical( filespec( "drive", pathname ) ||,
  1020.                      filespec( "path" , pathname ))
  1021.  
  1022. /*------------------------------------------------------------------
  1023.  * Create directory
  1024.  *------------------------------------------------------------------*/
  1025. DirCreate: procedure expose (globals)
  1026.  
  1027.   parse arg path
  1028.  
  1029.   path = DirCanonical( path )
  1030.   rc   = SysMkDir( path )
  1031.  
  1032.   if rc == 3 & pos( "\", path ) \= 0 then do
  1033.  
  1034.      parent = left( path, length(path) - pos( "\", reverse(path)))
  1035.      rc = DirCreate( parent )
  1036.  
  1037.      if rc == 0 then
  1038.         rc = SysMkDir( path )
  1039.   end
  1040. return rc
  1041.  
  1042. /*------------------------------------------------------------------
  1043.  * Checks existence of the directory
  1044.  *------------------------------------------------------------------*/
  1045. DirExist: procedure expose (globals)
  1046.  
  1047.   parse arg path
  1048.   if path == "" then return 0
  1049.   path = DirCanonical( path )
  1050.  
  1051.   setlocal
  1052.   path = directory( path )
  1053.   endlocal
  1054.  
  1055. return path \= ""
  1056.  
  1057.  
  1058. /* $Id: stop.cms,v 1.13 2001/05/11 08:54:34 glass Exp $ */
  1059.  
  1060. /*------------------------------------------------------------------
  1061.  * Stop Auto WGet Daemon
  1062.  *------------------------------------------------------------------*/
  1063. AwStop: procedure expose (globals)
  1064.  
  1065.   sys_running  = cfg.home'\'sys.running
  1066.   sys_killing  = cfg.home'\'sys.killing
  1067.  
  1068.   'del 'sys_running' /F 1>nul 2>nul'
  1069.  
  1070.   call lineout sys_killing, "Must die!"
  1071.   call charout, color.info || "■■■ "msg.wait_stopped"..."
  1072.  
  1073.   do 20 while stream( sys_running, 'c', 'query exist' ) \= ""
  1074.      call SysSleep  2
  1075.      call charout, "."
  1076.     'del 'sys_running' /F 1>nul 2>nul'
  1077.   end
  1078.   say ; say color.info || "■■■ "msg.stopped || color.usual
  1079.  
  1080.   rc = stream( sys_killing, 'c', 'close' )
  1081.  'del 'sys_killing' /F 1>nul 2>nul'
  1082.  
  1083. return ""
  1084.