PCRE|http://superb-west.dl.sourceforge.net/sourceforge/pcre/pcre-6.3.tar.bz2
 PTHREADS|ftp://sources.redhat.com/pub/pthreads-win32/pthreads-snap-2004-06-22.tar.gz
 OPENSSL|http://www.openssl.org/source/openssl-0.9.8b.tar.gz
-MYSQL|http://mirror.x10.com/mirror/mysql/Downloads/MySQL-5.0/mysql-noinstall-5.0.22-win32.zip|mysql-5.0.22-win32
+MYSQL|http://mirror.x10.com/mirror/mysql/Downloads/MySQL-5.0/mysql-noinstall-5.0.27-win32.zip|mysql-5.0.27-win32
 POSTGRESQL|ftp://ftp2.us.postgresql.org/postgresql/source/v8.1.4/postgresql-base-8.1.4.tar.bz2|postgresql-8.1.4
 SQLITE|http://www.sqlite.org/sqlite-3.3.8.tar.gz
-WX|http://superb-west.dl.sourceforge.net/sourceforge/wxwindows/wxWidgets-2.6.3.tar.gz
+WX|http://superb-west.dl.sourceforge.net/sourceforge/wxwindows/wxWidgets-2.7.0.tar.gz
 SCONS|http://superb-west.dl.sourceforge.net/sourceforge/scons/scons-0.96.92.tar.gz
 NSIS_BIN|http://superb-west.dl.sourceforge.net/sourceforge/nsis/nsis-2.17.zip
 NSIS_SRC|http://superb-west.dl.sourceforge.net/sourceforge/nsis/nsis-2.17-src.tar.bz2
 MT|http://www.ibiblio.org/pub/linux/system/backup/mt-st-0.9b.tar.gz
 SED|ftp://mirrors.kernel.org/gnu/sed/sed-4.1.5.tar.gz
 STAB2CV|http://superb-west.dl.sourceforge.net/sourceforge/stab2cv/stab2cv-0.1.tar.bz2
+CMD_UTILS|http://superb-west.dl.sourceforge.net/sourceforge/cmd-utils/cmd-utils-0.1.tar.gz
+DVD_RW_TOOLS|http://fy.chalmers.se/~appro/linux/DVD+RW/tools/dvd+rw-tools-7.0.tar.gz
+#CDRTOOLS|ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-2.01.01a22.tar.bz2
+MKISOFS|http://fy.chalmers.se/~appro/linux/DVD+RW/tools/win32/mkisofs.exe
+DVD_RW_TOOLS|http://fy.chalmers.se/~appro/linux/DVD+RW/tools/dvd+rw-tools-7.0.tar.gz
 
 PCRE|http://superb-west.dl.sourceforge.net/sourceforge/pcre/pcre-6.3.tar.bz2
 PTHREADS|ftp://sources.redhat.com/pub/pthreads-win32/pthreads-2004-06-22x.exe|pthreads-2004-06-22x|true
 OPENSSL|http://www.openssl.org/source/openssl-0.9.8b.tar.gz
-MYSQL|http://mirror.x10.com/mirror/mysql/Downloads/MySQL-5.0/mysql-noinstall-5.0.22-win32.zip|mysql-5.0.22-win32
+MYSQL|http://mirror.x10.com/mirror/mysql/Downloads/MySQL-5.0/mysql-noinstall-5.0.27-win32.zip|mysql-5.0.27-win32
 POSTGRESQL|ftp://ftp2.us.postgresql.org/postgresql/binary/v8.1.4/win32/postgresql-8.1.4-1-binaries-no-installer.zip|pgsql
 POSTGRESQL_SRC|ftp://ftp4.us.postgresql.org/pub/postgresql/source/v8.1.4/postgresql-8.1.4.tar.bz2
+SQLITE|http://www.sqlite.org/sqlite-3.3.8.tar.gz
 WX|http://superb-west.dl.sourceforge.net/sourceforge/wxwindows/wxWidgets-2.7.0.zip
 NSIS_BIN|http://superb-west.dl.sourceforge.net/sourceforge/nsis/nsis-2.17.zip
 MTX|http://superb-west.dl.sourceforge.net/sourceforge/mtx/mtx-1.3.9.tar.gz
 MT|ftp://ftp.ibiblio.org/pub/linux/system/backup/mt-st-0.9b.tar.gz
 SED|ftp://mirrors.kernel.org/gnu/sed/sed-4.1.5.tar.gz
-SQLITE|http://www.sqlite.org/sqlite-3.3.8.tar.gz
+CMD_UTILS|http://superb-west.dl.sourceforge.net/sourceforge/cmd-utils/cmd-utils-0.1.tar.gz
+#CDRTOOLS|ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-2.01.01a22.tar.bz2
+MKISOFS|http://fy.chalmers.se/~appro/linux/DVD+RW/tools/win32/mkisofs.exe
+DVD_RW_TOOLS|http://fy.chalmers.se/~appro/linux/DVD+RW/tools/dvd+rw-tools-7.0.tar.gz
 
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{825DFFD0-4747-43CA-8326-529655E31935}"
        ProjectSection(SolutionItems) = preProject
                build-depkgs-mingw32 = build-depkgs-mingw32
+               build-depkgs-msvc.cmd = build-depkgs-msvc.cmd
                build-msvc.cmd = build-msvc.cmd
                build-win32-cross-tools = build-win32-cross-tools
                External-mingw32 = External-mingw32
+               External-msvc = External-msvc
                README.mingw32 = README.mingw32
                README.vc8 = README.vc8
                README.win32 = README.win32
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{40CADEE4-8D53-4157-AA36-B256F4934FC3}"
        ProjectSection(SolutionItems) = preProject
                scripts\disk-changer.cmd = scripts\disk-changer.cmd
+               scripts\dvd-handler.cmd = scripts\dvd-handler.cmd
                scripts\mtx-changer.cmd = scripts\mtx-changer.cmd
        EndProjectSection
 EndProject
 
         ARCHIVE=`basename ${URL}`
         
         case ${ARCHIVE} in
-        *.tar.gz)       ARCHIVER="tar xzf"; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.gz'`;;
-        *.tar.bz2)      ARCHIVER="tar xjf"; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.bz2'`;;
+        *.tar.gz)       ARCHIVER="tar xzf";    [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.gz'`;;
+        *.tar.bz2)      ARCHIVER="tar xjf";    [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.bz2'`;;
         *.zip)          ARCHIVER="unzip -q";   [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.zip'`;;
+        *.exe)          ARCHIVER="";           [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.zip'`;;
         *)              echo Unsupported archive type - $ARCHIVE; exit 1;;
         esac
         
                 fi
         fi
 
+        [ -z "${ARCHIVER}" ] && return 0
+
         if [ ! -e "${SRC_DIR}" -o "${CLOBBER_SOURCE}" = "true" ]
         then
                 rm -rf ${SRC_DIR}
-                [ "${MAKE_DIR}" = "true" ] && mkdir ${SRC_DIR} && cd ${SRC_DIR}
                 echo Extracting ${ARCHIVE}
-                ${ARCHIVER} ${ARCHIVE} 2>&1 > ${ARCHIVE}.log
-                cd ${SRC_DIR}
+                if [ "${MAKE_DIR}" = "true" ]
+                then
+                        mkdir ${SRC_DIR}
+                        cd ${SRC_DIR}
+                        ${ARCHIVER} ../${ARCHIVE} > ../${ARCHIVE}.log 2>&1
+                else
+                        ${ARCHIVER} ${ARCHIVE} > ${ARCHIVE}.log 2>&1
+                        cd ${SRC_DIR}
+                fi
                 return 0
         fi
 
                             --host=mingw32 \
                             --prefix=${DEPPKG_DIR} \
                             --enable-utf8 \
-                            --enable-unicode-properties 2>&1 >make.log
+                            --enable-unicode-properties >make.log 2>&1
         fi
         echo Building PCRE
         do_make Makefile PREFIX=${DEPPKG_DIR} all
                             shared zlib-dynamic \
                             threads \
                             --with-zlib-include=${DEPPKG_DIR}/include \
-                            mingw32 2>&1 > make.log
+                            mingw32 > make.log 2>&1
         fi
         echo Building openssl
         perl util/mkdef.pl 32 libeay no-static-engine >ms/libeay32.def
 
                 # We need a native version of zic to build the timezone tables.
                 echo Configuring postgreSQL to build native zic
-                ./configure 2>&1 > make.log
+                ./configure > make.log 2>&1
 
                 echo Building native zic
                 cd src/timezone
-                do_make Makefile 2>&1 >> make.log
+                do_make Makefile >> make.log 2>&1
                 cp zic ../..
                 cd ../..
