@echo off
:-----------------------------------------------------------------------
: NLS Catgets Wrapper
:-----------------------------------------------------------------------
if not exist %ODBASE%\locale\%LANG%\%0.bat set LANG=en_US
set catgets=call %ODBASE%\locale\%lang%\%0.bat
if not exist %ODBASE%\locale\%LANG%\%0.bat set catgets=echo
:-----------------------------------------------------------------------



:-----------------------------------------------------------------------
: ODDESK Command
:-----------------------------------------------------------------------
: @(#)Z 1.24 nt/src/tools/oddesk.bat, odtools, od96nt, odnt9712d 97/03/21 17:39:59 (97/02/27 13:14:26)
:
: NT and OS2 batch file to rebuild ODCFG and ODPARTS
:-----------------------------------------------------------------------

if "%OS%x" == "Windows_NTx" goto PlatformNT
call odsetenv.bat
:PlatformNT

:-----------------------------------------------------------------------
: I need to generate a temporary empty directory for xcopy
: I'll remove it later.
:-----------------------------------------------------------------------
if %TMP%x == "x" set TMP=%ODBASE%
set MY_TMP_DIR=%TMP%\x-desk-x.tmp
set MY_TMP_SUB=w9x6y3z.tmp
set MY_TMP_DIR_DIR=%TMP%\x-desk-x.tmp\%MY_TMP_SUB%

%catgets% ODDESK_Start "OpenDoc DeskTop Reconstruction Facility"

:Step1
:-----------------------------------------------------------------------
:
: Make sure environment is set up by testing for ODCFG, ODPARTS,
: ODBASE, SOMBASE, and NLSPATH. If they are not set then report error
: and terminate.
:
:-----------------------------------------------------------------------

%catgets% ODVARS_Check "o Checking for OD environment variables..."
if "%ODBASE%x"  == "x" goto AbortNoEnv
if "%ODCFG%x"   == "x" goto AbortNoEnv
if "%ODPARTS%x" == "x" goto AbortNoEnv
if "%SOMBASE%x" == "x" goto AbortNoEnv
if "%NLSPATH%x" == "x" goto AbortNoEnv
if "%LANG%x"    == "x" goto AbortNoEnv
%catgets% ODVARS_Found "Found it."

:Step2
:-----------------------------------------------------------------------
:
: Now make sure the ODBASE directory exists.
:
:-----------------------------------------------------------------------
%catgets% ODBASE_Check "o Checking for ODBASE directory..."
if not exist %ODBASE%\nul goto AbortNoBase
echo   Found it.
%catgets% ODBASE_Found "Found it."

:Step3
:-----------------------------------------------------------------------
:
: Now make sure %ODBASE%\bin\odinst.exe exists.
:
:-----------------------------------------------------------------------
%catgets% ODINST_Check "o Checking for editor installer (odinst.exe)..."
set ODINST=%ODBASE%\bin\odinst.exe
if not exist %ODINST% goto AbortNoODInst
%catgets% ODINST_Found  "Found it."

:Step4
:-----------------------------------------------------------------------
:
: Now create the directories...
: The call to xcopy doesn't actually copy any files, just creates
: the directory. (See /T option.)
:
:-----------------------------------------------------------------------
%catgets% DIRS_Create "o Creating ODCFG and ODPARTS directories..."

if not exist %MY_TMP_DIR%\nul mkdir %MY_TMP_DIR% > \nul
if not exist %MY_TMP_DIR_DIR%\nul mkdir %MY_TMP_DIR_DIR% > \nul

set DIR=%ODCFG%\tmp
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODCFG%\work\docs
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODCFG%\work\plugins
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODCFG%\work\editors
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODCFG%\work\statry
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODPARTS%\bin
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODPARTS%\dll
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODPARTS%\lib
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODPARTS%\include
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODPARTS%\msg
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODPARTS%\doc
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODPARTS%\pkg
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODPARTS%\pkg\%LANG%
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODPARTS%\src
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODPARTS%\work\docs
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODPARTS%\work\plugins
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODPARTS%\work\editors
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

set DIR=%ODPARTS%\work\statry
if not exist %DIR%\nul xcopy /Q /E /I /T %MY_TMP_DIR% %DIR% > \nul
if not exist %DIR%\nul goto AbortInvalidDir
if exist %DIR%\%MY_TMP_SUB%\nul rmdir %DIR%\%MY_TMP_SUB% > \nul

%catgets% DIRS_Complete  "Done."

:-----------------------------------------------------------------------
:
: If the platform is Windows95 then we need to move some
: dlls.
:
:-----------------------------------------------------------------------
if "%OS%x" == "Windows_NTx" goto SkipDllCopy
if exist %ODBASE%\bin\som.dll     copy %ODBASE%\bin\som.dll %ODBASE%\dll > \nul
if exist %ODBASE%\bin\som.dll     del  %ODBASE%\bin\som.dll > \nul
if exist %ODBASE%\bin\somct.dll   copy %ODBASE%\bin\somct.dll %ODBASE%\dll > \nul
if exist %ODBASE%\bin\somct.dll   del  %ODBASE%\bin\somct.dll > \nul
if exist %ODBASE%\bin\somd.dll    copy %ODBASE%\bin\somd.dll %ODBASE%\dll > \nul
if exist %ODBASE%\bin\somd.dll    del  %ODBASE%\bin\somd.dll > \nul
if exist %ODBASE%\bin\somdbg.dll  copy %ODBASE%\bin\somdbg.dll %ODBASE%\dll > \nul
if exist %ODBASE%\bin\somdbg.dll  del  %ODBASE%\bin\somdbg.dll > \nul
if exist %ODBASE%\bin\somem.dll   copy %ODBASE%\bin\somem.dll %ODBASE%\dll > \nul
if exist %ODBASE%\bin\somem.dll   del  %ODBASE%\bin\somem.dll > \nul
if exist %ODBASE%\bin\somir.dll   copy %ODBASE%\bin\somir.dll %ODBASE%\dll > \nul
if exist %ODBASE%\bin\somir.dll   del  %ODBASE%\bin\somir.dll > \nul
if exist %ODBASE%\bin\soms.dll    copy %ODBASE%\bin\soms.dll %ODBASE%\dll > \nul
if exist %ODBASE%\bin\soms.dll    del  %ODBASE%\bin\soms.dll > \nul
if exist %ODBASE%\bin\somtc.dll   copy %ODBASE%\bin\somtc.dll %ODBASE%\dll > \nul
if exist %ODBASE%\bin\somtc.dll   del  %ODBASE%\bin\somtc.dll > \nul
if exist %ODBASE%\bin\somu.dll    copy %ODBASE%\bin\somu.dll %ODBASE%\dll > \nul
if exist %ODBASE%\bin\somu.dll    del  %ODBASE%\bin\somu.dll > \nul
if exist %ODBASE%\bin\somc.dll    copy %ODBASE%\bin\somc.dll %ODBASE%\dll > \nul
if exist %ODBASE%\bin\somc.dll    del  %ODBASE%\bin\somc.dll > \nul
if exist %ODBASE%\bin\some.dll    copy %ODBASE%\bin\some.dll %ODBASE%\dll > \nul
if exist %ODBASE%\bin\some.dll    del  %ODBASE%\bin\some.dll > \nul

if exist %ODBASE%\dll\oddsevnt.dll copy %ODBASE%\dll\oddsevnt.dll %ODPARTS%\dll > \nul
if exist %ODBASE%\dll\oddslsi.dll  copy %ODBASE%\dll\oddslsi.dll %ODPARTS%\dll > \nul
if exist %ODBASE%\dll\oddslsid.dll copy %ODBASE%\dll\oddslsid.dll %ODPARTS%\dll > \nul
if exist %ODBASE%\dll\oddsole.dll  copy %ODBASE%\dll\oddsole.dll %ODPARTS%\dll > \nul
if exist %ODBASE%\dll\oddsres.dll  copy %ODBASE%\dll\oddsres.dll %ODPARTS%\dll > \nul
if exist %ODBASE%\dll\oddsscr.dll  copy %ODBASE%\dll\oddsscr.dll %ODPARTS%\dll > \nul
if exist %ODBASE%\dll\oddssir.dll  copy %ODBASE%\dll\oddssir.dll %ODPARTS%\dll > \nul

if exist %ODBASE%\dll\odres.dll    copy %ODBASE%\dll\odres.dll %ODPARTS%\dll > \nul
:SkipDllCopy

:Step5
:-----------------------------------------------------------------------
:
: Install the shipped part editors
: Note: BaseContainer and SimplePart should be installed before
: the rest.
:
: If the NLS version of a part editor is available then the
: EN_US version will be installed.
:
:-----------------------------------------------------------------------
%catgets% PE_Install "o Installing part editors. This will take a few moments..."

REM Force registration of OlePart.
set ODREGPRT=%odbase%\bin\odregprt
set SC=%SOMBASE%\bin\sc.exe
%catgets% OLEPART_Install "...Registering OlePart"
%SC% -sir -u -mnolock -ESOMIR="%ODCFG%\opendoc.ir" -p -c -I. -I%SOMBASE%\include -D_PLATFORM_WIN32_ -D_PLATFORM_NT_ -I%ODBASE%\include -I%ODBASE%\samples\include %odbase%\include\olepart.idl

%ODREGPRT% OlePart > \nul
if errorlevel 1 goto AbortOlePartFailed

set PKGLANG=%ODBASE%\pkg\%LANG%
set PKGENUS=%ODBASE%\pkg\en_US

:pkg1
set PE=iodbasec.odz
set PKG=%PKGLANG%\%PE%
if not exist %PKG% set PKG=%PKGENUS%\%PE%
if not exist %PKG% %catgets% PKG_Warning "* Warning! Part editor package %PKG% was not found."
if exist %PKG%     %catgets% PKG_Install "...Installing %PKG%."
if exist %PKG% start /w %ODINST% -q %PKG% > \nul

:pkg2
set PE=iodsimpl.odz
set PKG=%PKGLANG%\%PE%
if not exist %PKG% set PKG=%PKGENUS%\%PE%
if not exist %PKG% %catgets% PKG_Warning "* Warning! Part editor package %PKG% was not found."
if exist %PKG%     %catgets% PKG_Install "...Installing %PKG%."
if exist %PKG% start /w %ODINST% -q %PKG% > \nul

:pkg3
set PE=iodshape.odz
set PKG=%PKGLANG%\%PE%
if not exist %PKG% set PKG=%PKGENUS%\%PE%
if not exist %PKG% %catgets% PKG_Warning "* Warning! Part editor package %PKG% was not found."
if exist %PKG%     %catgets% PKG_Install "...Installing %PKG%."
if exist %PKG% start /w %ODINST% -q %PKG% > \nul

:pkg4
set PE=iodlinkc.odz
set PKG=%PKGLANG%\%PE%
if not exist %PKG% set PKG=%PKGENUS%\%PE%
if not exist %PKG% %catgets% PKG_Warning "* Warning! Part editor package %PKG% was not found."
if exist %PKG%     %catgets% PKG_Install "...Installing %PKG%."
if exist %PKG% start /w %ODINST% -q %PKG% > \nul

:pkg5
set PE=iodtext.odz
set PKG=%PKGLANG%\%PE%
if not exist %PKG% set PKG=%PKGENUS%\%PE%
if not exist %PKG% %catgets% PKG_Warning "* Warning! Part editor package %PKG% was not found."
if exist %PKG%     %catgets% PKG_Install "...Installing %PKG%."
if exist %PKG% start /w %ODINST% -q %PKG% > \nul

:pkg6
set PE=iodscrgp.odz
set PKG=%PKGLANG%\%PE%
if not exist %PKG% set PKG=%PKGENUS%\%PE%
if not exist %PKG% %catgets% PKG_Warning "* Warning! Part editor package %PKG% was not found."
if exist %PKG%     %catgets% PKG_Install "...Installing %PKG%."
if exist %PKG% start /w %ODINST% -q %PKG% > \nul

:pkg7
set PE=iodtimer.odz
set PKG=%PKGLANG%\%PE%
if not exist %PKG% set PKG=%PKGENUS%\%PE%
if not exist %PKG% %catgets% PKG_Warning "* Warning! Part editor package %PKG% was not found."
if exist %PKG%     %catgets% PKG_Install "...Installing %PKG%."
if exist %PKG% start /w %ODINST% -q %PKG% > \nul


:Step6
:-----------------------------------------------------------------------
:
: Register Lotus Script component
:
:-----------------------------------------------------------------------
%catgets% LOTUS_Install  "o Registering Lotus Script component..."
if not exist %ODBASE%\bin\cmgrcmd.exe goto AbortNoCMGRCMD
%ODBASE%\bin\cmgrcmd -s ODDS LSCR > \nul
if NOT errorlevel 1 goto SkipCompIsRegistered
%ODBASE%\bin\cmgrcmd -r ODDS LSCR 0x0F ODLotusScriptComponent oddslsi.dll 0x10001 IBM "Lotus Script Component"
:SkipCompIsRegistered
%catgets% LOTUS_Complete   "Done."

:-----------------------------------------------------------------------
:
: End of Program
:
:-----------------------------------------------------------------------
goto Done


:-----------------------------------------------------------------------
:
: Routines to display error messages
:
:-----------------------------------------------------------------------

:AbortNoEnv
   %catgets% AbortNoEnv "OpenDoc environment not setup."
   echo * ODBASE  = "%ODBASE%"
   echo * ODCFG   = "%ODCFG%"
   echo * ODPARTS = "%ODPARTS%"
   echo * SOMBASE = "%SOMBASE%"
   echo * NLSPATH = "%NLSPATH%"
   echo * LANG    = "%LANG%"
   goto Done

:AbortNoBase
   %catgets% AbortNoBase "No %ODBASE% OpenDoc directory."
   goto Done

:AbortNoODInst
   %catgets% AbortNoODInst "Missing %ODBASE%\bin\ODINST.EXE (OpenDoc Part Installer)"
   goto Done

:AbortInvalidDir
   %catgets% AbortInvalidDir "Creation of directory  %DIR% failed."
   goto Done

:AbortNoCMGRCMD
   %catgets% AbortNoCMGCMD "Missing %ODBASE%\bin\cmgrcmd.exe (Lotus Script registration)
   goto Done

:AbortOlePartFailed
   %catgets% OlePart_Failed "* Install of OlePart failed."
   echo * SOMIR = "%somir%"
   goto Done

:AbortODInstFailed
   %catgets% ODINST_Failed "* Install of part %PKG% failed."
   goto Done


:Done

:-----------------------------------------------------------------------
:
: Clean up!
:
:-----------------------------------------------------------------------

if exist %MY_TMP_DIR_DIR%\nul rmdir %MY_TMP_DIR_DIR% > \nul
if exist %MY_TMP_DIR%\nul rmdir %MY_TMP_DIR% > \nul

%catgets% ODDESK_Finish "...End of ODDESK Command..."

if NOT "%OS%x" == "Windows_NTx" goto SkipPause
pause
:SkipPause
