Changeset 622


Ignore:
Timestamp:
Apr 21, 2007, 2:33:29 AM (18 years ago)
Author:
John Small
Message:
  • Major chnages: new parameters, removal of obsolete code,

restructured to enable future use of archivers (Warpin, ZIP, etc.).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cfgmgr.cmd

    r580 r622  
    3434call Init
    3535
     36/*
    3637call DeleteObsoleteFiles
     38*/
    3739
    3840parse arg args
     
    4749   signal NormalExit
    4850
    49 action_taken = 0
     51cfg.action_taken = 0
    5052do f = 1 to cfg.file.0
    5153   file_exists = stream(cfg.file.f.name, 'c' , 'query exists')
    52    if cfg.delete = 1 then
     54   if cfg.operation = 'INSTALL' then
    5355      if file_exists \= '' then
    5456         do
    55             'del 'cfg.file.f.name
    56             action_taken = 1
     57            if FilesAreDifferent(cfg.file.f.default, cfg.file.f.name) = 1 then
     58               if cfg.defaults = 1 then
     59                  do
     60                     call SysMkDir cfg.backupdir
     61                     if cfg.unattended = 0 then
     62                        do
     63                           user_choice = PromptForReplaceOption(f)
     64                           if user_choice == 'Q' then
     65                              signal NormalExit
     66                           if user_choice == 'N' then
     67                              iterate
     68                        end
     69                     /* unattended = 1 or user_choice = 'Y' */
     70                     cfg.errorcode = CfgAction( 'RESETTODEFAULT', f )
     71                  end
    5772         end
    5873      else
    59          nop
    60    else
    61       /* must be a "reset" operation */
    62       select
    63          when file_exists == '' then                     /* If file is missing... */
     74        cfg.errorcode = CfgAction( 'INSTALLDEFAULT', f )
     75   else /* operation = deinstall */
     76      do
     77         if BackupFileIsOK(f) = 0 then
     78            iterate
     79         if cfg.unattended = 0 then
    6480            do
    65                'copy 'cfg.file.f.tmpl8 cfg.file.f.name
    66                action_taken = 1
     81               user_choice = PromptForReplaceOption(f)
     82               if user_choice == 'Q' then
     83                  signal NormalExit
     84               if user_choice == 'N' then
     85                  iterate
    6786            end
    68          when cfg.reset_overwrite == 1 then
    69             if FilesAreDifferent(cfg.file.f.tmpl8, cfg.file.f.name) == 1 then
    70                if cfg.unattended == 1 | ,                   /* If unattended reset, or  */
    71                   cfg.reset_overwrite_option == 'A' then    /* user has wants "ALL" overwrites... */
    72                   do
    73                      'copy 'cfg.file.f.tmpl8 cfg.file.f.name
    74                      action_taken = 1
    75                   end
    76                else
    77                   if PromptedReset(f) == 'Y' then           /* If user has OK'd this overwrite... */
    78                      do
    79                         'copy 'cfg.file.f.tmpl8 cfg.file.f.name
    80                         action_taken = 1
    81                      end
    82          otherwise
    83             nop
     87         cfg.errorcode = CfgAction('DEINSTALL', f)
     88         if cfg.errorcode \= 0 then
     89            leave
    8490      end
    8591end
     
    8793if cfg.errorcode \= 0 then
    8894   signal ErrorExit
    89 if action_taken = 0 then
     95
     96if cfg.action_taken = 0 then
    9097   do
     98      say
     99      say 'No action taken.'
    91100      say
    92101      say 'FM/2 configuration files are already as you desire.'
    93102   end
     103
    94104signal NormalExit
    95105
     
    117127   cfg.              = ''
    118128   cfg.errorcode     = 0
    119    cfg.reset_overwrite = 0
     129   cfg.defaults      = 0
    120130   cfg.unattended    = 0
    121    cfg.delete        = 0
     131   cfg.backupdir     = '.\User_Config_Backup'
     132   cfg.actionmethod  = 'COPY'       /* The default method of backing up and restoring */
    122133
    123134   f = 0
     
    126137
    127138   f = f + 1
    128    cfg.file.f.tmpl8  = '.\Tmplates\assoc.tmp'
     139   cfg.file.f.default = '.\Tmplates\assoc.tmp'
    129140   cfg.file.f.name    = '.\assoc.dat'
    130141   cfg.file.f.desc.1  = 'FM/2 associations'
     
    132143
    133144   f = f + 1
    134    cfg.file.f.tmpl8  = '.\Tmplates\commands.tmp'
     145   cfg.file.f.default = '.\Tmplates\commands.tmp'
    135146   cfg.file.f.name    = '.\commands.dat'
    136147   cfg.file.f.desc.1  = 'FM/2 user-defined commands'
     
    138149
    139150   f = f + 1
    140    cfg.file.f.tmpl8  = '.\Tmplates\archiver.tmp'
     151   cfg.file.f.default = '.\Tmplates\archiver.tmp'
    141152   cfg.file.f.name    = '.\archiver.bb2'
    142153   cfg.file.f.desc.1  = 'FM/2 archiver definitions'
     
    144155
    145156   f = f + 1
    146    cfg.file.f.tmpl8  = '.\Tmplates\cmds.tmp'
     157   cfg.file.f.default = '.\Tmplates\cmds.tmp'
    147158   cfg.file.f.name    = '.\cmds.tls'
    148159   cfg.file.f.desc.1  = 'FM/2 toolbar: commands'
     
    150161
    151162   f = f + 1
    152    cfg.file.f.tmpl8  = '.\Tmplates\files.tmp'
     163   cfg.file.f.default = '.\Tmplates\files.tmp'
    153164   cfg.file.f.name    = '.\files.tls'
    154165   cfg.file.f.desc.1  = 'FM/2 toolbar: files'
     
    156167
    157168   f = f + 1
    158    cfg.file.f.tmpl8  = '.\Tmplates\select.tmp'
     169   cfg.file.f.default = '.\Tmplates\select.tmp'
    159170   cfg.file.f.name    = '.\select.tls'
    160171   cfg.file.f.desc.1  = 'FM/2 toolbar: select'
     
    162173
    163174   f = f + 1
    164    cfg.file.f.tmpl8  = '.\Tmplates\sort.tmp'
     175   cfg.file.f.default = '.\Tmplates\sort.tmp'
    165176   cfg.file.f.name    = '.\sort.tls'
    166177   cfg.file.f.desc.1  = 'FM/2 toolbar: sort'
     
    168179
    169180   f = f + 1
    170    cfg.file.f.tmpl8  = '.\Tmplates\utils.tmp'
     181   cfg.file.f.default = '.\Tmplates\utils.tmp'
    171182   cfg.file.f.name    = '.\utils.tls'
    172183   cfg.file.f.desc.1  = 'FM/2 toolbar: utils'
     
    174185
    175186   f = f + 1
    176    cfg.file.f.tmpl8  = '.\Tmplates\views.tmp'
     187   cfg.file.f.default = '.\Tmplates\views.tmp'
    177188   cfg.file.f.name    = '.\views.tls'
    178189   cfg.file.f.desc.1  = 'FM/2 toolbar: views'
     
    180191
    181192   f = f + 1
    182    cfg.file.f.tmpl8  = '.\Tmplates\config.tmp'
     193   cfg.file.f.default = '.\Tmplates\config.tmp'
    183194   cfg.file.f.name    = '.\config.tls'
    184195   cfg.file.f.desc.1  = 'FM/2 toolbar: config'
     
    186197
    187198   f = f + 1
    188    cfg.file.f.tmpl8  = '.\Tmplates\fm3tools.tmp'
     199   cfg.file.f.default = '.\Tmplates\fm3tools.tmp'
    189200   cfg.file.f.name    = '.\fm3tools.dat'
    190201   cfg.file.f.desc.1  = 'FM/2 toolbar: tools?'
     
    192203
    193204   f = f + 1
    194    cfg.file.f.tmpl8  = '.\Tmplates\filters.tmp'
     205   cfg.file.f.default = '.\Tmplates\filters.tmp'
    195206   cfg.file.f.name    = '.\filters.dat'
    196207   cfg.file.f.desc.1  = 'FM/2 filters'
     
    198209
    199210   f = f + 1
    200    cfg.file.f.tmpl8  = '.\Tmplates\quicktls.tmp'
     211   cfg.file.f.default = '.\Tmplates\quicktls.tmp'
    201212   cfg.file.f.name    = '.\quicktls.dat'
    202213   cfg.file.f.desc.1  = 'FM/2 toolbar list'
     
    204215
    205216   f = f + 1
    206    cfg.file.f.tmpl8  = '.\Tmplates\fatopt.tmp'
     217   cfg.file.f.default = '.\Tmplates\fatopt.tmp'
    207218   cfg.file.f.name    = '.\fatopt.cmd'
    208219   cfg.file.f.desc.1  = 'FM/2 FAT optimizing command'
     
    210221
    211222   f = f + 1
    212    cfg.file.f.tmpl8  = '.\Tmplates\hpfsopt.tmp'
     223   cfg.file.f.default = '.\Tmplates\hpfsopt.tmp'
    213224   cfg.file.f.name    = '.\hpfsopt.cmd'
    214225   cfg.file.f.desc.1  = 'FM/2 HPFS optimizing command'
     
    216227
    217228   f = f + 1
    218    cfg.file.f.tmpl8  = '.\Tmplates\jfsopt.tmp'
     229   cfg.file.f.default = '.\Tmplates\jfsopt.tmp'
    219230   cfg.file.f.name    = '.\jfsopt.cmd'
    220231   cfg.file.f.desc.1  = 'FM/2 JFS optimizing command'
     
    243254      parse var args param args
    244255      select
    245          when param = '/RESET' then
    246             if cfg.delete = 1 then
     256         when param = '/INSTALL' then
     257            if cfg.operation \= '' then
    247258               cfg.errorcode = 1
    248259            else
    249                cfg.reset_overwrite = 1
    250          when param = '/DELETE' then
    251             if cfg.reset_overwrite = 1 then
     260               cfg.operation = 'INSTALL'
     261         when param = '/DEINSTALL' then
     262            if cfg.operation \= '' then
    252263               cfg.errorcode = 1
    253264            else
    254                cfg.delete = 1
     265               cfg.operation = 'DEINSTALL'
    255266         when param = '/UNATTENDED' then
    256267            cfg.unattended = 1
     268         when param = '/DEFAULTS' then
     269            cfg.defaults = 1
    257270         otherwise
    258271            cfg.errorcode = 2
    259272      end
    260273   end
     274   if cfg.operation = '' then
     275      cfg.errorcode = 1
     276   else
     277      if cfg.operation = 'INSTALL' & cfg.defaults = 0 then
     278         cfg.unattended = 1
    261279return
    262280
    263281GetUserOptions: procedure expose (globals)
    264    if cfg.reset_overwrite = 1 then
     282   call SysCls
     283   option = ''
     284   if cfg.defaults = 1 then
    265285      do
    266          /* messages here about reset */
    267          call SysCls
    268          do while wordpos(cfg.reset_overwrite_option, 'A C Q') == 0
     286         do while wordpos(option, 'A C Q') == 0
    269287            say
    270288            say
     
    278296            say 'This program can ask for confirmation before each file,'
    279297            say 'if it already exists, is replaced with its default.'
    280             cfg.reset_overwrite_option = GetResponse('Type ''A'' for ALL files, ''C'' for Confirmations, ''Q'' to quit')
     298            say
     299            option = GetResponse('Type ''A'' for ALL files, ''C'' for Confirmations, ''Q'' to quit')
    281300         end
    282          cfg.userabort = (cfg.reset_overwrite_option == 'Q')
    283          if cfg.reset_overwrite_option == 'A' then
     301         cfg.userabort = (option == 'Q')
     302         if option == 'A' then
    284303            do
    285304               say
    286305               say
    287                say center(copies('   ** Warning!! **   ', 3), cfg.screen_width)
     306               say '****  WARNING  ****' || copies(d2c(7), 3)
    288307               say
    289308               say 'You have chosen to replace ALL configuration files with'
    290309               say 'default values.'
    291                cfg.userabort = (GetResponse('Type ''Y'' to proceed, anthing else cancels') \= 'Y')
     310               say
     311               if GetResponse('Type ''Y'' to proceed, anthing else cancels') = 'Y' then
     312                  cfg.unattended = 1
     313               else
     314                  cfg.userabort = 1
    292315            end
    293316      end
    294317   else
    295       if cfg.delete = 1 then
     318      if cfg.operation = 'DEINSTALL' then
    296319         do
    297320            /* messages here about delete */
    298321            call SysCls
    299322            say
    300             say center(copies('   ** Warning!! **   ', 3), cfg.screen_width)
     323            say '****  WARNING  ****' || copies(d2c(7), 3)
    301324            say
    302325            say 'If you provide your consent, this program will'
    303326            say 'DELETE all FM/2 configuration files.'
    304327            say
    305             cfg.userabort = (GetResponse('Type ''Y'' to proceed, anthing else cancels') \= 'Y')
     328            if GetResponse('Type ''Y'' to proceed, anthing else cancels') = 'Y' then
     329               cfg.unattended = 1
     330            else
     331               cfg.userabort = 1
    306332         end
    307333return
     
    309335GetResponse: procedure
    310336   parse arg prompt
    311    say
    312337   call charout , prompt || ': '
    313338   reply = translate(strip(SysGetKey()))
     
    315340   return reply
    316341
     342/*
    317343DeleteObsoleteFiles: procedure expose (globals)
    318344   i  =  0
     
    338364   end
    339365return
     366*/
    340367
    341368FilesAreDifferent: procedure
     
    355382return retval
    356383
    357 PromptedReset: procedure expose (globals)
     384PromptForReplaceOption: procedure expose (globals)
    358385   parse arg f
     386   filename = filespec('N', cfg.file.f.name)
    359387   call SysCls
    360388   say
     
    363391   say
    364392   say 'File:'
    365    say '   'substr(cfg.file.f.name, lastpos('\', cfg.file.f.name) + 1)
     393   say '   'filename
    366394   say
    367395   say 'Description:'
     
    370398   end
    371399   say
    372 return GetResponse('Type ''Y'' to reset to default')
     400   if cfg.operation = 'INSTALL' then
     401      do
     402         say 'Back up and then overwrite your current 'filename
     403         msg = 'with default values'
     404      end
     405   else
     406      msg = 'Replace your current 'filename' with the backup file'
     407return GetResponse(msg '(Y/n)?')
     408
     409novalue:
     410   say 'Unitialized variable: 'condition('D')' found on line: 'sigl
     411   say 'Line text: 'sourceline(sigl)
     412   say
     413   say 'Exiting...'
     414   signal NormalExit
     415
    373416
    374417Usage: procedure expose (globals)
    375    say 'Invalid usage. See below for acceptable calls:'
    376    say
    377    say cfg.pgmname' <no parameters>'
    378    say '   This installs missing configuration files with default values.'
    379    say
    380    say cfg.pgmname' /RESET'
    381    say '   This replaces existing configuration files with default values.'
    382    say '   You asked to confirm this action. You can choose to replace all'
    383    say '   files or you can request a file-by-file confirmation.'
    384    say
    385    say cfg.pgmname' /DELETE'
    386    say '   This deletes all configuration files. You are asked to confirm'
    387    say '   this action. (This is not an action users should normally take.)'
    388    say
    389    say cfg.pgmname' /RESET /UNATTENDED'
    390    say cfg.pgmname' /DELETE /UNATTENDED'
    391    say '   These operations operate as above except there is NO user'
    392    say '   interaction or confirmation! Use with extreme care!'
    393    say
     418   say 'Proper usage of 'cfg.pgmname':'
     419   say
     420   say cfg.pgmname' /INSTALL [/UNATTENDED]'
     421   say '   This installs any missing configuration files with default values.'
     422   say
     423   say cfg.pgmname' /INSTALL /DEFAULTS [/UNATTENDED]'
     424   say '   This action backs up user-modified configuration files and replaces'
     425   say '   them with default values. Unless /UNATTENDED, you are asked to confirm'
     426   say '   this action.'
     427   say
     428   say cfg.pgmname' /DEINSTALL /DEFAULTS [/UNATTENDED]'
     429   say '   This reverses the action described above.'
     430   say
     431   say cfg.pgmname' /DEINSTALL [/UNATTENDED]'
     432   say '   This deletes all configuration files. Unless /UNATTENDED, you are asked'
     433   say '   to confirm this action. (This is action is automatically done during'
     434   say '   de-installation of FM/2. It is not an action users should normally take.)'
     435   say
     436   say 'The optional parameter /UNATTENDED means there will be NO user interaction'
     437   say '   interaction during or confirmation of the operation!!!'
    394438   say 'The order of the parameters is not important.'
    395439return
     
    402446   say 'If this error continues after re-installing FM/2, contact FM/2 support'
    403447   say 'through the FM2USER group on Yahoo.'
    404 return
     448exit
    405449
    406450novalue:
     
    410454   signal ErrorExit
    411455
     456CfgAction: procedure expose (globals)
     457   parse arg action, f
     458   retval = 0
     459   select
     460      when action = 'RESETTODEFAULT' then
     461         select
     462            when cfg.actionmethod = 'COPY' then
     463               do
     464                  'copy 'cfg.file.f.name cfg.backupdir
     465                  'copy 'cfg.file.f.default cfg.file.f.name
     466                  cfg.action_taken = 1
     467               end
     468            /* Implement other archive/restore methods here */
     469            otherwise
     470               retval = 4
     471         end
     472      when action = 'INSTALLDEFAULT' then
     473         select
     474            when cfg.actionmethod = 'COPY' then
     475               do
     476                  'copy 'cfg.file.f.default cfg.file.f.name
     477                  cfg.action_taken = 1
     478               end
     479            /* Implement other archive/restore methods here */
     480            otherwise
     481               retval = 4
     482         end
     483      when action = 'DEINSTALL' then
     484         if cfg.defaults = 1 then
     485            select
     486               when cfg.actionmethod = 'COPY' then
     487                  do
     488                     'copy 'cfg.backupdir || '\' || cfg.file.f.name' .'
     489                     cfg.action_taken = 1
     490                  end
     491               /* Implement other archive/restore methods here */
     492               otherwise
     493                  retval = 4
     494            end
     495         else
     496            select
     497               when cfg.actionmethod = 'COPY' then
     498                  if stream(cfg.file.f.name, 'c', 'query exists') \= '' then
     499                     if FilesAreDifferent(cfg.file.f.name, cfg.file.f.default) = 0 then
     500                        do
     501                           'del 'cfg.file.f.name
     502                           cfg.action_taken = 1
     503                        end
     504               /* Implement other archive/restore methods here */
     505               otherwise
     506                  retval = 4
     507            end
     508      otherwise
     509         retval = 5
     510
     511   end
     512return retval
     513
     514BackupFileIsOK: procedure expose (globals)
     515   parse arg f
     516   retval = 1                    /* assume yes */
     517   if cfg.defaults = 1 then      /* Not needed when cfg.defaults = 0 */
     518      do
     519         retval = 0
     520         select
     521            when cfg.actionmethod = 'COPY' then
     522               do
     523                  backup_file = cfg.backupdir || '\' || cfg.file.f.name
     524                  if stream(backup_file, 'c', 'query exists') \= '' then
     525                     retval = FilesAreDifferent(cfg.file.f.name, backup_file)
     526               end
     527            /* Implement other archive/restore methods here */
     528            otherwise
     529               cfg.errorcode = 4
     530         end
     531      end
     532return retval
     533
Note: See TracChangeset for help on using the changeset viewer.