This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
createShortcuts.bat
2486 lines (2058 loc) · 109 KB
/
createShortcuts.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@echo off
setlocal EnableExtensions
REM : ------------------------------------------------------------------
REM : main
setlocal EnableDelayedExpansion
color 4F
set "THIS_SCRIPT=%~0"
REM : checking THIS_SCRIPT path
call:checkPathForDos "!THIS_SCRIPT!" > NUL 2>&1
set /A "cr=!ERRORLEVEL!"
if !cr! NEQ 0 (
echo ERROR Remove DOS reserved characters from the path "!THIS_SCRIPT!" ^(such as ^&^, %% or ^^!^)^, cr=!cr!
pause
exit 1
)
REM : directory of this script
set "SCRIPT_FOLDER="%~dp0"" && set "BFW_PATH=!SCRIPT_FOLDER:\"="!"
for %%a in (!BFW_PATH!) do set "parentFolder="%%~dpa""
for %%a in (!BFW_PATH!) do set "drive=%%~da"
set "GAMES_FOLDER=!parentFolder!"
if not [!GAMES_FOLDER!] == ["!drive!\"] set "GAMES_FOLDER=!parentFolder:~0,-2!""
set "BFW_TOOLS_PATH="!BFW_PATH:"=!\tools""
set "BFW_RESOURCES_PATH="!BFW_PATH:"=!\resources""
REM : checking arguments
set /A "nbArgs=0"
:continue
if "%~1"=="" goto:end
set "args[%nbArgs%]="%~1""
set /A "nbArgs +=1"
shift
goto:continue
:end
set "cmdOw="!BFW_RESOURCES_PATH:"=!\cmdOw.exe""
if %nbArgs% EQU 0 !cmdOw! @ /MAX > NUL 2>&1
set "BFW_LOGS="!BFW_PATH:"=!\logs""
if not exist !BFW_LOGS! mkdir !BFW_LOGS! > NUL 2>&1
set "rarExe="!BFW_RESOURCES_PATH:"=!\rar.exe""
set "brcPath="!BFW_RESOURCES_PATH:"=!\BRC_Unicode_64\BRC64.exe""
set "imgConverter="!BFW_RESOURCES_PATH:"=!\convert.exe""
set "quick_Any2Ico="!BFW_RESOURCES_PATH:"=!\quick_Any2Ico.exe""
set "xmlS="!BFW_RESOURCES_PATH:"=!\xml.exe""
set "wiiTitlesDataBase="!BFW_RESOURCES_PATH:"=!\WiiU-Titles-Library.csv""
set "Start="!BFW_RESOURCES_PATH:"=!\vbs\Start.vbs""
set "StartWait="!BFW_RESOURCES_PATH:"=!\vbs\StartWait.vbs""
set "StartHidden="!BFW_RESOURCES_PATH:"=!\vbs\StartHidden.vbs""
set "StartHiddenWait="!BFW_RESOURCES_PATH:"=!\vbs\StartHiddenWait.vbs""
REM set "StartMaximizedWait="!BFW_RESOURCES_PATH:"=!\vbs\StartMaximizedWait.vbs""
set "browseFolder="!BFW_RESOURCES_PATH:"=!\vbs\BrowseFolderDialog.vbs""
set "MessageBox="!BFW_RESOURCES_PATH:"=!\vbs\MessageBox.vbs""
set "logFile="!BFW_LOGS:"=!\Host_!USERDOMAIN!.log""
set "glogFile="!BFW_LOGS:"=!\gamesLibrary.log""
REM : check if folder name contains forbiden character for batch file
call:securePathForDos !GAMES_FOLDER! SAFE_PATH
if not [!GAMES_FOLDER!] == [!SAFE_PATH!] (
echo ERROR ^: please rename your folders to have this compatible path
echo !SAFE_PATH!
pause
exit 95
)
REM : set current char codeset
call:setCharSet
if not exist !logFile! (
echo You have to launch the setup before this script ^^! launching setup^.bat
set "setup="!BFW_PATH:"=!\setup.bat""
wscript /nologo !Start! !setup!
timeout /t 4 > NUL 2>&1
exit 51
)
set "USERSLIST="
set /A "nbUsers=0"
for /F "tokens=2 delims=~=" %%i in ('type !logFile! ^| find /I "USER_REGISTERED" 2^>NUL') do (
set "USERSLIST=%%i !USERSLIST!"
set /A "nbUsers+=1"
)
if ["!USERSLIST!"] == [""] (
echo You have to launch the setup before this script ^^! launching setup^.bat
set "setup="!BFW_PATH:"=!\setup.bat""
wscript /nologo !Start! !setup!
timeout /t 4 > NUL 2>&1
exit 51
)
REM : cd to GAMES_FOLDER
pushd !GAMES_FOLDER!
REM : get current date
for /F "usebackq tokens=1,2 delims=~=" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set "ldt=%%j"
set "ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%_%ldt:~8,2%-%ldt:~10,2%-%ldt:~12,6%"
set "DATE=%ldt%"
REM : Intel legacy options
set "argLeg="
REM : with no arguments to this script, activating user inputs
set /A "QUIET_MODE=0"
if %nbArgs% NEQ 0 goto:getArgsValue
title Create CEMU^'s shortcuts for selected games
REM : rename folders that contains forbiden characters : & ! . ( )
wscript /nologo !StartHiddenWait! !brcPath! /DIR^:!GAMES_FOLDER! /REPLACECI^:^^!^: /REPLACECI^:^^^&^: /REPLACECI^:^^.^: /REPLACECI^:^^(^:[ /REPLACECI^:^^)^:] /EXECUTE
set "BFW_GP_FOLDER="!GAMES_FOLDER:"=!\_BatchFw_Graphic_Packs""
REM : rename GFX folders that contains forbiden characters : & ! . ( )
wscript /nologo !StartHidden! !brcPath! /DIR^:!BFW_GP_FOLDER! /REPLACECI^:^^!^:# /REPLACECI^:^^^&^: /REPLACECI^:^^.^: /REPLACECI^:^^(^:[ /REPLACECI^:^^)^:] /EXECUTE
REM : check if DLC and update folders are presents (some games need to be prepared)
call:checkGamesToBePrepared
echo Checking for update ^.^.^.
REM : update BatchFw
set "ubw="!BFW_TOOLS_PATH:"=!\updateBatchFw.bat""
call !ubw!
set /A "cr=!ERRORLEVEL!"
if !cr! EQU 0 (
echo BatchFw updated^, please relaunch
set "ChangeLog="!BFW_PATH:"=!\Change.log""
wscript /nologo !Start! "%windir%\System32\notepad.exe" !ChangeLog!
timeout /t 4 > NUL 2>&1
exit 75
)
timeout /t 1 > NUL 2>&1
cls
echo Please select CEMU install folder
:askCemuFolder
for /F %%b in ('cscript /nologo !browseFolder! "Select a Cemu's install folder"') do set "folder=%%b" && set "CEMU_FOLDER=!folder:?= !"
if [!CEMU_FOLDER!] == ["NONE"] (
choice /C yn /N /M "No item selected, do you wish to cancel (y, n)? : "
if !ERRORLEVEL! EQU 1 timeout /T 4 > NUL 2>&1 && exit 75
goto:askCemuFolder
)
REM : check if folder name contains forbiden character for !CEMU_FOLDER!
set "tobeLaunch="!BFW_PATH:"=!\tools\detectAndRenameInvalidPath.bat""
call !tobeLaunch! !CEMU_FOLDER!
set /A "cr=!ERRORLEVEL!"
if !cr! GTR 1 (
echo Path to !CEMU_FOLDER! is not DOS compatible^!^, please choose another location
pause
goto:askCemuFolder
)
REM : check that cemu.exe exist in
set "cemuExe="!CEMU_FOLDER:"=!\cemu.exe" "
if not exist !cemuExe! (
echo ERROR^, No Cemu^.exe file found under !CEMU_FOLDER! ^^!
goto:askCemuFolder
)
set "folder=NOT_FOUND"
for /F "tokens=2 delims=~=" %%i in ('type !logFile! ^| find "Create " 2^>NUL') do set "folder=%%i"
if ["!folder!"] == ["NOT_FOUND"] goto:askOutputFolder
set "OUTPUT_FOLDER="!folder:\Wii-U Games=!""
REM : if called with shortcut, OUTPUT_FOLDER already set, goto:inputsAvailables
if not [!OUTPUT_FOLDER!] == [!BFW_PATH!] goto:inputsAvailables
:askOutputFolder
echo Please define where to create shortcuts ^(a Wii-U Games subfolder will be created^)
for /F %%b in ('cscript /nologo !browseFolder! "Select an output folder (a Wii-U Games subfolder will be created)"') do set "folder=%%b" && set "OUTPUT_FOLDER=!folder:?= !"
if [!OUTPUT_FOLDER!] == ["NONE"] (
choice /C yn /N /M "No item selected, do you wish to cancel (y, n)? : "
if !ERRORLEVEL! EQU 1 timeout /T 4 > NUL 2>&1 && exit 75
goto:askOutputFolder
)
REM : check if folder name contains forbiden character for batch file
set "tobeLaunch="!BFW_PATH:"=!\tools\detectAndRenameInvalidPath.bat""
call !tobeLaunch! !OUTPUT_FOLDER!
set /A "cr=!ERRORLEVEL!"
if !cr! GTR 1 (
echo Path to !OUTPUT_FOLDER! is not DOS compatible^!^, please choose another location
pause
goto:askOutputFolder
)
goto:inputsAvailables
:getArgsValue
if %nbArgs% GTR 5 (
echo ERROR on arguments passed ^(%nbArgs%^)
echo SYNTAX^: "!THIS_SCRIPT!" CEMU_FOLDER OUTPUT_FOLDER -noImport^* -ignorePrecomp^* -no^/Legacy^*
echo ^(^* for optional^ argument^)
echo given {%*}
pause
exit /b 9
)
if %nbArgs% LSS 2 (
echo ERROR on arguments passed ^^!
echo SYNTAX^: "!THIS_SCRIPT!" CEMU_FOLDER OUTPUT_FOLDER -noImport^* -ignorePrecomp^* -no^/Legacy^*
echo ^(^* for optional^ argument^)
echo given {%*}
pause
exit /b 99
)
if %nbArgs% EQU 2 goto:getCemuFolder
REM : flag for ignoring precompiled cache
set "IGNORE_PRECOMP=DISABLED"
REM : flag for automatic import
set "IMPORT_MODE=ENABLED"
if [!args[2]!] == ["-noImport"] set "IMPORT_MODE=DISABLED"
if [!args[2]!] == ["-ignorePrecomp"] set "IGNORE_PRECOMP=ENABLED"
if [!args[2]!] == ["-noLegacy"] set "argLeg=-noLegacy"
if [!args[2]!] == ["-Legacy"] set "argLeg=-Legacy"
if %nbArgs% EQU 3 goto:getCemuFolder
if [!args[3]!] == ["-noImport"] set "IMPORT_MODE=DISABLED"
if [!args[3]!] == ["-ignorePrecomp"] set "IGNORE_PRECOMP=ENABLED"
if [!args[3]!] == ["-noLegacy"] set "argLeg=-noLegacy"
if [!args[3]!] == ["-Legacy"] set "argLeg=-Legacy"
if %nbArgs% EQU 4 goto:getCemuFolder
if [!args[4]!] == ["-noImport"] set "IMPORT_MODE=DISABLED"
if [!args[4]!] == ["-ignorePrecomp"] set "IGNORE_PRECOMP=ENABLED"
if [!args[4]!] == ["-noLegacy"] set "argLeg=-noLegacy"
if [!args[4]!] == ["-Legacy"] set "argLeg=-Legacy"
:getCemuFolder
REM : get and check CEMU_FOLDER
set CEMU_FOLDER=!args[0]!
if not exist !CEMU_FOLDER! (
echo ERROR CEMU folder !CEMU_FOLDER! does not exist ^^!
pause
exit /b 1
)
REM : get OUTPUT_FOLDER
set OUTPUT_FOLDER=!args[1]!
if not exist !OUTPUT_FOLDER! (
echo ERROR Shortcuts folder !OUTPUT_FOLDER! does not exist ^^!
pause
exit /b 2
)
REM : with arguments to this script, deactivating user inputs
set /A "QUIET_MODE=1"
:inputsAvailables
REM : clean log files specific to a launch
set "tobeDeleted="!BFW_PATH:"=!\logs\fnr_*.*""
del /F /S !tobeDeleted! > NUL 2>&1
set "tobeDeleted="!BFW_PATH:"=!\logs\jnust_*.*""
del /F /S !tobeDeleted! > NUL 2>&1
set "tobeDeleted="!BFW_PATH:"=!\logs\fnr""
rmdir /Q /S !tobeDeleted! > NUL 2>&1
cls
REM : check if folder name contains forbidden character for batch file
set "tobeLaunch="!BFW_PATH:"=!\tools\detectAndRenameInvalidPath.bat""
call !tobeLaunch! !BFW_PATH!
set /A "cr=!ERRORLEVEL!"
if !cr! NEQ 0 (
echo Please rename !BFW_PATH:"=! to be DOS compatible ^^!^, exiting
pause
exit /b 3
)
REM : basename of CEMU_FOLDER to get CEMU version (used to name shorcut)
for %%a in (!CEMU_FOLDER!) do set "CEMU_FOLDER_NAME=%%~nxa"
REM : CEMU's log file
set "clog="!CEMU_FOLDER:"=!\log.txt""
REM : get the version from log file (CEMU < 1.25.3) or from the executable
set "versionRead=NOT_FOUND"
if exist !clog! (
for /f "tokens=1-6" %%a in ('type !clog! ^| find "Init Cemu"') do set "versionRead=%%e"
) else (
REM : get it from the executable
set "cemuExe="!CEMU_FOLDER:"=!\Cemu.exe""
set "here="%CD:"=%""
pushd !BFW_TOOLS_PATH!
set "versionReadFromExe=NOT_FOUND"
for /F %%a in ('getDllOrExeVersion.bat !cemuExe!') do set "versionReadFromExe=%%a"
if not ["!versionReadFromExe!"] == ["NOT_FOUND"] set "versionRead=!versionReadFromExe:~0,-2!"
pushd !here!
)
if ["!versionRead!"] == ["NOT_FOUND"] (
echo ERROR^: BatchFw supports only version of CEMU ^>= v1^.11^.6
echo Install earlier versions per game and per user
echo exiting
pause
exit /b 77
)
echo !versionRead! | findStr /R "^[0-9]*\.[0-9]*\.[0-9]*[a-z]*.$" > NUL 2>&1 && goto:versionOK
echo versionRead=!versionRead!
echo ERROR^: BatchFw can^'t get CEMU^'s version^.
echo This version seems to be not supported.
echo exiting
pause
exit /b 78
:versionOK
set /A "treatAllGames=0"
if !QUIET_MODE! EQU 1 goto:bfwShortcuts
REM : when launched with shortcut = no args = QUIET_MODE=0
choice /C yn /N /M "Do you want to create shortcuts for ALL your games (y, n = select games)? : "
if !ERRORLEVEL! EQU 1 (
set /A "QUIET_MODE=1"
set /A "treatAllGames=1"
)
cls
REM : update graphic packs
set "ugp="!BFW_PATH:"=!\tools\updateGraphicPacksFolder.bat""
call !ugp! -silent
set /A "cr=!ERRORLEVEL!"
echo ---------------------------------------------------------
if !cr! NEQ 0 (
echo ERROR Graphics packs folder update failed^!
)
cls
echo =========================================================
echo Creating CEMU !versionRead! shortcuts
echo =========================================================
REM : if not exist logFile goto:bfwShortcuts
if not exist !logFile! goto:bfwShortcuts
REM : check if this version, was already installed
REM : if already installed but its path is invalid : clear logFile
REM : search in logFile, getting only the last occurence
set "previousPath=NONE"
for /F "tokens=2 delims=~=" %%i in ('type !logFile! ^| find !CEMU_FOLDER! 2^>NUL') do (
set "previousPath=%%i"
)
if ["!previousPath!"] == ["NONE"] (
goto:bfwShortcuts
)
REM : a path was found, if not exist : flush logHostFile for CEMU_FOLDER_NAME
if not exist "!previousPath!" call:cleanHostLogFile !CEMU_FOLDER_NAME!
:bfwShortcuts
REM : check if an internet connexion is active
set "ACTIVE_ADAPTER=NOT_FOUND"
for /F "tokens=1 delims=~=" %%f in ('wmic nic where "NetConnectionStatus=2" get NetConnectionID /value 2^>NUL ^| find "="') do set "ACTIVE_ADAPTER=%%f"
if !QUIET_MODE! EQU 0 (
echo Creating own shortcuts
)
call:fwShortcuts
REM : importing CEMU VERSION controller profiles under !GAMES_FOLDER:"=!\_BatchFw_Controller_Profiles
call:syncControllerProfiles
echo ---------------------------------------------------------
echo Controller profiles folders synchronized ^(!CEMU_FOLDER_NAME!\ControllerProfiles vs _BatchFW_Controller_Profiles^)
if !QUIET_MODE! EQU 1 goto:openCemuAFirstTime
echo ---------------------------------------------------------
REM : flush logFile of SCREEN_MODE
call:cleanHostLogFile SCREEN_MODE
choice /C yn /N /M "Do you want to launch CEMU in fullscreen (y, n)? : "
if !ERRORLEVEL! EQU 1 goto:openCemuAFirstTime
set "msg="SCREEN_MODE=windowed""
call:log2HostFile !msg!
:openCemuAFirstTime
set "cs="!CEMU_FOLDER:"=!\settings.xml""
if exist !clog! if exist !cs! goto:compareCemuVersion
echo ---------------------------------------------------------
echo opening CEMU !versionRead!^.^.^.
echo.
echo - If a mlc01 folder creation message popup^, answer 'Yes'
echo - Ignore graphic pack folder download notification^.
echo - Ignore quick start assistant ^(next^).
echo.
echo Set your REGION^, language and all common settings for your
echo games ^(default GFX API^, controllers^, sound^, overlay^.^.^.^)
echo No need to set accounts for user^(s^)
echo.
echo Then close CEMU to continue
echo.
echo ^(if cemuHook and/or sharedFonts are missing^, BatchFw will
echo install them for you^)
echo.
set "cemu="!CEMU_FOLDER:"=!\Cemu.exe""
wscript /nologo !StartWait! !cemu!
REM : set GAMES_FOLDER as Games Path (to avoid CEMU popup on first run)
set "csTmp="!CEMU_FOLDER:"=!\settings.bfw_tmp""
!xmlS! ed -s "//GamePaths" -t elem -n "Entry" -v !GAMES_FOLDER! !cs! > !csTmp! 2>NUL
if exist !csTmp! (
del /F !cs! > NUL 2>&1
move /Y !csTmp! !cs! > NUL 2>&1
)
:compareCemuVersion
REM : suppose : version > 1.25.1
set /A "v1251=1"
set /A "v1151=1"
set /A "v114=1"
set /A "v1116=1"
call:compareVersions !versionRead! "1.25.1" v1251 > NUL 2>&1
if ["!v1251!"] == [""] echo Error when comparing versions
if !v1251! EQU 50 echo Error when comparing versions
REM : version >= 1.25.1
if !v1251! LEQ 1 goto:checkCemuHook
call:compareVersions !versionRead! "1.22" v122 > NUL 2>&1
if ["!v122!"] == [""] echo Error when comparing versions
if !v122! EQU 50 echo Error when comparing versions
REM : version >= 1.22 (V6+V4 packs)
if !v122! LEQ 1 goto:checkCemuHook
REM : version < 1.22
REM : comparing to 1.15.1 (used later)
call:compareVersions !versionRead! "1.15.1" v1151 > NUL 2>&1
if ["!v1151!"] == [""] echo Error when comparing versions
if !v1151! EQU 50 echo Error when comparing versions
REM : version >= 1.15.1 (V4 packs)
if !v1151! LEQ 1 goto:checkV4Packs
REM : version < 1.15.1
call:compareVersions !versionRead! "1.14.0" v114 > NUL 2>&1
if ["!v114!"] == [""] echo Error when comparing versions
if !v114! EQU 50 echo Error when comparing versions
REM : version >= 1.14
if !v114! LEQ 1 goto:checkV4Packs
REM : version < 1.14
call:compareVersions !versionRead! "1.11.6" v1116 > NUL 2>&1
if ["!v1116!"] == [""] echo Error when comparing versions
if !v1116! EQU 50 echo Error when comparing versions
if !v1116! EQU 2 (
echo ERROR this version is not supported by BatchFw
echo ^(only versions ^>= 1^.11^.6^)
pause
exit /b 99
)
REM : 1.14 > version >= 1.11.6
set "gfxv2="!GAMES_FOLDER:"=!\_BatchFw_Graphic_Packs\_graphicPacksV2""
if exist !gfxv2! goto:checkCemuHook
mkdir !gfxv2! > NUL 2>&1
set "rarFile="!BFW_RESOURCES_PATH:"=!\V2_GFX_Packs.rar""
echo ---------------------------------------------------------
echo graphic pack V2 are needed for this version^, extracting^.^.^.
wscript /nologo !StartHidden! !rarExe! x -o+ -inul -w!BFW_LOGS! !rarFile! !gfxv2! > NUL 2>&1
set /A "cr=!ERRORLEVEL!"
if !cr! GTR 1 (
echo ERROR while extracting V2_GFX_Packs^, exit 21
pause
exit /b 21
)
goto:checkCemuHook
:checkV4Packs
REM : 1.14 <= version < 1.22
REM : TODO uncomment when V4 packs will not be mixed with V6 one in GFX repo
REM set "gfxv4="!GAMES_FOLDER:"=!\_BatchFw_Graphic_Packs\_graphicPacksV4""
REM if exist !gfxv4! goto:checkCemuHook
REM : TODO comment when V4 packs will not be mixed with V6 one in GFX repo
goto:checkCemuHook
mkdir !gfxv4! > NUL 2>&1
set "rarFile="!BFW_RESOURCES_PATH:"=!\V4_GFX_Packs.rar""
echo ---------------------------------------------------------
echo graphic pack V4 are needed for this version^, extracting^.^.^.
wscript /nologo !StartHidden! !rarExe! x -o+ -inul -w!BFW_LOGS! !rarFile! !gfxv4! > NUL 2>&1
set /A "cr=!ERRORLEVEL!"
if !cr! GTR 1 (
echo ERROR while extracting V4_GFX_Packs^, exiting 22
pause
exit /b 22
)
:checkCemuHook
REM : check if CemuHook is installed
set "dllFile="!CEMU_FOLDER:"=!\keystone.dll""
if exist !dllFile! goto:checkSharedFonts
echo Installing CemuHook^.^.^.
call:installCemuHook
:checkSharedFonts
REM : disable SharedFonts install for CEMU >= 1.25.1
if !v1251! LEQ 1 goto:autoImportMode
REM : check if sharedFonts were downloaded
set "sharedFonts="!CEMU_FOLDER:"=!\sharedFonts""
set "cs="!CEMU_FOLDER:"=!\settings.xml""
if exist !sharedFonts! goto:autoImportMode
echo Installing sharedFonts^.^.^.
set "rarFile="!BFW_RESOURCES_PATH:"=!\sharedFonts.rar""
wscript /nologo !StartHidden! !rarExe! x -o+ -inul -w!BFW_LOGS! !rarFile! !CEMU_FOLDER! > NUL 2>&1
set /A "cr=!ERRORLEVEL!"
if !cr! GTR 1 (
echo WARNING ^: while extracting sharedFonts
pause
)
timeout /T 3 > NUL 2>&1
:autoImportMode
echo ---------------------------------------------------------
REM : importMode
set "IMPORT_MODE=ENABLED"
REM call:getUserInput "Disable automatic settings import? (y,n : default in 10sec): " "n,y" ANSWER 10
REM if [!ANSWER!] == ["y"] set "IMPORT_MODE=DISABLED"
REM
REM set "msg="!CEMU_FOLDER_NAME! installed with automatic import=!IMPORT_MODE:"=!""
REM call:log2HostFile !msg!
REM : get GPU_VENDOR
set "GPU_VENDOR=NOT_FOUND"
set "gpuType=OTHER"
for /F "tokens=2 delims=~=" %%i in ('wmic path Win32_VideoController get Name /value 2^>NUL ^| find "="') do (
set "string=%%i"
echo "!string!" | find /I "NVIDIA" > NUL 2>&1 && (
set "gpuType=NVIDIA"
set "GPU_VENDOR=!string: =!"
)
echo "!string!" | find /I "AMD" > NUL 2>&1 && (
set "gpuType=AMD"
set "GPU_VENDOR=!string: =!"
)
)
if ["!GPU_VENDOR!"] == ["NOT_FOUND"] set "GPU_VENDOR=!string: =!"
call:secureStringForDos !GPU_VENDOR! GPU_VENDOR > NUL 2>&1
set "GPU_VENDOR=!GPU_VENDOR:"=!"
set "IGNORE_PRECOMP=DISABLED"
REM : GPU is NVIDIA => ignoring precompiled shaders cache
if ["!gpuType!"] == ["NVIDIA"] set "IGNORE_PRECOMP=ENABLED"
set "msg="!CEMU_FOLDER_NAME:"=! install with ignoring precompiled shader cache=!IGNORE_PRECOMP:"=!""
call:log2HostFile !msg!
if !QUIET_MODE! EQU 1 goto:scanGamesFolder
REM : check if main GPU is iGPU. Ask for -nolegacy if it is the case
set "noIntel=!GPU_VENDOR:Intel=!"
if ["!gpuType!"] == ["OTHER"] if not ["!noIntel!"] == ["!GPU_VENDOR!"] (
REM : CEMU < 1.15.1
if !v1151! LEQ 1 (
call:getUserInput "Disable all Intel GPU workarounds (add -NoLegacy)? (y,n): " "n,y" ANSWER
if [!ANSWER!] == ["n"] goto:scanGamesFolder
set "argOpt=%argOpt% -noLegacy"
goto:scanGamesFolder
)
REM : CEMU >= 1.15.1
if !v1151! EQU 0 (
call:getUserInput "Enable all Intel GPU workarounds (add -Legacy)? (y,n): " "n,y" ANSWER
if [!ANSWER!] == ["n"] goto:scanGamesFolder
set "argOpt=%argOpt% -Legacy"
goto:scanGamesFolder
)
if !v1151! EQU 2 (
call:getUserInput "Enable all Intel GPU workarounds (add -Legacy)? (y,n): " "n,y" ANSWER
if [!ANSWER!] == ["n"] goto:scanGamesFolder
set "argOpt=%argOpt% -Legacy"
goto:scanGamesFolder
)
)
:scanGamesFolder
REM : check if exist game's folder(s) containing non supported characters
set "tmpFile="!BFW_PATH:"=!\logs\detectInvalidGamesFolder_cs.log""
dir /B /A:D > !tmpFile! 2>&1
for /F %%i in ('type !tmpFile! ^| find "?"') do (
cls
echo =========================================================
echo ERROR Unknown characters found in game^'s folder^(s^) that is not handled by your current DOS charset ^(%CHARSET%^)
echo List of game^'s folder^(s^)^:
echo ---------------------------------------------------------
type !tmpFile! | find "?"
del /F !tmpFile!
echo ---------------------------------------------------------
echo Fix-it by removing characters here replaced in the folder^'s name by^?
echo Exiting until you rename or move those folders
echo =========================================================
pause
)
if !QUIET_MODE! EQU 0 cls
echo =========================================================
echo Creating !CEMU_FOLDER_NAME! shortcuts for your games^.^.^.
if !QUIET_MODE! EQU 0 echo =========================================================
if !QUIET_MODE! EQU 0 (
REM : clean BFW_LOGS
pushd !BFW_LOGS!
for /F "delims=~" %%i in ('dir /B /S /A:D 2^> NUL') do rmdir /Q /S "%%i" > NUL 2>&1
for /F "delims=~" %%i in ('dir /B /S /A:L 2^> NUL') do rmdir /Q /S "%%i" > NUL 2>&1
)
REM : cd to GAMES_FOLDER
pushd !GAMES_FOLDER!
REM : temporary game library log file (updated here to remove uninstalled games data)
set "glogFileNew="!BFW_PATH:"=!\logs\gamesLibrary.new""
del /F /S !glogFileNew! > NUL 2>&1
set /A "NB_GAMES_TREATED=0"
set /A "NB_OUTPUTS=0"
REM : loop on game's code folders found
for /F "delims=~" %%g in ('dir /b /o:n /a:d /s code 2^>NUL ^| find /I /V "\mlc01" ^| find /I /V "\_BatchFw_Install"') do (
set "codeFullPath="%%g""
set "GAME_FOLDER_PATH=!codeFullPath:\code=!"
REM : check path
call:checkPathForDos !GAME_FOLDER_PATH! > NUL 2>&1
set /A "cr=!ERRORLEVEL!"
if !cr! EQU 0 (
REM : check if folder name contains forbiden character for batch file
set "tobeLaunch="!BFW_PATH:"=!\tools\detectAndRenameInvalidPath.bat""
call !tobeLaunch! !GAME_FOLDER_PATH!
set /A "cr=!ERRORLEVEL!"
if !cr! GTR 1 echo Please rename !GAME_FOLDER_PATH! to be DOS compatible^, otherwise it will be ignored by BatchFW ^^!
if !cr! EQU 1 goto:scanGamesFolder
call:gameShortcut
) else (
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for %%a in (!GAME_FOLDER_PATH!) do set "folderName=%%~nxa"
echo !folderName!^: Unsupported characters found^, rename it otherwise it will be ignored by BatchFW ^^!
for %%a in (!GAME_FOLDER_PATH!) do set "basename=%%~dpa"
REM : windows forbids creating folder or file with a name that contains \/:*?"<>| but &!% are also a problem with dos expansion
set "str="!folderName!""
set "str=!str:&=!"
set "str=!str:\!=!"
set "str=!str:%%=!"
set "str=!str:\.=!"
set "str=!str:?=!"
set "str=!str:\"=!"
set "str=!str:^=!"
set "newFolderName=!str:"=!"
set "newName="!basename!!newFolderName:"=!""
set /A "attempt=1"
:tryToMove
call:getUserInput "Renaming folder for you? (y, n) : " "y,n" ANSWER
if [!ANSWER!] == ["y"] (
move /Y !GAME_FOLDER_PATH! !newName! > NUL 2>&1
if !ERRORLEVEL! NEQ 0 (
if !attempt! EQU 1 (
!MessageBox! "Check failed on !GAME_FOLDER_PATH:"=!^, close any program that could use this location" 4112
set /A "attempt+=1"
goto:tryToMove
)
REM : basename of GAME FOLDER PATH to get GAME_TITLE
for /F "delims=~" %%g in (!GAME_FOLDER_PATH!) do set "GAME_TITLE=%%~nxg"
call:fillOwnerShipPatch !GAME_FOLDER_PATH! "!GAME_TITLE!" patch
!MessageBox! "Check still failed^, take the ownership on !GAME_FOLDER_PATH:"=! with running as an administrator the script !patch:"=!^. If it^'s done^, do you wish to retry^?" 4116
if !ERRORLEVEL! EQU 6 goto:tryToMove
)
)
if [!ANSWER!] == ["y"] if !ERRORLEVEL! EQU 0 timeout /t 2 > NUL 2>&1 && goto:scanGamesFolder
if [!ANSWER!] == ["y"] if !ERRORLEVEL! NEQ 0 echo Failed to rename game^'s folder ^(contain ^'^^!^'^?^), please do it by yourself otherwise the game will be ignored^!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
)
)
REM : if not called from the setup.bat
if !QUIET_MODE! EQU 0 (
type !glogFileNew! | sort > !glogFile!
del /F /S !glogFileNew! > NUL 2>&1
)
if !QUIET_MODE! EQU 1 if !treatAllGames! EQU 0 goto:log
echo =========================================================
echo Treated !NB_GAMES_TREATED! games
if !nbUsers! GTR 1 echo Created !NB_OUTPUTS! shortcuts
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo BatchFw share a common GFX packs folder with all versions
echo of CEMU ^(installed in your game library as _BatchFw_Graphic_Packs^)
echo do not use the update feature in CEMU but the provided scripts^.
echo.
echo Same remark concerning the auto update feature of CEMU UI^:
echo The point of BatchFw is to install the both versions ^(previous and
echo current^) before removing the previous one if the last one runs all
echo your games without any issue.
echo ---------------------------------------------------------
if !treatAllGames! EQU 0 pause
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo If you want to change global CEMU^'s settings you^'ve just
echo entered here^:
echo ---------------------------------------------------------
echo ^> simply delete the shortcuts and recreate them using
echo Wii-U Games^\Create CEMU^'s shortcuts for selected games^.lnk
echo to register a SINGLE version of CEMU
echo ---------------------------------------------------------
if !treatAllGames! EQU 0 pause
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo If you encounter any issues or have made a mistake when
echo collecting settings for a game^:
echo ---------------------------------------------------------
echo ^> delete the settings saved for !CEMU_FOLDER_NAME! using
echo the shortcut in Wii-U Games^\CEMU^\!CEMU_FOLDER_NAME!
echo Delete all my !CEMU_FOLDER_NAME!^'s settings^.lnk
echo ---------------------------------------------------------
if !treatAllGames! EQU 0 pause
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo This windows will close automatically in 15s
echo ^(n^)^: don^'t close^, i want to read history log first
echo ^(q^)^: close it now and quit
echo ---------------------------------------------------------
call:getUserInput "Enter your choice? : " "q,n" ANSWER 15
if [!ANSWER!] == ["n"] (
REM Waiting before exiting
pause
)
:log
REM : log to host log file
set "msg="!CEMU_FOLDER_NAME! install folder path=!CEMU_FOLDER:"=!""
call:log2HostFile !msg!
if !NB_GAMES_TREATED! NEQ 0 (
set "msg="Create shortcuts for !CEMU_FOLDER_NAME! with import mode !IMPORT_MODE! in=!OUTPUT_FOLDER:"=!\Wii-U Games""
call:log2HostFile !msg!
)
echo =========================================================
if !QUIET_MODE! EQU 0 echo Waiting the end of all child processes before ending^.^.^.
call:waitProcessesEnd
if %nbArgs% EQU 0 endlocal
exit /b 0
goto:eof
REM : ------------------------------------------------------------------
REM : ------------------------------------------------------------------
REM : functions
:fillOwnerShipPatch
set "folder=%1"
set "title=%2"
set "patch="%USERPROFILE:"=%\Desktop\BFW_GetOwnerShip_!title:"=!.bat""
set "WIIU_GAMES_FOLDER="NONE""
for /F "tokens=2 delims=~=" %%i in ('type !logFile! ^| find "Create shortcuts" 2^>NUL') do set "WIIU_GAMES_FOLDER="%%i""
if not [!WIIU_GAMES_FOLDER!] == ["NONE"] (
set "patchFolder="!WIIU_GAMES_FOLDER:"=!\OwnerShip Patchs""
if not exist !patchFolder! mkdir !patchFolder! > NUL 2>&1
set "patch="!patchFolder:"=!\!title:"=!.bat""
)
set "%3=!patch!"
echo echo off > !patch!
echo REM ^: RUN THIS SCRIPT AS ADMINISTRATOR >> !patch!
type !patch! | find /I !folder! > NUL 2>&1 && goto:eof
echo echo ------------------------------------------------------->> !patch!
echo echo Get the ownership of !folder! >> !patch!
echo echo ------------------------------------------------------->> !patch!
echo takeown /F !folder! /R /SKIPSL >> !patch!
echo icacls !folder! /grant %%username%%^:F /T /L >> !patch!
echo pause >> !patch!
echo del /F %%0 >> !patch!
goto:eof
:installCemuHook
REM : cemuHook for versions < 1.12.1
set "rarFile="!BFW_RESOURCES_PATH:"=!\cemuhook_1116_0564.rar""
if !v122! EQU 2 goto:extractCemuHook
set "rarFile="!BFW_RESOURCES_PATH:"=!\cemuhook_1159_0573.rar""
if !v1251! EQU 2 goto:extractCemuHook
set "rarFile="!BFW_RESOURCES_PATH:"=!\cemuhook_1251_0574.rar""
:extractCemuHook
wscript /nologo !StartHidden! !rarExe! x -o+ -inul -w!BFW_LOGS! !rarFile! !CEMU_FOLDER! > NUL 2>&1
set /A "cr=!ERRORLEVEL!"
if !cr! GTR 1 (
echo WARNING ^: while extracting CemuHook
pause
)
goto:eof
REM : ------------------------------------------------------------------
:waitProcessesEnd
set /A "disp=0"
:waitingLoopProcesses
wmic process get Commandline 2>NUL | find ".exe" | find /I "_BatchFW_Install" | find /I /V "wmic" | find /I "rar.exe" | find /I /V "winRar" |find /I /V "find" > NUL 2>&1 && (
if !disp! EQU 0 (
set /A "disp=1"
echo Still extracting V2 GFX packs^, please wait ^.^.^.
)
goto:waitingLoopProcesses
)
goto:eof
REM : ------------------------------------------------------------------
REM : check if (DLC) or (UPDATE DATA) folders exist
:checkGamesToBePrepared
REM : already pushed to GAMES_FOLDER
set /A "needImport=0"
set "pat="*(DLC)*""
for /F "delims=~" %%i in ('dir /A:d /B !pat! 2^>NUL') do set /A "needImport=1"
set "pat="*(UPDATE DATA)*""
for /F "delims=~" %%i in ('dir /A:d /B !pat! 2^>NUL') do set /A "needImport=1"
REM : if need call import script and wait
if !needImport! EQU 0 goto:eof
echo Hum^.^.^. some DLC and UPDATE DATA folders were found
echo Preparing those games for emulation^.^.^.
timeout /T 5 > NUL 2>&1
REM : calling createShortcuts.bat
set "tobeLaunch="!BFW_TOOLS_PATH:"=!\importGames.bat""
call !tobeLaunch! !GAMES_FOLDER!
set /A "cr=!ERRORLEVEL!"
echo ^> Games ready for emulation
timeout /T 5 > NUL 2>&1
cls
goto:eof
REM : ------------------------------------------------------------------
REM : remove DOS forbiden character from a path
:securePathForDos
REM : str is expected protected with double quotes
set "string=%~1"
echo "%~1" | find "*" > NUL 2>&1 && (
echo ^* is not allowed in path
set "string=!string:*=!"
)
echo "%~1" | find "(" > NUL 2>&1 && (
echo ^( is not allowed in path
set "string=!string:(=!"
)
echo "%~1" | find ")" > NUL 2>&1 && (
echo ^) is not allowed in path
set "string=!string:)=!"
)
if ["!string!"] == ["%~1"] (
set "string=!string:&=!"
set "string=!string:?=!"
set "string=!string:\!=!"
set "string=!string:%%=!"
set "string=!string:^=!"
set "string=!string:/=!"
set "string=!string:>=!"
set "string=!string:<=!"
set "string=!string:|=!"
REM : WUP restrictions
set "string=!string:?=!"
set "string=!string:?=!"
set "string=!string:?=!"
set "string=!string:?=E!"
)
set "%2="!string!""
goto:eof
REM : ------------------------------------------------------------------
REM : remove DOS forbiden character from a path
:secureStringForDos
REM : str is expected protected with double quotes
set "string=%~1"
echo "%~1" | find "*" > NUL 2>&1 && (
echo ^* is not allowed in path
set "string=!string:*=!"
)
echo "%~1" | find "(" > NUL 2>&1 && (
echo ^( is not allowed in path
set "string=!string:(=!"
)
echo "%~1" | find ")" > NUL 2>&1 && (
echo ^) is not allowed in path
set "string=!string:)=!"
)
if ["!string!"] == ["%~1"] (
set "string=!string:&=!"
set "string=!string:?=!"
set "string=!string:\!=!"
set "string=!string:%%=!"
set "string=!string:^=!"
set "string=!string:/=!"
set "string=!string:\=!"
set "string=!string:>=!"
set "string=!string:<=!"
set "string=!string:|=!"
REM : replace '_' by ' ' (if needed)
set "string=!string:_= !"
REM : WUP restrictions
set "string=!string:?=!"
set "string=!string:?=!"
set "string=!string:?=!"
set "string=!string:?=E!"
)
set "%2="!string!""
goto:eof
REM : ------------------------------------------------------------------
:cleanHostLogFile
REM : pattern to ignore in log file
set "pat=%~1"
set "logFileTmp="!logFile:"=!.bfw_tmp""
if exist !logFileTmp! (
del /F !logFile! > NUL 2>&1
move /Y !logFileTmp! !logFile! > NUL 2>&1
)
if exist !logFileTmp! (
del /F !logFile! > NUL 2>&1
move /Y !logFileTmp! !logFile! > NUL 2>&1
)
type !logFile! | find /I /V "!pat!" > !logFileTmp!