Skip to content

Commit

Permalink
Merge pull request #82 from LmeSzinc/dev
Browse files Browse the repository at this point in the history
Add webapp
  • Loading branch information
LmeSzinc authored Sep 10, 2023
2 parents 0e1b657 + 2f596c7 commit 2f845bd
Show file tree
Hide file tree
Showing 182 changed files with 18,258 additions and 185 deletions.
124 changes: 123 additions & 1 deletion assets/gui/icon/alas.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 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,9 @@ Deploy:
# '["alas"]' specified "alas" config
# '["alas","alas2"]' specified "alas" "alas2" configs
Run: null
# To update app.asar
# [In most cases] true
AppAsarUpdate: true
# --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
11 changes: 9 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,9 @@ Deploy:
# '["alas"]' specified "alas" config
# '["alas","alas2"]' specified "alas" "alas2" configs
Run: null
# To update app.asar
# [In most cases] true
AppAsarUpdate: true
# --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
29 changes: 29 additions & 0 deletions console.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@rem
@echo off

set "_root=%~dp0"
set "_root=%_root:~0,-1%"
%~d0
cd "%_root%"

color F0

set "_pyBin=%_root%\toolkit"
set "_GitBin=%_root%\toolkit\Git\mingw64\bin"
set "_adbBin=%_root%\toolkit\Lib\site-packages\adbutils\binaries"
set "PATH=%_root%\toolkit\alias;%_root%\toolkit\command;%_pyBin%;%_pyBin%\Scripts;%_GitBin%;%_adbBin%;%PATH%"
set "ELECTRON_ENABLE_LOGGING=1"

title Alas Console Debugger
echo This is an console to run adb, git, python and pip.
echo adb devices
echo git log
echo python -V
echo pip -V
echo. & echo ----- & echo.
echo.
)
echo.

PROMPT $P$_$G$G$G
cmd /Q /K
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
12 changes: 7 additions & 5 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 @@ -48,8 +48,10 @@ def app_asar_replace(folder, path='./toolkit/WebApp/resources/app.asar'):
def app_update(self):
logger.hr(f'Update app', 0)

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

return self.app_asar_replace(os.getcwd())
# self.app_asar_replace(os.getcwd())
# Progress.UpdateAlasApp()
24 changes: 17 additions & 7 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 @@ -61,6 +62,11 @@ class ConfigModel:
Password: Optional[str] = None
CDN: Union[str, bool] = False
Run: Optional[str] = None
AppAsarUpdate: bool = True
NoSandbox: bool = True

# Dynamic
GitOverCdn: bool = False


class DeployConfig(ConfigModel):
Expand All @@ -73,10 +79,13 @@ 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'

# Bypass webui.config.DeployConfig.__setattr__()
# Don't write these into deploy.yaml
super().__setattr__('GitOverCdn', self.Repository in ['cn'])
if self.Repository in ['global', 'cn']:
super().__setattr__('Repository', 'https://github.com/LmeSzinc/StarRailCopilot')

self.write()
self.show_config()

Expand Down Expand Up @@ -111,11 +120,13 @@ def filepath(self, path):
Returns:
str: Absolute filepath.
"""
if os.path.isabs(path):
return path

return (
os.path.abspath(os.path.join(self.root_filepath, path))
.replace(r"\\", "/")
.replace("\\", "/")
.replace('"', '"')
)

@cached_property
Expand All @@ -124,7 +135,6 @@ def root_filepath(self):
os.path.abspath(os.path.join(os.path.dirname(__file__), "../../"))
.replace(r"\\", "/")
.replace("\\", "/")
.replace('"', '"')
)

@cached_property
Expand Down
46 changes: 44 additions & 2 deletions deploy/Windows/git.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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
from deploy.git_over_cdn.client import GitOverCdnClient


class GitConfigParser(configparser.ConfigParser):
Expand All @@ -15,6 +17,25 @@ def check(self, section, option, value):
return False


class GitOverCdnClientWindows(GitOverCdnClient):
def update(self, *args, **kwargs):
Progress.GitInit()
_ = super().update(*args, **kwargs)
Progress.GitShowVersion()
return _

@cached_property
def latest_commit(self) -> str:
_ = super().latest_commit
Progress.GitLatestCommit()
return _

def download_pack(self):
_ = super().download_pack()
Progress.GitDownloadPack()
return _


class GitManager(DeployConfig):
@staticmethod
def remove(file):
Expand All @@ -41,6 +62,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 +82,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,20 +118,37 @@ 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_over_cdn(self):
client = GitOverCdnClient(
url='https://vip.123pan.cn/1815343254/pack/LmeSzinc_StarRailCopilot_master',
folder=self.root_filepath,
)
client.logger = logger
_ = client.update(keep_changes=self.KeepLocalChanges)
return _

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

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

if self.GitOverCdn:
if self.git_over_cdn():
return

self.git_repository_init(
repo=self.Repository,
source='origin',
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
39 changes: 39 additions & 0 deletions deploy/Windows/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,43 @@ def hr(title, level=3):
logger.info(f"<<< {title} >>>")


def attr(name, text):
print(f'[{name}] {text}')


logger.hr = hr
logger.attr = attr


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)

GitLatestCommit = Percentage(25)
GitDownloadPack = Percentage(40)

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

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

# Must have a 100%
Finish = Percentage(100)
Loading

0 comments on commit 2f845bd

Please sign in to comment.