
xcopy rhapsody\*.* c:\hp\hpqware\rhapsody\ /e

@echo OFF
@REM :
@REM : Author: *** John Thomas - Thu Oct 20, 2005,  1:32 PM ***
@REM :
@REM :
@REM : Description:
@REM :
@REM :  Install script for <program name>. 
@REM :
@REM : Variables Used:
@REM :
@REM :  MySrcDir   - Source bits path name.

setlocal enabledelayedexpansion

@REM :---------------------------------------------------------------------
@REM :            From JGT Block Template
@REM :---------------------------------------------------------------------
@REM : Initialize Error Checking Variables

@REM : "MyTryCmd" should be set to log the command returning an error status.
@REM : "MyErrLvl" should be set to log the ERRORLEVEL associated with the
@REM :            error.
@REM : "MyErrMsg" should be set to log the reason for the error.
@REM : "MyErrSec" should be set to log the section of this script detecting
@REM :            the error.

@REM : "MyDir0"   should be set to the directory path name that will contain a
@REM :            list (i.e, copy) of the desktop links before running the
@REM :            setup.  

@REM : Initialize the MyTryCmd (command image), MyErrMsg (error message),
@REM :   MyErrLvl (ERRORLEVEL), and MyErrSec (code section) to nothing.
@REM :   These variables are used in error logging.
set MyTryCmd=
set MyErrMsg=
set MyErrLvl=
set MyErrSec=
@REM :---------------------------------------------------------------------


@REM :---------------------------------------------------------------------
@REM : Section 0.1
@REM :---------------------------------------------------------------------
set MyErrSec=0.1

@REM :---------------------------------------------------------------------
@REM : Block Template:
@REM : Determine the block name in case needed for error reporting.
@REM :---------------------------------------------------------------------
for %%f in (*.block) do set BlockName=%%~nf
if "%BlockName%"=="" set BlockName=[ Block name not found ]

echo %BlockName%: %date% %time% - Begin install.cmd, section %MyErrSec% >> %LOG%\rhap.txt
echo %BlockName%: Lang_Country: %ISO_LG%_%ISO_COUNTRY% >> %LOG%\rhap.txt


@REM :---------------------------------------------------------------------
@REM : Make sure Desk Top Links Folder variable is defined.  
@REM :---------------------------------------------------------------------
if not defined DTShortCutsFolder set DTShortCutsFolder=\hp\hpqware\dtshortcuts

set MyAuditModeFlag=0

set MySrcDir=src
set MySetup=%MySrcDir%\RhapsodyHp.EXE


@REM :---------------------------------------------------------------------
@REM : Section 1.0
@REM :---------------------------------------------------------------------
set MyErrSec=1.0


@REM :---------------------------------------------------------------------
@REM : Begin Automatic Desktop Link Name Determination (part 1)
@REM : 
@REM : Save all original desktop shortcuts prior to running setup.  We'll
@REM : use this list to compare with the desktop shortcuts existing after
@REM : setup runs.  Then we can determine which desktop link is new in this
@REM : install.  The goal is to have an algorithm that works for any
@REM : linkname change and be language-independent.  
@REM : 
@REM :---------------------------------------------------------------------

@REM : Save directory name containing desktop links prior to running setup.
set MyDir0=DesktopLinksSave0

if not exist %MyDir0%\ (
   set MyTryCmd=md %MyDir0%
   set MyErrMsg=

   !MyTryCmd!
   if errorlevel 1 (
      call :get_errorlevel

      @REM : Note: Never do a "set" command between the command setting the
      @REM :   the errorevel and where errorlevel is being checked because
      @REM :   "set" destroys the ERRORLEVEL value.

      set MyErrMsg=Setup failed.  ErrorLevel= !MyErrLvl!.
      goto :error
      )

   if not exist %MyDir0%\ (
      set MyErrMsg=Attempt to create DesktopLinksSave0 failed.
      )

   ) else (
      @REM : Ensure no pre-exiting Desktop links are saved.
      del /f /q .\DesktopLinksSave0\
      )


copy "%COMMON DESKTOP%\*" "%MyDir0%\."


@reg query HKLM\System\Setup\Status | find /i "AuditBoot" | find /i "0x1" >NUL && set MyAuditModeFlag=1

@REM : Define jtDebug when we want to test as if in Audit Mode.
if defined jtDebugFlag set MyAuditModeFlag=1






