Skip to content

Commit 77f6836

Browse files
committed
Fix: fix wrong uiautomator2 init
1 parent fc03131 commit 77f6836

File tree

3 files changed

+57
-23
lines changed

3 files changed

+57
-23
lines changed

alas.bat

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
:: Last updated: 2020-08-23
66
:: >>> Get updated from: https://github.com/LmeSzinc/AzurLaneAutoScript <<<
77
@echo off
8+
chcp | find "932" >NUL && set "IME=true" || set "IME=false"
9+
if "%IME%"=="true" (
10+
echo ====================================================================================================
11+
echo Incorrect encoding, visit this link to correct: https://bit.ly/34t8ubY
12+
echo To copy, select the link and CTRL+SHFT+C
13+
echo ====================================================================================================
14+
pause
15+
goto :eof
16+
)
817
pushd "%~dp0"
918
setlocal EnableDelayedExpansion
1019
set "Version=3.0"
@@ -19,6 +28,17 @@ set "root=%~dp0"
1928
set "root=%root:~0,-1%"
2029
cd "%root%"
2130

31+
rem ================= Variables =================
32+
33+
set "pyBin=%root%\toolkit\python.exe"
34+
set "adbBin=%root%\toolkit\Lib\site-packages\adbutils\binaries\adb.exe"
35+
set "gitBin=%root%\toolkit\Git\mingw64\bin\git.exe"
36+
set "curlBin=%root%\toolkit\Git\mingw64\bin\curl.exe"
37+
set "api_json=%root%\config\api_git.json"
38+
set "AlasConfig=%root%\config\alas.ini"
39+
set "template=%root%\config\template.ini"
40+
set "gitFolder=%root%\.git"
41+
2242
:: Import main settings (%Language%, %Region%, %SystemType%) and translation text.
2343
call command\Get.bat Main
2444
:: Import the Proxy setting and apply. Then show more info in Option6.
@@ -32,14 +52,6 @@ call command\Get.bat DeployMode
3252

3353
:: Start of Deployment
3454
title Alas Run Tool V3
35-
set "pyBin=%root%\toolkit\python.exe"
36-
set "adbBin=%root%\toolkit\Lib\site-packages\adbutils\binaries\adb.exe"
37-
set "gitBin=%root%\toolkit\Git\mingw64\bin\git.exe"
38-
set "curlBin=%root%\toolkit\Git\mingw64\bin\curl.exe"
39-
set "api_json=%root%\config\api_git.json"
40-
set "AlasConfig=%root%\config\alas.ini"
41-
set "template=%root%\config\template.ini"
42-
set "gitFolder=%root%\.git"
4355
if "%IsUsingGit%"=="yes" if "%DeployMode%"=="unknown" ( xcopy /Y toolkit\config .git\ > NUL )
4456
call :UpdateChecker_Alas
4557

@@ -104,7 +116,6 @@ rem ================= OPTION 1 =================
104116
:en
105117
call :CheckBsBeta
106118
call :AdbConnect
107-
rem call :uiautomator2init
108119
echo ====================================================================================================
109120
echo Python Found in %pyBin% Proceeding..
110121
echo Opening alas_en.pyw in %root%
@@ -118,7 +129,6 @@ rem ================= OPTION 2 =================
118129
:cn
119130
call :CheckBsBeta
120131
call :AdbConnect
121-
rem call :uiautomator2init
122132
echo ====================================================================================================
123133
echo Python Found in %pyBin% Proceeding..
124134
echo Opening alas_en.pyw in %root%
@@ -131,7 +141,6 @@ rem ================= OPTION 3 =================
131141
:jp
132142
call :CheckBsBeta
133143
call :AdbConnect
134-
rem call :uiautomator2init
135144
echo ====================================================================================================
136145
echo Python Found in %pyBin% Proceeding..
137146
echo Opening alas_en.pyw in %root%
@@ -413,6 +422,11 @@ goto ReturnToSetting
413422

414423
rem ================= FUNCTIONS =================
415424

