1
0
mirror of https://gitee.com/sui-feng-cb/AzurLaneAutoScript1 synced 2026-03-22 02:29:16 +08:00

Tweaks: Added improvements on Easy_Install

- Now it will be more difficult to occur mistake by user.
- Added GIT to winpython.
- Now alas.bat only use binarys embedded in python-3.7.6.amd64 folder
This commit is contained in:
whoamikyo
2020-06-24 09:26:13 -03:00
parent ab1f416819
commit 8471b2cb4d
2 changed files with 209 additions and 81 deletions

View File

@@ -1,14 +1,25 @@
@SETLOCAL EnableExtensions EnableDelayedExpansion
@echo off @echo off
pushd "%~dp0" pushd "%~dp0"
:: VARIABLES INSTALL
SET CMD=%SystemRoot%\system32\cmd.exe
SET LMESZINC=https://github.com/LmeSzinc/AzurLaneAutoScript.git
SET WHOAMIKYO=https://github.com/whoamikyo/AzurLaneAutoScript.git
rem SET ROOT_UPPER=%~dp0
rem SET ADB_PATH=%AZURLANESCRIPT%\python-3.7.6.amd64\Lib\site-packages\adbutils\binaries
:: -----------------------------------------------------------------------------
:: Make sure we're running with administrator privileges
echo. echo.
echo :: Checking For Administrator Elevation... echo :: Checking For Administrator Elevation...
echo. echo.
timeout /t 1 /nobreak > NUL net session >nul 2>&1
openfiles > NUL 2>&1 if %errorLevel% == 0 (
if %errorlevel%==0 (
echo Elevation found! Proceeding... echo Elevation found! Proceeding...
) else ( goto menu
) else (
echo :: You are NOT running as Administrator echo :: You are NOT running as Administrator
echo. echo.
echo Right-click and select ^'Run as Administrator^' and try again. echo Right-click and select ^'Run as Administrator^' and try again.
@@ -16,11 +27,36 @@ if %errorlevel%==0 (
pause > NUL pause > NUL
exit exit
) )
REM PowerShell -Command "Start-Sleep -s 3" > nul 2>&1
:: -----------------------------------------------------------------------------
set PATH=%PATH%;%PROGRAMDATA%\chocolatey\lib\adb\tools\platform-tools\;%PROGRAMFILES%\Git\cmd;%PROGRAMDATA%\chocolatey\bin :: Make sure the second path exists. The first path won't be created until the second script is run
rem IF NOT EXIST !ADB_PATH! (ECHO Path not found: %ADB_PATH% && GOTO ExitBatch)
:: -----------------------------------------------------------------------------
:: Add paths
rem CALL :AddPath %ADB_PATH%
rem CALL :AddPath %GIT_PATH%
rem CALL :AddPath %AZURLANESCRIPT%
rem CALL :AddPath %ROOT_UPPER%
pause
:: Branch to UpdateEnv if we need to update
REM IF DEFINED UPDATE (GOTO UpdateEnv)
REM GOTO ExitBatch
:: -----------------------------------------------------------------------------
REM :UpdateEnv
REM ECHO Making updated PATH go live . . .
REM REG delete HKCU\Environment /F /V TEMPVAR > nul 2>&1
REM setx TEMPVAR 1 > nul 2>&1
REM REG delete HKCU\Environment /F /V TEMPVAR > nul 2>&1
REM IF NOT !cmdcmdline! == !CMDLINERUNSTR! (CALL :KillExplorer)
REM GOTO ExitBatch
:: -----------------------------------------------------------------------------
goto menu goto menu
:menu :menu
cls cls
echo. echo.
@@ -28,25 +64,24 @@ goto menu
echo. echo.
echo This script will install Python 3.7.6 + requirements.txt + ADB + GIT + CHOCOLATEY echo This script will install Python 3.7.6 + requirements.txt + ADB + GIT + CHOCOLATEY
echo. echo.
echo :: For fresh install, Run from step "1" to "3" echo :: For fresh install, Run step "1" and "2"
echo. echo.
echo 1.Essentials programs echo 1.Python 3.7.6 + ADB + GIT + requirements.txt
echo 2.Clone repository (Download the latest version from LmeSzinc repository) echo 2.Clone repository (Download the latest version from LmeSzinc repository)
echo 3.Python 3.7.6 + requirements.txt echo 3.Programs (ADB + GIT Alternative way with CHOCOLATEY)
echo 4.Updater ONLY (Do not update if you are doing a fresh install) echo 4.Updater ONLY (Do not update if you are doing a fresh install)
echo. echo.
echo JUST RUN UPDATER INSIDE AzurLaneAutoScript FOLDER echo JUST RUN UPDATER INSIDE AzurLaneAutoScript FOLDER
echo. echo.
echo Install in order echo Install in order
echo. echo.
echo :: Type a 'number' and press ENTER echo :: Type a 'number' and press ENTER
echo :: Type 'exit' to quit echo :: Type 'exit' to quit
echo. echo.
set /P menu= set /P menu=
if %menu%==1 GOTO programs if %menu%==1 GOTO python
if %menu%==2 GOTO clone if %menu%==2 GOTO clone
if %menu%==3 GOTO python if %menu%==3 GOTO programs
if %menu%==4 GOTO updater if %menu%==4 GOTO updater
if %menu%==exit GOTO EOF if %menu%==exit GOTO EOF
@@ -61,8 +96,7 @@ goto menu
pause > NUL pause > NUL
goto menu goto menu
) )
:: -----------------------------------------------------------------------------
:programs :programs
cls cls
echo. echo.
@@ -92,85 +126,122 @@ cls
echo :: if you have problems I suggest uninstalling all packages mentioned in the control panel (windows) echo :: if you have problems I suggest uninstalling all packages mentioned in the control panel (windows)
echo. echo.
timeout /t 1 /nobreak > NUL timeout /t 1 /nobreak > NUL
SET PATH=%PATH%;%PROGRAMDATA%\chocolatey\lib\adb\tools\platform-tools\;%PROGRAMFILES%\Git\cmd;%PROGRAMDATA%\chocolatey\bin
echo Installing chocolatey on this machine echo Installing chocolatey on this machine
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))">>chocolatey-%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.log && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin @powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))">>chocolatey-%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.log && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
) )
echo Installing Essentials programs, It may take echo Installing Essentials programs, It may take
@powershell -NoProfile -ExecutionPolicy Bypass -Command "choco install -y --force --allow-empty-checksums adb git">>Essentials-%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.log @powershell -NoProfile -ExecutionPolicy Bypass -Command "choco install -y --force --allow-empty-checksums adb git">>Essentials-%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.log
) )
:: timout
PowerShell -Command "Start-Sleep -s 3" > nul 2>&1
call refreshenv call refreshenv
set PATH=%PATH%;%PROGRAMDATA%\chocolatey\lib\adb\tools\platform-tools\ goto menu
:: -----------------------------------------------------------------------------
:: killing adb server :: killing adb server
call adb --version >nul :killadb
call %ADB_PATH% --version >nul
if %errorlevel% == 0 ( if %errorlevel% == 0 (
echo ADB Found! Proceeding.. echo ADB Found! Proceeding..
echo killing adb server.. echo killing adb server..
call adb kill-server > nul 2>&1 call %ADB_PATH% kill-server > nul 2>&1
goto menu
) else ( ) else (
echo :: ADB not found, maybe there was an installation issue, try opening another CMD window and type choco install adb echo :: ADB not found, maybe there was an installation issue, try opening another CMD window and type choco install adb
echo. echo.
pause > NUL pause > NUL
) goto menu
REM call adb kill-server > nul 2>&1 )
goto menu :: -----------------------------------------------------------------------------
:clone :clone
set ROOT=%~dp0AzurLaneAutoScript SET AZURLANESCRIPT=%~dp0AzurLaneAutoScript
SET PATH=%PATH%;%PROGRAMFILES%\Git\cmd SET GIT_PATH=%AZURLANESCRIPT%\python-3.7.6.amd64\Git\cmd
echo Cloning repository SET GIT=%GIT_PATH%\git.exe
if exist %ROOT% ( call %GIT% --version >nul
RMDIR /S /Q %ROOT%
)
call git --version >nul
if %errorlevel% == 0 ( if %errorlevel% == 0 (
echo Cloning repository
echo GIT Found! Proceeding.. echo GIT Found! Proceeding..
echo Cloning repository... echo Cloning repository...
call git clone https://github.com/LmeSzinc/AzurLaneAutoScript.git && cd AzurLaneAutoScript && git remote add whoamikyo https://github.com/whoamikyo/AzurLaneAutoScript.git cd %AZURLANESCRIPT%
echo Deleting folder unused files
for /D %%D in ("*") do (
if /I not "%%~nxD"=="python-3.7.6.amd64" rd /S /Q "%%~D"
)
for %%F in ("*") do (
del "%%~F"
)
echo ## initializing..
call %GIT% init
echo ## adding origin..
call %GIT% remote add origin %LMESZINC%
echo ## pulling project...
call %GIT% pull origin master
echo ## setting default branch...
call %GIT% branch --set-upstream-to=origin/master master
call %GIT% remote add whoamikyo %WHOAMIKYO%
echo The installation was successful
echo Press any key to proceed
pause > NUL
goto menu
) else ( ) else (
echo :: Git not found, maybe there was an installation issue, try opening another CMD window and type choco install git echo :: Git not found, maybe there was an installation issue, try opening another CMD window and type choco install git
echo. echo.
pause > NUL pause > NUL
) )
REM PowerShell -Command "Start-Sleep -s 3" > nul 2>&1 :: -----------------------------------------------------------------------------
goto menu
:python :python
cls cls
echo. echo.
echo :: Installing Python 3.7.6 + requirements.txt echo :: Python 3.7.6 + ADB + GIT + requirements.txt
echo. echo.
echo. echo.
set ROOT=%~dp0AzurLaneAutoScript SET PYTHON=%~dp0AzurLaneAutoScript/python-3.7.6.amd64/python.exe
set FILE_URL="https://gitlab.com/whoamikyo/alas-venv/-/raw/master/python.zip" SET AZURLANESCRIPT=%~dp0AzurLaneAutoScript
set FILE_DEST=%ROOT%\pythonpackage.zip SET FILE_URL=https://gitlab.com/whoamikyo/alas-venv/-/raw/master/python.zip
if not exist %ROOT% ( SET FILE_DEST=%AZURLANESCRIPT%\pythonpackage.zip
mkdir %ROOT% if not exist %AZURLANESCRIPT% (
echo WILL BE CREATED A FOLDER "AzurLaneAutoScript"
echo DO NOT RENAME THE FOLDER NEVER
mkdir %AZURLANESCRIPT%
) )
if not exist "%FILE_DEST%" ( if not exist "%FILE_DEST%" (
echo Downloading with powershell: %FILE_URL% to %FILE_DEST% echo Downloading with powershell: %FILE_URL% to %FILE_DEST%
powershell.exe -command "$webclient = New-Object System.Net.WebClient; $url = \"%FILE_URL%\"; $file = \"%FILE_DEST%\"; $webclient.DownloadFile($url,$file);" powershell.exe -command "$webclient = New-Object System.Net.WebClient; $url = \"%FILE_URL%\"; $file = \"%FILE_DEST%\"; $webclient.DownloadFile($url,$file);"
echo Expanding with powershell to: %ROOT% echo Expanding with powershell to: %AZURLANESCRIPT%
powershell -command "$shell_app=new-object -com shell.application; $zip_file = $shell_app.namespace(\"%FILE_DEST%\"); $destination = $shell_app.namespace(\"%ROOT%\"); $destination.Copyhere($zip_file.items())" powershell -command "$shell_app=new-object -com shell.application; $zip_file = $shell_app.namespace(\"%FILE_DEST%\"); $destination = $shell_app.namespace(\"%AZURLANESCRIPT%\"); $destination.Copyhere($zip_file.items())"
) else ( ) else (
echo "pythonpackage.zip already downloaded, delete to re-download" echo "pythonpackage.zip already downloaded, delete to re-download"
pause > NUL pause > NUL
) )
call %~dp0AzurLaneAutoScript/python-3.7.6.amd64/python.exe --version >nul call %PYTHON% --version >nul
if %errorlevel% == 0 ( if %errorlevel% == 0 (
echo Python Found! Proceeding.. echo Python Found! Proceeding..
echo initializing uiautomator2.. echo initializing uiautomator2..
%~dp0AzurLaneAutoScript/python-3.7.6.amd64/python.exe -m uiautomator2 init call %PYTHON% -m uiautomator2 init
echo The installation was successful
echo Press any key to proceed
pause > NUL
goto menu
) else ( ) else (
echo :: it was not possible to install uiautomator2, make sure you have a folder python-3.7.6.amd64 echo :: it was not possible to install uiautomator2
echo :: make sure you have a folder "python-3.7.6.amd64"
echo :: inside AzurLaneAutoScript folder. echo :: inside AzurLaneAutoScript folder.
echo. echo.
pause > NUL pause > NUL
goto menu
) )
goto menu :: -----------------------------------------------------------------------------
:updater :updater
SET GIT_ALAS=%~dp0python-3.7.6.amd64\Git\cmd\git.exe
SET GLP=%GIT_ALAS%
SET ALAS_PY=alas.py
if exist %ALAS_PY% (
goto updater_menu
) else (
cd AzurLaneAutoScript
echo.
goto updater_menu
)
:: -----------------------------------------------------------------------------
:updater_menu
cls cls
echo. echo.
echo :: This update only will work if you downloaded ALAS with this file using option 2. clone echo :: This update only will work if you downloaded ALAS with this file using option 2. clone
@@ -207,49 +278,102 @@ goto menu
echo Press any key to return to the menu... echo Press any key to return to the menu...
echo. echo.
pause > NUL pause > NUL
goto updater goto updater_menu
) )
:: -----------------------------------------------------------------------------
:LmeSzinc :LmeSzinc
call git --version >nul call %GLP% --version >nul
if %errorlevel% == 0 ( if %errorlevel% == 0 (
echo GIT Found! Proceeding.. echo GIT Found! Proceeding..
echo Updating from LmeSzinc repository.. echo Updating from LmeSzinc repository..
call git fetch origin master && git reset --hard origin/master && git pull --ff-only origin master call %GLP% fetch origin master
call %GLP% reset --hard origin/master
call %GLP% pull --ff-only origin master
echo DONE!
echo Press any key to proceed
pause > NUL
goto updater_menu
) else ( ) else (
echo :: Git not detected, maybe there was an installation issue, try opening another CMD window and type choco install git echo :: Git not detected, maybe there was an installation issue
echo check if you have this directory:
echo AzurLaneAutoScript\python-3.7.6.amd64\Git\cmd
echo. echo.
pause > NUL pause > NUL
) )
:: timout :: -----------------------------------------------------------------------------
PowerShell -Command "Start-Sleep -s 3" > nul 2>&1
goto updater
:whoamikyo :whoamikyo
call git --version >nul call %GLP% --version >nul
if %errorlevel% == 0 ( if %errorlevel% == 0 (
echo GIT Found! Proceeding.. echo GIT Found! Proceeding..
echo Updating from whoamikyo repository.. echo Updating from whoamikyo repository..
call git fetch whoamikyo master && git reset --hard whoamikyo/master && git pull --ff-only whoamikyo master call %GLP% fetch whoamikyo master
call %GLP% reset --hard whoamikyo/master
call %GLP% pull --ff-only whoamikyo master
echo DONE!
echo Press any key to proceed
pause > NUL
goto updater_menu
) else ( ) else (
echo :: Git not detected, maybe there was an installation issue, try opening another CMD window and type choco install git echo :: Git not detected, maybe there was an installation issue
echo. echo check if you have this directory:
echo AzurLaneAutoScript\python-3.7.6.amd64\Git\cmd
pause > NUL pause > NUL
goto updater_menu
) )
:: timout :: -----------------------------------------------------------------------------
PowerShell -Command "Start-Sleep -s 3" > nul 2>&1
goto updater
:nightly :nightly
call git --version >nul call %GLP% --version >nul
if %errorlevel% == 0 ( if %errorlevel% == 0 (
echo GIT Found! Proceeding.. echo GIT Found! Proceeding..
echo Updating from whoamikyo nightly repository.. echo Updating from whoamikyo nightly repository..
call git fetch whoamikyo nightly && git reset --hard whoamikyo/nightly && git pull --ff-only whoamikyo nightly call %GLP% fetch whoamikyo nightly
call %GLP% reset --hard whoamikyo/nightly
call %GLP% pull --ff-only whoamikyo nightly
echo Press any key to proceed
pause > NUL
goto updater_menu
) else ( ) else (
echo :: Git not detected, maybe there was an installation issue, try opening another CMD window and type choco install git echo :: Git not detected, maybe there was an installation issue
echo check if you have this directory:
echo AzurLaneAutoScript\python-3.7.6.amd64\Git\cmd
echo. echo.
pause > NUL pause > NUL
goto updater_menu
) )
:: timout
PowerShell -Command "Start-Sleep -s 3" > nul 2>&1 :: -----------------------------------------------------------------------------
goto updater
rem :AddPath <pathToAdd>
rem ECHO %PATH% | FINDSTR /C:"%~1" > nul
rem IF ERRORLEVEL 1 (
rem REG add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /f /v PATH /t REG_SZ /d "%PATH%;%~1" > nul 2>&1
rem IF ERRORLEVEL 0 (
rem ECHO Adding %1 . . . Success!
rem SET "PATH=%PATH%;%~1"
rem SET UPDATE=1
rem ) ELSE (
rem ECHO Adding %1 . . . FAILED. Run this script with administrator privileges.
rem )
rem ) ELSE (
rem ECHO Skipping %1 - Already in PATH
rem )
rem EXIT /b
:: -----------------------------------------------------------------------------
rem :KillExplorer
rem ECHO Your desktop is being restarted, please wait. . .
rem ping -n 5 127.0.0.1 > NUL 2>&1
rem ECHO Killing process Explorer.exe. . .
rem taskkill /f /im explorer.exe
rem ECHO.
rem ECHO Your desktop is now loading. . .
rem ping -n 5 127.0.0.1 > NUL 2>&1
rem ECHO.
rem ping -n 5 127.0.0.1 > NUL 2>&1
rem START explorer.exe
rem START explorer.exe %CD%
rem EXIT /b
:: -----------------------------------------------------------------------------