@REM :---------------------------------------------------------------------
@REM : If the setup file doesn't exist, log an error.
@REM :---------------------------------------------------------------------
@if NOT exist %MySetup% (
   @REM :---------------------------------------------------------------
   @REM : Section 1.1
   @REM :---------------------------------------------------------------
   set MyErrSec=1.1

   set MyErrMsg=Missing setup file: "%MySetup%".

   goto :error
   )

@REM :------------------------------------------------------------------
@REM : 
@REM : Rhapsody installer notes:
@REM : 
@REM : To run a basic silent install, use the "/s" command line
@REM : parameter.  
@REM : 
@REM : The installation takes about 120 seconds.  To verify that the
@REM : installation has completed, verify that the installed Rhapsody
@REM : client exists in the \Program Files\HP Rhapsody folder (default
@REM : folder).  The installer will also create a desktop shortcut, and
@REM : an entry in the Start Menu.  
@REM : 
@REM : The application can be installed into any desired location by
@REM : using these additional parameters on the command line after /s.  
@REM : 
@REM : Example:
@REM : RhapsodyHpq.EXE /s /dir "\Program Files\Rhapsody"
@REM : 
@REM :------------------------------------------------------------------

@REM : Prepare for error reporting.
set MyTryCmd=%MySetup% /s
set MyErrLvl=
set MyErrMsg=

@REM :------------------------------------------------------------------
@REM : Section 1.2
@REM :------------------------------------------------------------------
set MyErrSec=1.2

@REM : Run the setup program.
!MyTryCmd!
if errorlevel 1 (
   call :get_errorlevel

   @REM : Note: Never do a "set" command between the command setting the
   @REM :   the errorevel and where errorlevel is being checked because
   @REM :   "set" destroys the ERRORLEVEL value.

   set MyErrMsg=Command returned status: ERRORLEVEL=!MyErrLvl!.
   goto :error
   )


@REM : ---------------------------------------------------------------------
@REM : JGT Block Template:
@REM : ---------------------------------------------------------------------
@REM : Search for the desktop link added by setup.  The new link will exist
@REM : in the %COMMON DESKTOP% folder but not in .\DesktopLinksSave0\.  Once
@REM : we have the name of the new desktop link, we can determine by the
@REM : SWIT POR if we should keep it or not.  
@REM : ---------------------------------------------------------------------
for %%l in ( "%COMMON DESKTOP%\*.lnk" ) do (
   if not exist "%MyDir0%\%%~nxl" (

      echo %BlockName%: Application added link: %%l  >> %LOG%\rhap.txt


      @REM : If control reaches here, we know that setup has added a new
      @REM : Desktop Link.

      @REM :---------------------------------------------------------------
      @REM : Block Template:
      @REM : If running in Audit mode, save Desktop Links in \hp\hpqware\dtshortcuts.
      @REM :---------------------------------------------------------------
      if %MyAuditModeFlag%==1 (

         echo %BlockName%: In Audit Mode.  >> %LOG%\rhap.txt

         @REM :------------------------------------------------------------
         @REM : If Desktop Links are desired we must put the link into
         @REM : the \hp\hpqware\dtshortcuts\<lang_country> directory
         @REM : where, <lang_country> corresponds to the lang_country
         @REM : where link is desired.
         @REM :------------------------------------------------------------

         if /i "%ISO_LG%_%ISO_COUNTRY%"=="EN_US" (
            @REM :---------------------------------------------------------
            @REM : Section 2.0
            @REM :---------------------------------------------------------
            set MyErrSec=2.0

            @REM : If non-existent, create the desktop links folder and copy the
            @REM : desktop links to it.

            if not exist %DTShortCutsFolder%\EN_US (
               set MyTryCmd=md %DTShortCutsFolder%\EN_US
                
               !MyTryCmd!
               if errorlevel 1 (
                  call :get_errorlevel
                  goto :error
                  )
               )

            echo Rhapsody icon should appear after first boot only if Lang_country is "en_US".

            @REM : Prepare for error reporting.
            set MyTryCmd=xcopy /y /i "%%l" "%DTShortCutsFolder%\EN_US"
            set MyErrLvl=
            set MyErrMsg=

            !MyTryCmd!
            if errorlevel 1 (
               call :get_errorlevel
               goto :xcopy_error
               )

            ) 

         @REM :------------------------------------------------------------
         @REM : Remove the potentially duplicate link from the desktop.  The
         @REM : build process will restore all desktop links from
         @REM : \hp\hpqware\dtshortcuts i.e., %DTShortCutsFolder% later at the 
         @REM : end of the build process.  

         @REM : Then only a single instance of this application's link
         @REM : should remain showing on the desktop.  This technique
         @REM : leveraged from Doug Jaccard.  
         @REM :------------------------------------------------------------

         @REM : Remember during debugging: Prior to first boot completion, the
         @REM : desktop icon will not appear.

         echo %BlockName%: Remove %%l from Desktop.  >> %LOG%\rhap.txt
         del /f /q "%%l"

      ) else (

         @REM :------------------------------------------------------------
         @REM : Section 2.2
         @REM :------------------------------------------------------------
         set MyErrSec=2.2

         echo %BlockName%: Recovery Mode.  >> %LOG%\rhap.txt

         if NOT "%ISO_LG%_%ISO_COUNTRY%"=="EN_US" (
            echo %BlockName%: Remove %%l from Desktop.  >> %LOG%\rhap.txt
            del /f /q "%%l"
         ) else (
            echo %BlockName%: Leave %%l on Desktop. >> %LOG%\rhap.txt
           )

         )

      )

   )