-                do_make GNUmakefile distclean 2>&1 >> make.log
+                do_make GNUmakefile distclean >> make.log 2>&1
 
                 echo Configuring postgreSQL for MinGW32
 
                             --enable-thread-safety \
                             --prefix=${DEPPKG_DIR} \
                             --with-includes=${DEPPKG_DIR}/include:${DEPPKG_DIR}/include/pthreads \
-                            --with-libraries=${DEPPKG_DIR}/lib 2>&1 >> make.log
+                            --with-libraries=${DEPPKG_DIR}/lib >> make.log 2>&1
         fi
         echo Building postgreSQL
         ZIC=`pwd`/zic
         cp -p include/wx/generic/* ../../include/wx/generic 2>&1 | grep -v 'omitting directory'
         mkdir ../../include/wx/msw
         cp -p include/wx/msw/* ../../include/wx/msw 2>&1 | grep -v 'omitting directory'
+        mkdir ../../include/wx/msw/ole
+        cp -p include/wx/msw/ole/* ../../include/wx/msw/ole 2>&1 | grep -v 'omitting directory'
         cp -p lib/gcc_dll/*.dll ../../bin
         rm -rf ../../lib/wx_dll
         mkdir ../../lib/wx_dll
 {
         get_source "${URL_SCONS}" "${DIR_SCONS}" "${MKD_SCONS}"
         echo Installing scons
-        if python setup.py install --prefix=${DEPPKG_DIR}/scons 2>&1 > make.log
+        if python setup.py install --prefix=${DEPPKG_DIR}/scons > make.log 2>&1
         then
                 :
         else
                 echo Configuring sed
                 ./configure --host=mingw32 \
                             --prefix=${DEPPKG_DIR} \
-                            --disable-nls 2>&1 >make.log
+                            --disable-nls >make.log 2>&1
         fi
         echo Building sed
         do_make Makefile all
                 # do_patch stab2cv.patch
                 echo Configuring stab2cv
                 ./configure --prefix=${DEPPKG_DIR}/tools \
-                            2>&1 >make.log
+                            >make.log 2>&1
         fi
         echo Building stab2c
         do_make Makefile 
         do_make Makefile install
 }
 
+process_cmd_utils()
+{
+        if get_source "${URL_CMD_UTILS}" "${DIR_CMD_UTILS}" "${MKD_CMD_UTILS}"
+        then
+                # echo Patching cmd-utils
+                # >patch.log
+                # do_patch cmd-utils.patch
+                echo Configuring cmd-utils
+                ./configure --host=mingw32 \
+                            --prefix=${DEPPKG_DIR} \
+                            >make.log 2>&1
+        fi
+        echo Building cmd-utils
+        do_make Makefile 
+        echo Installing cmd-utils
+        do_make Makefile install
+}
+
+process_mkisofs()
+{
+        get_source "${URL_MKISOFS}" "${DIR_MKISOFS}" "${MKD_MKISOFS}"
+        echo Installing mkisofs
+        cp `basename ${URL_MKISOFS}` ${DEPPKG_DIR}/bin
+}
+
+process_dvd_rw_tools()
+{
+        if get_source "${URL_DVD_RW_TOOLS}" "${DIR_DVD_RW_TOOLS}" "${MKD_DVD_RW_TOOLS}"
+        then
+                echo Patching dvd+rw-tools
+                >patch.log
+                do_patch dvd+rw-tools.patch
+        fi
+        echo Building dvd+rw-tools
+       m4 -DOS=XMINGW32 Makefile.m4 | make -f - dvd+rw-tools >make.log 2>&1
+        echo Installing dvd+rw-tools
+       m4 -DOS=XMINGW32 Makefile.m4 | make -f - prefix=${DEPPKG_DIR} install >>make.log 2>&1
+}
+
 if [ "$#" -eq 0 ]
 then
         process_zlib
         process_mt
         process_sed
         process_stab2cv
+        process_cmd_utils
+        process_mkisofs
+        process_dvd_rw_tools
 else
         for dependency in "$@"
         do
 
 
 IF "%CLOBBER_SOURCE%"=="" SET CLOBBER_SOURCE=false
 
-FOR /F "eol=# delims=| tokens=1-4" %%I in ( External-msvc ) DO SET URL_%%I=%%J & SET DIR_%%I=%%K & SET MKD_%%I=%%L
+FOR /F "eol=# delims=| tokens=1-4" %%I in ( External-msvc ) DO SET URL_%%I=%%J& SET DIR_%%I=%%K& SET MKD_%%I=%%L
 
 SET CWD=%CD%
 FOR %%I IN ( %0 ) DO CD %%~dpI
 
 CD src
 
-COPY NUL parse_output.sed
+COPY NUL parse_output.sed >nul 2>&1
 REM ECHO /\\$/N >>parse_output.sed
 REM ECHO s/\\\n// >>parse_output.sed
 ECHO s/\t\+/ /g >>parse_output.sed
        CALL :process_mtx
        CALL :process_mt
        CALL :process_sed
+       CALL :process_cmd_utils
+       CALL :process_mkisofs
+       CALL :process_dvd_rw_tools
        GOTO :EOF
 
 :ProcessArgs
        SET BASENAME=
 
        IF NOT "%SRC_DIR%"=="" GOTO :get_source_make_src
-       FOR %%I IN ( %URL% ) DO (SET BASENAME=%%~nI & IF NOT "%%~xI"==".gz" IF NOT "%%~xI"==".bz2" SET SRC_DIR=%%~nI)
+       FOR %%I IN ( %URL% ) DO (SET BASENAME=%%~nI& IF NOT "%%~xI"==".gz" IF NOT "%%~xI"==".bz2" SET SRC_DIR=%%~nI)
        IF "%SRC_DIR%"=="" FOR %%I IN ( %BASENAME% ) DO SET SRC_DIR=%%~nI
 
 :get_source_make_src
        IF /I "%MAKE_SRC_ENABLE:~0,1%"=="t" SET MAKE_SRC_DIR=true
        IF /I "%MAKE_SRC_ENABLE:~0,1%"=="1" SET MAKE_SRC_DIR=true
 
-       FOR %%I IN ( %URL% ) DO SET ARCHIVE=%%~nxI
+       FOR %%I IN ( %URL% ) DO ( SET ARCHIVE=%%~nxI& SET ARCHIVE_EXT=%%~xI)
        
        CD %DEPPKG_DIR%\src
        
        EXIT /B 2
 
 :get_source_check_srcdir
+       IF /I "%ARCHIVE_EXT%"==".exe" EXIT /B 0
        IF NOT EXIST %SRC_DIR%\nul GOTO :get_source_extract
        IF NOT "%CLOBBER_SOURCE%"=="true" GOTO :get_source_skipped
-       IF EXIST "%SRC_DIR%\nul" RD /s /q "%SRC_DIR%"
+       IF EXIST %SRC_DIR%\nul RD /s /q "%SRC_DIR%"
 :get_source_extract
+       IF /I "%ARCHIVE_EXT%"==".exe" EXIT /B 0
        SET TAR_ARCHIVE=
        FOR %%I IN ( "%ARCHIVE%" ) do IF "%%~xI"==".gz" SET TAR_ARCHIVE=%%~nI
        FOR %%I IN ( "%ARCHIVE%" ) do IF "%%~xI"==".bz2" SET TAR_ARCHIVE=%%~nI
 
        SET TARGET_DIR=.
-       IF DEFINED MAKE_SRC_DIR IF NOT EXIST "%SRC_DIR%\nul" MKDIR %SRC_DIR%
+       IF DEFINED MAKE_SRC_DIR IF NOT EXIST %SRC_DIR%\nul MKDIR %SRC_DIR%
        IF DEFINED MAKE_SRC_DIR SET TARGET_DIR=%SRC_DIR%
 
        ECHO Extracting %ARCHIVE%
        ECHO Unable to download sed source from %URL_MT%
        EXIT /B 1
 
+:process_cmd_utils
+       CALL :get_source %URL_CMD_UTILS% %DIR_CMD_UTILS% %MKD_CMD_UTILS%
+       IF ERRORLEVEL 2 GOTO :cmd_utils_error
+       IF ERRORLEVEL 1 GOTO :cmd_utils_skip_patch
+REM    ECHO Patching cmd-utils
+REM    COPY /Y nul patch.log
+REM    CALL :do_patch cmd_utils_msc.patch
+:cmd_utils_skip_patch
+       ECHO Building cmd-utils
+       vcbuild /nologo cmd-utils.sln "Release|WIN32" 2>&1 | tee -a make.log | sed -nf "%DEPPKG_DIR%\src\parse_output.sed"
+       IF ERRORLEVEL 1 GOTO :cmd_utils_build_error
+       ECHO Installing cmd-utils
+       XCOPY Release\*.exe %DEPPKG_DIR%\bin
+       EXIT /B 0
+:cmd_utils_build_error
+       ECHO Make failed - Check %CD%\make.log > con
+       EXIT /B 1
+:cmd_utils_error
+       ECHO Unable to download cmd-utils source from %URL_MT%
+       EXIT /B 1
+
+:process_mkisofs
+       CALL :get_source %URL_MKISOFS% %DIR_MKISOFS% %MKD_MKISOFS%
+       IF ERRORLEVEL 2 GOTO :mkisofs_error
+       ECHO Installing mkisofs
+       FOR %%i IN ( %URL_MKISOFS% ) DO XCOPY %DEPPKG_DIR%\src\%%~nxi %DEPPKG_DIR%\bin /Y /Q >nul 2>&1
+       EXIT /B 0
+:mkisofs_error
+       ECHO Unable to download mkisofs source from %URL_MKISOFS%
+       EXIT /B 1
+
+:process_dvd_rw_tools
+       CALL :get_source %URL_DVD_RW_TOOLS% %DIR_DVD_RW_TOOLS% %MKD_DVD_RW_TOOLS%
+       IF ERRORLEVEL 2 GOTO :dvd_rw_tools_error
+       IF ERRORLEVEL 1 GOTO :dvd_rw_tools_skip_patch
+       ECHO Patching dvd+rw-tools
+       COPY /Y nul patch.log
+       CALL :do_patch dvd+rw-tools.patch
+:dvd_rw_tools_skip_patch
+       ECHO Building dvd+rw-tools
+       IF NOT EXIST Release\nul MKDIR Release
+       CALL :do_nmake Makefile.msc dvd+rw-tools
+       ECHO Installing dvd+rw-tools
+       CALL :do_nmake Makefile.msc prefix=%DEPPKG_DIR% install
+       EXIT /B 0
+:dvd_rw_tools_error
+       ECHO Unable to download dvd+rw-tools source from %URL_DVD_RW_TOOLS%
+       EXIT /B 1
+
 :do_patch
        SET PATCH_FILE=%SCRIPT_DIR%\patches\%1
        SHIFT
 
 :do_nmake
        nmake /nologo -f %* 2>&1 | tee -a make.log | sed -nf "%DEPPKG_DIR%\src\parse_output.sed"
-       IF NOT ERRORLEVEL 1 EXIT/B 0
+       IF NOT ERRORLEVEL 1 EXIT /B 0
        ECHO Make failed - Check %CD%\make.log > con
        EXIT /B 1
 
 
+++ /dev/null
-rem !/bin/sh\r
-rem \r
-rem  shell script to grant privileges to the bdb database\r
-rem \r
-rem  nothing to do here\r
 
        scsitape.exe \
        sed.exe \
        tapeinfo.exe \
-       wxbase26_gcc_bacula.dll \
-       wxmsw26_core_gcc_bacula.dll
+       expr64.exe \
+       snooze.exe \
+       mkisofs.exe \
+       growisofs.exe \
+       dvd-ram-control.exe \
+       dvd+rw-booktype.exe \
+       dvd+rw-format.exe \
+       dvd+rw-mediainfo.exe \
+       wxbase270_gcc_bacula.dll \
+       wxmsw270_core_gcc_bacula.dll
 
 NONGCC_BINARIES := \
        libmysql.dll
        mingwm10.dll
 
 SCRIPT_FILES := \
-       mtx-changer.cmd
+       mtx-changer.cmd \
+       disk-changer.cmd \
+       dvd-handler.cmd
 
 CAT_FILES := \
        create_mysql_database.cmd \
        create_sqlite3_database.cmd \
        drop_sqlite3_database.cmd \
        make_sqlite3_tables.cmd \
+       make_sqlite3_tables.sql \
        drop_sqlite3_tables.cmd \
        grant_sqlite3_privileges.cmd \
        make_sqlite3_catalog_backup.cmd \
 
 SET BACULA_TOOLS=bcopy.exe bextract.exe bls.exe bscan.exe bsleep.exe bsmtp.exe btape.exe dbcheck.exe scsilist.exe
 
 SET DEP_DLLS=libeay32.dll pthreadVCE.dll ssleay32.dll zlib1.dll zlib1.dll.manifest wxbase270_vc_bacula.dll wxmsw270_core_vc_bacula.dll libmysql.dll libpq.dll comerr32.dll libintl-2.dll libiconv-2.dll krb5_32.dll
-SET DEP_EXES=openssl.exe loaderinfo.exe mt.exe mtx.exe scsitape.exe sed.exe tapeinfo.exe sqlite3.exe sqlite3.exe.manifest
+SET DEP_EXES=openssl.exe loaderinfo.exe mt.exe mtx.exe scsitape.exe sed.exe tapeinfo.exe sqlite3.exe sqlite3.exe.manifest expr64.exe snooze.exe mkisofs.exe growisofs.exe dvd-ram-control.exe dvd+rw-booktype.exe dvd+rw-format.exe dvd+rw-mediainfo.exe
+
+SET SCRIPTS=mtx-changer.cmd disk-changer.cmd dvd-handler.cmd
 
-SET SCRIPTS=mtx-changer.cmd 
 SET CATS_MYSQL_CMD=create_mysql_database.cmd drop_mysql_database.cmd make_mysql_tables.cmd drop_mysql_tables.cmd grant_mysql_privileges.cmd
 SET CATS_MYSQL_SQL=make_mysql_tables.sql drop_mysql_tables.sql grant_mysql_privileges.sql
 SET CATS_PGSQL_CMD=create_postgresql_database.cmd drop_postgresql_database.cmd make_postgresql_tables.cmd drop_postgresql_tables.cmd grant_postgresql_privileges.cmd
 SET DOC_PDF_FILES=%DOCS_DIR%\bacula.pdf %DOCS_DIR%\bacula\*.html %DOCS_DIR%\bacula\*.png %DOCS_DIR%\bacula\*.css
 SET DOC_HTML_FILES=%DOCS_DIR%\bacula\*.html %DOCS_DIR%\bacula\*.png %DOCS_DIR%\bacula\*.css
 
-FOR %%i in ( %BACULA_DLLS% )     DO COPY %1%2\%%i %1installer\%2
-FOR %%i in ( %BACULA_EXES% )     DO COPY %1%2\%%i %1installer\%2
-FOR %%i in ( %BACULA_TOOLS% )    DO COPY %1%2\%%i %1installer\%2
+FOR %%i in ( %BACULA_DLLS% )     DO XCOPY %1%2\%%i %1installer\%2\ /y
+FOR %%i in ( %BACULA_EXES% )     DO XCOPY %1%2\%%i %1installer\%2\ /y
+FOR %%i in ( %BACULA_TOOLS% )    DO XCOPY %1%2\%%i %1installer\%2\ /y
 
-FOR %%i in ( %DEP_DLLS% )        DO COPY %DEPKG_DIR%\bin\%%i %1installer\%2
-FOR %%i in ( %DEP_EXES% )        DO COPY %DEPKG_DIR%\bin\%%i %1installer\%2
+FOR %%i in ( %DEP_DLLS% )        DO XCOPY %DEPKG_DIR%\bin\%%i %1installer\%2\ /y
+FOR %%i in ( %DEP_EXES% )        DO XCOPY %DEPKG_DIR%\bin\%%i %1installer\%2\ /y
 
-FOR %%i in ( %SCRIPTS% )         DO COPY %1scripts\%%i %1installer\%2
-FOR %%i in ( %CATS_MYSQL_CMD% )  DO COPY %1cats\%%i %1installer\%2
-FOR %%i in ( %CATS_MYSQL_SQL% )  DO COPY %1cats\%%i %1installer\%2
-FOR %%i in ( %CATS_PGSQL_CMD% )  DO COPY %1cats\%%i %1installer\%2
-FOR %%i in ( %CATS_PGSQL_SQL% )  DO COPY %1cats\%%i %1installer\%2
-FOR %%i in ( %CATS_SQLITE_CMD% ) DO COPY %1cats\%%i %1installer\%2
-FOR %%i in ( %CATS_SQLITE_SQL% ) DO COPY %1cats\%%i %1installer\%2
+FOR %%i in ( %SCRIPTS% )         DO XCOPY %1scripts\%%i %1installer\%2\ /y
+FOR %%i in ( %CATS_MYSQL_CMD% )  DO XCOPY %1cats\%%i %1installer\%2\ /y
+FOR %%i in ( %CATS_MYSQL_SQL% )  DO XCOPY %1cats\%%i %1installer\%2\ /y
+FOR %%i in ( %CATS_PGSQL_CMD% )  DO XCOPY %1cats\%%i %1installer\%2\ /y
+FOR %%i in ( %CATS_PGSQL_SQL% )  DO XCOPY %1cats\%%i %1installer\%2\ /y
+FOR %%i in ( %CATS_SQLITE_CMD% ) DO XCOPY %1cats\%%i %1installer\%2\ /y
+FOR %%i in ( %CATS_SQLITE_SQL% ) DO XCOPY %1cats\%%i %1installer\%2\ /y
 
-FOR %%i in ( %CATS_CATALOG% )    DO COPY %1cats\%%i %1installer\%2
+FOR %%i in ( %CATS_CATALOG% )    DO XCOPY %1cats\%%i %1installer\%2\ /y
 
-FOR %%i in ( %DIRD_FILES% )      DO COPY %1..\dird\%%i %1installer\%2
-FOR %%i in ( %SSL_FILES% )       DO COPY %DEPKG_DIR%\%%i %1installer\%2
+FOR %%i in ( %DIRD_FILES% )      DO XCOPY %1..\dird\%%i %1installer\%2\ /y
+FOR %%i in ( %SSL_FILES% )       DO XCOPY %DEPKG_DIR%\%%i %1installer\%2\ /y
 
-IF NOT EXIST %1installer\%2\manual MKDIR %1installer\%2\manual
-FOR %%i in ( %DOC_PDF_FILES% )   DO COPY %%i %1installer\%2\manual
+FOR %%i in ( %DOC_PDF_FILES% )   DO XCOPY %%i %1installer\%2\manual\ /y
 
-IF NOT EXIST %1installer\%2\manual\bacula MKDIR %1installer\%2\manual\bacula
-FOR %%i in ( %DOC_HTML_FILES% )  DO COPY %%i %1installer\%2\manual\bacula
+FOR %%i in ( %DOC_HTML_FILES% )  DO XCOPY %%i %1installer\%2\manual\bacula\ /y
 
-COPY %4\x86\Microsoft.VC80.CRT\msvcm80.dll %1installer\%2
-COPY %4\x86\Microsoft.VC80.CRT\msvcp80.dll %1installer\%2
-COPY %4\x86\Microsoft.VC80.CRT\msvcr80.dll %1installer\%2
-COPY %4\x86\Microsoft.VC80.CRT\Microsoft.VC80.CRT.manifest %1installer\%2
-COPY %4\Debug_NonRedist\x86\Microsoft.VC80.DebugCRT\msvcm80d.dll %1installer\%2
-COPY %4\Debug_NonRedist\x86\Microsoft.VC80.DebugCRT\msvcp80d.dll %1installer\%2
-COPY %4\Debug_NonRedist\x86\Microsoft.VC80.DebugCRT\msvcr80d.dll %1installer\%2
-COPY %4\Debug_NonRedist\x86\Microsoft.VC80.DebugCRT\Microsoft.VC80.DebugCRT.manifest %1installer\%2
+XCOPY %4\x86\Microsoft.VC80.CRT\msvcm80.dll %1installer\%2\ /y
+XCOPY %4\x86\Microsoft.VC80.CRT\msvcp80.dll %1installer\%2\ /y
+XCOPY %4\x86\Microsoft.VC80.CRT\msvcr80.dll %1installer\%2\ /y
+XCOPY %4\x86\Microsoft.VC80.CRT\Microsoft.VC80.CRT.manifest %1installer\%2\ /y
+XCOPY %4\Debug_NonRedist\x86\Microsoft.VC80.DebugCRT\msvcm80d.dll %1installer\%2\ /y
+XCOPY %4\Debug_NonRedist\x86\Microsoft.VC80.DebugCRT\msvcp80d.dll %1installer\%2\ /y
+XCOPY %4\Debug_NonRedist\x86\Microsoft.VC80.DebugCRT\msvcr80d.dll %1installer\%2\ /y
+XCOPY %4\Debug_NonRedist\x86\Microsoft.VC80.DebugCRT\Microsoft.VC80.DebugCRT.manifest %1installer\%2\ /y
 
 PATH %DEPKG_DIR%\nsis;%DEPKG_DIR%\tools;%PATH%
 
 
     File "${SRC_DIR}\bsleep.exe"
     File "${SRC_DIR}\bsmtp.exe"
     File "${SRC_DIR}\bacula.dll"
+    File "${SRC_DIR}\expr64.exe"
+    File "${SRC_DIR}\snooze.exe"
 
     CreateShortCut "$SMPROGRAMS\Bacula\Documentation\View Readme.lnk" "write.exe" '"$INSTDIR\Readme.txt"'
 
   File "${SRC_DIR}\bscan.exe"
   File "${SRC_DIR}\btape.exe"
   File "${SRC_DIR}\scsilist.exe"
+  File "${SRC_DIR}\mkisofs.exe"
+  File "${SRC_DIR}\growisofs.exe"
+  File "${SRC_DIR}\dvd-ram-control.exe"
+  File "${SRC_DIR}\dvd+rw-booktype.exe"
+  File "${SRC_DIR}\dvd+rw-format.exe"
+  File "${SRC_DIR}\dvd+rw-mediainfo.exe"
 
   File "/oname=$PLUGINSDIR\mtx-changer.cmd" "${SRC_DIR}\mtx-changer.cmd"
 
   StrCpy $1 mtx-changer.cmd
   Call ConfigEditAndCopy
 
+  File "/oname=$PLUGINSDIR\disk-changer.cmd" "${SRC_DIR}\disk-changer.cmd"
+
+  StrCpy $0 "$INSTDIR\bin"
+  StrCpy $1 disk-changer.cmd
+  Call ConfigEditAndCopy
+
+  File "/oname=$PLUGINSDIR\dvd-handler.cmd" "${SRC_DIR}\dvd-handler.cmd"
+
+  StrCpy $0 "$INSTDIR\bin"
+  StrCpy $1 dvd-handler.cmd
+  Call ConfigEditAndCopy
+
   File "/oname=$PLUGINSDIR\bacula-sd.conf" "bacula-sd.conf.in"
 
   StrCpy $0 "$APPDATA\Bacula"
     File /oname=$PLUGINSDIR\create_database.cmd ${SRC_DIR}\create_sqlite3_database.cmd
     File /oname=$PLUGINSDIR\drop_database.cmd ${SRC_DIR}\drop_sqlite3_database.cmd
     File /oname=$PLUGINSDIR\make_tables.cmd ${SRC_DIR}\make_sqlite3_tables.cmd
+    File ${SRC_DIR}\make_sqlite3_tables.sql
     File /oname=$PLUGINSDIR\drop_tables.cmd ${SRC_DIR}\drop_sqlite3_tables.cmd
     File /oname=$PLUGINSDIR\grant_privileges.cmd ${SRC_DIR}\grant_sqlite3_privileges.cmd
     File /oname=$PLUGINSDIR\make_catalog_backup.cmd ${SRC_DIR}\make_sqlite3_catalog_backup.cmd
   File "${SRC_DIR}\wxmsw270_core_vc_bacula.dll"
 !endif
 !if "${BUILD_TOOLS}" == "MinGW"
-  File "${SRC_DIR}\wxbase26_gcc_bacula.dll"
-  File "${SRC_DIR}\wxmsw26_core_gcc_bacula.dll"
+  File "${SRC_DIR}\wxbase270_gcc_bacula.dll"
+  File "${SRC_DIR}\wxmsw270_core_gcc_bacula.dll"
 !endif
 
   File "${SRC_DIR}\wx-console.exe"
 
--- /dev/null
+--- ../orig/dvd+rw-tools-7.0/growisofs.c       2006-09-24 10:28:53.000000000 -0700
++++ ./growisofs.c      2006-12-07 01:56:17.000000000 -0800
+@@ -370,12 +370,17 @@
+  *   upon Layer Break command, therefore longer timeout is required;
+  * - Linux: deploy BLKFLSBUF to avoid media reloads when possible;
+  * - add unit buffer utilization indicator [by request from K3b];
++ * 7.0.1: (by Nicolas Boichat, Bacula project)
++ * - Allow session to cross 4GB boundary regardless of medium type
++ *   (don't need to have a DL media)
++ * - Add a -F option (used instead of -M or -Z), which displays next_session
++ *   offset and capacity (free space = next_session - capacity).
+  */
+ #define PRINT_VERSION(cmd)    do {                    \
+     char *s=strrchr((cmd),'/');                               \
+     s ? s++ : (s=(cmd));                              \
+     printf ("* %.*sgrowisofs by <appro@fy.chalmers.se>,"\
+-          " version 7.0,\n",(int)(s-(cmd)),(cmd));    \
++          " version 7.0.1,\n",(int)(s-(cmd)),(cmd));  \
+ } while (0)
+ \f
+ #define _LARGEFILE_SOURCE 
+@@ -2576,7 +2581,8 @@
+       else                                    arg = mkisofs_argv[0];
+ 
+       cmdsz--;
+-      assert ((len0=strlen (arg)) < cmdsz);
++      len0 = strlen (arg);
++      assert (len0 < cmdsz);
+ 
+       strcpy (cmd,arg), cmd[len0++] = ' ', cmdsz -= len0;
+ 
+@@ -2773,6 +2779,18 @@
+               else          in_device = argv[++i];
+               dev_found = 'Z';
+           }
++          else if (argv[i][1] == 'F')
++          {   if (len > 2) in_device = argv[i]+2;
++              else         in_device = argv[++i];
++              dev_found = 'F';
++              dry_run = 1; /* NEVER write anything with -F */
++          }
++          else if (!strncmp(opt,"-free-space",11))
++          {   if (len > 11) in_device = opt+11;
++              else          in_device = argv[++i];
++              dev_found = 'F';
++              dry_run = 1; /* NEVER write anything with -F */
++          }
+           else if (!strcmp(opt,"-poor-man"))
+           {   if (poor_man<0) poor_man = 1;
+               continue;
+@@ -2898,7 +2916,7 @@
+           else if (argv[i][1] == '?' || !strcmp(opt,"-help"))
+           {   PRINT_VERSION (argv[0]);
+               printf ("- usage: %s [-dvd-compat] [-overburn] [-speed=1] \\\n"
+-                      "         -[ZM] /dev/dvd <mkisofs options>\n",argv[0]);
++                      "         -[ZMF] /dev/dvd <mkisofs options>\n",argv[0]);
+               printf ("  for <mkisofs options> see 'mkisofs %s'\n",opt);
+               exit (FATAL_START(EINVAL));
+           }
+@@ -2993,7 +3011,13 @@
+               fprintf (stderr,"    you most likely want to use -Z option.\n"), 
+               exit (FATAL_START(errno));
+ 
+-          if (dev_found == 'M')
++          if ((dev_found == 'M') || 
++              ((dev_found == 'F') && !(mmc_profile&0x10000)) &&
++               (saved_descriptors[0].type[0] ||
++                saved_descriptors[0].type[1] ||
++                saved_descriptors[0].type[2]))
++              /* -F : The medium is not blank, there is a fs on it (the_buffer[0,1 or 2] != 0),
++                      so compute next_session. */
+           {   if (memcmp (saved_descriptors[0].type,"\1CD001",6))
+                   fprintf (stderr,":-( %s doesn't look like isofs...\n",
+                               in_device), exit(FATAL_START(EMEDIUMTYPE));
+@@ -3016,8 +3040,7 @@
+                       exit(FATAL_START(EINVAL));
+               }
+               else if (next_session > (0x200000-0x5000)) /* 4GB/2K-40MB/2K */
+-                  if ((mmc_profile&0xFFFF)<0x20 ||
+-                      ((mmc_profile&0xFFFF)<0x40 && !no_4gb_check))
++                  if ((mmc_profile&0xFFFF)<0x40 && !no_4gb_check)
+                       fprintf (stderr,":-( next session would cross 4GB "
+                                       "boundary, aborting...\n"),
+                       exit (FATAL_START(ENOSPC));
+@@ -3060,7 +3083,7 @@
+       exit (FATAL_START(EINVAL));
+ 
+     if (imgfd<0)
+-    { if (mkisofs_argc==1)
++    { if ((mkisofs_argc==1) && (dev_found != 'F'))
+           fprintf (stderr,"%s: no mkisofs options specified, "
+                           "aborting...\n",argv[0]),
+           exit (FATAL_START(EINVAL));
+@@ -3244,6 +3267,15 @@
+       }
+     }
+ 
++    if (dev_found == 'F') {
++      off64_t capacity = 0;
++      printf("next_session=%d\n", next_session * CD_BLOCK);
++      if (ioctl_handle!=INVALID_HANDLE)
++          capacity = get_capacity (ioctl_handle);
++      printf("capacity=%lld\n", capacity);
++      exit(0);
++    }
++
+     if (imgfd>=0)
+     { quiet--;
+       if (builtin_dd (imgfd,out_fd,next_session*CD_BLOCK) < 0)
+--- ../orig/dvd+rw-tools-7.0/Makefile  2006-08-27 13:07:37.000000000 -0700
++++ ./Makefile 2006-12-07 01:56:17.000000000 -0800
+@@ -9,7 +9,7 @@
+ 
+ CHAIN=growisofs dvd+rw-format dvd+rw-booktype dvd+rw-mediainfo dvd-ram-control
+ clean:
+-      -(rm *.o $(CHAIN) rpl8 btcflash; exit 0) < /dev/null > /dev/null 2>&1
++      -(rm *.o $(CHAIN) $(CHAIN:=.exe) rpl8 btcflash; exit 0) < /dev/null > /dev/null 2>&1
+ 
+ VER=7.0
+ DIST=dvd+rw-tools-$(VER)
+--- ../orig/dvd+rw-tools-7.0/Makefile.m4       2006-09-24 10:55:19.000000000 -0700
++++ ./Makefile.m4      2006-12-07 01:59:30.000000000 -0800
+@@ -1,12 +1,5 @@
+ # OBS! M4 processed!
+ changequote([, ])
+-[
+-CHAIN=growisofs dvd+rw-format dvd+rw-booktype dvd+rw-mediainfo dvd-ram-control
+-
+-dvd+rw-tools: $(CHAIN)
+-
+-WARN=#-Wall   # developers are welcomed to build with `make WARN=-Wall'
+-]
+ 
+ # fix-up OS macro
+ ifelse(substr(OS,0,7),[CYGWIN_],[define([OS],[MINGW32])])
+@@ -38,11 +31,36 @@
+ #
+ # MINGW section
+ #
++SUFFIXES+=.exe
+ CC    =gcc
+ CFLAGS        +=$(WARN) -mno-cygwin -O2
+ CXX   =g++
+ CXXFLAGS+=$(WARN) -mno-cygwin -O2 -fno-exceptions
+ LINK.o        =$(LINK.cc)
++EXE   =.exe
++])
++
++ifelse(OS,XMINGW32,[
++#
++# MINGW cross-compile section
++#
++SUFFIXES+=.exe
++CC    =mingw32-gcc
++CFLAGS        +=$(WARN) -mno-cygwin -O2
++CXX   =mingw32-g++
++CXXFLAGS+=$(WARN) -mno-cygwin -O2 -fno-exceptions
++LINK.o        =$(LINK.cc)
++EXE   =.exe
++%.exe:%.o
++      $(CXX) $(CXXFLAGS) -o $@ $> $^ $(LDFLAGS) $(LDLIBS)
++
++install:      dvd+rw-tools
++      [[ -d $(prefix)/bin ]] || mkdir -p $(prefix)/bin
++      install -m 0755 $(CHAIN) $(prefix)/bin
++      [[ -d $(manprefix)/man1 ]] || mkdir -p $(manprefix)/man1
++      install -m 0644 growisofs.1 $(manprefix)/man1
++      -[[ -f rpl8 ]] && install -m 0755 rpl8 $(prefix)/bin; :
++      -[[ -f btcflash ]] && install -m 0755 btcflash $(prefix)/bin; :
+ ])
+ 
+ ifelse(OS,BSD,[
+@@ -207,27 +225,33 @@
+ 
+ # common section
+ [
+-growisofs:            growisofs_mmc.o growisofs.o
++CHAIN=growisofs$(EXE) dvd+rw-format$(EXE) dvd+rw-booktype$(EXE) dvd+rw-mediainfo$(EXE) dvd-ram-control$(EXE)
++
++dvd+rw-tools: $(CHAIN)
++
++WARN=#-Wall   # developers are welcomed to build with `make WARN=-Wall'
++
++growisofs$(EXE):      growisofs_mmc.o growisofs.o
+ growisofs.o:          growisofs.c mp.h
+ growisofs_mmc.o:      growisofs_mmc.cpp transport.hxx
+ 
+-dvd+rw-format:                dvd+rw-format.o
++dvd+rw-format$(EXE):  dvd+rw-format.o
+ dvd+rw-format.o:      dvd+rw-format.cpp transport.hxx
+ 
+-dvd+rw-mediainfo:     dvd+rw-mediainfo.o
++dvd+rw-mediainfo$(EXE):       dvd+rw-mediainfo.o
+ dvd+rw-mediainfo.o:   dvd+rw-mediainfo.cpp transport.hxx
+ 
+-dvd+rw-booktype:      dvd+rw-booktype.o
++dvd+rw-booktype$(EXE):        dvd+rw-booktype.o
+ dvd+rw-booktype.o:    dvd+rw-booktype.cpp transport.hxx
+ 
+-dvd-ram-control:      dvd-ram-control.o
++dvd-ram-control$(EXE):        dvd-ram-control.o
+ dvd-ram-control.o:    dvd-ram-control.cpp transport.hxx
+ 
+-rpl8:                 rpl8.o
++rpl8$(EXE):           rpl8.o
+ rpl8.o:                       rpl8.cpp transport.hxx
+ +rpl8:                        rpl8
+ #so that I can invoke `make +rpl8' to build rpl8...
+-btcflash:             btcflash.o
++btcflash$(EXE):               btcflash.o
+ btcflash.o:           btcflash.cpp transport.hxx
+ +btcflash:            btcflash
+ #so that I can invoke `make +btcflash' to build btcflash...
+--- ../orig/dvd+rw-tools-7.0/Makefile.msc      1969-12-31 16:00:00.000000000 -0800
++++ ./Makefile.msc     2006-12-07 01:56:17.000000000 -0800
+@@ -0,0 +1,48 @@
++CHAIN=growisofs.exe dvd+rw-format.exe dvd+rw-booktype.exe dvd+rw-mediainfo.exe dvd-ram-control.exe
++
++DEFINES=/D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_MBCS" 
++CFLAGS=$(DEFINES) /O2 /FD /EHsc /MD /W3 /nologo /c /Wp64 /Zi
++CPPFLAGS=$(DEFINES) /O2 /FD /EHsc /MD /W3 /nologo /c /Wp64 /Zi
++LDFLAGS=/NOLOGO /SUBSYSTEM:CONSOLE /MANIFEST
++
++all:
++
++clean:
++      -del *.obj *.manifest *.pdb *.idb $(CHAIN) > nul 2>&1
++
++install: $(CHAIN)
++      !xcopy $** $(prefix)\bin\ /y
++
++dvd+rw-tools: $(CHAIN)
++
++growisofs.exe:                growisofs_mmc.obj growisofs.obj
++      link $(LDFLAGS) /MANIFESTFILE:$@.manifest /out:$@ $** 
++      mt /nologo /outputresource:"$@;#1" -manifest $@.manifest
++
++growisofs.obj:                growisofs.c mp.h
++
++growisofs_mmc.obj:    growisofs_mmc.cpp transport.hxx
++
++dvd+rw-format.exe:    dvd+rw-format.obj
++      link $(LDFLAGS) /MANIFESTFILE:$@.manifest /out:$@ $** 
++      mt /nologo /outputresource:"$@;#1" -manifest $@.manifest
++
++dvd+rw-format.obj:    dvd+rw-format.cpp transport.hxx
++
++dvd+rw-mediainfo.exe: dvd+rw-mediainfo.obj
++      link $(LDFLAGS) /MANIFESTFILE:$@.manifest /out:$@ $** 
++      mt /nologo /outputresource:"$@;#1" -manifest $@.manifest
++
++dvd+rw-mediainfo.obj: dvd+rw-mediainfo.cpp transport.hxx
++
++dvd+rw-booktype.exe:  dvd+rw-booktype.obj
++      link $(LDFLAGS) /MANIFESTFILE:$@.manifest /out:$@ $** 
++      mt /nologo /outputresource:"$@;#1" -manifest $@.manifest
++
++dvd+rw-booktype.obj:  dvd+rw-booktype.cpp transport.hxx
++
++dvd-ram-control.exe:  dvd-ram-control.obj
++      link $(LDFLAGS) /MANIFESTFILE:$@.manifest /out:$@ $** 
++      mt /nologo /outputresource:"$@;#1" -manifest $@.manifest
++
++dvd-ram-control.obj:  dvd-ram-control.cpp transport.hxx
 
           update.o util.o vacuum.o \
           vdbe.o vdbeapi.o vdbeaux.o vdbefifo.o vdbemem.o \
           where.o utf.o legacy.o
-@@ -174,7 +174,7 @@
- # of the most recently modified source code file
- #
- last_change:  $(SRC)
--      cat $(SRC) | grep '$$Id: ' | sort +4 | tail -1 \
-+      cat $(SRC) | grep '$$Id: ' | sort -k 5 | tail -1 \
-           | $(NAWK) '{print $$5,$$6}' >last_change
- 
- libsqlite3.a: $(LIBOBJ)
-@@ -264,7 +264,7 @@
-       $(TCCX) -c opcodes.c
- 
- opcodes.c:    opcodes.h $(TOP)/mkopcodec.awk
--      sort -n -b +2 opcodes.h | $(NAWK) -f $(TOP)/mkopcodec.awk >opcodes.c
-+      sort -n -b -k 3 opcodes.h | $(NAWK) -f $(TOP)/mkopcodec.awk >opcodes.c
- 
- opcodes.h:    parse.h $(TOP)/src/vdbe.c $(TOP)/mkopcodeh.awk
-       cat parse.h $(TOP)/src/vdbe.c | $(NAWK) -f $(TOP)/mkopcodeh.awk >opcodes.h
-@@ -360,8 +360,8 @@
+@@ -394,8 +394,8 @@
  
  # Rules for building test programs and for running tests
  #
                $(TOP)/src/tclsqlite.c libsqlite3.a $(LIBTCL) $(THREADLIB)
  
  testfixture$(EXE):    $(TOP)/src/tclsqlite.c libsqlite3.a $(TESTSRC)
-@@ -563,8 +563,8 @@
+@@ -604,8 +604,8 @@
  
  # Standard install and cleanup targets
  #
 
 @ECHO off\r
-REM !@PYTHON@\r
 REM \r
 REM  Check the free space available on a writable DVD\r
 REM  Should always exit with 0 status, otherwise it indicates a serious error.\r
 REM \r
 REM   operations used by Bacula:\r
 REM \r
-REM    free  (no arguments)\r
-REM          Scan the device and report the available space. It returns:\r
-REM          Prints on the first output line the free space available in bytes.\r
-REM          If an error occurs, prints a negative number (-errno), followed,\r
-REM          on the second line, by an error message.\r
+REM    free   (no arguments)\r
+REM       Scan the device and report the available space. It returns:\r
+REM       Prints on the first output line the free space available in \r
+REM       bytes.\r
+REM       If an error occurs, prints a negative number (-errno), followed,\r
+REM       on the second line, by an error message.\r
 REM \r
 REM    write  op filename\r
-REM           Write a part file to disk.\r
-REM           This operation needs two additional arguments.\r
-REM           The first (op) indicates to\r
-REM               0 -- append\r
-REM               1 -- first write to a blank disk\r
-REM               2 -- blank or truncate a disk\r
+REM        Write a part file to disk.\r
+REM        This operation needs two additional arguments.\r
+REM        The first (op) indicates to\r
+REM           0 -- append\r
+REM           1 -- first write to a blank disk\r
+REM           2 -- blank or truncate a disk\r
 REM \r
-REM            The second is the filename to write\r
+REM        The second is the filename to write\r
 REM \r
-REM    operations available but not used by Bacula:\r
+REM   operations available but not used by Bacula:\r
 REM \r
 REM    test      Scan the device and report the information found.\r
-REM           This operation needs no further arguments.\r
+REM              This operation needs no further arguments.\r
 REM    prepare   Prepare a DVD+/-RW for being used by Bacula.\r
-REM           Note: This is only useful if you already have some\r
-REM           non-Bacula data on a medium, and you want to use\r
-REM           it with Bacula. Don't run this on blank media, it\r
-REM           is useless.\r
+REM              Note: This is only useful if you already have some\r
+REM              non-Bacula data on a medium, and you want to use\r
+REM              it with Bacula. Don't run this on blank media, it\r
+REM              is useless.\r
 REM \r
 REM  \r
 REM  $Id: dvd-handler.in,v 1.11 2006/08/30 16:19:30 kerns Exp $\r
 REM \r
 \r
 setlocal ENABLEDELAYEDEXPANSION\r
-\r
+SET PATH=%PATH%;@bin_dir_cmd@\r
 REM  Configurable values:\r
-   \r
-SET self_dvdrwmediainfo=dvd+rw-mediainfo.exe\r
-SET self_growcmd=growisofs.exe\r
-SET self_dvdrwformat=dvd+rw-format.exe\r
-SET self_dd=dd.exe\r
-SET self_margin=5120\r
+\r
+SET dvdrwmediainfo=dvd+rw-mediainfo.exe\r
+SET growcmd=growisofs.exe\r
+SET dvdrwformat=dvd+rw-format.exe\r
+SET dd=dd.exe\r
+SET margin=10485760\r
 \r
 REM Comment the following line if you want the tray to be reloaded\r
 REM when writing ends.\r
-SET self_growcmd=%self_growcmd% -use-the-force-luke^^^^^=notray\r
+SET growcmd=%growcmd% -use-the-force-luke^^^^^=notray\r
 \r
 REM  end of configurable values\r
 \r
    CALL :prepare\r
    ECHO Medium prepared successfully.\r
 ) ELSE IF "%2" == "test" (\r
-   IF %self_freespace_collected% EQU 0 CALL :collect_freespace\r
-   IF %self_mediumtype_collected% EQU 0 CALL :collect_mediumtype\r
-   ECHO Class disk, initialized with device %self_device%\r
-   ECHO  type = '!self_disktype!' mode='!self_diskmode!' status = '!self_diskstatus!'\r
-   ECHO  next_session = !self_next_session! capacity = !self_capacity!\r
-   ECHO  Hardware device is '!self_hardwaredevice!'\r
-   ECHO  growcmd = '!self_growcmd!'\r
-   ECHO  growparams = '!self_growparams!'\r
+   IF %freespace_collected% EQU 0 CALL :collect_freespace\r
+   IF %mediumtype_collected% EQU 0 CALL :collect_mediumtype\r
+   ECHO Class disk, initialized with device %device%\r
+   ECHO  type = '!disktype!' mode='!diskmode!' status = '!diskstatus!'\r
+   ECHO  next_session = !next_session! capacity = !capacity!\r
+   ECHO  Hardware device is '!hardwaredevice!'\r
+   ECHO  growcmd = '!growcmd!'\r
+   ECHO  growparams = '!growparams!'\r
    ECHO.\r
    SET empty_disk=false\r
    CALL :is_blank\r
 )\r
 EXIT /b 0\r
 \r
-REM ##############################################################################\r
-REM \r
-REM  This class represents DVD disk informations.\r
-REM  When instantiated, it needs a device name.\r
-REM  Status information about the device and the disk loaded is collected only when\r
-REM  asked for (for example dvd-freespace doesn't need to know the media type, and\r
-REM  dvd-writepart doesn't not always need to know the free space).\r
-REM \r
-REM  The following methods are implemented:\r
-REM  __init__   we need that...\r
-REM  __repr__   this seems to be a good idea to have.\r
-REM             Quite minimalistic implementation, though.\r
-REM  __str__    For casts to string. Return the current disk information\r
-REM  is_empty   Returns TRUE if the disk is empty, blank... this needs more\r
-REM             work, especially concerning non-RW media and blank vs. no\r
-REM             filesystem considerations. Here, we should also look for\r
-REM             other filesystems - probably we don't want to silently\r
-REM             overwrite UDF or ext2 or anything not mentioned in fstab...\r
-REM             (NB: I don't think it is a problem)\r
-REM  free       Returns the available free space.\r
-REM  write      Writes one part file to disk, either starting a new file\r
-REM             system on disk, or appending to it.\r
-REM             This method should also prepare a blank disk so that a\r
-REM             certain part of the disk is used to allow detection of a\r
-REM             used disk by all / more disk drives.\r
-REM  blank      Blank the device\r
+REM ##########################################################################\r
+REM\r
+REM  The rest of this file is a set of subroutines that return DVD disk \r
+REM  information.\r
+REM\r
+REM  Status information about the device and the disk loaded is collected \r
+REM  only when asked for (for example dvd-freespace doesn't need to know the \r
+REM  media type, and dvd-writepart doesn't not always need to know the free \r
+REM  space).\r
+REM\r
+REM  The following subroutines are implemented:\r
+REM  init       we need that...\r
+REM  is_empty   Set ERRORLEVEL to TRUE if the disk is empty, blank... \r
+REM              this needs more work, especially concerning non-RW media \r
+REM              and blank vs. no filesystem considerations. Here, we \r
+REM              should also look for other filesystems - probably we don't\r
+REM              want to silently overwrite UDF or ext2 or anything not \r
+REM              mentioned in fstab...\r
+REM              (NB: I don't think it is a problem)\r
+REM  is_RW       Set ERRORLEVEL to TRUE if the disk is RW (DVD-RW or DVD+RW)\r
+REM  is_plus_RW  Set ERRORLEVEL to TRUE if the disk is DVD+RW\r
+REM  is_minus_RW Set ERRORLEVEL to TRUE if the disk is DVD-RW\r
+REM  is_blank    Set ERRORLEVEL to TRUE if the disk is blank\r
+REM  free        Returns the available free space.\r
+REM  write       Writes one part file to disk, either starting a new file\r
+REM              system on disk, or appending to it.\r
+REM              This method should also prepare a blank disk so that a\r
+REM              certain part of the disk is used to allow detection of a\r
+REM              used disk by all / more disk drives.\r
+REM  blank       Blank the device\r
 REM \r
-REM ##############################################################################\r
+REM ##########################################################################\r
+\r
 :init\r
-SET self_device=%1\r
-SET self_disktype=none\r
-SET self_diskmode=none\r
-SET self_diskstatus=none\r
-SET self_hardwaredevice=none\r
-SET self_pid=0\r
-SET self_next_session=-1\r
-SET self_capacity=-1\r
-\r
-SET self_freespace_collected=0\r
-SET self_mediumtype_collected=0\r
-\r
-SET self_growcmd=%self_growcmd% -quiet -use-the-force-luke^^^=4gms\r
-\r
-SET self_growparams=-A "Bacula Data" -input-charset=default -iso-level 3 -pad\r
-SET self_growparams=%self_growparams% -p "dvd-handler / growisofs" -sysid "BACULADATA" -R\r
+SET device=%1\r
+SET disktype=none\r
+SET diskmode=none\r
+SET diskstatus=none\r
+SET hardwaredevice=none\r
+SET pid=0\r
+SET next_session=-1\r
+SET capacity=-1\r
+\r
+SET freespace_collected=0\r
+SET mediumtype_collected=0\r
+\r
+SET growcmd=%growcmd% -quiet -use-the-force-luke^^^=4gms\r
+\r
+SET growparams=-A "Bacula Data" -input-charset=default -iso-level 3 -pad\r
+SET growparams=%growparams% -p "dvd-handler / growisofs" -sysid "BACULADATA" -R\r
 GOTO :EOF\r
 \r
 :collect_freespace\r
-SET self_next_session=0\r
-SET self_capacity=0\r
-FOR /f "delims== tokens=1*" %%i in ( '%self_growcmd% -F %self_device%' ) DO (\r
+SET next_session=0\r
+SET capacity=0\r
+FOR /f "delims== tokens=1*" %%i in ( '%growcmd% -F %device%' ) DO (\r
    IF "%%i" == "next_session" ( \r
-      SET self_next_session=%%j\r
+      SET next_session=%%j\r
    ) ELSE IF "%%i" == "capacity" (\r
-      SET self_capacity=%%j\r
+      SET capacity=%%j\r
    ) ELSE IF "%%j" == "" (\r
       SET result=!result! %%i\r
    ) ELSE (\r
    SET /a STATUS=STATUS ^& 0x7F\r
    IF !STATUS! EQU 112 (\r
       REM Kludge to force dvd-handler to return a free space of 0\r
-      self_next_session = 1\r
-      self_capacity = 1\r
-      self_freespace_collected = 1\r
+      next_session = 1\r
+      capacity = 1\r
+      freespace_collected = 1\r
       GOTO :EOF\r
    ) ELSE (\r
-      ECHO growisofs returned with an error !STATUS!. Please check your are using a patched version of dvd+rw-tools.\r
+      ECHO growisofs returned with an error !STATUS!. Please check you are using a patched version of dvd+rw-tools.\r
       EXIT !STATUS!\r
    )\r
 )\r
 \r
-IF %self_next_session% EQU 0 IF %self_capacity% EQU 0 (\r
+IF %next_session% EQU 0 IF %capacity% EQU 0 (\r
    ECHO Cannot get next_session and capacity from growisofs.\r
    ECHO Returned: %result:|=^|%\r
    EXIT 1\r
 )\r
-SET self_freespace_collected=1\r
+SET freespace_collected=1\r
 GOTO :EOF\r
 \r
 :collect_mediumtype\r
-SET self_hardwaredevice=\r
-SET self_disktype=\r
-SET self_diskmode=\r
-SET self_diskstatus=\r
-SET self_lasterror=\r
-FOR /f "delims=: tokens=1,2 usebackq" %%i in ( `"%self_dvdrwmediainfo%" %self_device%` ) DO (\r
-   IF "%%i" == "INQUIRY" FOR /f "tokens=*" %%k in ( "%%j" ) DO SET self_hardwaredevice=%%k\r
+SET hardwaredevice=\r
+SET disktype=\r
+SET diskmode=\r
+SET diskstatus=\r
+SET lasterror=\r
+FOR /f "delims=: tokens=1,2 usebackq" %%i in ( `"%dvdrwmediainfo%" %device%` ) DO (\r
+   IF "%%i" == "INQUIRY" FOR /f "tokens=*" %%k in ( "%%j" ) DO SET hardwaredevice=%%k\r
    IF "%%i" == " Mounted Media" FOR /f "tokens=1,2* delims=, " %%k in ( "%%j" ) DO (\r
-      SET self_disktype=%%l\r
-      SET self_diskmode=%%m\r
+      SET disktype=%%l\r
+      SET diskmode=%%m\r
    )\r
-   IF "%%i" == " Disc status" FOR /f "tokens=*" %%k in ( "%%j" ) DO SET self_diskstatus=%%k\r
+   IF "%%i" == " Disc status" FOR /f "tokens=*" %%k in ( "%%j" ) DO SET diskstatus=%%k\r
 )\r
 \r
-IF NOT DEFINED self_disktype (\r
-   ECHO Media type not found in %self_dvdrwmediainfo% output\r
+IF NOT DEFINED disktype (\r
+   ECHO Media type not found in %dvdrwmediainfo% output\r
    EXIT 1\r
 )\r
 \r
-IF "%self_disktype%" == "DVD-RW" IF NOT DEFINED self_diskmode (\r
-   ECHO Media mode not found for DVD-RW in %self_dvdrwmediainfo% output\r
+IF "%disktype%" == "DVD-RW" IF NOT DEFINED diskmode (\r
+   ECHO Media mode not found for DVD-RW in %dvdrwmediainfo% output\r
    EXIT 1\r
 )\r
-      \r
-IF NOT DEFINED self_diskstatus (\r
-   ECHO Disc status not found in %self_dvdrwmediainfo% output\r
+\r
+IF NOT DEFINED diskstatus (\r
+   ECHO Disc status not found in %dvdrwmediainfo% output\r
    EXIT 1\r
 )\r
 \r
-SET self_mediumtype_collected=1\r
+SET mediumtype_collected=1\r
 GOTO :EOF\r
 \r
 :is_empty\r
-IF %self_freespace_collected% EQU 0 CALL :collect_freespace\r
-IF %self_next_session% EQU 0 ( EXIT /b 1 ) ELSE EXIT /b 0\r
+IF %freespace_collected% EQU 0 CALL :collect_freespace\r
+IF %next_session% EQU 0 ( EXIT /b 1 ) ELSE EXIT /b 0\r
 \r
 :is_RW\r
-IF %self_mediumtype_collected% EQU 0 CALL :collect_mediumtype\r
-IF %self_disktype% == "DVD-RW" EXIT /b 1\r
-IF %self_disktype% == "DVD+RW" EXIT /b 1\r
-IF %self_disktype% == "DVD-RAM" EXIT /b 1\r
+IF %mediumtype_collected% EQU 0 CALL :collect_mediumtype\r
+IF %disktype% == "DVD-RW" EXIT /b 1\r
+IF %disktype% == "DVD+RW" EXIT /b 1\r
+IF %disktype% == "DVD-RAM" EXIT /b 1\r
 EXIT /b 0\r
 \r
 :is_plus_RW\r
-IF %self_mediumtype_collected% EQU 0 CALL :collect_mediumtype\r
-IF "%self_disktype%" == "DVD+RW" EXIT /b 1\r
+IF %mediumtype_collected% EQU 0 CALL :collect_mediumtype\r
+IF "%disktype%" == "DVD+RW" EXIT /b 1\r
 EXIT /b 0\r
 \r
 :is_minus_RW\r
-IF %self_mediumtype_collected% EQU 0 CALL :collect_mediumtype\r
-IF "%self_disktype%" == "DVD-RW" EXIT /b 1\r
+IF %mediumtype_collected% EQU 0 CALL :collect_mediumtype\r
+IF "%disktype%" == "DVD-RW" EXIT /b 1\r
 EXIT /b 0\r
       \r
 :is_restricted_overwrite\r
-IF %self_mediumtype_collected% EQU 0 CALL :collect_mediumtype\r
-IF "%self_diskmode%" == "Restricted Overwrite" EXIT /b 1\r
+IF %mediumtype_collected% EQU 0 CALL :collect_mediumtype\r
+IF "%diskmode%" == "Restricted Overwrite" EXIT /b 1\r
 EXIT /b 0\r
 \r
 :is_blank\r
-IF %self_mediumtype_collected% EQU 0 CALL :collect_mediumtype\r
-IF "%self_diskstatus%" == "blank" EXIT /b 1\r
+IF %mediumtype_collected% EQU 0 CALL :collect_mediumtype\r
+IF "%diskstatus%" == "blank" EXIT /b 1\r
 EXIT /b 0\r
 \r
 :free\r
-IF %self_freespace_collected% EQU 0 CALL :collect_freespace\r
-SET /a fr=self_capacity - self_next_session - self_margin\r
-IF %fr% LSS 0 ( EXIT /b 0 ) ELSE EXIT /b %fr%\r
+IF %freespace_collected% EQU 0 CALL :collect_freespace\r
+FOR /f %%i in ( 'expr64 "capacity - next_session - margin"' ) DO SET fr=%%i\r
+expr64 /q "fr < 0" && ( EXIT /b 0 ) || EXIT /b %fr%\r
 \r
 REM %1 - newvol, %2 - partfile\r
 :write\r
 IF %ERRORLEVEL% NEQ 0 IF %1 NEQ 0 (\r
    CALL :is_restricted_overwrite\r
    IF !ERRORLEVEL! EQU 0 (\r
-      ECHO DVD-RW is in %self_diskmode% mode, reformating it to Restricted Overwrite\r
+      ECHO DVD-RW is in %diskmode% mode, reformating it to Restricted Overwrite\r
       CALL :reformat_minus_RW\r
       ECHO Done, now writing the part file.\r
    )\r
 ) ELSE (\r
    SET cmd_opts= -M\r
 )\r
-ECHO Running %self_growcmd% %self_growparams% %cmd_opts% %self_device% %2\r
-%self_growcmd% %self_growparams% %cmd_opts% %self_device% %2\r
+ECHO Running %growcmd% %growparams% %cmd_opts% %device% %2\r
+%growcmd% %growparams% %cmd_opts% %device% %2\r
 IF %ERRORLEVEL% NEQ 0 (\r
    ECHO Exited with status !ERRORLEVEL!\r
    EXIT !ERRORLEVEL!\r
 IF %ERRORLEVEL% EQU 1 (\r
    CALL :is_restricted_overwrite\r
    IF !ERRORLEVEL! EQU 0 (\r
-      ECHO DVD-RW is in %self_diskmode% mode, reformating it to Restricted Overwrite\r
+      ECHO DVD-RW is in %diskmode% mode, reformating it to Restricted Overwrite\r
       CALL :reformat_minus_RW\r
       GOTO :EOF\r
    )\r
 )\r
-\r
 CALL :blank\r
 GOTO :EOF\r
 \r
 :blank\r
-ECHO Running %self_growcmd% -Z %self_device% =/dev/zero\r
-%self_growcmd% -Z %self_device% =/dev/zero\r
+ECHO Running %growcmd% -Z %device% =/dev/zero\r
+%growcmd% -Z %device% =/dev/zero\r
 IF %ERRORLEVEL% NEQ 0 (\r
    ECHO Exited with status !ERRORLEVEL!\r
    EXIT !ERRORLEVEL!\r
 GOTO :EOF\r
 \r
 :reformat_minus_RW\r
-ECHO Running %self_dvdrwformat% -force %self_device%\r
-%self_dvdrwformat% -force %self_device%\r
+ECHO Running %dvdrwformat% -force %device%\r
+%dvdrwformat% -force %device%\r
 IF %ERRORLEVEL% NEQ 0 (\r
    ECHO Exited with status !ERRORLEVEL!\r
    EXIT !ERRORLEVEL!\r
 ECHO where DVD-DRIVE is the drive letter of the DVD burner like D:\r
 ECHO.\r
 ECHO Operations:\r
-ECHO test         Scan the device and report the information found.\r
-ECHO      This operation needs no further arguments.\r
-ECHO free         Scan the device and report the available space.\r
-ECHO write        Write a part file to disk.\r
-ECHO      This operation needs two additional arguments.\r
-ECHO      The first indicates to append (0), restart the\r
-ECHO      disk (1) or restart existing disk (2). The second\r
-ECHO      is the file to write.\r
-ECHO prepare    Prepare a DVD+/-RW for being used by Bacula.\r
-ECHO      Note: This is only useful if you already have some\r
-ECHO      non-Bacula data on a medium, and you want to use\r
-ECHO      it with Bacula. Don't run this on blank media, it\r
-ECHO      is useless.\r
+ECHO test      Scan the device and report the information found.\r
+ECHO           This operation needs no further arguments.\r
+ECHO free      Scan the device and report the available space.\r
+ECHO write     Write a part file to disk.\r
+ECHO           This operation needs two additional arguments.\r
+ECHO           The first indicates to append (0), restart the\r
+ECHO           disk (1) or restart existing disk (2). The second\r
+ECHO           is the file to write.\r
+ECHO prepare   Prepare a DVD+/-RW for being used by Bacula.\r
+ECHO           Note: This is only useful if you already have some\r
+ECHO           non-Bacula data on a medium, and you want to use\r
+ECHO           it with Bacula. Don't run this on blank media, it\r
+ECHO           is useless.\r
 \r
 EXIT /b 1\r