ProjectArcade
734 строки · 19.1 Кб
1@echo off
2setlocal EnableDelayedExpansion
3
4goto:rem
5---------------------------------------
6build.bat
7---------------------------------------
8This batch script is made to help download all the required software for RetroBat,
9to set the default configuration and to build the setup from sources.
10---------------------------------------
11:rem
12
13:: ---- BUILDER OPTION ----
14
15set retrobat_version=6.0.1
16set retroarch_version=1.16.0
17
18set get_batgui=0
19set get_batocera_ports=1
20set get_bios=1
21set get_decorations=1
22set get_default_theme=1
23set get_emulationstation=1
24set get_emulators=0
25set get_lrcores=0
26set get_retroarch=0
27set get_retrobat_binaries=1
28set get_system=1
29set get_wiimotegun=1
30
31:: ---- ARCHIVE OPTIONS ----
32
33:: archive_format: zip|7z
34:: archive_compression: 0|1|3|5|7|9
35
36set archive_format=zip
37set archive_compression=3
38
39:: ---- LOOP LIST ----
40
41set setup_compiler=ISCC
42
43set deps_list=(git !setup_compiler! 7za wget curl)
44set submodules_list=(bios decorations system)
45set packages_list=(retrobat_binaries batgui emulationstation default_theme batocera_ports mega_bezels retroarch roms wiimotegun)
46set legacy_cores_list=(4do emuscv fake08 hatarib imageviewer mame2014 mame2016)
47set emulators_black_list=(3dsen magicengine pico8 retroarch ryujinx steam teknoparrot yuzu yuzu-early-access)
48
49:: ---- GET STARTED ----
50
51set script_type=builder
52set user_choice=0
53set git_branch=master
54set branch=stable
55set release_version=null
56set log_file=build.log
57set exit_timeout=0
58
59:loop_arg
60
61if not "%1"=="" (
62
63if "%1"=="-config" (
64
65set custom_config=%2
66shift
67)
68
69shift
70goto :loop_arg
71)
72
73call :set_root
74call :set_install
75call :set_builder
76
77if %user_choice% NEQ 0 (
78
79if %user_choice% EQU 1 (
80call :get_packages
81call :set_config
82call :build_setup
83call :create_archive
84call :exit_door
85goto :eof
86)
87
88if %user_choice% EQU 2 (
89call :get_packages
90call :set_config
91call :exit_door
92goto :eof
93)
94
95if %user_choice% EQU 3 (
96call :build_setup
97call :exit_door
98goto :eof
99)
100
101if %user_choice% EQU 4 (
102call :create_archive
103call :exit_door
104goto :eof
105)
106
107if %user_choice% EQU 5 (
108call :butler_push
109call :exit_door
110goto :eof
111)
112)
113
114:: ---- UI ----
115
116call :banner
117
118echo This script can help you to download all the required
119echo softwares and build the RetroBat Setup with the NullSoft
120echo Scriptable Install System.
121echo +===========================================================+
122echo (1) - full compilation
123echo (2) - download, configure
124echo (3) - build setup executable
125echo (4) - archive
126if exist "!buildtools_path!\butler.exe" echo (5) - push
127echo (Q) - Quit
128echo +===========================================================+
129if not exist "!buildtools_path\butler.exe" choice /C 1234Q /N /T 20 /D 1 /M "Please type your choice here: "
130if exist "!buildtools_path\butler.exe" choice /C 12345Q /N /T 20 /D 1 /M "Please type your choice here: "
131echo +===========================================================+
132set user_choice=%ERRORLEVEL%
133
134if %user_choice% EQU 1 (
135
136call :get_packages
137call :set_config
138call :build_setup
139call :create_archive
140call :exit_door
141goto :eof
142)
143
144if %user_choice% EQU 2 (
145
146call :get_packages
147call :set_config
148call :exit_door
149goto :eof
150)
151
152if %user_choice% EQU 3 (
153
154call :build_setup
155call :exit_door
156goto :eof
157)
158
159if %user_choice% EQU 4 (
160
161call :create_archive
162call :exit_door
163goto :eof
164)
165
166if not exist "!buildtools_path\butler.exe" if %user_choice% EQU 5 (
167
168(set exit_code=0)
169call :exit_door
170goto :eof
171)
172
173if exist "!buildtools_path\butler.exe" if %user_choice% EQU 5 (
174
175call :butler_push
176call :exit_door
177goto :eof
178)
179
180if exist "!buildtools_path\butler.exe" if %user_choice% EQU 6 (
181
182(set exit_code=0)
183call :exit_door
184goto :eof
185)
186
187:: ---- LABELS ----
188
189:: ---- SET ROOT PATH ----
190
191:set_root
192
193set task=set_root
194
195set current_file=%~nx0
196set current_drive="%cd:~0,2%"
197set current_dir="%cd:~3%"
198set current_drive=%current_drive:"=%
199set current_dir=%current_dir:"=%
200set current_path=!current_drive!\!current_dir!
201set root_path=!current_path!
202
203if not "%log_file%" == "" if exist "!root_path!\%log_file%" del/Q "!root_path!\%log_file%" >nul
204(echo %date% %time% [START] Run: !current_file!)>> "!root_path!\%log_file%"
205(echo %date% %time% [LABEL] :!task!)>> "!root_path!\%log_file%"
206(echo %date% %time% [INFO] Current Path: "!current_path!")>> "!root_path!\%log_file%"
207
208goto :eof
209
210:: ---- SET INSTALL INFOS ----
211
212:set_install
213
214set task=set_install
215(echo %date% %time% [LABEL] :!task!)>> "!root_path!\%log_file%"
216
217:: ---- SET CUSTOM OPTIONS ----
218
219if not "!custom_config!" == "" if exist "!root_path!\!custom_config!" (
220
221for /f "delims=" %%x in (!root_path!\!custom_config!) do (set %%x)
222(echo %date% %time% [INFO] Using build config file: "!custom_config!")>> "!root_path!\%log_file%"
223)
224
225:: ---- SET TMP FILE ----
226
227set tmp_infos_file=!root_path!\rb_infos.tmp
228if not "%tmp_infos_file%" == "" if exist "!tmp_infos_file!" del/Q "!tmp_infos_file!"
229
230:: ---- CALL SHARED VARIABLES SCRIPT ----
231
232if exist "!root_path!\system\scripts\shared-variables.cmd" (
233
234cd "!root_path!\system\scripts"
235call shared-variables.cmd
236
237) else (
238
239(set exit_code=2)
240call :exit_door
241goto :eof
242)
243
244:: ---- GET INFOS STORED IN TMP FILE ----
245
246if exist "!tmp_infos_file!" (
247
248for /f "delims=" %%x in ('type "!tmp_infos_file!"') do (set "%%x")
249if not "%tmp_infos_file%" == "" del/Q "!tmp_infos_file!"
250
251) else (
252
253(set/A exit_code=2)
254call :exit_door
255goto :eof
256)
257
258(echo %date% %time% [INFO] Version: %name%-%retrobat_version%-%branch%)>> "!root_path!\%log_file%"
259(echo %date% %time% [INFO] Build Path: "!build_path!")>> "!root_path!\%log_file%"
260(echo %date% %time% [INFO] Download Path: "!download_path!")>> "!root_path!\%log_file%"
261
262:: ---- WINDOW TITLE ----
263
264title !name! builder script
265
266goto :eof
267
268:: ---- DEPENDENCIES CHECKING ----
269
270:set_builder
271
272set task=set_builder
273(echo %date% %time% [LABEL] :!task!)>> "!root_path!\%log_file%"
274
275call :banner
276
277echo :: SETTING BUILD ENVIRONMENT...
278
279if not exist "!build_path!\." md "!build_path!"
280if not exist "!download_path!\." md "!download_path!"
281
282(set/A found_total=0)
283
284if "%archx%"=="x86_64" (set "git_path=%ProgramFiles%\Git\cmd") else (set "git_path=%ProgramFiles(x86)%\Git\cmd")
285
286for %%i in %deps_list% do (
287
288(set/A found_%%i=0)
289(set/A found_total=!found_total!+1)
290(set package_name=%%i)
291(set buildtools_path=!root_path!\system\tools)
292
293if "!package_name!"=="git" (set buildtools_path=!git_path!)
294if "!package_name!"=="makensis" (set "buildtools_path=%ProgramFiles(x86)%\NSIS" & set "compiler_path=!buildtools_path!")
295if "!package_name!"=="ISCC" (set "buildtools_path=%ProgramFiles(x86)%\Inno Setup 6" & set "compiler_path=!buildtools_path!")
296
297if exist "!buildtools_path!\!package_name!.exe" (
298
299(set/A found_%%i=!found_%%i!+1)
300(echo %%i: found)
301(echo %date% %time% [INFO] %%i: found)>> "!root_path!\%log_file%"
302
303) else (
304
305(echo %%i: not found)
306(echo %date% %time% [INFO] %%i: not found)>> "!root_path!\%log_file%"
307)
308
309(set/A found_total=!found_total!-!found_%%i!)
310)
311
312if !found_total! NEQ 0 (
313
314(set/A exit_code=2)
315call :exit_door
316goto :eof
317)
318
319timeout /t 3 >nul
320
321goto :eof
322
323:: ---- GET PACKAGES ----
324
325:get_packages
326
327set task=get_packages
328(echo %date% %time% [LABEL] :!task!)>> "!root_path!\%log_file%"
329
330echo :: GETTING REQUIRED PACKAGES...
331
332cd !root_path!
333git submodule update --init
334
335if %ERRORLEVEL% NEQ 0 (
336
337(set/A exit_code=%ERRORLEVEL%)
338call :exit_door
339goto :eof
340)
341
342if "%get_retrobat_binaries%"=="1" (
343for %%i in (txt) do (xcopy "!root_path!\*.%%i" "!build_path!" /v /y)
344if exist "!build_path!\butler.exe" del/Q "!build_path!\butler.exe"
345
346(echo %date% %time% [INFO] retrobat_binaries copied to "!build_path!")>> "!root_path!\%log_file%"
347)
348
349for %%i in %submodules_list% do (
350
351if "!get_%%i!"=="1" (
352
353(set package_name=%%i)
354(set destination_path=!%%i_path!)
355
356if "!package_name!"=="bios" (set folder=bios)
357if "!package_name!"=="default_theme" (set folder=emulationstation\.emulationstation\themes\es-theme-carbon)
358if "!package_name!"=="decorations" (set folder=system\decorations)
359if "!package_name!"=="system" (set folder=system)
360
361xcopy "!root_path!\!folder!" "!destination_path!\" /s /e /v /y
362
363(echo %date% %time% [INFO] !package_name! copied to "!destination_path!")>> "!root_path!\%log_file%"
364)
365)
366
367for %%i in %packages_list% do (
368
369if "!get_%%i!"=="1" (
370
371(set package_name=%%i)
372(set package_file=%%i.7z)
373(set download_url=!%%i_url!)
374(set destination_path=!%%i_path!)
375
376if "!package_name!"=="retrobat_binaries" (set package_file=%%i_%git_branch%.7z)
377if "!package_name!"=="emulationstation" (set package_file=EmulationStation-Win32.zip)
378if "!package_name!"=="batocera_ports" (set package_file=batocera-ports.zip)
379if "!package_name!"=="retroarch" (set package_file=RetroArch.7z)
380if "!package_name!"=="wiimotegun" (set package_file=WiimoteGun.zip)
381if "!package_name!"=="default_theme" (set package_file=master.zip)
382
383call :download
384call :hash_file
385call :extract
386)
387)
388
389if "%get_lrcores%"=="1" (
390
391for /f "usebackq delims=" %%x in ("%system_path%\configgen\lrcores_names.lst") do (
392
393(set package_name=%%x)
394(set package_file=%%x_libretro.dll.zip)
395(set download_url=%lrcores_url%/!package_file!)
396(set destination_path=%lrcores_path%)
397
398call :download
399call :hash_file
400call :extract
401)
402)
403
404if "%get_emulators%"=="1" (
405
406for /f "usebackq delims=" %%x in ("%system_path%\configgen\emulators_names.lst") do (
407
408(set package_name=%%x)
409(set package_file=%%x.7z)
410(set download_url=%emulators_url%)
411(set destination_path=!emulators_path!\%%x)
412
413set skip=0
414
415for %%i in %emulators_black_list% do (
416
417if "!package_name!"=="%%i" (set skip=1)
418)
419
420if "!skip!"=="0" (
421
422call :download
423call :hash_file
424call :extract
425)
426)
427)
428
429goto :eof
430
431:: ---- SET RETROBAT CONFIG ----
432
433:set_config
434
435set task=set_config
436(echo %date% %time% [LABEL] :!task!)>> "!root_path!\%log_file%"
437
438echo :: SETTING CONFIG FILES...
439
440for /f "usebackq delims=" %%x in ("%system_path%\configgen\retrobat_tree.lst") do (if not exist "!build_path!\%%x\." md "!build_path!\%%x")
441for /f "usebackq delims=" %%x in ("%system_path%\configgen\emulators_names.lst") do (if not exist "!build_path!\emulators\%%x\." md "!build_path!\emulators\%%x")
442for /f "usebackq delims=" %%x in ("%system_path%\configgen\systems_names.lst") do (if not exist "!build_path!\roms\%%x\." md "!build_path!\roms\%%x")
443for /f "usebackq delims=" %%x in ("%system_path%\configgen\systems_names.lst") do (if not exist "!build_path!\saves\%%x\." md "!build_path!\saves\%%x")
444
445if exist "!build_path!\retrobat.exe" (
446
447"!build_path!\retrobat.exe" /NOF #GetConfigFiles
448"!build_path!\retrobat.exe" /NOF #SetEmulationStationSettings
449"!build_path!\retrobat.exe" /NOF #SetEmulatorsSettings
450
451if %ERRORLEVEL% NEQ 0 (
452(set/A exit_code=%ERRORLEVEL%)
453call :exit_door
454goto :eof
455)
456
457) else (
458
459(set/A exit_code=2)
460call :exit_door
461goto :eof
462)
463
464if exist "!build_path!\retrobat.ini" del/Q "!build_path!\retrobat.ini"
465
466if exist "!system_path!\templates\emulationstation\es_features.locale\." xcopy "!system_path!\templates\emulationstation\es_features.locale" "!emulationstation_path!\es_features.locale\" /s /e /v /y
467
468if exist "!system_path!\resources\emulationstation\video\*.mp4" xcopy /v /y "!system_path!\resources\emulationstation\video\*.mp4" "!build_path!\emulationstation\.emulationstation\video"
469if exist "!system_path!\resources\emulationstation\music\*.ogg" xcopy /v /y "!system_path!\resources\emulationstation\music\*.ogg" "!build_path!\emulationstation\.emulationstation\music"
470
471if not exist "!build_path!\system\version.info" (
472
473(set timestamp=%date:~6,4%%date:~3,2%%date:~0,2%)
474
475if "%branch%" == "stable" (
476(set release_version=%retrobat_version%-%branch%-%arch%)
477) else (
478(set release_version=%retrobat_version%-!timestamp!-%branch%-%arch%)
479)
480
481(echo|set/P=!release_version!)> "!build_path!\system\version.info"
482)
483
484echo build version is: !release_version!
485
486(set/A exit_code=0)
487
488goto :eof
489
490:: ---- BUILD RETROBAT SETUP ----
491
492:build_setup
493
494set task=build_setup
495(echo %date% %time% [LABEL] :!task!)>> "!root_path!\%log_file%"
496
497echo :: BUILDING RETROBAT SETUP...
498
499call :check_version
500
501set package_file=%name%-v%release_version%-setup.exe
502
503if not exist "!build_path!\%package_file%" (
504
505if "%setup_compiler%"=="makensis" ("!compiler_path!\makensis.exe" /V4 /DRELEASE_VERSION=%release_version% "!root_path!\installer\setup.nsi")
506if "%setup_compiler%"=="ISCC" if "%archx%"=="x86_64" ("!compiler_path!\ISCC.exe" /DMyAppVersion=%release_version% /DMyAppArchitecture=x64 /DSourceDir="!build_path!" /DInstallRootUrl="%installroot_url%/repo/%arch%" "!root_path!\installer\installer.iss")
507if "%setup_compiler%"=="ISCC" if "%archx%"=="x86" ("!compiler_path!\ISCC.exe" /DMyAppVersion=%release_version% /DMyAppArchitecture=x86 /DSourceDir="!build_path!" /DInstallRootUrl="%installroot_url%/repo/%arch%" "!root_path!\installer\installer.iss")
508)
509
510timeout/t 2 >nul
511
512if exist "!root_path!\installer\%package_file%" (
513
514(set/A exit_code=0)
515move /Y "!root_path!\installer\%package_file%" "!build_path!"
516(echo %date% %time% [INFO] Build "%package_file%" in "!build_path!")>> "!root_path!\%log_file%"
517)
518
519call :hash_file
520
521goto :eof
522
523:: ---- CREATE ARCHIVE ----
524
525:create_archive
526
527set task=create_archive
528(echo %date% %time% [LABEL] :!task!)>> "!root_path!\%log_file%"
529
530echo :: CREATING ARCHIVE...
531
532call :check_version
533
534set package_file=%name%-v%release_version%.%archive_format%
535set exclude_list=(exclude.lst hash_list.txt %name%-v%release_version%-setup.exe %name%-v%release_version%-setup.exe.sha256.txt %name%-v%release_version%.%archive_format% %name%-v%release_version%.%archive_format%.sha256.txt)
536
537if not exist "!build_path!\%package_file%" (
538
539if exist "!build_path!\exclude.lst" del/Q "!build_path!\exclude.lst"
540for %%i in %exclude_list% do ((echo "%%i")>> "!build_path!\exclude.lst")
541
542!buildtools_path!\7za.exe a -t%archive_format% "!build_path!\%package_file%" "!build_path!\*" -xr@"!build_path!\exclude.lst" -mx=%archive_compression%
543if exist "!build_path!\exclude.lst" del/Q "!build_path!\exclude.lst"
544)
545
546if exist "!build_path!\%package_file%" (
547
548(set/A exit_code=0)
549(echo %date% %time% [INFO] Created "%package_file%" in "!build_path!")>> "!root_path!\%log_file%"
550)
551
552call :hash_file
553
554goto :eof
555
556:: ---- BUTLER PUSH ----
557
558:: need butler installed
559
560:butler_push
561
562set task=butler_push
563(echo %date% %time% [LABEL] :!task!)>> "!root_path!\%log_file%"
564
565echo :: Butler push...
566
567call :check_version
568
569if exist "!build_path!\system\version.info" (
570
571if exist "!build_path!\%name%-v%release_version%-setup.exe" (
572
573"!buildtools_path\butler.exe" push "!build_path!\%name%-v%release_version%-setup.exe" retrobatofficial/retrobat:%arch%-%branch% --userversion-file "!build_path!\system\version.info"
574rem "!buildtools_path\butler.exe" butler push --ignore "!build_path!\%name%-v%release_version%-setup.exe" --ignore "!build_path!\%name%-v%release_version%-setup.exe.sha256.txt" --ignore "%name%-v%release_version%.%archive_format%" --ignore "%name%-v%release_version%.%archive_format%.sha256" --ignore "!build_path!\*.log" --ignore "!build_path!\hash_list.txt" --ignore "!build_path!\emulationstation\.emulationstation\es_settings.cfg" "!build_path!\" retrobatofficial/retrobat:%arch%-%branch% --userversion-file "!build_path!\system\version.info"
575(set/A exit_code=%ERRORLEVEL%)
576)
577
578if exist "!build_path!\%name%-v%release_version%-full-setup.exe" (
579
580"!buildtools_path\butler.exe" push "!build_path!\%name%-v%release_version%-full-setup.exe" retrobatofficial/retrobat:%arch%-%branch% --userversion-file "!build_path!\system\version.info"
581rem "!buildtools_path\butler.exe" push --ignore "!build_path!\%name%-v%release_version%-full-setup.exe" --ignore "!build_path!\%name%-v%release_version%-full-setup.exe.sha256.txt" --ignore "%name%-v%release_version%.%archive_format%" --ignore "%name%-v%release_version%.%archive_format%.sha256" --ignore "!build_path!\*.log" --ignore "!build_path!\hash_list.txt" --ignore "!build_path!\emulationstation\.emulationstation\es_settings.cfg" "!build_path!\" retrobatofficial/retrobat:%arch%-%branch% --userversion-file "!build_path!\system\version.info"
582(set/A exit_code=%ERRORLEVEL%)
583)
584)
585
586if %exit_code% EQU 0 ((echo %date% %time% [INFO] Pushed "%name%-v%release_version%")>> "!root_path!\%log_file%")
587
588goto :eof
589
590:: ---- BANNER ----
591
592:banner
593
594cls
595echo +===========================================================+
596echo !name! builder script
597echo +===========================================================+
598goto :eof
599
600:: ---- DOWNLOAD PACKAGES ----
601
602:download
603
604echo *************************************************************
605
606for %%j in %legacy_cores_list% do (
607
608if "!package_name!"=="%%j" (set download_url=https://www.retrobat.ovh/repo/%arch%/legacy/lrcores)
609)
610
611if exist "%download_path%\%package_file%" goto :eof
612
613"%buildtools_path%\wget" --continue --no-check-certificate --retry-connrefused --waitretry=1 --read-timeout=20 --timeout=15 -t 3 -P "%download_path%" !download_url!/!package_file! -q --show-progress
614(set/A exit_code=%ERRORLEVEL%)
615
616if not exist "%download_path%\%package_file%" (
617
618call :exit_door
619goto :eof
620)
621
622(echo %date% %time% [INFO] Get !package_name! from !download_url!)>> "!root_path!\%log_file%"
623
624goto :eof
625
626:: ---- EXTRACT PACKAGES ----
627
628:extract
629
630echo *************************************************************
631
632if not exist "%extraction_path%\." md "%extraction_path%"
633"%buildtools_path%\7za.exe" -y x "%download_path%\%package_file%" -aoa -o"%extraction_path%"
634
635set true=1
636
637if "!package_name!"=="retroarch" (
638
639set true=0
640
641if "%archx%"=="x86_64" (
642
643xcopy "%extraction_path%\RetroArch-Win64" "%destination_path%\" /s /e /v /y
644rmdir /s /q "%download_path%\extract\RetroArch-Win64"
645)
646
647if "%archx%"=="x86" (
648
649xcopy "%extraction_path%\RetroArch" "%destination_path%\" /s /e /v /y
650rmdir /s /q "%download_path%\extract\RetroArch"
651)
652)
653
654if "%true%"=="1" (
655
656xcopy "%extraction_path%" "%destination_path%\" /e /v /y
657)
658
659rmdir /s /q "%download_path%\extract"
660if not "%package_file%" == "" del/Q "%download_path%\%package_file%"
661
662(echo %date% %time% [INFO] Copy !package_name! to !destination_path!)>> "!root_path!\%log_file%"
663
664goto :eof
665
666:: ---- CHECK VERSION ----
667
668:check_version
669
670if "%release_version%"=="null" (
671
672if exist "!build_path!\system\version.info" (
673
674set/P release_version=<"!build_path!\system\version.info"
675
676) else (
677
678(set/A exit_code=2)
679goto :eof
680)
681)
682
683goto :eof
684
685:: ---- HASH FILE ----
686
687:hash_file
688
689if "!task!" == "get_packages" (
690
691set hash_path=!download_path!
692
693) else (
694
695set hash_path=!build_path!
696
697)
698
699if exist "!hash_path!\!package_file!" (
700
701(set "first_line=1")
702for /f "skip=1 delims=" %%i in ('certutil -hashfile "!hash_path!\!package_file!" SHA256') do (
703if [!first_line!]==[1] (
704(set file_hash=%%i)
705(set "first_line=0")
706)
707)
708
709if "!task!" == "get_packages" (
710REM (echo !package_name!_sha256=!file_hash!)>> "!build_path!\hash_list.txt"
711REM (echo %date% %time% [INFO] !package_name!_sha256=!file_hash! ^> "!build_path!\hash_list.txt")>> "!root_path!\%log_file%"
712)
713
714if not "!task!" == "get_packages" (
715(echo|set/P=!file_hash!)> "!build_path!\!package_file!.sha256.txt"
716(echo %date% %time% [INFO] Created "!package_file!.sha256.txt" in "!build_path!")>> "!root_path!\%log_file%"
717)
718)
719
720goto :eof
721
722:: ---- EXIT ----
723
724:exit_door
725
726echo :: EXITING...
727
728if "%exit_code%" == "" (set/A exit_code=2)
729(echo %date% %time% [EXIT] !exit_code!)>> "!root_path!\build.log"
730
731if %exit_timeout% GTR 0 (timeout /t %exit_timeout%)>nul
732if %exit_timeout% EQU 0 (pause)
733
734exit !exit_code!