View File

@@ -1,7 +1,10 @@
@SETLOCAL EnableExtensions EnableDelayedExpansion
@echo off @echo off
title ALAS run title ALAS run
call adb kill-server > nul 2>&1 SET ADB=%~dp0python-3.7.6.amd64\Lib\site-packages\adbutils\binaries\adb.exe
SET PYTHON=%~dp0python-3.7.6.amd64\python.exe
call %ADB% kill-server > nul 2>&1
set SCREENSHOT_FOLDER=%~dp0screenshots set SCREENSHOT_FOLDER=%~dp0screenshots
if not exist %SCREENSHOT_FOLDER% ( if not exist %SCREENSHOT_FOLDER% (
@@ -34,7 +37,7 @@ REM
set /p ADB_PORT=<adb_port.ini set /p ADB_PORT=<adb_port.ini
echo connecting at %ADB_PORT% echo connecting at %ADB_PORT%
adb connect %ADB_PORT% call %ADB% connect %ADB_PORT%
::echo initializing uiautomator2 ::echo initializing uiautomator2
::%~dp0python-3.7.6.amd64/python.exe -m uiautomator2 init ::%~dp0python-3.7.6.amd64/python.exe -m uiautomator2 init
@@ -77,24 +80,25 @@ goto alas
) )
:en :en
call %~dp0python-3.7.6.amd64/python.exe --version >nul call %PYTHON% --version >nul
if %errorlevel% == 0 ( if %errorlevel% == 0 (
echo Python Found! Proceeding.. echo Python Found! Proceeding..
echo Opening alas_en.pyw... echo Opening alas_en.pyw...
%~dp0python-3.7.6.amd64/python.exe alas_en.pyw call %PYTHON% alas_en.pyw
) else ( ) else (
echo :: it was not possible to open alas_en.pyw, make sure you have a folder python-3.7.6.amd64 echo :: it was not possible to open alas_en.pyw, make sure you have a folder python-3.7.6.amd64
echo :: inside AzurLaneAutoScript folder. echo :: inside AzurLaneAutoScript folder.
echo. echo.
pause > NUL pause > NUL
) )
PowerShell -Command "Start-Sleep -s 10" > nul 2>&1
goto alas goto alas
:cn :cn
call %~dp0python-3.7.6.amd64/python.exe --version >nul call %PYTHON% --version >nul
if %errorlevel% == 0 ( if %errorlevel% == 0 (
echo Python Found! Proceeding.. echo Python Found! Proceeding..
echo Opening alas_en.pyw... echo Opening alas_en.pyw...
%~dp0python-3.7.6.amd64/python.exe alas_cn.pyw call %PYTHON% alas_cn.pyw
) else ( ) else (
echo :: it was not possible to open alas_cn.pyw, make sure you have a folder python-3.7.6.amd64 echo :: it was not possible to open alas_cn.pyw, make sure you have a folder python-3.7.6.amd64
echo :: inside AzurLaneAutoScript folder. echo :: inside AzurLaneAutoScript folder.
@@ -103,11 +107,11 @@ goto alas
) )
goto alas goto alas
:jp :jp
call %~dp0python-3.7.6.amd64/python.exe --version >nul call %PYTHON% --version >nul
if %errorlevel% == 0 ( if %errorlevel% == 0 (
echo Python Found! Proceeding.. echo Python Found! Proceeding..
echo Opening alas_en.pyw... echo Opening alas_en.pyw...
%~dp0python-3.7.6.amd64/python.exe alas_jp.pyw call %PYTHON% alas_jp.pyw
) else ( ) else (
echo :: it was not possible to open alas_jp.pyw, make sure you have a folder python-3.7.6.amd64 echo :: it was not possible to open alas_jp.pyw, make sure you have a folder python-3.7.6.amd64
echo :: inside AzurLaneAutoScript folder. echo :: inside AzurLaneAutoScript folder.