goto :EOF



@REM :---------------------------------------------------------------------
@REM :   JGT Error Processing Block Template
@REM :---------------------------------------------------------------------
@REM : The %ERRORLEVEL% environment variable is not very persistent.
@REM : Therefore this inefficient but simple routine saves the %ERRORLEVEL%
@REM : in MyErrLvl.
@REM : Note: In order to have this routine function properly, MyErrLvl
@REM : must not be defined upon calling this routine.
@REM :---------------------------------------------------------------------
:get_errorlevel
@for /L %%i in ( 255, -1, 0 ) do @(
   if errorlevel %%i (
      if not defined MyErrLvl set MyErrLvl=%%i
	   )
   )

exit /b %MyErrLvl%


@REM :---------------------------------------------------------------------
@REM : Block Template:
@REM : Translate errorlevel to a reason in text for the xcopy failure.
@REM :---------------------------------------------------------------------
:xcopy_error
set MyErrMsg=

if %MyErrLvl% EQU 5 (
   set MyErrMsg=xcopy errorlevel 5: Disk write error occurred.
   )

if %MyErrLvl% EQU 4 (
   set MyErrMsg=xcopy errorlevel 4: Insufficient memory or disk space, invalid drive name, or invalid syntax on command line.
   )

@REM : There is no error text associated with errorlevel 3.

if %MyErrLvl% EQU 2 (
   set MyErrMsg=xcopy errorlevel 2: The user pressed CTRL+C to terminate xcopy.
   )

if %MyErrLvl% EQU 1 (
   set MyErrMsg=xcopy errorlevel 1: No files were found to copy.
   )

@REM : If we don't know the error decode, log what little we do know.
if "%MyErrMsg%"=="" (
   set MyErrMsg= xcopy: ErrorLevel=%MyErrLvl%, Unknown error.
   )


@REM :---------------------------------------------------------------------
@REM : Block Template:
@REM : Log error to error.txt file.
@REM : Note: Build tools will use the existence of \blocks\error.txt as
@REM :   an indicator that an error occurred and stop the build.  The build
@REM :   tools append the error text to "\hp\support\finis_it.txt" and/or
@REM :   "\hp\support\mlerr.txt".
@REM :---------------------------------------------------------------------
:error
@if exist \blocks\allblocks (
                       echo %BlockName%: %date% %time% - Error detected by install.cmd, section %MyErrSec% >> \blocks\error.txt
   if defined MyTryCmd echo %BlockName%: CMD=%MyTryCmd% >> \blocks\error.txt
                       echo %BlockName%: ERR=%MyErrMsg% >> \blocks\error.txt
) else (
                       echo %BlockName%: %date% %time% - Error detected by install.cmd, section %MyErrSec% >> \hp\support\error.txt
   if defined MyTryCmd echo %BlockName%: CMD=%MyTryCmd% >> \hp\support\error.txt
                       echo %BlockName%: ERR=%MyErrMsg% >> \hp\support\error.txt
   )

                    echo %BlockName%: %date% %time% - Error detected by install.cmd, section %MyErrSec% >> %LOG%\rhap.txt
if defined MyTryCmd echo %BlockName%: CMD=%MyTryCmd% >> %LOG%\rhap.txt
                    echo %BlockName%: ERR=%MyErrMsg% >> %LOG%\rhap.txt


:EOF
echo %BlockName%: %date% %time% - End.
endlocal

set MyAuditModeFlag=
set BlockName=
set DTLink=
set DTShortCutsFolder=
set MyDir0=
set MyErrLvl=
set MyErrMsg=
set MyErrSec=
set MySetup=
set MySrcDir=
set MySrcDir0=
set MyTryCmd=


exit
