chcp 65001
rem ------------------------ INPUT ------------------------------
SET /p appName="Please enter the Name of the Installer (style_*): "
SET /p exeName="Please enter the Name of the App (*.exe): "

rem ------------------------ PROCESSED INPUT --------------------
SET pathSourceDirectory="%~dp0%exeName%"
SET pathSourceExe=%pathSourceDirectory%/bin/%exeName%.exe

SET pathResourcesDirectory=%~dp0res
SET pathCertificate=%pathResourcesDirectory%/certificate_2019-2021.p12
SET pathPathsIni=%pathResourcesDirectory%/paths.ini

rem ------------------------ ATTRIBUTES - PC --------------------
for /f "delims== tokens=1,2" %%G in (%pathPathsIni%) do set %%G=%%H

rem ------------------------ ATTRIBUTES - App -------------------
rem -

rem ------------------------ ATTRIBUTES - Raumgleiter -----------
SET pathExtraction=%%USERPROFILE%%\documents\Raumgleiter\

SET pathInstallerExe="%~dp0OUT/%appName%_WIN_Install.exe"
SET pathUpdaterExe="%~dp0OUT/%appName%_WIN_Update.exe"
SET pathIcon="%exeName%/style_%appName%/icon.ico"
SET pathLogo="%exeName%/style_%appName%/logo.bmp"


rem ------------------------ STATS ------------------------------


rem *************************************************************
rem Starting Process

rem -------------------------------------------------------------
rem Signing App
"%pathSignTool%" sign /a /t http://timestamp.comodoca.com /f %pathCertificate% /p Doornik1142 %pathSourceExe%

rem -------------------------------------------------------------
rem Write Comment

CALL :WriteComment false

rem -------------------------------------------------------------
rem Packaging Updater
"%pathWinRar%" a -r -ep1 -scuc -sfx -iicon%~dp0%pathIcon% -iimg%~dp0%pathLogo% -z%pathCommentUnicode% %pathUpdaterExe% %pathSourceDirectory%
timeout /T 3 /nobreak

rem -------------------------------------------------------------
rem Signing Updater
"%pathSignTool%" sign /a /t http://timestamp.comodoca.com /f %pathCertificate% /p Doornik1142 %pathUpdaterExe%


rem -------------------------------------------------------------
rem Add Shortcut to Comment

CALL :WriteComment true

rem -------------------------------------------------------------
rem Packaging Installer
"%pathWinRar%" a -r -ep1 -scuc -sfx -iicon%~dp0%pathIcon% -iimg%~dp0%pathLogo% -z%pathCommentUnicode% %pathInstallerExe% %pathSourceDirectory%
timeout /T 3 /nobreak

rem -------------------------------------------------------------
rem Signing Installer
"%pathSignTool%" sign /a /t http://timestamp.comodoca.com /f %pathCertificate% /p Doornik1142 %pathInstallerExe%


rem -------------------------------------------------------------
rem Success!
pause



rem *************************************************************
rem functions

rem -------------------------------------------------------------

:WriteComment

SET pathTempDirectory=%~dp0tmp
SET nameCommentFile=Comment.txt
SET pathCommentUnicode=%pathTempDirectory%/%nameCommentFile%

rem Preparing tmp directory
if not exist "%pathTempDirectory%" mkdir "%pathTempDirectory%"

rem -------------------------------------------------------------
rem Write Comment
SET TmpLogFile="%Tmp%\%~n0.txt"
If Exist %TmpLogFile% Del %TmpLogFile%
(
	echo Delete=%exeName%
	echo Path=%pathExtraction%
	echo SavePath
	echo License=Bestimmungen der Raumgleiter AG
	echo ^{
	echo ^<span style="font-family: industry, Verdana, Geneva, sans-serif; font-style: normal; font-weight: 300; font-size: 11pt;"^>
	echo Klicken Sie auf ^<b^>Annehmen^</b^>, um unsere Bestimmungen zu akzeptieren:^<br^>
	echo ^<br^>
	echo ^<li^>^<a target="_blank" href=http://app.raumgleiter.com/Info/Privacy/de^>Datenschutzerklärung^</a^>^</li^>^<br^>
	echo ^<li^>^<a target="_blank" href=http://app.raumgleiter.com/Info/EULA/de^>Endnutzer-Lizenzvertrag^</a^>^</li^>^<br^>
	echo ^<li^>^<a target="_blank" href=http://app.raumgleiter.com/Info/GTC/de^>Allgemeine Geschäftsbedingungen^</a^>^</li^>^<br^>
	echo ^</span^>
	echo ^}

	echo Title=Raumgleiter App Installieren
	echo Text
	echo ^{
	echo ^<span style="font-family: industry, Verdana, Geneva, sans-serif; font-style: normal; font-weight: 300; font-size: 11pt;"^>
	echo ^<li^>Diese Installation erstellt eine Verknüpfung auf Ihrem ^<b^>Desktop^</b^>.^</li^>^<br^>
	echo ^<br^>
	echo ^<li^>Drücken Sie ^<b^>Installieren^</b^>, um den Vorgang zu starten.^</li^>^<br^>
	echo ^</span^>
	echo ^}

	echo Setup="%exeName%/bin/%exeName%.exe"

	if %* == true (echo Shortcut=D, "%exeName%/bin/%exeName%.exe", , "A Raumgleiter App", %appName%, %pathIcon%)

)>>%TmpLogFile%

rem Formatting the output to unicode
CMD /U /C Type %TmpLogFile% > "%pathCommentUnicode%"
EXIT /B 0

rem -------------------------------------------------------------


rem -------------------------------------------------------------


rem -------------------------------------------------------------
