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 SMPlayer and MPlayer.
10echo.
11echo This script will temporarily rename the smplayer-build and mplayer directories.
12echo Make sure these files ^& directories are not opened when running the script.
13echo.
14echo 1 - NSIS                          10 - NSIS [32-bit/64-bit]
15echo 2 - NSIS [64-bit]                 11 - Portable [32-bit/64-bit]
16echo 3 - Portable                      20 - Portable SFX [32-bit/64-bit]
17echo 4 - Portable [64-bit]
18echo 5 - Without MPlayer
19echo 6 - Without MPlayer [64-bit]
20echo.
21
22:: Relative directory of all the source files to this script
23set TOP_LEVEL_DIR=..
24
25:: Reset in case ran again in same command prompt instance
26set ALL_PKG_VER=
27set VER_MAJOR=
28set VER_MINOR=
29set VER_BUILD=
30set VER_REVISION=
31set VER_REV_CMD=
32set MAKENSIS_EXE_PATH=
33
34:: NSIS path
35if exist "nsis_path" (
36  for /f "tokens=*" %%y in ('type nsis_path') do if exist %%y set MAKENSIS_EXE_PATH="%%y"
37)
38
39if not defined MAKENSIS_EXE_PATH (
40  for %%x in ("%PROGRAMFILES(X86)%\NSIS\Unicode\makensis.exe" "%PROGRAMFILES%\NSIS\Unicode\makensis.exe") do if exist %%x set MAKENSIS_EXE_PATH=%%x
41)
42
43if not defined MAKENSIS_EXE_PATH (
44  echo Warning: Unable to locate NSIS in the default path, create the file ^'nsis_path^' with the full correct path
45  echo to makensis.exe or the existing ^'nsis_path^' may be incorrect.
46  echo.
47)
48
49:: Works only in Vista+
50where /q where.exe 2>NUL && (
51  where /q 7za.exe 2>NUL || (
52  echo Warning: 7za.exe not found in path or current directory!
53  echo.
54  )
55)
56
57set SMPLAYER_DIR=%TOP_LEVEL_DIR%\smplayer-build
58set SMPLAYER_DIR64=%TOP_LEVEL_DIR%\smplayer-build64
59set MPLAYER_DIR=%TOP_LEVEL_DIR%\mplayer
60set OUTPUT_DIR=%TOP_LEVEL_DIR%\output
61set PORTABLE_EXE_DIR=%TOP_LEVEL_DIR%\portable
62
63:cmdline_parsing
64if "%1" == ""               goto reask
65for %%w in (1 2 3 4 5 6 10 11 20) do (
66  if "%1" == "%%w" (
67    set USER_CHOICE=%%w
68    goto pkgver
69  )
70)
71
72echo Unknown option: "%1"
73echo.
74goto superend
75
76:reask
77set USER_CHOICE=
78set /P USER_CHOICE="Choose an action: "
79echo.
80
81for %%z in (1 2 3 4 5 6 10 11 20) do if "%USER_CHOICE%" == "%%z" goto pkgver
82if "%USER_CHOICE%" == ""  goto superend
83goto reask
84
85:pkgver
86if exist "pkg_version" (
87  for /f "tokens=*" %%i in ('type pkg_version') do set ALL_PKG_VER=%%i
88  goto parse_version
89)
90
91echo Format: VER_MAJOR.VER_MINOR.VER_BUILD[.VER_REVISION]
92echo VER_REVISION is optional (set to 0 if blank)
93:pkgver_manual
94echo.
95set ALL_PKG_VER=
96set VER_MAJOR=
97set VER_MINOR=
98set VER_BUILD=
99set VER_REVISION=
100set VER_REV_CMD=
101set /p ALL_PKG_VER="Version: "
102echo.
103
104:parse_version
105for /f "tokens=1 delims=." %%j in ("%ALL_PKG_VER%")  do set VER_MAJOR=%%j
106for /f "tokens=2 delims=." %%k in ("%ALL_PKG_VER%")  do set VER_MINOR=%%k
107for /f "tokens=3 delims=." %%l in ("%ALL_PKG_VER%")  do set VER_BUILD=%%l
108for /f "tokens=4 delims=." %%m in ("%ALL_PKG_VER%")  do set VER_REVISION=%%m
109
110echo %VER_MAJOR%|findstr /r /c:"^[0-9][0-9]*$" >nul
111if errorlevel 1 (
112  echo Invalid version string. VER_MAJOR is not defined or is not a number [#.x.x]
113  goto pkgver_manual & ver>nul
114)
115
116echo %VER_MINOR%|findstr /r /c:"^[0-9][0-9]*$" >nul
117if errorlevel 1 (
118  echo Invalid version string. VER_MINOR is not defined or is not a number [x.#.x]
119  goto pkgver_manual & ver>nul
120)
121echo %VER_BUILD%|findstr /r /c:"^[0-9][0-9]*$" >nul
122if errorlevel 1 (
123  echo Invalid version string. VER_BUILD is not defined or is not a number [x.x.#]
124  goto pkgver_manual & ver>nul
125)
126
127if defined VER_REVISION (
128  echo %VER_REVISION%|findstr /r /c:"^[0-9][0-9]*$" >nul
129  if errorlevel 1 (
130    echo Invalid version string. VER_REVISION is not a number [x.x.x.#]
131    goto pkgver_manual & ver>nul
132  ) else (
133    set VER_REV_CMD=/DVER_REVISION=%VER_REVISION% & ver>nul
134  )
135) else (
136  set VER_REV_CMD=
137)
138
139if not defined VER_REVISION (
140  set PORTABLE_PKG_VER=%ALL_PKG_VER%.0
141) else (
142  set PORTABLE_PKG_VER=%ALL_PKG_VER%
143)
144
145if "%USER_CHOICE%" == "1"  goto nsispkg
146if "%USER_CHOICE%" == "2"  goto nsispkg64
147if "%USER_CHOICE%" == "3"  goto portable
148if "%USER_CHOICE%" == "4"  goto portable64
149if "%USER_CHOICE%" == "5"  goto nomplayer
150if "%USER_CHOICE%" == "6"  goto nomplayer64
151if "%USER_CHOICE%" == "10"  goto nsispkg
152if "%USER_CHOICE%" == "11"  goto portable
153if "%USER_CHOICE%" == "20"  goto portablesfx
154:: Should not happen
155goto end
156
157:nsispkg
158
159echo --- SMPlayer NSIS Package [32-bit] ---
160echo.
161
162if exist %TOP_LEVEL_DIR%\smplayer-build (
163  %MAKENSIS_EXE_PATH% /V3 /DVER_MAJOR=%VER_MAJOR% /DVER_MINOR=%VER_MINOR% /DVER_BUILD=%VER_BUILD% %VER_REV_CMD% %TOP_LEVEL_DIR%\smplayer.nsi
164)
165
166if not "%USER_CHOICE%" == "10"  goto end
167
168:nsispkg64
169echo --- SMPlayer NSIS Package [64-bit] ---
170echo.
171
172if exist %TOP_LEVEL_DIR%\smplayer-build64 (
173  %MAKENSIS_EXE_PATH% /V3 /DVER_MAJOR=%VER_MAJOR% /DVER_MINOR=%VER_MINOR% /DVER_BUILD=%VER_BUILD% %VER_REV_CMD% /DWIN64 %TOP_LEVEL_DIR%\smplayer.nsi
174)
175
176goto end
177
178:portable
179echo --- SMPlayer Portable Package [32-bit] ---
180echo.
181
182if not exist %SMPLAYER_DIR% (
183  echo SMPlayer sources missing.
184  goto end
185)
186
187REM Check for portable exes
188if not exist "%PORTABLE_EXE_DIR%\smplayer-portable.exe" (
189  echo SMPlayer portable EXE not found!
190  goto end
191)
192
193REM if not exist "%PORTABLE_EXE_DIR%\smtube-portable.exe" (
194REM  echo Warning: SMTube portable EXE not found!
195REM )
196
197if exist "%SMPLAYER_DIR%\QtCore4.dll" (
198  set PORTABLE_DIR_NAME=smplayer-portable-%PORTABLE_PKG_VER%-Qt4
199) else (
200  set PORTABLE_DIR_NAME=smplayer-portable-%PORTABLE_PKG_VER%
201)
202
203ren "%SMPLAYER_DIR%" "%PORTABLE_DIR_NAME%"
204set SMPLAYER_PORTABLE_DIR="%TOP_LEVEL_DIR%\%PORTABLE_DIR_NAME%"
205
206if not exist "%SMPLAYER_PORTABLE_DIR%" (
207  echo Oops! Unable to find renamed directory, make sure no files are opened.
208  goto end
209)
210
211echo Backing up files...
212
213ren "%SMPLAYER_PORTABLE_DIR%\smplayer.exe" smplayer.bak
214REM ren "%SMPLAYER_PORTABLE_DIR%\smtube.exe" smtube.bak
215
216echo Creating screenshots dir...
217
218mkdir "%SMPLAYER_PORTABLE_DIR%\screenshots"
219
220echo Creating smplayer.ini...
221
222echo [%%General]> "%SMPLAYER_PORTABLE_DIR%\smplayer.ini"
223echo screenshot_directory=.\\screenshots>> "%SMPLAYER_PORTABLE_DIR%\smplayer.ini"
224echo.>> "%SMPLAYER_PORTABLE_DIR%\smplayer.ini"
225echo [smplayer]>> "%SMPLAYER_PORTABLE_DIR%\smplayer.ini"
226echo check_if_upgraded=false>> "%SMPLAYER_PORTABLE_DIR%\smplayer.ini"
227
228echo Creating smplayer_orig.ini...
229
230echo [%%General]> "%SMPLAYER_PORTABLE_DIR%\smplayer_orig.ini"
231echo screenshot_directory=.\\screenshots>> "%SMPLAYER_PORTABLE_DIR%\smplayer_orig.ini"
232echo.>> "%SMPLAYER_PORTABLE_DIR%\smplayer_orig.ini"
233echo [smplayer]>> "%SMPLAYER_PORTABLE_DIR%\smplayer_orig.ini"
234echo check_if_upgraded=false>> "%SMPLAYER_PORTABLE_DIR%\smplayer_orig.ini"
235
236REM echo Creating mplayer config...
237
238REM echo ^<cachedir^>../fontconfig^</cachedir^>> "%SMPLAYER_PORTABLE_DIR%\mplayer\fonts\local.conf"
239
240echo Copying portable .exe...
241
242copy /y "%PORTABLE_EXE_DIR%\smplayer-portable.exe" "%SMPLAYER_PORTABLE_DIR%\smplayer.exe"
243REM copy /y "%PORTABLE_EXE_DIR%\smtube-portable.exe" "%SMPLAYER_PORTABLE_DIR%\smtube.exe"
244
245echo Finalizing package...
2467za a -t7z "%OUTPUT_DIR%\%PORTABLE_DIR_NAME%.7z" "%SMPLAYER_PORTABLE_DIR%" -xr!*.bak* -xr!qxtcore.dll -xr!mplayer64.exe -xr!mencoder.exe -xr!mencoder64.exe -xr!mplayer64.exe.debug -xr!mencoder64.exe.debug -xr!mplayer.exe.debug -xr!mencoder.exe.debug -xr!gdb.exe -xr!gdb64.exe -xr!vfw2menc.exe -xr!buildinfo -xr!buildinfo64 -xr!buildinfo-mencoder-32 -xr!buildinfo-mencoder-debug-32 -xr!buildinfo-mplayer-32 -xr!buildinfo-mplayer-debug-32 -xr!buildinfo-mencoder-64 -xr!buildinfo-mencoder-debug-64 -xr!buildinfo-mplayer-64 -xr!buildinfo-mplayer-debug-64 -xr!mpv64.exe -xr!mpv64.com -xr!d3dcompiler_43-64.dll -xr!libaacs64.dll -xr!libbdplus64.dll -mx9 >nul
247
248echo.
249echo Restoring source folder(s) back to its original state...
250echo.
251rmdir "%SMPLAYER_PORTABLE_DIR%\screenshots"
252del "%SMPLAYER_PORTABLE_DIR%\smplayer.ini"
253del "%SMPLAYER_PORTABLE_DIR%\smplayer_orig.ini"
254del "%SMPLAYER_PORTABLE_DIR%\smplayer.exe"
255REM del "%SMPLAYER_PORTABLE_DIR%\smtube.exe"
256REM del "%SMPLAYER_PORTABLE_DIR%\mplayer\fonts\local.conf"
257ren "%SMPLAYER_PORTABLE_DIR%\smplayer.bak" smplayer.exe
258REM ren "%SMPLAYER_PORTABLE_DIR%\smtube.bak" smtube.exe
259ren "%SMPLAYER_PORTABLE_DIR%" smplayer-build
260
261if not "%USER_CHOICE%" == "11"  goto end
262
263:portable64
264echo --- SMPlayer Portable Package [64-bit] ---
265echo.
266
267if not exist %SMPLAYER_DIR64% (
268  echo SMPlayer sources missing.
269  goto end
270)
271
272REM Check for portable exes
273if not exist "%PORTABLE_EXE_DIR%\smplayer-portable64.exe" (
274  echo SMPlayer portable EXE not found!
275  goto end
276)
277
278REM if not exist "%PORTABLE_EXE_DIR%\smtube-portable64.exe" (
279REM  echo Warning: SMTube portable EXE not found!
280REM )
281
282set PORTABLE_DIR_NAME=smplayer-portable-%PORTABLE_PKG_VER%-x64
283
284ren "%SMPLAYER_DIR64%" "%PORTABLE_DIR_NAME%"
285set SMPLAYER_PORTABLE_DIR="%TOP_LEVEL_DIR%\%PORTABLE_DIR_NAME%"
286
287if not exist "%SMPLAYER_PORTABLE_DIR%" (
288  echo Oops! Unable to find renamed directory, make sure no files are opened.
289  goto end
290)
291
292echo Backing up files...
293
294ren "%SMPLAYER_PORTABLE_DIR%\smplayer.exe" smplayer.bak
295REM ren "%SMPLAYER_PORTABLE_DIR%\smtube.exe" smtube.bak
296ren "%SMPLAYER_PORTABLE_DIR%\mplayer\mplayer.exe" mplayer.exe.bak32
297ren "%SMPLAYER_PORTABLE_DIR%\mplayer\libaacs.dll" libaacs.dll.bak32
298ren "%SMPLAYER_PORTABLE_DIR%\mplayer\libbdplus.dll" libbdplus.dll.bak32
299ren "%SMPLAYER_PORTABLE_DIR%\mplayer\mplayer64.exe" mplayer.exe
300ren "%SMPLAYER_PORTABLE_DIR%\mplayer\libaacs64.dll" libaacs.dll
301ren "%SMPLAYER_PORTABLE_DIR%\mplayer\libbdplus64.dll" libbdplus.dll
302
303if exist "%SMPLAYER_PORTABLE_DIR%\mpv\fonts" (
304  ren "%SMPLAYER_PORTABLE_DIR%\mpv\fonts" fonts.bak32
305)
306if exist "%SMPLAYER_PORTABLE_DIR%\mpv\mpv" (
307  ren "%SMPLAYER_PORTABLE_DIR%\mpv\mpv" mpv.bak32
308)
309
310ren "%SMPLAYER_PORTABLE_DIR%\mpv\mpv.exe" mpv.exe.bak32
311ren "%SMPLAYER_PORTABLE_DIR%\mpv\mpv.com" mpv.com.bak32
312ren "%SMPLAYER_PORTABLE_DIR%\mpv\d3dcompiler_43.dll" d3dcompiler_43.dll.bak32
313ren "%SMPLAYER_PORTABLE_DIR%\mpv\mpv64.exe" mpv.exe
314ren "%SMPLAYER_PORTABLE_DIR%\mpv\mpv64.com" mpv.com
315ren "%SMPLAYER_PORTABLE_DIR%\mpv\d3dcompiler_43-64.dll" d3dcompiler_43.dll
316
317echo Creating screenshots dir...
318
319mkdir "%SMPLAYER_PORTABLE_DIR%\screenshots"
320
321echo Creating smplayer.ini...
322
323echo [%%General]> "%SMPLAYER_PORTABLE_DIR%\smplayer.ini"
324echo screenshot_directory=.\\screenshots>> "%SMPLAYER_PORTABLE_DIR%\smplayer.ini"
325echo.>> "%SMPLAYER_PORTABLE_DIR%\smplayer.ini"
326echo [smplayer]>> "%SMPLAYER_PORTABLE_DIR%\smplayer.ini"
327echo check_if_upgraded=false>> "%SMPLAYER_PORTABLE_DIR%\smplayer.ini"
328
329echo Creating smplayer_orig.ini...
330
331echo [%%General]> "%SMPLAYER_PORTABLE_DIR%\smplayer_orig.ini"
332echo screenshot_directory=.\\screenshots>> "%SMPLAYER_PORTABLE_DIR%\smplayer_orig.ini"
333echo.>> "%SMPLAYER_PORTABLE_DIR%\smplayer_orig.ini"
334echo [smplayer]>> "%SMPLAYER_PORTABLE_DIR%\smplayer_orig.ini"
335echo check_if_upgraded=false>> "%SMPLAYER_PORTABLE_DIR%\smplayer_orig.ini"
336
337REM echo Creating mplayer config...
338
339REM echo ^<cachedir^>../fontconfig^</cachedir^>> "%SMPLAYER_PORTABLE_DIR%\mplayer\fonts\local.conf"
340
341echo Copying portable .exe...
342
343copy /y "%PORTABLE_EXE_DIR%\smplayer-portable64.exe" "%SMPLAYER_PORTABLE_DIR%\smplayer.exe"
344REM copy /y "%PORTABLE_EXE_DIR%\smtube-portable64.exe" "%SMPLAYER_PORTABLE_DIR%\smtube.exe"
345
346echo Finalizing package...
3477za a -t7z "%OUTPUT_DIR%\%PORTABLE_DIR_NAME%.7z" "%SMPLAYER_PORTABLE_DIR%" -xr!*.bak* -xr!qxtcore.dll -xr!mencoder.exe -xr!mencoder64.exe  -xr!mplayer64.exe.debug -xr!mencoder64.exe.debug -xr!mplayer.exe.debug -xr!mencoder.exe.debug -xr!gdb.exe -xr!gdb64.exe -xr!vfw2menc.exe -xr!codecs -xr!buildinfo -xr!buildinfo64 -xr!buildinfo-mencoder-32 -xr!buildinfo-mencoder-debug-32 -xr!buildinfo-mplayer-32 -xr!buildinfo-mplayer-debug-32 -xr!buildinfo-mencoder-64 -xr!buildinfo-mencoder-debug-64 -xr!buildinfo-mplayer-64 -xr!buildinfo-mplayer-debug-64 -mx9 >nul
348
349echo.
350echo Restoring source folder(s) back to its original state...
351echo.
352rmdir "%SMPLAYER_PORTABLE_DIR%\screenshots"
353del "%SMPLAYER_PORTABLE_DIR%\smplayer.ini"
354del "%SMPLAYER_PORTABLE_DIR%\smplayer_orig.ini"
355del "%SMPLAYER_PORTABLE_DIR%\smplayer.exe"
356REM del "%SMPLAYER_PORTABLE_DIR%\smtube.exe"
357ren "%SMPLAYER_PORTABLE_DIR%\mplayer\mplayer.exe" mplayer64.exe
358ren "%SMPLAYER_PORTABLE_DIR%\mplayer\libaacs.dll" libaacs64.dll
359ren "%SMPLAYER_PORTABLE_DIR%\mplayer\libbdplus.dll" libbdplus64.dll
360ren "%SMPLAYER_PORTABLE_DIR%\mplayer\mplayer.exe.bak32" mplayer.exe
361ren "%SMPLAYER_PORTABLE_DIR%\mplayer\libaacs.dll.bak32" libaacs.dll
362ren "%SMPLAYER_PORTABLE_DIR%\mplayer\libbdplus.dll.bak32" libbdplus.dll
363REM del "%SMPLAYER_PORTABLE_DIR%\mplayer\fonts\local.conf"
364ren "%SMPLAYER_PORTABLE_DIR%\smplayer.bak" smplayer.exe
365REM ren "%SMPLAYER_PORTABLE_DIR%\smtube.bak" smtube.exe
366
367ren "%SMPLAYER_PORTABLE_DIR%\mpv\mpv.exe" mpv64.exe
368ren "%SMPLAYER_PORTABLE_DIR%\mpv\mpv.com" mpv64.com
369ren "%SMPLAYER_PORTABLE_DIR%\mpv\d3dcompiler_43.dll" d3dcompiler_43-64.dll
370ren "%SMPLAYER_PORTABLE_DIR%\mpv\mpv.exe.bak32" mpv.exe
371ren "%SMPLAYER_PORTABLE_DIR%\mpv\mpv.com.bak32" mpv.com
372ren "%SMPLAYER_PORTABLE_DIR%\mpv\d3dcompiler_43.dll.bak32" d3dcompiler_43.dll
373
374if exist "%SMPLAYER_PORTABLE_DIR%\mpv\fonts.bak32" (
375  ren "%SMPLAYER_PORTABLE_DIR%\mpv\fonts.bak32" fonts
376)
377if exist "%SMPLAYER_PORTABLE_DIR%\mpv\mpv.bak32" (
378  ren "%SMPLAYER_PORTABLE_DIR%\mpv\mpv.bak32" mpv
379)
380
381ren "%SMPLAYER_PORTABLE_DIR%" smplayer-build64
382
383goto end
384
385:portablesfx
386
387if exist %PORTABLE_EXE_DIR%\smplayer-portable.exe (
388  if exist %TOP_LEVEL_DIR%\smplayer-build (
389  %MAKENSIS_EXE_PATH% /V3 /DVER_MAJOR=%VER_MAJOR% /DVER_MINOR=%VER_MINOR% /DVER_BUILD=%VER_BUILD% %VER_REV_CMD% %TOP_LEVEL_DIR%\smportable.nsi
390  )
391)
392
393if exist %PORTABLE_EXE_DIR%\smplayer-portable64.exe (
394  if exist %TOP_LEVEL_DIR%\smplayer-build64 (
395  %MAKENSIS_EXE_PATH% /V3 /DVER_MAJOR=%VER_MAJOR% /DVER_MINOR=%VER_MINOR% /DVER_BUILD=%VER_BUILD% %VER_REV_CMD% /DWIN64 %TOP_LEVEL_DIR%\smportable.nsi
396  )
397)
398
399goto end
400
401:nomplayer
402echo --- Creating SMPlayer w/o MPlayer Package [32-bit] ---
403echo.
404
405ren %SMPLAYER_DIR% smplayer-%ALL_PKG_VER%
406set SMPLAYER_NOMP_DIR=%TOP_LEVEL_DIR%\smplayer-%ALL_PKG_VER%
407
408::
409echo Finalizing package...
4107za a -t7z %OUTPUT_DIR%\smplayer-%ALL_PKG_VER%_without_mplayer.7z %SMPLAYER_NOMP_DIR% -xr!mplayer -mx9 >nul
411
412ren %SMPLAYER_NOMP_DIR% smplayer-build
413
414echo.
415echo Restoring source folder(s) back to its original state....
416
417goto end
418
419:nomplayer64
420echo --- Creating SMPlayer w/o MPlayer Package [64-bit] ---
421echo.
422
423ren %SMPLAYER_DIR64% smplayer-%ALL_PKG_VER%-x64
424set SMPLAYER_NOMP_DIR=%TOP_LEVEL_DIR%\smplayer-%ALL_PKG_VER%-x64
425
426::
427echo Finalizing package...
4287za a -t7z %OUTPUT_DIR%\smplayer-%ALL_PKG_VER%-x64_without_mplayer.7z %SMPLAYER_NOMP_DIR% -xr!mplayer -mx9 >nul
429
430ren %SMPLAYER_NOMP_DIR% smplayer-build64
431
432echo.
433echo Restoring source folder(s) back to its original state....
434
435goto end
436
437:end
438
439timeout /t 10
440
441:superend
442set ALL_PKG_VER=
443set VER_MAJOR=
444set VER_MINOR=
445set VER_BUILD=
446set VER_REVISION=
447