@set INKSCAPE_PATH=C:\Program Files (x86)\Inkscape

::  Inkscape Windows launcher
::  -------------------------
::
::  -h | --help for help
::  

@echo off

:init
if '%1' EQU '--help' goto help
if '%1' EQU '-h' goto help
if '%1' EQU '--version' goto version
if '%1' EQU '-v' goto version

if NOT EXIST "%INKSCAPE_PATH%\inkscape.exe" goto error

if '%1' EQU '--script' goto set-ink
if '%1' EQU '-s' goto set-ink
goto exits

:set-ink
set _PYTHONPATH=%PYTHONPATH%
set _PYTHONHOME=%PYTHONHOME%
set PYTHONPATH=
set PYTHONHOME=%INKSCAPE_PATH%\python

:run
"%INKSCAPE_PATH%\Inkscape.exe" %2 %3 %4 %5 %6 %7 %8 %9

:re-set
set PYTHONHOME=%_PYTHONHOME%
set PYTHONPATH=%_PYTHONPATH%
goto end

:exits
set params=%*
cd /D "%INKSCAPE_PATH%"
start /b inkscape.exe %params%
exit

:help
echo inkscape.bat [ -s ^| --script ] [ files ^&^| params ]
echo.
echo Script params:
echo   files ^&^| params   Optional filenames and/or parameters to Inkscape.
echo.
echo   -s ^| --script     Script mode. !! Must be first parameter !! 
echo                     Resets PYTHONHOME and PYTHONPATH after Inkscape exits.
echo                     Does not exit CMD.
echo.
echo   -v ^| --version    Display version.
echo.
echo   -h ^| --help       This help.
echo.
echo Installation: 
echo   1. Place this file wherever you feel good.
echo   2. Adjust INKSCAPE_PATH at the top of this file.
echo   3. (Optional) Create a shortcut in a place of your liking.
echo   4. (Mandatory) Do awesome stuff.
echo.
echo Default behaviour:
echo   1. Clear PYTHONPATH.
echo   2. Set PYTHONHOME to path/to/Inkscape/python for current CMD.
echo   3. Launch Inkscape and pass optional file and/or params.
echo   4. Exit CMD.
echo.
echo Script mode:
echo   To prevent exit CMD, add -s or --script as first parameter
echo.
echo Examples:
echo   inkscape.bat my.svg - Open my.svg with Inkscape, exit CMD.
echo   inkscape.bat -s my.svg --export-pdf:my.pdf - Script mode, return to CMD.
echo.
echo Inkscape path currently set to:
echo   "%INKSCAPE_PATH%"
echo   If this is incorrect, edit the first line in this file:
echo   @set INKSCAPE_PATH=path/to/inkscape
echo.
echo No copyright, no licence, no support.
echo mikael@smwht.org, 2013.

goto end

:version
echo inkscape.bat version: 0.0.1.0.1b
echo.
echo Testing...
echo.
ping localhost -n 3 >NUL
echo Not very tested on animals.
echo.

goto end

:error
echo Error: %0 %*
echo.
echo Could not find Inkscape.exe at:
echo   %INKSCAPE_PATH%
echo.
echo Edit the first line in this file to your inkscape path:
echo   @set INKSCAPE_PATH=path/to/inkscape
echo.

goto end

:end
