Skip to content

Commit

Permalink
Upd: [ALAS] installer
Browse files Browse the repository at this point in the history
  • Loading branch information
LmeSzinc committed Sep 9, 2023
1 parent f7bc698 commit 0067e34
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 31 deletions.
8 changes: 6 additions & 2 deletions config/deploy.template-cn.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Deploy:
Git:
# URL of AzurLaneAutoScript repository
# [Other] Use 'https://github.com/LmeSzinc/StarRailCopilot'
Repository: https://e.coding.net/llop18870/alas/AzurLaneAutoScript.git
# [CN user] Use 'cn' to get update from git-over-cdn service
# [Other] Use 'global' to get update from https://github.com/LmeSzinc/StarRailCopilot
Repository: cn
# Branch of Alas
# [Developer] Use 'dev', 'app', etc, to try new features
# [Other] Use 'master', the stable branch
Expand Down Expand Up @@ -156,3 +157,6 @@ Deploy:
# '["alas"]' specified "alas" config
# '["alas","alas2"]' specified "alas" "alas2" configs
Run: null
# --no-sandbox. https://github.com/electron/electron/issues/30966
# Some Windows systems cannot call the GPU normally for virtualization, and you need to manually turn off sandbox mode
NoSandbox: false
8 changes: 6 additions & 2 deletions config/deploy.template.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Deploy:
Git:
# URL of AzurLaneAutoScript repository
# [Other] Use 'https://github.com/LmeSzinc/StarRailCopilot'
Repository: https://github.com/LmeSzinc/StarRailCopilot
# [CN user] Use 'cn' to get update from git-over-cdn service
# [Other] Use 'global' to get update from https://github.com/LmeSzinc/StarRailCopilot
Repository: global
# Branch of Alas
# [Developer] Use 'dev', 'app', etc, to try new features
# [Other] Use 'master', the stable branch
Expand Down Expand Up @@ -156,3 +157,6 @@ Deploy:
# '["alas"]' specified "alas" config
# '["alas","alas2"]' specified "alas" "alas2" configs
Run: null
# --no-sandbox. https://github.com/electron/electron/issues/30966
# Some Windows systems cannot call the GPU normally for virtualization, and you need to manually turn off sandbox mode
NoSandbox: false
6 changes: 4 additions & 2 deletions deploy/Windows/adb.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import os

from deploy.Windows.emulator import EmulatorManager
from deploy.Windows.logger import logger
from deploy.Windows.utils import *
from deploy.Windows.logger import Progress, logger


def show_fix_tip(module):
Expand All @@ -23,9 +23,11 @@ def adb_install(self):
if self.ReplaceAdb:
logger.hr('Replace ADB', 1)
self.adb_replace()
Progress.AdbReplace()
if self.AutoConnect:
logger.hr('ADB Connect', 1)
self.brute_force_connect()
Progress.AdbConnect()

if False:
logger.hr('Uiautomator2 Init', 1)
Expand Down
19 changes: 13 additions & 6 deletions deploy/Windows/alas.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import time
import typing as t

from deploy.Windows.config import DeployConfig
from deploy.Windows.logger import logger
from deploy.Windows.utils import *
from deploy.Windows.logger import Progress, logger
from deploy.Windows.utils import DataProcessInfo, cached_property, iter_process


