home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / awget167.zip / install.cmd < prev    next >
OS/2 REXX Batch file  |  2001-06-11  |  39KB  |  1,085 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.46 2001/05/15 10:49:45 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.7 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.7 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.7 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=WINDOWABLEVIO;"                   ||,
  470.                   "MINIMIZED=YES;"                            ||,
  471.                   "ICONFILE="instpath"\Icons\awgadd.ico;"     ||,
  472.                   'PARAMETERS=/C awgadd.cmd "['msg.enter_url']"'
  473.  
  474. call CreateObject "U", "WPProgram", msg.obj_readme_en,,
  475.                   "<AWG2_INFO>",,
  476.                   "EXENAME=E.EXE;"                            ||,
  477.                   "OBJECTID=<AWG2_README_EN>;"                ||,
  478.                   "STARTUPDIR="instpath";"                    ||,
  479.                   "PARAMETERS="instpath"\readme.001;"         ||,
  480.                   "ICONFILE="instpath"\Icons\awgread.ico;"
  481.  
  482. if stream( instpath"\readme."country, "c", "query exist" ) \= "" then do
  483.    call CreateObject "R", "WPProgram", msg.obj_readme,,
  484.                   "<AWG2_INFO>",,
  485.                   "EXENAME=E.EXE;"                            ||,
  486.                   "OBJECTID=<AWG2_README>;"                   ||,
  487.                   "STARTUPDIR="instpath";"                    ||,
  488.                   "PARAMETERS="instpath"\readme."country";"   ||,
  489.                   "ICONFILE="instpath"\Icons\awgread.ico;"
  490.    end
  491. else
  492.    call SysDestroyObject "<AWG2_README>"
  493.  
  494. call CreateObject "U", "WPProgram", msg.obj_changes_en,,
  495.                   "<AWG2_INFO>",,
  496.                   "EXENAME=E.EXE;"                            ||,
  497.                   "OBJECTID=<AWG2_CHANGES_EN>;"               ||,
  498.                   "STARTUPDIR="instpath";"                    ||,
  499.                   "PARAMETERS="instpath"\changes;"            ||,
  500.                   "ICONFILE="instpath"\Icons\awgread.ico;"
  501.  
  502. call CreateObject "U", "WPProgram", msg.obj_license_en,,
  503.                   "<AWG2_INFO>",,
  504.                   "EXENAME=E.EXE;"                            ||,
  505.                   "OBJECTID=<AWG2_LICENSE_EN>;"               ||,
  506.                   "STARTUPDIR="instpath";"                    ||,
  507.                   "PARAMETERS="instpath"\license;"            ||,
  508.                   "ICONFILE="instpath"\Icons\awgread.ico;"
  509.  
  510. if SysOs2Ver() > "2.30" then do
  511.    call CreateObject "U", "WPUrl", msg.obj_url_ru,,
  512.                   "<AWG2_INFO>",,
  513.                   "OBJECTID=<AWG2_URL_RU>;"                   ||,
  514.                   "ICONFILE="instpath"\Icons\awgurls.ico;"    ||,
  515.                   "URL=http://www.geocities.com/SiliconValley/Vista/7567/software/awget.html"
  516.  
  517.    call CreateObject "U", "WPUrl", msg.obj_url_en,,
  518.                   "<AWG2_INFO>",,
  519.                   "OBJECTID=<AWG2_URL_EN>;"                   ||,
  520.                   "ICONFILE="instpath"\Icons\awgurls.ico;"    ||,
  521.                   "URL=http://www.geocities.com/SiliconValley/Vista/7567/software/english/awget.html"
  522. end
  523.  
  524. call SysSetObjectData "<AWG2_DAEMON>", "OPEN=DEFAULT"
  525.  
  526. say color.info || "■■■ "msg.started
  527. say color.info || "■■■ Done!" || color.usual
  528. exit 0
  529.  
  530. /*------------------------------------------------------------------
  531.  * Create directory
  532.  *------------------------------------------------------------------*/
  533. CreateDirectory: procedure expose (globals)
  534.  
  535.  parse arg path
  536.  rc = 0
  537.  
  538.  if \DirExist( path ) then do
  539.     rc = DirCreate( path )
  540.  
  541.     if rc == 0 then
  542.        call LogDo inf, msg.dir_done  || ": "path
  543.     else
  544.        call LogDo err, msg.dir_error || ": "path", rc="rc
  545.  end
  546. return rc == 0
  547.  
  548. /*------------------------------------------------------------------
  549.  * Copy file
  550.  *------------------------------------------------------------------*/
  551. CopyFile: procedure expose (globals)
  552.  
  553.  parse arg from, to
  554.  "copy "from to" 1> nul 2>nul"
  555.  
  556.  if rc == 0 then
  557.     call LogDo inf, msg.copy_done  || ": "from
  558.  else
  559.     call LogDo err, msg.copy_error || ": "from", rc="rc
  560. return rc == 0
  561.  
  562. /*------------------------------------------------------------------
  563.  * Compile REXX file
  564.  *------------------------------------------------------------------*/
  565. CompileFile: procedure expose (globals)
  566.  
  567.  parse arg from, to
  568.  "rexxc "from to" 1> nul 2>nul"
  569.  
  570.  if rc == 0 then
  571.     call LogDo inf, msg.compile_done  || ": "from
  572.  else
  573.     call LogDo err, msg.compile_error || ": "from", rc="rc
  574. return rc == 0
  575.  
  576. /*------------------------------------------------------------------
  577.  * Create WPS object
  578.  *------------------------------------------------------------------*/
  579. CreateObject: procedure expose (globals)
  580.  
  581.    parse arg action, class, objname, folder, prmstr
  582.  
  583.    rc = SysCreateObject( class, replace( objname, "\n", "0D0A"x ),,
  584.                                          folder, prmstr, action )
  585.  
  586.    objname = replace( objname, "\n"   , " " )
  587.    objname = replace( objname, '0D0A'x, " " )
  588.  
  589.    if rc then
  590.       call LogDo inf, msg.object_done  || " "substr(class,1,12) || ": "objname
  591.    else
  592.       call LogDo err, msg.object_error || " "substr(class,1,12) || ": "objname
  593. return rc
  594.  
  595. /*------------------------------------------------------------------
  596.  * Terminate installation
  597.  *------------------------------------------------------------------*/
  598. terminate: procedure expose (globals)
  599.  
  600.   call beep 1000, 100
  601.   call LogDo err, msg.install_aborted
  602.   exit 1
  603. return
  604.  
  605. /*------------------------------------------------------------------
  606.  * Write Log Record
  607.  *------------------------------------------------------------------*/
  608. LogDo: procedure expose (globals)
  609.  
  610.   parse arg type, message
  611.   type = translate(type)
  612.  
  613.   if type == "INF" then type = "INFO"
  614.   if type == "ERR" then type = "ERROR"
  615.  
  616.   rc = stream( "install.log", "c", "open write" )
  617.   call lineout "install.log", replace( message, '0D0A'x, '0D0A'x || copies( ' ', 21 ))
  618.   rc = stream( "install.log", "c", "close" )
  619.  
  620.   say color.type"■■■ " ||,
  621.       replace( message, '0D0A'x, '0D0A'x || copies( ' ', 4 )) || color.usual
  622.  
  623. return ""
  624.  
  625. /* $Id: init.cms,v 1.26 2001/05/11 09:45:01 glass Exp $ */
  626.  
  627. /*------------------------------------------------------------------
  628.  * Initialization
  629.  *------------------------------------------------------------------*/
  630. AwInit: procedure expose (globals)
  631.  
  632.   if RxFuncQuery('SysLoadFuncs') then do
  633.      call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  634.      call SysLoadFuncs
  635.   end
  636.  
  637.   '@echo off'
  638.  
  639.   sys.config_file = value( "ETC",, "OS2ENVIRONMENT" )"\awget.cfg"
  640.   sys.connected   = 1
  641.   sys.active_time = 0
  642.  
  643.   /* enable ANSI extended screen and keyboard control */
  644.   '@ansi on > nul'
  645.  
  646.   color.brown   = "1B"x"[0;33m"
  647.   color.red     = "1B"x"[1;31m"
  648.   color.green   = "1B"x"[1;32m"
  649.   color.yellow  = "1B"x"[1;33m"
  650.   color.blue    = "1B"x"[1;34m"
  651.   color.magenta = "1B"x"[1;35m"
  652.   color.cyan    = "1B"x"[1;36m"
  653.   color.white   = "1B"x"[1;37m"
  654.   color.gray    = "1B"x"[0m"
  655.  
  656.   color.usual   = color.gray
  657.   color.bold    = color.white
  658.   color.error   = color.red
  659.   color.info    = color.green
  660.   color.debug   = color.brown
  661.  
  662.   /* known download utilites */
  663.  
  664.   sys.utils.0      = 2
  665.   sys.utils.1.prog = wget.exe
  666.   sys.utils.1.name = "GNU WGet"
  667.   sys.utils.1.parm = '-c -t 10 -w 30 -P "%p" "%u"'
  668.   sys.utils.2.prog = curl.exe
  669.   sys.utils.2.name = "cURL"
  670.   sys.utils.2.parm = '-y 300 -Y 1 -v -C - -o "%p/%f" "%u"'
  671.  
  672.   sys.utils.default.prog = sys.utils.1.prog
  673.   sys.utils.default.name = sys.utils.1.name
  674.   sys.utils.default.parm = sys.utils.1.parm
  675.  
  676.   /* service semaphores */
  677.  
  678.   sys.running = "$live$"
  679.   sys.killing = "$stop$"
  680.   sys.pushing = "$push$"
  681.   sys.tqueue  = "$term$"
  682.  
  683.   /* stream's open modes */
  684.  
  685.   parse version version .
  686.   if version = "OBJREXX" then do
  687.      sys.open_read  = "OPEN READ  SHAREREAD"
  688.      sys.open_write = "OPEN WRITE SHAREREAD"
  689.      end
  690.   else do
  691.      sys.open_read  = "OPEN READ"
  692.      sys.open_write = "OPEN WRITE"
  693.   end
  694. return
  695.  
  696. /* $Id: nls.cms,v 1.13 2001/05/11 08:54:34 glass Exp $ */
  697.  
  698. /*------------------------------------------------------------------
  699.  * Read messages
  700.  *------------------------------------------------------------------*/
  701. MsgRead: procedure expose (globals)
  702.  
  703.   parse arg msgfile
  704.   parse source OS2 what msgpath
  705.  
  706.   msgfile = filespec( "disk", msgpath ) ||,
  707.             filespec( "path", msgpath ) || "NLS\" || msgfile
  708.  
  709.   country = MsgCountryID()
  710.  
  711.   if stream( msgfile"."country, "c", "query exists" ) == "" then
  712.      country = "001"
  713.  
  714.   msgfile = msgfile"."country
  715.   rc = stream( msgfile, "C", sys.open_read )
  716.  
  717.   if rc \= "READY:" then do
  718.      say  color.error || "■■■ Error on open NLS file: "msgfile
  719.      exit 1
  720.   end
  721.  
  722.   do while lines(msgfile) > 0
  723.      line = strip(linein(msgfile))
  724.  
  725.      do while right(line,1) == "\"
  726.         line = left( line, length(line)-1 )
  727.         line = line || strip(linein(msgfile))
  728.      end
  729.  
  730.      if line \= "" & left(line,1) \= "#" then do
  731.         parse value line with id "=" msg
  732.  
  733.         id  = strip(id )
  734.         msg = strip(msg)
  735.  
  736.         i = pos( "\n", msg )
  737.         do while i > 0
  738.            msg = substr( msg, 1, i-1 ) || '0D0A'x || substr( msg, i+2 )
  739.            i = pos( "\n", msg )
  740.         end
  741.  
  742.         msg.id = msg
  743.      end
  744.   end
  745.  
  746.   rc = stream( msgfile, "C", "CLOSE" )
  747. return
  748.  
  749. /*------------------------------------------------------------------
  750.  * Returns Country Identifier
  751.  *------------------------------------------------------------------*/
  752. MsgCountryID: procedure expose (globals)
  753.  
  754.   country = strip( SysIni( "BOTH", "PM_National", "iCountry" ),, '0'x )
  755.  
  756.   if country == "ERROR:" then
  757.      country =  "001"
  758.   else
  759.      country =  right( country, 3, "0" )
  760.  
  761. return country
  762.  
  763. /*------------------------------------------------------------------
  764.  * Get Yes or No
  765.  *------------------------------------------------------------------*/
  766. MsgYesNo: procedure expose (globals)
  767.  
  768.   parse arg prompt
  769.   ok = 0
  770.  
  771.   do until ok
  772.      call charout, prompt"? "
  773.      pull reply
  774.      reply = left(reply,1)
  775.  
  776.      ok = (reply == "Y") |,
  777.           (reply == "N") |,
  778.           (pos( reply, msg.yes ) > 0 ) |,
  779.           (pos( reply, msg.no  ) > 0 )
  780.  
  781.      if \ok then do
  782.         say msg.bad_yesno
  783.      end
  784.   end
  785.  
  786. return (reply = "Y") | ( pos( reply, msg.yes ) > 0 )
  787.  
  788. /*------------------------------------------------------------------
  789.  * Get numeric value
  790.  *------------------------------------------------------------------*/
  791. MsgGetNum: procedure expose (globals)
  792.  
  793.   parse arg prompt, min, max
  794.   ok = 0
  795.  
  796.   do until ok
  797.      call charout, prompt"? "
  798.      pull reply
  799.  
  800.      ok = datatype( reply, "NUMBER" ) & reply >= min & reply <= max
  801.   end
  802.  
  803. return reply
  804.  
  805. /* $Id: config.cms,v 1.29 2001/05/11 08:54:34 glass Exp $ */
  806.  
  807. /*------------------------------------------------------------------
  808.  * Returns Confguration Keys
  809.  *------------------------------------------------------------------*/
  810. CfgKeys: procedure expose (globals)
  811.  
  812. return "HOME "                      ||,
  813.        "DOWNLOAD "                  ||,
  814.        "DOWNLOADS_SIMULTANEOUSLY "  ||,
  815.        "DOWNLOADS_ATTEMPTS "        ||,
  816.        "DOWNLOADS_UTILITY "         ||,
  817.        "DOWNLOADS_PARAMETERS "      ||,
  818.        "SCAN_INTERVAL "             ||,
  819.        "LOG_FILE "                  ||,
  820.        "ERROR_LOG "                 ||,
  821.        "LOG_KEEP "                  ||,
  822.        "MESSAGE_DONE "              ||,
  823.        "MESSAGE_ERROR "             ||,
  824.        "MESSAGES "                  ||,
  825.        "CHECK_CONNECTION "          ||,
  826.        "USE_DESKTOP "               ||,
  827.        "KEEP_FAILED_URL "           ||,
  828.        "KEEP_DONE_URL "
  829.  
  830. /*------------------------------------------------------------------
  831.  * Get Configuration
  832.  *------------------------------------------------------------------*/
  833. CfgRead: procedure expose (globals)
  834.  
  835.   cfg.home                     = "."
  836.   cfg.download                 = "."
  837.   cfg.downloads_simultaneously = 3
  838.   cfg.downloads_attempts       = 15
  839.   cfg.downloads_utility        = sys.utils.default.prog
  840.   cfg.downloads_parameters     = sys.utils.default.parm
  841.   cfg.scan_interval            = 30
  842.   cfg.log_file                 = "nul"
  843.   cfg.error_log                = "nul"
  844.   cfg.log_keep                 = 15
  845.   cfg.message_done             = 'start /n pmpopup2.exe "%m:~~%u" "Auto WGet Daemon" /BELL /B1:"OK" /T:900 /F:"8.Helv"'
  846.   cfg.message_error            = 'start /n pmpopup2.exe "%m:~~%u~%i" "Auto WGet Daemon" /BELL /B1:"OK" /T:900 /F:"8.Helv"'
  847.   cfg.messages                 = 1
  848.   cfg.check_connection         = 0
  849.   cfg.use_desktop              = 0
  850.   cfg.keep_failed_url          = 1
  851.   cfg.keep_done_url            = 0
  852.  
  853.   rc = stream( sys.config_file, "C", sys.open_read )
  854.  
  855.   do while lines(sys.config_file) > 0
  856.      parse value linein(sys.config_file) with command "=" argument
  857.  
  858.      command  = translate(strip(command))
  859.      argument = strip(argument)
  860.  
  861.      select
  862.         when command == "HOME",
  863.            | command == "DOWNLOAD",
  864.            | command == "DOWNLOADS_SIMULTANEOUSLY",
  865.            | command == "DOWNLOADS_ATTEMPTS",
  866.            | command == "DOWNLOADS_UTILITY",
  867.            | command == "DOWNLOADS_PARAMETERS",
  868.            | command == "SCAN_INTERVAL",
  869.            | command == "LOG_FILE",
  870.            | command == "ERROR_LOG",
  871.            | command == "LOG_KEEP",
  872.            | command == "MESSAGE_DONE",
  873.            | command == "MESSAGE_ERROR" then
  874.  
  875.              cfg.command = argument
  876.  
  877.         when command == "MESSAGES",
  878.            | command == "CHECK_CONNECTION",
  879.            | command == "USE_DESKTOP",
  880.            | command == "KEEP_FAILED_URL",
  881.            | command == "KEEP_DONE_URL" then
  882.  
  883.              cfg.command = (argument == "1")
  884.         otherwise
  885.      end
  886.   end
  887.  
  888.   rc = stream( sys.config_file, "C", "CLOSE" )
  889.   cfg.file_date = stream( sys.config_file, "C", "QUERY DATETIME" )
  890. return
  891.  
  892. /*------------------------------------------------------------------
  893.  * Show Configuration
  894.  *------------------------------------------------------------------*/
  895. CfgShow: procedure expose (globals)
  896.  
  897.   key_list = CfgKeys()
  898.   do i = 1 to words(key_list)
  899.  
  900.      key = word(key_list,i)
  901.  
  902.      if  key \= "LOG_FILE"      &,
  903.          key \= "ERROR_LOG"     &,
  904.          key \= "MESSAGE_DONE"  &,
  905.          key \= "MESSAGE_ERROR" &,
  906.          cfg.key \= ""          &,
  907.          cfg.key \= "nul" then do
  908.  
  909.          say color.usual || "*** "msg.key  || ": " || color.bold || cfg.key
  910.      end
  911.   end
  912.  
  913.   call charout , color.usual
  914. return ""
  915.  
  916. /*------------------------------------------------------------------
  917.  * Save Configuration
  918.  *------------------------------------------------------------------*/
  919. CfgSave: procedure expose (globals)
  920.  
  921.   rc = stream( sys.config_file, "C", sys.open_read )
  922.  
  923.   do i = 1 while lines(sys.config_file) > 0
  924.      body.i = linein(sys.config_file)
  925.   end
  926.   body.0 = i - 1
  927.   rc = stream( sys.config_file, "C", "CLOSE" )
  928.  
  929.   key_list = CfgKeys()
  930.  
  931.   do i = 1 to words(key_list)
  932.      key = word(key_list,i)
  933.  
  934.      do j = 1 to body.0
  935.         if left( strip( body.j ), 1 ) == "#" then
  936.            iterate
  937.  
  938.         parse value body.j with command "="
  939.         command = translate(strip(command))
  940.  
  941.         if key == command then
  942.            leave
  943.      end j
  944.  
  945.      if cfg.key \= "nul" then do
  946.         if j > body.0 then do
  947.            comment = "CFG_"  || key
  948.            body.j  = "# "replace( msg.comment, "0D0A"x, "0D0A"x || "# " ) ||,
  949.                      "0D0A"x || "0D0A"x || key "=" cfg.key || "0D0A"x
  950.            end
  951.         else
  952.            body.j = key "=" cfg.key
  953.  
  954.         if j > body.0 then
  955.           body.0 = j
  956.      end
  957.   end i
  958.  
  959.   if stream( sys.config_file, "C", "QUERY EXISTS" ) \= "" then
  960.      "@del " sys.config_file
  961.  
  962.   rc = stream( sys.config_file, "C", sys.open_write )
  963.  
  964.   do j = 1 to body.0
  965.      parse value body.j with command "="
  966.      command  = translate(strip(command))
  967.  
  968.      if command \= "MAXIMUM_DOWNLOADS_SIMULTANEOUSLY" &,
  969.         command \= "WGET_PARAMETERS" then
  970.         call lineout sys.config_file, body.j
  971.   end
  972.  
  973.   rc = stream( sys.config_file, "C", "CLOSE" )
  974. return
  975.  
  976.  
  977. /* $Id: replace.cms,v 1.5 2001/05/11 08:54:34 glass Exp $ */
  978.  
  979. /*------------------------------------------------------------------
  980.  * Search and replace string
  981.  *------------------------------------------------------------------*/
  982. replace: procedure expose (globals)
  983.  
  984.   parse arg source, string, substitute
  985.   string = translate(string)
  986.  
  987.   i = pos( string, translate(source))
  988.  
  989.   do while i \= 0
  990.      source = substr( source, 1, i-1 ) || substitute ||,
  991.               substr( source, i+length(string))
  992.  
  993.      i = pos( string, translate(source), i + length(substitute))
  994.   end
  995.  
  996. return source
  997.  
  998. /* $Id: dirs.cms,v 1.24 2001/05/11 08:54:34 glass Exp $ */
  999.  
  1000. /*------------------------------------------------------------------
  1001.  * Converts directory to canonical form
  1002.  *------------------------------------------------------------------*/
  1003. DirCanonical: procedure expose (globals)
  1004.  
  1005.   parse arg path
  1006.   path = translate( path, "\", "/" )
  1007.  
  1008.   if right( path, 1 ) == "\" & pos( ":", path ) \= length(path)-1 then
  1009.      path = left( path, length(path)-1 )
  1010.  
  1011. return path
  1012.  
  1013. /*------------------------------------------------------------------
  1014.  * Returns path to file
  1015.  *------------------------------------------------------------------*/
  1016. DirPath: procedure expose (globals)
  1017.  
  1018.   parse arg pathname
  1019.  
  1020. return DirCanonical( filespec( "drive", pathname ) ||,
  1021.                      filespec( "path" , pathname ))
  1022.  
  1023. /*------------------------------------------------------------------
  1024.  * Create directory
  1025.  *------------------------------------------------------------------*/
  1026. DirCreate: procedure expose (globals)
  1027.  
  1028.   parse arg path
  1029.  
  1030.   path = DirCanonical( path )
  1031.   rc   = SysMkDir( path )
  1032.  
  1033.   if rc == 3 & pos( "\", path ) \= 0 then do
  1034.  
  1035.      parent = left( path, length(path) - pos( "\", reverse(path)))
  1036.      rc = DirCreate( parent )
  1037.  
  1038.      if rc == 0 then
  1039.         rc = SysMkDir( path )
  1040.   end
  1041. return rc
  1042.  
  1043. /*------------------------------------------------------------------
  1044.  * Checks existence of the directory
  1045.  *------------------------------------------------------------------*/
  1046. DirExist: procedure expose (globals)
  1047.  
  1048.   parse arg path
  1049.   if path == "" then return 0
  1050.   path = DirCanonical( path )
  1051.  
  1052.   setlocal
  1053.   path = directory( path )
  1054.   endlocal
  1055.  
  1056. return path \= ""
  1057.  
  1058.  
  1059. /* $Id: stop.cms,v 1.13 2001/05/11 08:54:34 glass Exp $ */
  1060.  
  1061. /*------------------------------------------------------------------
  1062.  * Stop Auto WGet Daemon
  1063.  *------------------------------------------------------------------*/
  1064. AwStop: procedure expose (globals)
  1065.  
  1066.   sys_running  = cfg.home'\'sys.running
  1067.   sys_killing  = cfg.home'\'sys.killing
  1068.  
  1069.   'del 'sys_running' /F 1>nul 2>nul'
  1070.  
  1071.   call lineout sys_killing, "Must die!"
  1072.   call charout, color.info || "■■■ "msg.wait_stopped"..."
  1073.  
  1074.   do 20 while stream( sys_running, 'c', 'query exist' ) \= ""
  1075.      call SysSleep  2
  1076.      call charout, "."
  1077.     'del 'sys_running' /F 1>nul 2>nul'
  1078.   end
  1079.   say ; say color.info || "■■■ "msg.stopped || color.usual
  1080.  
  1081.   rc = stream( sys_killing, 'c', 'close' )
  1082.  'del 'sys_killing' /F 1>nul 2>nul'
  1083.  
  1084. return ""
  1085.