Skip to content

Commit

Permalink
Merge pull request #76 from sanmusen214/dev
Browse files Browse the repository at this point in the history
Global server version update
  • Loading branch information
sanmusen214 authored Jul 23, 2024
2 parents 2a741d9 + 05f2a50 commit a5e8866
Show file tree
Hide file tree
Showing 52 changed files with 502 additions and 119 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ compact_log.txt
/_internal
/BAAH.exe
/BAAH_GUI.exe
/platform-tools-latest.zip
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
6 changes: 0 additions & 6 deletions BAAH.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ def BAAH_main():
执行BAAH主程序,在此之前config应该已经被单独import然后解析为用户指定的配置文件->随后再导入my_AllTask以及其他依赖config的模块
"""
try:
# TODO: 加任务执行前后bash脚本
config.sessiondict["BAAH_START_TIME"] = time.strftime("%Y-%m-%d %H:%M:%S")
print_BAAH_start()
BAAH_run_pre_command()
Expand Down Expand Up @@ -329,8 +328,3 @@ def BAAH_main():
BAAH_send_err_mail(e)
print_BAAH_finish()
BAAH_auto_quit(forcewait=True)


if __name__ in ["__main__", "__mp_main__"]:
# 不带GUI运行
BAAH_main()
5 changes: 3 additions & 2 deletions BAAH_CONFIGS/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
"AUTO_ASSAULT": false,
"AUTO_ASSAULT_LEVEL": 4,
"RUN_UNTIL_TRY_TIMES": 9,
"RUN_UNTIL_WAIT_TIME": 0.7,
"RUN_UNTIL_WAIT_TIME": 0.5,
"ADB_DIRECT_USE_SERIAL_NUMBER": false,
"ADB_SEIAL_NUMBER": "emulator-5554",
"IS_AUTO_ASSAULT_STUDENT_HELP": false,
Expand All @@ -254,5 +254,6 @@
"PRE_COMMAND": "",
"POST_COMMAND": "",
"SHOP_NORMAL_SWITCH": true,
"SHOP_CONTEST_SWITCH": true
"SHOP_CONTEST_SWITCH": true,
"USER_DEF_TASKS": ""
}
Binary file modified DATA/assets/BUTTON/BUTTON_JUMP.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified DATA/assets/BUTTON/BUTTON_NOT_JUMP.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed DATA/assets/PAGE/PAGE_CRAFT_FINISH.png
Binary file not shown.
Binary file removed DATA/assets/PAGE/PAGE_CRAFT_SELECT.png
Binary file not shown.
Binary file modified DATA/assets/PAGE/PAGE_FIGHT_CENTER.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions DATA/assets/PageName.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class PageName:
PAGE_CLUB = "PAGE_CLUB"

PAGE_CRAFT = "PAGE_CRAFT"
PAGE_CRAFT_SELECT = "PAGE_CRAFT_SELECT"
PAGE_CRAFT_FINISH = "PAGE_CRAFT_FINISH"

PAGE_FIGHT_CENTER = "PAGE_FIGHT_CENTER"

Expand Down
4 changes: 3 additions & 1 deletion DATA/assets/差异.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
日服

国际服
几个月后会实装简易攻略

国服
BUTTON_CAFE_SET_ROOM.png 暂无:国服的咖啡厅切换(版本未到)
礼服日奈的fes也许会把竞技场的跳过战斗文字改动。
礼服日奈的fes会把社团的入口改动
Binary file modified DATA/assets_cn/PAGE/PAGE_CRAFT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed DATA/assets_cn/PAGE/PAGE_CRAFT_FINISH.png
Binary file not shown.
Binary file removed DATA/assets_cn/PAGE/PAGE_CRAFT_SELECT.png
Binary file not shown.
Binary file modified DATA/assets_global_en/BUTTON/BUTTON_JUMP.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified DATA/assets_global_en/BUTTON/BUTTON_NOT_JUMP.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed DATA/assets_global_en/PAGE/PAGE_CRAFT_FINISH.png
Binary file not shown.
Binary file removed DATA/assets_global_en/PAGE/PAGE_CRAFT_SELECT.png
Binary file not shown.
Binary file modified DATA/assets_global_en/PAGE/PAGE_FIGHT_CENTER.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed DATA/assets_jp/PAGE/PAGE_CRAFT_FINISH.png
Binary file not shown.
Binary file removed DATA/assets_jp/PAGE/PAGE_CRAFT_SELECT.png
Binary file not shown.
1 change: 1 addition & 0 deletions DATA/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"push_hard":"Explore Hard Quest",
"push_main_story":"Explore Eposide",
"task_assault": "Assault",
"task_user_def_task": "User Defined Task",

"setting_emulator": "Emulator Configuration",
"setting_server": "Server Configuration",
Expand Down
1 change: 1 addition & 0 deletions DATA/i18n/jp_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"push_hard": "難関ステージの攻略",
"push_main_story": "メインストーリーの進行",
"task_assault": "総力戦",
"task_user_def_task": "ユーザー定義タスク",

"setting_emulator": "エミュレータ設定",
"setting_server": "サーバー設定",
Expand Down
1 change: 1 addition & 0 deletions DATA/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"push_hard":"困难图推图",
"push_main_story":"推主线剧情",
"task_assault":"总力战",
"task_user_def_task": "自定义任务",

"setting_emulator":"模拟器配置",
"setting_server":"服务器配置",
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ Japanese server support from [@LLL1997](https://github.com/LLL1997)

CN server support from [@子墨](https://space.bilibili.com/11179370)

Fully English logging support from [@ly5519](https://github.com/ly5519)
Fully English logging support and function enhancement from [@ly5519](https://github.com/ly5519)

Linux platform suitable by [@lonzzi](https://github.com/lonzzi)

[opencv-python](https://github.com/opencv/opencv)

Expand Down
8 changes: 8 additions & 0 deletions docs/README_dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@

自动脚本项目从main.py作为入口,从命令行读取用户指定的用户配置文件,然后通过AllTask下的myAllTask类解析此用户配置文件的每日任务,为每个任务创建相应的Task实例为一个列表,在BAAH.py里按序运行这些Task实例。

# 项目打包

使用pyinstaller打包,打包命令为

```python
python package.py
```

# 关键类

## modules/configs/Configger类
Expand Down
8 changes: 8 additions & 0 deletions docs/README_dev_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@

The automatic script project runs from main.py as the entry point. It reads the user-specified configuration file from the command line and then parses the daily tasks for this user configuration file through the myAllTask class under AllTask. It creates corresponding Task instances for each task in a list and sequentially runs these Task instances in BAAH.py.

# Project Package

Mainly use pyinstaller for packaging. The packaging command is

```python
python package.py
```

# Key Classes

## modules/configs/Configger Class
Expand Down
6 changes: 6 additions & 0 deletions gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from gui.pages.Setting_vpn import set_vpn
from gui.pages.Setting_Assault import set_assault
from gui.pages.Setting_BuyAP import set_buyAP
from gui.pages.Setting_UserTask import set_usertask



Expand Down Expand Up @@ -57,6 +58,7 @@ def show_GUI(load_jsonname, config, shared_softwareconfig):
"普通推图":config.get_text("push_normal"),
"困难推图":config.get_text("push_hard"),
"主线剧情":config.get_text("push_main_story"),
"自定义任务":config.get_text("task_user_def_task"),
}

# =============================================
Expand Down Expand Up @@ -84,6 +86,7 @@ def show_GUI(load_jsonname, config, shared_softwareconfig):
ui.link(config.get_text("task_assault"), '#ASSAULT')
ui.link(config.get_text("task_hard"), '#HARD')
ui.link(config.get_text("task_normal"), '#NORMAL')
ui.link(config.get_text("task_user_def_task"), '#USER_DEF_TASK')
ui.link(config.get_text("setting_other"), '#TOOL_PATH')


Expand Down Expand Up @@ -139,6 +142,9 @@ def show_GUI(load_jsonname, config, shared_softwareconfig):
# 普通关卡
set_normal(config)

# 用户定义任务
set_usertask(config)

# 其他设置
set_other(config, load_jsonname)

Expand Down
90 changes: 90 additions & 0 deletions gui/components/check_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
from nicegui import ui, run
import time
import requests
import os

async def only_check_version(config):
# 比较访问https://gitee.com/api/v5/repos/sammusen/BAAH/releases/latest和https://api.github.com/repos/sanmusen214/BAAH/releases/latest哪一个快
urls={
"gitee":"https://gitee.com/api/v5/repos/sammusen/BAAH/releases/latest",
"github":"https://api.github.com/repos/sanmusen214/BAAH/releases/latest"
}
# 比较访问两个网站的时间,哪个快用哪个
eachtime = {}
# tag去掉BAAH字样
eachnewesttag = {}
eachdowloadurl = {}
for key in urls:
nowtime = time.time()
try:
r = await run.io_bound(requests.get, urls[key], timeout=5)
if r.status_code == 200:
eachtime[key] = time.time() - nowtime
data = r.json()
eachnewesttag[key]=data["tag_name"].replace("BAAH", "")
eachdowloadurl[key]=[each["browser_download_url"] for each in data["assets"]]
except:
pass
print(eachtime)
print(eachnewesttag)
print(eachdowloadurl)
resultdict = {}
# 如果两个网站都访问失败
if len(eachtime) == 0:
ui.notify(config.get_text("notice_fail"))
resultdict["status"] = False
resultdict["msg"] = f'{config.get_text("notice_fail")} Fail to connect Github/Gitee'
return resultdict
# 找到访问时间最短的网站key
fastestkey = min(eachtime, key=eachtime.get)
# 判断是否需要更新
if config.get_one_version_num(eachnewesttag[fastestkey]) > config.get_one_version_num():
ui.notify(f'{config.get_text("notice_get_new_version")}: {eachnewesttag[fastestkey]} ({fastestkey})')
resultdict["status"] = True
resultdict["msg"] = f'{config.get_text("notice_get_new_version")}: {eachnewesttag[fastestkey]} ({fastestkey})'
resultdict["urls"] = eachdowloadurl[fastestkey]
else:
ui.notify(config.get_text("notice_no_new_version"))
resultdict["status"] = False
resultdict["msg"] = config.get_text("notice_no_new_version")
return resultdict

# 检查更新
async def get_newest_version(config):
"""检查最新版本并下载更新包"""
ui.notify(config.get_text("button_check_version"))
resultdict = await only_check_version(config)
ui.notify(resultdict["msg"])
if not resultdict["status"]:
return
# 下载
ui.notify(config.get_text("notice_download_version"))
target_urls = resultdict["urls"]
# 找到urls里面以_update.zip结尾的url
target_url = ""
for each in target_urls:
if each.endswith("_update.zip"):
target_url = each
break
# 下载target_url到当前目录
if target_url == "":
ui.notify(config.get_text("notice_fail"))
return
# 如果zip文件不在本地就下载
targetfilename = target_url.split("/")[-1]
if not os.path.exists(targetfilename):
try:
r = await run.io_bound(requests.get, target_url, timeout=10)

if r.status_code == 200:
with open(targetfilename, "wb") as f:
f.write(r.content)
ui.notify(config.get_text("notice_download_version") + " : " +config.get_text("notice_success"))
else:
ui.notify(config.get_text("notice_download_version") + " : " +config.get_text("notice_fail"))
return
except:
ui.notify(config.get_text("notice_download_version") + " : " +config.get_text("notice_fail"))
return
# 下载完成后解压
# 将压缩包内BAAH文件夹内的文件解压到当前目录
12 changes: 11 additions & 1 deletion gui/components/run_baah_in_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
import threading
import queue
import locale
from nicegui import ui, run

# 显示命令行输出的地方
Expand All @@ -21,6 +22,7 @@ def enqueue_output(pipe, queue):
for line in iter(pipe.readline, ''):
queue.put(line)
pipe.close()
print("enqueue_output finished.")
except Exception as e:
print(e)

Expand All @@ -31,14 +33,20 @@ def enqueue_output(pipe, queue):
logArea.push(config.nowuserconfigname)
# 使用subprocess.Popen来运行外部程序
try:
with subprocess.Popen(command, stdout=subprocess.PIPE, text=True, bufsize=1) as process:
prefered_encoding = locale.getpreferredencoding()
print("Use encoding: ", prefered_encoding)
with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1, encoding=prefered_encoding) as process:
# 创建队列来保存子进程输出
stdout_queue = queue.Queue()

# 启动线程来读取子进程的标准输出
stdout_thread = threading.Thread(target=enqueue_output, args=(process.stdout, stdout_queue))
stdout_thread.daemon = True
stdout_thread.start()

stderr_thread = threading.Thread(target=enqueue_output, args=(process.stderr, stdout_queue))
stderr_thread.daemon = True
stderr_thread.start()

while True:
# 尝试从stdout_queue中获取数据
Expand All @@ -63,6 +71,8 @@ def enqueue_output(pipe, queue):
process.wait()
break
time.sleep(0.1)
stdout_thread.join()
stderr_thread.join()
except Exception as e:
import traceback
traceback.print_exc()
Expand Down
Loading

0 comments on commit a5e8866

Please sign in to comment.