title MirandaNG packer
rem Packing compiled MirandaNG
rem use with param 32 or 64
rem set target platform %tp% from first parameter
set tp=%1
set dp=%2
if  "%tp%"=="" (echo "please specify target platform 32 or 64!"&&pause&&goto :EOF)

call a_SetVar%tp%.bat

if exist %Arch% rd /Q /S "%Arch%" >nul

rem making temp dirs
mkdir %Arch%

if  not exist "bin10\Release%tp%" goto EOF

:FILECHECK
pushd "bin10\Release%tp%"
if exist %Errors% del /F /Q %Errors%
if exist %NoErrors% del /F /Q %NoErrors%
for /f %%a in (..\..\z2_PackPluginUpater_x%tp%.txt) do (if not exist %%a echo %%a >> %Errors%)

:COMPRESS
REM Core
%ZipIt% "%Arch%\miranda%tp%.zip" "Miranda%tp%.exe" "Core\*.dll" "Plugins\Dbx_mmap.dll" "Plugins\DbChecker.dll" "Icons\Proto_MetaContacts.dll" "Libs\mir_app.mir" "Libs\mir_core.mir" "Libs\libjson.mir" "Libs\Pcre16.mir" "Libs\Zlib.mir" "Libs\libeay32.mir" "Libs\ssleay32.mir"
%ZipIt% "%Arch%\msvcp100.zip" msvcp100.dll
%ZipIt% "%Arch%\msvcr100.zip" msvcr100.dll
REM end Core

REM Langpacks
for /f %%a in ('dir Languages\lang*.txt /B /L') do (%ZipIt% "%Arch%\Languages\%%~na.zip" "Languages\%%~nXa")
REM end Langpacks

REM Protocols
REM for /f %%a in ('dir Protocols\*.dll /B /L') do (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Plugins\%%~nXa")
REM end Protocols

REM Plugins
for /f %%a in ('dir plugins\*.dll /B /L') do (
	rem check for special plugins and pack additional files first.
	if /I "%%a"=="Actman.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Plugins\services.ini")
	if /I "%%a"=="AIM.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_AIM.dll")
	if /I "%%a"=="BASS_interface.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Plugins\BASS\*.dll")
	if /I "%%a"=="Boltun.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Plugins\boltun.mindw")
	if /I "%%a"=="Clist_modern.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Plugins\AVS.dll" "Icons\Toolbar_icons.dll")
	if /I "%%a"=="CmdLine.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "MimCmd.exe")
	if /I "%%a"=="Discord.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_Discord.dll")
	if /I "%%a"=="Dropbox.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_Dropbox.dll")
	if /I "%%a"=="Dummy.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_Dummy.dll")
	if /I "%%a"=="Facebook.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_Facebook.dll")
	if /I "%%a"=="FavContacts.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Gadgets\favcontacts.gadget")
	if /I "%%a"=="Fingerprint.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Fp_icons.dll")
	if /I "%%a"=="FTPFile.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Libs\libcurl.mir")
	if /I "%%a"=="GG.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_GG.dll")
	if /I "%%a"=="HistoryPP.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\HistoryPP_icons.dll")
	if /I "%%a"=="ICQ.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_ICQ.dll" "Icons\xStatus_ICQ.dll")
	if /I "%%a"=="ImportTXT.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Libs\pcre3.dll" Plugins\Importtxt\*.ini)
	if /I "%%a"=="IRC.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_IRC.dll")
	if /I "%%a"=="Jabber.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_Jabber.dll" "Icons\xStatus_Jabber.dll" "Libs\libaxolotl.mir")
	if /I "%%a"=="Listeningto.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Plugins\Listeningto\*.dll")
	if /I "%%a"=="MinecraftDynmap.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_MinecraftDynmap.dll")
	if /I "%%a"=="MirLua.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Scripts\*.dll" "Libs\lua*.dll")
	if /I "%%a"=="MRA.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_MRA.dll" "Icons\xStatus_MRA.dll")
	if /I "%%a"=="mRadio.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_mRadio.dll" "Plugins\BASS\*.dll")
	if /I "%%a"=="MSN.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_MSN.dll")
	if /I "%%a"=="NewsAggregator.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_NewsAggregator.dll")
	if /I "%%a"=="NotifyAnything.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "SendLog*.exe")
	if /I "%%a"=="Nudge.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Sounds\nudge.wav")
	if /I "%%a"=="Omegle.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_Omegle.dll")
	if /I "%%a"=="PluginUpdater.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "pu_stub.exe")
	if /I "%%a"=="Quotes.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_Quotes.dll" "Plugins\Quotes\*.xml")
	if /I "%%a"=="RemovePersonalSettings.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "RemovePersonalSettings.ini")
	if /I "%%a"=="Sametime.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_Sametime.dll")
	if /I "%%a"=="SecureIM.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Plugins\CryptoPP.dll" "Icons\SecureIM_icons.dll")
	if /I "%%a"=="SkypeWeb.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_Skype.dll")
	if /I "%%a"=="SpellChecker.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Flags_icons.dll" "Libs\hunspell.mir")
	if /I "%%a"=="Steam.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_Steam.dll")
	if /I "%%a"=="TabSRMM.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\TabSRMM_icons.dll")
	if /I "%%a"=="Tlen.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_Tlen.dll")
	if /I "%%a"=="Tox.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_Tox.dll" "Libs\libtox.dll")
	if /I "%%a"=="Twitter.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_Twitter.dll")
	if /I "%%a"=="UInfoEx.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\UInfoEx_icons.dll")
	if /I "%%a"=="VKontakte.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_VKontakte.dll")
	if /I "%%a"=="Watrack.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Watrack_buttons.dll" "Icons\Watrack_icons.dll" "Plugins\player.ini")
	if /I "%%a"=="Weather.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_Weather.dll" "Plugins\Weather\*.ini")
	if /I "%%a"=="WhatsApp.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_WhatsApp.dll" "Libs\libaxolotl.mir")
	if /I "%%a"=="YAMN.dll" (%ZipIt% "%Arch%\Plugins\%%~na.zip" "Icons\Proto_YAMN.dll")
	rem now adding plugin itself into archive
	%ZipIt% "%Arch%\Plugins\%%~na.zip" %%a
)
REM end Plugins

REM Icons
for /f %%a in ('dir .\Icons\*.dll /B /L') do (%ZipIt% "%Arch%\Icons\%%~na.zip" "-ir-!Icons\%%~nXa")
REM end Icons

REM CRC32
copy /y /v hashes.txt %Arch%\hash.txt
copy /y /v ..\CRC32.exe %Arch%
pushd %Arch%

if /i '%dp%' == 'DEV_N_STABLE' (
  echo ;DoNotSwitchToStable > hashes.txt
) else if /i '%dp%' == 'DEV_ONLY' (
  echo DoNotSwitchToStable > hashes.txt
) else (
  echo ;StableAllowed > hashes.txt
)

for /f "tokens=1,2 delims= " %%i in (hash.txt) do call :WriteLine %%i %%j
%ZipIt% "hashes.zip" hashes.txt
del /f /q hash*.txt
del /f /q CRC32.exe
popd
REM end CRC32

if not exist %Errors% echo "No errors!" >> %NoErrors%

cd ..

:EOF
popd
goto :eof
:: END OF WORK

:WriteLine
for /F "tokens=1,2 delims=:" %%i in ('crc32.exe %~dpn1.zip') do echo %1 %2 %%j >> hashes.txt
goto :eof