1@echo off
2if exist "turnon_echo" (
3  @echo on
4)
5
6:: Reset working dir especially when using 'Run as administrator'
7@cd /d "%~dp0"
8
9echo This batch file can help you to create a packages for SMTube.
10echo.
11echo 1 - NSIS
12echo 2 - NSIS [64-bit]
13echo.
14
15:: Relative directory of all the source files to this script
16set TOP_LEVEL_DIR=..
17
18set OUTPUT_DIR=%TOP_LEVEL_DIR%\output
19
20:: Reset in case ran again in same command prompt instance
21set ALL_PKG_VER=
22set VER_MAJOR=
23set VER_MINOR=
24set VER_BUILD=
25set VER_REVISION=
26set VER_REV_CMD=
27set MAKENSIS_EXE_PATH=
28
29:: NSIS path
30if exist "nsis_path" (
31  for /f "tokens=*" %%y in ('type nsis_path') do if exist %%y set MAKENSIS_EXE_PATH="%%y"
32)
33
34if not defined MAKENSIS_EXE_PATH (
35  for %%x in ("%PROGRAMFILES(X86)%\NSIS\Bin\makensis.exe" "%PROGRAMFILES%\NSIS\Bin\makensis.exe") do if exist %%x set MAKENSIS_EXE_PATH=%%x
36)
37
38if not defined MAKENSIS_EXE_PATH (
39  echo Warning: Unable to locate NSIS in the default path, create the file ^'nsis_path^' with the full correct path
40  echo to makensis.exe or the existing ^'nsis_path^' may be incorrect.
41  echo.
42)
43
44:: Works only in Vista+
45REM where /q where.exe 2>NUL && (
46REM   where /q 7za.exe 2>NUL || (
47REM    echo Warning: 7za.exe not found in path or current directory!
48REM    echo.
49REM   )
50REM )
51
52:cmdline_parsing
53if "%1" == ""               goto reask
54for %%w in (1 2) do (
55  if "%1" == "%%w" (
56    set USER_CHOICE=%%w
57    goto pkgver
58  )
59)
60
61echo Unknown option: "%1"
62echo.
63goto superend
64
65:reask
66set USER_CHOICE=
67set /P USER_CHOICE="Choose an action: "
68echo.
69
70for %%z in (1 2) do if "%USER_CHOICE%" == "%%z" goto pkgver
71if "%USER_CHOICE%" == ""  goto superend
72goto reask
73
74:pkgver
75if exist "pkg_version" (
76  for /f "tokens=*" %%i in ('type pkg_version') do set ALL_PKG_VER=%%i
77  goto parse_version
78)
79
80echo Format: VER_MAJOR.VER_MINOR.VER_BUILD[.VER_REVISION]
81echo VER_REVISION is optional (set to 0 if blank)
82:pkgver_manual
83echo.
84set ALL_PKG_VER=
85set VER_MAJOR=
86set VER_MINOR=
87set VER_BUILD=
88set VER_REVISION=
89set VER_REV_CMD=
90set /p ALL_PKG_VER="Version: "
91echo.
92
93:parse_version
94for /f "tokens=1 delims=." %%j in ("%ALL_PKG_VER%")  do set VER_MAJOR=%%j
95for /f "tokens=2 delims=." %%k in ("%ALL_PKG_VER%")  do set VER_MINOR=%%k
96for /f "tokens=3 delims=." %%l in ("%ALL_PKG_VER%")  do set VER_BUILD=%%l
97for /f "tokens=4 delims=." %%m in ("%ALL_PKG_VER%")  do set VER_REVISION=%%m
98
99echo %VER_MAJOR%|findstr /r /c:"^[0-9][0-9]*$" >nul
100if errorlevel 1 (
101  echo Invalid version string. VER_MAJOR is not defined or is not a number [#.x.x]
102  goto pkgver_manual & ver>nul
103)
104
105echo %VER_MINOR%|findstr /r /c:"^[0-9][0-9]*$" >nul
106if errorlevel 1 (
107  echo Invalid version string. VER_MINOR is not defined or is not a number [x.#.x]
108  goto pkgver_manual & ver>nul
109)
110echo %VER_BUILD%|findstr /r /c:"^[0-9][0-9]*$" >nul
111if errorlevel 1 (
112  echo Invalid version string. VER_BUILD is not defined or is not a number [x.x.#]
113  goto pkgver_manual & ver>nul
114)
115
116if defined VER_REVISION (
117  echo %VER_REVISION%|findstr /r /c:"^[0-9][0-9]*$" >nul
118  if errorlevel 1 (
119    echo Invalid version string. VER_REVISION is not a number [x.x.x.#]
120    goto pkgver_manual & ver>nul
121  ) else (
122    set VER_REV_CMD=/DVER_REVISION=%VER_REVISION% & ver>nul
123  )
124) else (
125  set VER_REV_CMD=
126)
127
128if "%USER_CHOICE%" == "1"  goto nsispkg
129if "%USER_CHOICE%" == "2"  goto nsispkg64
130:: Should not happen
131goto end
132
133:nsispkg
134
135echo --- SMTube NSIS Package [32-bit] ---
136echo.
137
138%MAKENSIS_EXE_PATH% /V3 /DVER_MAJOR=%VER_MAJOR% /DVER_MINOR=%VER_MINOR% /DVER_BUILD=%VER_BUILD% %VER_REV_CMD% %TOP_LEVEL_DIR%\smtube.nsi
139
140goto end
141
142:nsispkg64
143echo --- SMTube NSIS Package [64-bit] ---
144echo.
145
146%MAKENSIS_EXE_PATH% /V3 /DVER_MAJOR=%VER_MAJOR% /DVER_MINOR=%VER_MINOR% /DVER_BUILD=%VER_BUILD% %VER_REV_CMD% /DWIN64 %TOP_LEVEL_DIR%\smtube.nsi
147
148goto end
149
150:end
151
152REM pause
153
154:superend
155set ALL_PKG_VER=
156set VER_MAJOR=
157set VER_MINOR=
158set VER_BUILD=
159set VER_REVISION=
160