425+
:CheckAdbConnect
426+
for /f "tokens=1*" %%g IN ('%adbBin% connect 127.0.0.1:5555') do set adbCheck=%%g
427+
if "%adbCheck%"=="cannot"
428+
echo %adbCheck%
429+
416430
:ReturnToSetting
417431
echo. & echo Press any key to continue...
418432
pause > NUL
@@ -444,6 +458,7 @@ for /f "tokens=3" %%a in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\BlueStacks_bgp6
444458
set SerialRealtime=127.0.0.1:%port%
445459
echo ====================================================================================================
446460
echo connecting at %SerialRealtime%
461+
%adbBin% kill-server > nul 2>&1
447462
%adbBin% connect %SerialRealtime%
448463
echo ====================================================================================================
449464
if "%FirstRun%"=="yes" (
@@ -456,14 +471,23 @@ echo Old Serial: %SerialAlas%
456471
echo New Serial: %SerialRealtime%
457472
echo ====================================================================================================
458473
echo Press any to continue...
474+
%pyBin% -m uiautomator2 init
459475
pause > NUL
460476
:: -----------------------------------------------------------------------------
461477
goto :eof
462478

463479
:AdbConnect
464480
if "%RealtimeMode%"=="enable" goto :eof
465-
if "%FirstRun%"=="yes" ( %adbBin% connect %serial_input% && goto :eof )
466-
%adbBin% connect %Serial%
481+
if "%FirstRun%"=="yes" ( goto :eof )
482+
%adbBin% kill-server > nul 2>&1
483+
%adbBin% connect %Serial% | find /i "connected to" >nul
484+
if errorlevel 1 (
485+
echo The connection was not successful
486+
goto Serial_setting
487+
) else (
488+
%pyBin% -m uiautomator2 init
489+
echo The connection was Successful
490+
)
467491
goto :eof
468492

469493
:KillAdb

command/GenerateConsoleBatch.bat

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
:: Used for "ADT-V4.bat" in :Create_Console-bat
33
:: Please make sure that: only call this batch when %cd% is %root%;
44
:: e.g.
5-
:: call command\GenerateDownloadBatch.bat portable
5+
:: call command\GenerateConsoleBatch.bat portable
66

77
@echo off
88
set "console-bat-filename=console.bat"
99
REM if "%DeployMode%"=="unknown" exit
10-
call :GenerateDownloadBatch_Common
11-
call :GenerateDownloadBatch-%~1
12-
call :GenerateDownloadBatch_Common2
10+
call :GenerateConsoleBatch_Common
11+
call :GenerateConsoleBatch-%~1
12+
call :GenerateConsoleBatch_Common2
1313
goto :eof
1414

1515

1616
rem ================= FUNCTIONS =================
1717

1818

19-
:GenerateDownloadBatch_Common
19+
:GenerateConsoleBatch_Common
2020
( echo @rem
2121
echo @echo off
2222
echo.
@@ -50,7 +50,7 @@ echo if NOT exist toolkit\command md toolkit\command
5050
echo del /Q toolkit\command\*.cmd ^>NUL 2^>NUL) > %console-bat-filename%
5151
goto :eof
5252

53-
:GenerateDownloadBatch_Common2
53+
:GenerateConsoleBatch_Common2
5454
( REM :: Show the instructions
5555
echo title Alas Console Debugger
5656
echo echo This is an console to run adb, git, python and pip.
@@ -70,7 +70,7 @@ echo PROMPT $P$_$G$G$G
7070
echo cmd /Q /K) >> %console-bat-filename%
7171
goto :eof
7272

73-
:GenerateDownloadBatch-New
73+
:GenerateConsoleBatch-New
7474
( echo echo @"%%_pyBin%%\python.exe" "%%_pyBin%%\Scripts\pip3.exe" %%%%*^> toolkit\command\pip3.cmd
7575
echo echo @"%%_pyBin%%\python.exe" "%%_pyBin%%\Scripts\pip.exe" %%%%*^> toolkit\command\pip.cmd
7676
echo echo @"%%_pyBin%%\python.exe" "%%_pyBin%%\Scripts\wheel.exe" %%%%*^> toolkit\command\wheel.cmd

command/Get.bat

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ goto :eof
1313

1414
rem ================= FUNCTIONS =================
1515

16+
:Importo_Deploy
17+
1618
:: %cd%: "%root%"
1719
:: Get %Language% , %Region% , %SystemType%
1820
:Import_Main
@@ -65,9 +67,17 @@ echo If you misstype, you can set in Settings menu Option 3
6567
echo =========================================================================
6668
set /p serial_input=Please input - SERIAL ^(DEFAULT 127.0.0.1:5555 ^):
6769
if "%serial_input%"=="" ( set "serial_input=127.0.0.1:5555" )
68-
call command\Config.bat Serial %serial_input%
69-
call command\ConfigTemplate.bat SerialTemplate %serial_input%
70-
70+
%adbBin% kill-server > nul 2>&1
71+
%adbBin% connect %serial_input% | find /i "connected to" >nul
72+
if errorlevel 1 (
73+
echo The connection was not successful
74+
goto Import_Serial
75+
) else (
76+
call command\Config.bat Serial %serial_input%
77+
call command\ConfigTemplate.bat SerialTemplate %serial_input%
78+
%pyBin% -m uiautomator2 init
79+
echo The connection was Successful
80+
)
7181
echo =========================================================================
7282
echo Old Serial: %Serial%
7383
echo New Serial: %serial_input%

0 commit comments

Comments
 (0)