@echo off

if "%1"=="" goto usage

if /i "%1" EQU "Win32" goto check_2
if /i "%1" EQU "x64" goto check_2
echo # Error: Valid platforms: Win32, x64
goto usage

:check_2
if "%2"=="" goto usage

set BUILDDIR=Release-%1
set TARGETDIR=%2

if not exist "%BUILDDIR%\aspell.exe" goto missingbuild
if not exist "%BUILDDIR%\word-list-compress.exe" goto missingbuild
if not exist "%BUILDDIR%\prezip-bin.exe" goto missingbuild

echo # Creating directories
mkdir %TARGETDIR%       1> nul 2> nul
mkdir %TARGETDIR%\dict  1> nul 2> nul
mkdir %TARGETDIR%\data  1> nul 2> nul
mkdir %TARGETDIR%\doc   1> nul 2> nul
mkdir %TARGETDIR%\doc\html   1> nul 2> nul

echo # Copying binary files
copy "%BUILDDIR%\aspell.exe" "%TARGETDIR%\aspell.exe" >nul
copy "%BUILDDIR%\word-list-compress.exe" "%TARGETDIR%\word-list-compress.exe" >nul
copy "%BUILDDIR%\prezip-bin.exe" "%TARGETDIR%\prezip-bin.exe" >nul
copy "scripts\install-dict.txt" "%TARGETDIR%\" >nul
copy "scripts\install-dict.bat" "%TARGETDIR%\" >nul
copy "scripts\install-dict-%1.cab" "%TARGETDIR%\install-dict.cab" >nul

echo # Copying data files
copy "..\data\*.*" "%TARGETDIR%\data" >nul
del "%TARGETDIR%\data\Makefile.*" >nul
copy "..\modules\filter\modes\*.amf" "%TARGETDIR%\dict" >nul

echo # Copying doc files
copy "..\COPYING" "%TARGETDIR%\COPYING" >nul
copy "..\manual\aspell.html\*.*" "%TARGETDIR%\doc\html" >nul
echo ^<html^>^<head^>^<META HTTP-EQUIV="refresh" CONTENT="1;URL=html/index.html"^>^<script^>location.replace("html/index.html");^</script^>^</head^>^</html^> > "%TARGETDIR%\doc\doc.html"


echo # Done!
echo # Now, to install a dictionary, download it from http://aspell.net
echo #   and use the install-dict.bat script from the installation directory
echo #   to install it. More information in install-dict.txt.

goto end

:missingbuild
echo # Error: The %1 build seems incomplete, please use VS2005 project
echo #        to build the relevant Release configuration
echo #

:usage
echo # Install script for aspell on Windows
echo #
echo # Requirements:
echo #  - Windows XP or later, Win32 or x64 processor
echo #  - The files to be installed must have already been built using
echo #    the Visual Studio 2005 projects in this directory
echo #
echo # Usage: install.bat platform targetdirectory
echo #
echo # Platform must be Win32 or x64
echo # You don't need to create targetdirectory before running install.bat
echo # Careful: existing files in targetdirectory may be replaced
echo #                 without additional warning
echo #
echo # Make sure you use back slashes (\) in paths, not forward slashes (/)
echo #         because the copy command is picky...

:end
set BUILDDIR=
set TARGETDIR=