class AlasManager(DeployConfig):
Expand Down Expand Up @@ -43,8 +44,9 @@ def iter_process_by_names(self, names, in_alas=False) -> t.Iterable[DataProcessI
if proc.pid == self.self_pid:
continue
if in_alas:
cmdline = proc.cmdline.replace(r"\\", "/").replace("\\", "/")
for folder in self.alas_folder:
if folder in proc.cmdline:
if folder in cmdline:
yield proc
else:
yield proc
Expand All @@ -56,15 +58,20 @@ def kill_process(self, process: DataProcessInfo):
self.execute(f'taskkill /f /t /pid {process.pid}', allow_failure=True, output=False)

def alas_kill(self):
while 1:
for _ in range(10):
logger.hr(f'Kill existing Alas', 0)
proc_list = list(self.iter_process_by_names(['alas.exe', 'python.exe'], in_alas=True))
proc_list = list(self.iter_process_by_names(['python.exe'], in_alas=True))
if not len(proc_list):
break
Progress.KillExisting()
return True
for proc in proc_list:
logger.info(proc)
self.kill_process(proc)

logger.warning('Unable to kill existing Alas, skip')
Progress.KillExisting()
return False


if __name__ == '__main__':
self = AlasManager()
Expand Down
8 changes: 5 additions & 3 deletions deploy/Windows/app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import filecmp
import os
import shutil

from deploy.Windows.config import DeployConfig
from deploy.Windows.logger import logger
from deploy.Windows.utils import *
from deploy.Windows.logger import Progress, logger


class AppManager(DeployConfig):
Expand Down Expand Up @@ -50,6 +50,8 @@ def app_update(self):

if not self.AutoUpdate:
logger.info('AutoUpdate is disabled, skip')
Progress.UpdateAlasApp()
return False

return self.app_asar_replace(os.getcwd())
self.app_asar_replace(os.getcwd())
Progress.UpdateAlasApp()
10 changes: 4 additions & 6 deletions deploy/Windows/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import copy
import os
import subprocess
from typing import Optional, Union

from deploy.Windows.logger import logger
from deploy.Windows.utils import *
from deploy.Windows.utils import DEPLOY_CONFIG, DEPLOY_TEMPLATE, cached_property, poor_yaml_read, poor_yaml_write


class ExecutionError(Exception):
Expand Down Expand Up @@ -54,7 +55,7 @@ class ConfigModel:

# Webui
WebuiHost: str = "0.0.0.0"
WebuiPort: int = 22367
WebuiPort: int = 22267
Language: str = "en-US"
Theme: str = "default"
DpiScaling: bool = True
Expand All @@ -73,10 +74,7 @@ def __init__(self, file=DEPLOY_CONFIG):
self.config = {}
self.config_template = {}
self.read()
if self.Repository == 'https://gitee.com/LmeSzinc/AzurLaneAutoScript':
self.Repository = 'https://e.coding.net/llop18870/alas/AzurLaneAutoScript.git'
if self.Repository == 'https://gitee.com/lmeszinc/azur-lane-auto-script-mirror':
self.Repository = 'https://e.coding.net/llop18870/alas/AzurLaneAutoScript.git'

self.write()
self.show_config()

Expand Down
13 changes: 11 additions & 2 deletions deploy/Windows/git.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import configparser
import os

from deploy.Windows.config import DeployConfig
from deploy.Windows.logger import logger
from deploy.Windows.utils import *
from deploy.Windows.logger import Progress, logger
from deploy.Windows.utils import cached_property


class GitConfigParser(configparser.ConfigParser):
Expand Down Expand Up @@ -41,6 +42,7 @@ def git_repository_init(
self.remove('./.git/HEAD')
self.remove('./.git/ORIG_HEAD')
self.execute(f'"{self.git}" init')
Progress.GitInit()

logger.hr('Set Git Proxy', 1)
if proxy:
Expand All @@ -60,14 +62,17 @@ def git_repository_init(
else:
if not self.git_config.check('http', 'sslVerify', value='false'):
self.execute(f'"{self.git}" config --local http.sslVerify false', allow_failure=True)
Progress.GitSetConfig()

logger.hr('Set Git Repository', 1)
if not self.git_config.check(f'remote "{source}"', 'url', value=repo):
if not self.execute(f'"{self.git}" remote set-url {source} {repo}', allow_failure=True):
self.execute(f'"{self.git}" remote add {source} {repo}')
Progress.GitSetRepo()

logger.hr('Fetch Repository Branch', 1)
self.execute(f'"{self.git}" fetch {source} {branch}')
Progress.GitFetch()

logger.hr('Pull Repository Branch', 1)
# Remove git lock
Expand All @@ -93,18 +98,22 @@ def git_repository_init(
self.execute(f'"{self.git}" pull --ff-only {source} {branch}')
else:
self.execute(f'"{self.git}" reset --hard {source}/{branch}')
Progress.GitReset()
# Since `git fetch` is already called, checkout is faster
if not self.execute(f'"{self.git}" checkout {branch}', allow_failure=True):
self.execute(f'"{self.git}" pull --ff-only {source} {branch}')
Progress.GitCheckout()

logger.hr('Show Version', 1)
self.execute(f'"{self.git}" --no-pager log --no-merges -1')
Progress.GitShowVersion()

def git_install(self):
logger.hr('Update Alas', 0)

if not self.AutoUpdate:
logger.info('AutoUpdate is disabled, skip')
Progress.GitShowVersion()
return

self.git_repository_init(
Expand Down
1 change: 1 addition & 0 deletions deploy/Windows/installer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
DataAdbDevice(serial='127.0.0.1:16480', status='device')
DataAdbDevice(serial='127.0.0.1:7555', status='device')
Process: [ 100% ]
中文测试,!@#nfoir
"""


Expand Down
31 changes: 31 additions & 0 deletions deploy/Windows/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,34 @@ def hr(title, level=3):


logger.hr = hr


class Percentage:
def __init__(self, progress):
self.progress = progress

def __call__(self, *args, **kwargs):
logger.info(f'Process: [ {self.progress}% ]')


class Progress:
Start = Percentage(0)
ShowDeployConfig = Percentage(10)

GitInit = Percentage(12)
GitSetConfig = Percentage(13)
GitSetRepo = Percentage(15)
GitFetch = Percentage(40)
GitReset = Percentage(45)
GitCheckout = Percentage(48)
GitShowVersion = Percentage(50)

KillExisting = Percentage(60)
UpdateDependency = Percentage(70)
UpdateAlasApp = Percentage(75)

AdbReplace = Percentage(80)
AdbConnect = Percentage(95)

# Must have a 100%
Finish = Percentage(100)
10 changes: 8 additions & 2 deletions deploy/Windows/pip.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
import re
import typing as t
from dataclasses import dataclass
from urllib.parse import urlparse

from deploy.Windows.config import DeployConfig
from deploy.Windows.logger import logger
from deploy.Windows.utils import *
from deploy.Windows.logger import logger, Progress
from deploy.Windows.utils import cached_property


@dataclass
Expand All @@ -20,6 +22,7 @@ def __post_init__(self):
# PyYaml -> pyyaml
self.name = self.name.lower()
self.version = self.version.strip()
self.version = re.sub(r'\.0$', '', self.version)

@cached_property
def pretty_name(self):
Expand Down Expand Up @@ -93,10 +96,12 @@ def pip_install(self):

if not self.InstallDependencies:
logger.info('InstallDependencies is disabled, skip')
Progress.UpdateDependency()
return

if not len(self.set_dependency_to_install):
logger.info('All dependencies installed')
Progress.UpdateDependency()
return
else:
logger.info(f'Dependencies to install: {self.set_dependency_to_install}')
Expand Down Expand Up @@ -124,3 +129,4 @@ def pip_install(self):
logger.hr('Update Dependencies', 1)
arg = ' ' + ' '.join(arg) if arg else ''
self.execute(f'{self.pip} install -r {self.requirements_file}{arg}')
Progress.UpdateDependency()
8 changes: 6 additions & 2 deletions deploy/Windows/template.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Deploy:
Git:
# URL of AzurLaneAutoScript repository
# [Other] Use 'https://github.com/LmeSzinc/StarRailCopilot'
Repository: 'https://github.com/LmeSzinc/StarRailCopilot'
# [CN user] Use 'cn' to get update from git-over-cdn service
# [Other] Use 'global' to get update from https://github.com/LmeSzinc/StarRailCopilot
Repository: 'global'
# Branch of Alas
# [Developer] Use 'dev', 'app', etc, to try new features
# [Other] Use 'master', the stable branch
Expand Down Expand Up @@ -156,3 +157,6 @@ Deploy:
# '["alas"]' specified "alas" config
# '["alas","alas2"]' specified "alas" "alas2" configs
Run: null
# --no-sandbox. https://github.com/electron/electron/issues/30966
# Some Windows systems cannot call the GPU normally for virtualization, and you need to manually turn off sandbox mode
NoSandbox: false
2 changes: 1 addition & 1 deletion deploy/Windows/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import re
from dataclasses import dataclass
from typing import Callable, Iterable, Generic, TypeVar
from typing import Callable, Generic, Iterable, TypeVar

T = TypeVar("T")

Expand Down
12 changes: 10 additions & 2 deletions deploy/installer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from deploy.Windows.logger import Progress, logger
from deploy.Windows.patch import pre_checks

pre_checks()
Expand All @@ -22,5 +23,12 @@ def install(self):
exit(1)


if __name__ == '__main__':
Installer().install()
def run():
Progress.Start()
installer = Installer()
Progress.ShowDeployConfig()

installer.install()

logger.info('Finish')
Progress.Finish()
Loading

0 comments on commit 0067e34

Please sign in to comment.