@echo off

:: Tip
:: If you want to avoid mkdir - make sure to append a \ on the end of any directories you want to copy
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if "%1" == "" goto help

@echo on

:: We're using VS 2012 to build the package now
call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\vsvars32.bat"

:: Clean build outputs
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
rmdir /S/Q ..\_package
del /F "*.log"
del /F .\*.zip

:: Clean up generated files
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
rmdir /S/Q .\pipeline\GameTalkConfig\bin
rmdir /S/Q .\pipeline\GameTalkConfig\obj
rmdir /S/Q .\tools\FileTalk\bin
rmdir /S/Q .\tools\FileTalk\obj
rmdir /S/Q .\tools\FileTalkInstaller\bin
rmdir /S/Q .\tools\FileTalkInstaller\obj
rmdir /S/Q .\tools\FileTalkMessages\bin
rmdir /S/Q .\tools\FileTalkMessages\obj
rmdir /S/Q .\tools\FileTalkServer\bin
rmdir /S/Q .\tools\FileTalkServer\obj
rmdir /S/Q .\tools\GameTalk\bin
rmdir /S/Q .\tools\GameTalk\obj
rmdir /S/Q .\tools\GameTalkMessages\bin
rmdir /S/Q .\tools\GameTalkMessages\obj
rmdir /S/Q .\tools\GameTalkRouter\bin
rmdir /S/Q .\tools\GameTalkRouter\obj
rmdir /S/Q .\tools\GameTalkServer\bin
rmdir /S/Q .\tools\GameTalkServer\obj
rmdir /S/Q .\tools\GameTalkServer-32bit\bin
rmdir /S/Q .\tools\GameTalkServer-32bit\obj
rmdir /S/Q .\tools\GameTalkViewer\bin
rmdir /S/Q .\tools\GameTalkViewer\obj
rmdir /S/Q .\tools\GameTalkWin32\Debug
rmdir /S/Q .\tools\GameTalkWin32\Release
rmdir /S/Q .\tools\Microsoft.DevKits.Xenon\Debug
rmdir /S/Q .\tools\Microsoft.DevKits.Xenon\Release

:: Clean up the project/solution generated files
del /F .\tools\GameTalk.ncb
del /F .\tools\GameTalk.suo
del /F .\tools\GameTalk.sdf

:: Copy Source
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
xcopy /S/Y .\*.* ..\_package\dev\
rmdir /S/Q ..\_package\dev\tools\GameTalkViewer\Assemblies
del /F ..\_package\dev\tools\GameTalk\GameServer\GameTalkMessages.dll
del /F ..\_package\dev\tools\GameTalk\GameServer\GameTalkRouter.dll
del /F ..\_package\dev\tools\GameTalk\GameServer\GameTalkServer.exe
del /F ..\_package\dev\tools\GameTalk\GameServer\GameTalkServer-32bit.exe
del /F/Q ..\_package\dev\tools\GameTalk\UsbService\*.*
del /F ..\_package\dev\tools\GameTalk\GameTalkViewer\GameTalkViewer.exe
:: Delete all SandCastle exectuable files - since it apparently makes the package too large as well
rmdir /S/Q ..\_package\dev\docs\Tools\Sandcastle
del /F ..\_package\dev\docs\Tools\hhc.exe
del /F ..\_package\dev\docs\Tools\itcc.dll

:: Build
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
devenv.exe .\tools\gametalk.sln /build debug /out "package-tools-debug.log"
devenv.exe .\tools\gametalk.sln /build release /out "package-tools-release.log"
devenv.exe .\pipeline\gametalkconfig\gametalkconfig.sln /build debug /out "package-pipeline-debug.log"
devenv.exe .\pipeline\gametalkconfig\gametalkconfig.sln /build release /out "package-pipeline-release.log"

:: Publish runtime
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
xcopy /S/Y .\game ..\_package\
xcopy /S/Y .\scripts ..\_package\scripts\

:: Publish pipeline
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
mkdir ..\_package\bin\pipeline
copy .\pipeline\gametalkconfig\bin\release\*.exe ..\_package\bin\pipeline

:: Publish tool binaries
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
mkdir ..\_package\bin\clients\csharp\debug
copy .\tools\gametalkrouter\bin\debug\*.dll ..\_package\bin\clients\csharp\debug
copy .\tools\gametalkrouter\bin\debug\*.pdb ..\_package\bin\clients\csharp\debug
copy .\tools\filetalkinstaller\bin\debug\*.dll ..\_package\bin\clients\csharp\debug
copy .\tools\filetalkinstaller\bin\debug\*.exe ..\_package\bin\clients\csharp\debug
copy .\tools\filetalkinstaller\bin\debug\*.pdb ..\_package\bin\clients\csharp\debug
mkdir ..\_package\bin\clients\csharp\release
copy .\tools\gametalkrouter\bin\release\*.dll ..\_package\bin\clients\csharp\release
copy .\tools\filetalkinstaller\bin\release\*.dll ..\_package\bin\clients\csharp\release
copy .\tools\filetalkinstaller\bin\release\*.exe ..\_package\bin\clients\csharp\release
mkdir ..\_package\bin\clients\win32\debug
copy .\tools\gametalkwin32\debug\*.lib ..\_package\bin\clients\win32\debug
mkdir ..\_package\bin\clients\win32\release
copy .\tools\gametalkwin32\release\*.lib ..\_package\bin\clients\win32\release
mkdir ..\_package\bin\clients\win32\include
copy .\tools\gametalkwin32\GameTalkWin32.hpp ..\_package\bin\clients\win32\include

:: Publish docs
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
mkdir ..\_package\docs
xcopy /S/Y .\docs\*.ppt ..\_package\docs
xcopy /S/Y .\docs\*.txt ..\_package\docs
xcopy /S/Y .\docs\*.vsd ..\_package\docs
xcopy /S/Y .\docs\*.chm ..\_package\docs
xcopy /S/Y .\docs\*.doc ..\_package\docs

:: Publish manifest
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
copy .\Manifest.xml ..\_package
copy .\ReadMe.txt ..\_package
copy .\Changes.txt ..\_package
copy .\GameTalk.build ..\_package
copy .\masterconfig.xml ..\_package

:: Zip package
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
mkdir C:\GameTalk\%1\
xcopy /S/Y ..\_package\*.* C:\GameTalk\%1\
dir /b/s C:\GameTalk > list.txt
"C:\Program Files\WinRAR\WinRAR.exe" a GameTalk-%1.zip @.\list.txt
"C:\Program Files (x86)\WinRAR\WinRAR.exe" a GameTalk-%1.zip @.\list.txt
del /F .\list.txt
rmdir /S/Q C:\GameTalk\

goto end

:help
echo Packaging Help
echo     [version] specifies the version number to use such as 1.2.3.0

:end
