(*
 * LANGUAGE    : ANS Forth with extensions
 * PROJECT     : Forth Environments
 * DESCRIPTION : Installs iForth 2.1 on Windows
 * CATEGORY    : Utilities
 * AUTHOR      : Marcel Hendrix 
 * LAST CHANGE : Monday, September 20, 2010, 21:15, Marcel Hendrix, added IFORTH_DIR and IFORTH_EDIT
 * LAST CHANGE : Sunday, December 13, 2009, 12:18, Marcel Hendrix, added 64 bit iForth additions
 * LAST CHANGE : Thursday, December 01, 2005, 22:41 PM, Marcel Hendrix, added ICON handling
 * LAST CHANGE : November 27, 2005, Marcel Hendrix 
 *)



        NEEDS -miscutil
        NEEDS -winreg

        REVISION -install "--- Windows installer   Version 1.04 ---"

        PRIVATES

        WINDOWS? 0= [IF] CR .( Sorry: Windows only! ) ABORT [THEN]

DOC General
(*
*)
ENDDOC

-- Don't change this! -----------------------------------------------------------------------------------------------------

CREATE $ENV-PATH     ," SYSTEM\CurrentControlSet\Control\Session Manager\Environment\" ( -- c-addr u )

-- Change according to taste ----------------------------------------------------------------------------------------------

CREATE $UTIL-PATH    ," \dfwforth\ifwinnt\bin"                                  ( -- c-addr u ) \ on CD, utility directory
CREATE $SOURCE-PATH  ," \dfwforth"                                              ( -- c-addr u ) \ on CD, files to install
CREATE $BASE-PATH    ," C:\dfwforth"                                            ( -- c-addr u ) \ on disk, where to install
CREATE $DIR-PATH     ," c:\utils\ls -a -C -F "                                  ( -- c-addr u ) \ on disk, favourite file lister
CREATE $EDIT-PATH    ," c:\textpad\txtpad32 "                                   ( -- c-addr u ) \ on disk, favourite editor
                                                                                                \  also needed for IFORTH
CREATE $ICON-PATH    ," %ALLUSERSPROFILE%\Start Menu\Programs\iforth.lnk"       ( -- c-addr u ) \ for shortcut
CREATE $EXE-PATH     ," C:\dfwforth\ifwinnt\bin\iwserver.exe"                   ( -- c-addr u ) \ for shortcut
CREATE $IMAGE-PATH   ," C:\dfwforth\ifwinnt\bin\iforth.img"                     ( -- c-addr u ) \ needed for IFORTHBIN
CREATE $EXE64-PATH   ," C:\dfwforth\ifwinnt64\bin\iwserver.exe"                 ( -- c-addr u ) \ for shortcut
CREATE $IMAGE64-PATH ," C:\dfwforth\ifwinnt64\bin\iforth.img"                   ( -- c-addr u ) \ needed for IFORTHBIN64

-- ------------------------------------------------------------------------------------------------------------------------

: -OK? ( -- bool ) CR ." Proceed? (Yy/Nn)"  EKEY >UPC 'Y' <> ( -- bool ) CR ;

: OK? ( c-addr u -- )
        CR 2DUP TYPE
        -OK? IF  CR ." No permission to execute: " TYPE EXIT  ENDIF 
        SYSTEM ;

-- ------------------------------------------------------------------------------------------------------------------------

: ?SHOW-FILE-STATUS ( -- )
        CR CR >INVERSE< ." *** Copying all files *** (modify install.frt as appropriate)" >INVERSE< CR ;

: COPY-FILES ( -- )
        ?SHOW-FILE-STATUS 
        S" XCOPY " $SOURCE-PATH COUNT $+  S" \*.* " $+
                   $BASE-PATH   COUNT $+
                   S"  /E /I /F"      $+  OK? 
        CR
        S" ATTRIB -R " $BASE-PATH COUNT $+ S"  /S /D" $+ OK? ;

-- ------------------------------------------------------------------------------------------------------------------------

: ?SHOW-ICON-STATUS ( -- )
        CR CR >INVERSE< ." *** Setting shortcuts ***  (modify install.frt as appropriate)" >INVERSE< CR ;

: INSTALL-ICON32 ( -- ) 
        $UTIL-PATH COUNT
        S~ \shortcut /f:"~ $+ $ICON-PATH COUNT $+ S~ " /a:c ~   $+      \ create shortcut
        S~ /t:"~ $+ $EXE-PATH  COUNT $+ S~ " ~                  $+      \ target path
        S~ /w:"~ $+ $BASE-PATH COUNT $+ S~ \examples" ~         $+      \ working dir
        S~ /p:"include iforth.prf cr" >nul ~                    $+      \ command line parameters
        S~ /i:"~ $+ $EXE-PATH  COUNT $+ S~ " ~                  $+      \ file with icon
        OK? ;

: INSTALL-ICON64 ( -- ) 
        $UTIL-PATH COUNT
        S~ \shortcut /f:"~ $+ $ICON-PATH COUNT $+ S~ " /a:c ~   $+      \ create shortcut
        S~ /t:"~ $+ $EXE64-PATH  COUNT $+ S~ " ~                $+      \ target path
        S~ /w:"~ $+ $BASE-PATH COUNT $+ S~ \examples" ~         $+      \ working dir
        S~ /p:"include iforth.prf cr" >nul ~                    $+      \ command line parameters
        S~ /i:"~ $+ $EXE64-PATH  COUNT $+ S~ " ~                $+      \ file with icon
        OK? ;

: INSTALL-ICON ( -- ) 
        ?SHOW-ICON-STATUS
	INSTALL-ICON32 
	INSTALL-ICON64 ;

-- ------------------------------------------------------------------------------------------------------------------------

: ?SHOW-ENV-STATUS ( -- )
        CR CR >INVERSE< ." *** Setting environment variables *** (modify install.frt as appropriate)" >INVERSE< CR ;

: SET-ENVVARS ( -- )
        ?SHOW-ENV-STATUS
        CR S" set IFORTH="      $BASE-PATH    COUNT $+ TYPE
        CR S" set IFORTHBIN="   $IMAGE-PATH   COUNT $+ TYPE
        CR S" set IFORTHBIN64=" $IMAGE64-PATH COUNT $+ TYPE
        CR S" set IFORTH_DIR="  $DIR-PATH     COUNT $+ TYPE
        CR S" set IFORTHBIN64=" $EDIT-PATH    COUNT $+ TYPE
        -OK? IF  CR ." No permission to set environment variables." EXIT  ENDIF
        $BASE-PATH    COUNT  hklm $ENV-PATH COUNT S" IFORTH"      RegSetENV
        $IMAGE-PATH   COUNT  hklm $ENV-PATH COUNT S" IFORTHBIN"   RegSetENV 
        $IMAGE64-PATH COUNT  hklm $ENV-PATH COUNT S" IFORTHBIN64" RegSetENV 
        $DIR-PATH     COUNT  hklm $ENV-PATH COUNT S" IFORTH_DIR"  RegSetENV 
        $EDIT-PATH    COUNT  hklm $ENV-PATH COUNT S" IFORTH_EDIT" RegSetENV ;

-- ------------------------------------------------------------------------------------------------------------------------

: INSTALL ( -- )
        COPY-FILES
        INSTALL-ICON
        SET-ENVVARS ;

:ABOUT  CR ." Type: INSTALL -- installs iForth on Windows (when run from CD)" 
        CR ."       BYE     -- quit this program" ;

	NESTING @ 1 = [IF] .ABOUT -install CR  [THEN]
                           DEPRIVE

                              (* End of Source *)