/* THE OS/2 Icon Collection Installation Script */
/* Modified by Fred Ng, based on the Icon Heaven installation script */
/* Copyright(c) 1993-1994 by The Frobozz Magic Software Company */

call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs

'@echo off'

call SysCls

say '        THE OS/2 Icon Collection #10 (Icon Heaven Edition) Installation'
say ''
say 'THE OS/2 Icon Collection requires Icon Heaven 1.12 to be installed, as well as'
say '6MB of free space.  If you are not sure about either requirement, press "Y"'
say 'followed by <Enter> to abort installation now.  Otherwise, press <Enter> to'
say 'continue...'
pull noih

if left(noih, 1) = 'Y' then do
  say ''
  say 'Installation aborted.  Install Icon Heaven, and run Install.CMD again.'
  exit
end

ini = value('USER_INI',,'OS2ENVIRONMENT')

tDrive = left(ini,1)

instdir=tDrive':\OS2Icons'

say 'Enter the path where THE OS/2 Icon Collection will be installed, or press'
say '<Enter> to select the default path ['instdir']...'
pull newdir

if newdir <> '' then
  instdir = newdir

if length(instdir) = 3 then do
  if substr(instdir,3,1) ='\' then
    instdir = left(instdir,2)
end

say 'THE OS/2 Icon Collection will be installed in ['instdir']'
'pause'

res = SysMkDir(instdir)

if res <> 0 then do
  say 'The directory ['instdir'] you specified cannot be created!'
  say 'Installation aborted.'
  exit
end

say 'Copying files to 'instdir', please wait...'
'copy *.FIM 'instdir' >nul'
'copy Folder*.ICO 'instdir' >nul'
'copy ReadMe.TXT 'instdir' >nul'
say 'Done.'
say ''

say 'Creating THE OS/2 Icon Collection folder on your desktop...'
classname = 'WPFolder'
title     = 'THE OS/2 Icon Collection'
location  = '<WP_DESKTOP>'
setup     = 'OBJECTID=<THEICNIH>;'||,
            'ICONFILE='instdir'\Folder.ICO;'||,
            'ICONNFILE=1,'instdir'\Folder1.ICO;'
retval = SysCreateObject(classname, title, location, setup, 'R')
say 'Done.'
say ''

'del 'instdir'\Folder*.ICO'

call instlibs '.'

say 'Installation has been successfully completed.'
say 'Do you wish to have the installation directory cleaned up? [N/y]'
pull reply
if left(reply, 1) = 'Y' then do
  call cleanup
end

exit

instlibs:

dir=ARG(1)

call SysFileTree dir'\*.FIM', 'file.', 'FO'

say 'Installing icon libraries...'

do i=1 to file.0
  targ = instdir'\'filespec('n',file.i)
  'copy' file.i targ '>nul'
  cookie1 = charin(targ)
  cookie2 = charin(targ)
  if cookie1 = 'L' & cookie2 = 'I' then do
    dum = charin(targ,,8)
    n = ''
    c = charin(targ)
    do until c2d(c) = 0
      n = n''c
      c= charin(targ)
    end
    retval = SysCreateObject('FIMFolder', n, '<THEICNIH>', 'ICONLIBRARY='targ, 'R')
    say 'Library 'n' added'
    call stream targ,'C','CLOSE'
  end
  else do
    call stream targ,'C','CLOSE'
    'del 'targ
  end
end

say 'Done.'
say ''

return


cleanup:

'del *.FIM Folder*.ICO ReadMe.TXT HPKIcons.TXT Install.CMD'

return
