diff --git a/.gitignore b/.gitignore index 959e339c..684938c1 100644 --- a/.gitignore +++ b/.gitignore @@ -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] diff --git a/BAAH.py b/BAAH.py index a06300e9..bbafd3b0 100644 --- a/BAAH.py +++ b/BAAH.py @@ -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() @@ -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() \ No newline at end of file diff --git a/BAAH_CONFIGS/example.json b/BAAH_CONFIGS/example.json index 984fd90b..559ee044 100644 --- a/BAAH_CONFIGS/example.json +++ b/BAAH_CONFIGS/example.json @@ -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, @@ -254,5 +254,6 @@ "PRE_COMMAND": "", "POST_COMMAND": "", "SHOP_NORMAL_SWITCH": true, - "SHOP_CONTEST_SWITCH": true + "SHOP_CONTEST_SWITCH": true, + "USER_DEF_TASKS": "" } \ No newline at end of file diff --git a/DATA/assets/BUTTON/BUTTON_JUMP.png b/DATA/assets/BUTTON/BUTTON_JUMP.png index 0d0f5f2b..ed3e9014 100644 Binary files a/DATA/assets/BUTTON/BUTTON_JUMP.png and b/DATA/assets/BUTTON/BUTTON_JUMP.png differ diff --git a/DATA/assets/BUTTON/BUTTON_NOT_JUMP.png b/DATA/assets/BUTTON/BUTTON_NOT_JUMP.png index 966724a3..ea090c9f 100644 Binary files a/DATA/assets/BUTTON/BUTTON_NOT_JUMP.png and b/DATA/assets/BUTTON/BUTTON_NOT_JUMP.png differ diff --git a/DATA/assets/PAGE/PAGE_CRAFT_FINISH.png b/DATA/assets/PAGE/PAGE_CRAFT_FINISH.png deleted file mode 100644 index 8ec41f92..00000000 Binary files a/DATA/assets/PAGE/PAGE_CRAFT_FINISH.png and /dev/null differ diff --git a/DATA/assets/PAGE/PAGE_CRAFT_SELECT.png b/DATA/assets/PAGE/PAGE_CRAFT_SELECT.png deleted file mode 100644 index db57790d..00000000 Binary files a/DATA/assets/PAGE/PAGE_CRAFT_SELECT.png and /dev/null differ diff --git a/DATA/assets/PAGE/PAGE_FIGHT_CENTER.png b/DATA/assets/PAGE/PAGE_FIGHT_CENTER.png index 498fc40f..28b4ae8d 100644 Binary files a/DATA/assets/PAGE/PAGE_FIGHT_CENTER.png and b/DATA/assets/PAGE/PAGE_FIGHT_CENTER.png differ diff --git a/DATA/assets/PageName.py b/DATA/assets/PageName.py index 8e629d90..ac00044e 100644 --- a/DATA/assets/PageName.py +++ b/DATA/assets/PageName.py @@ -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" diff --git "a/DATA/assets/\345\267\256\345\274\202.txt" "b/DATA/assets/\345\267\256\345\274\202.txt" index f16994fa..30b83acf 100644 --- "a/DATA/assets/\345\267\256\345\274\202.txt" +++ "b/DATA/assets/\345\267\256\345\274\202.txt" @@ -1,6 +1,8 @@ 日服 国际服 +几个月后会实装简易攻略 国服 -BUTTON_CAFE_SET_ROOM.png 暂无:国服的咖啡厅切换(版本未到) +礼服日奈的fes也许会把竞技场的跳过战斗文字改动。 +礼服日奈的fes会把社团的入口改动 diff --git a/DATA/assets_cn/PAGE/PAGE_CRAFT.png b/DATA/assets_cn/PAGE/PAGE_CRAFT.png index a7f0ef93..af69514c 100644 Binary files a/DATA/assets_cn/PAGE/PAGE_CRAFT.png and b/DATA/assets_cn/PAGE/PAGE_CRAFT.png differ diff --git a/DATA/assets_cn/PAGE/PAGE_CRAFT_FINISH.png b/DATA/assets_cn/PAGE/PAGE_CRAFT_FINISH.png deleted file mode 100644 index 6be0e6be..00000000 Binary files a/DATA/assets_cn/PAGE/PAGE_CRAFT_FINISH.png and /dev/null differ diff --git a/DATA/assets_cn/PAGE/PAGE_CRAFT_SELECT.png b/DATA/assets_cn/PAGE/PAGE_CRAFT_SELECT.png deleted file mode 100644 index 3f1f93b5..00000000 Binary files a/DATA/assets_cn/PAGE/PAGE_CRAFT_SELECT.png and /dev/null differ diff --git a/DATA/assets_global_en/BUTTON/BUTTON_JUMP.png b/DATA/assets_global_en/BUTTON/BUTTON_JUMP.png index a8f13b1a..088a7751 100644 Binary files a/DATA/assets_global_en/BUTTON/BUTTON_JUMP.png and b/DATA/assets_global_en/BUTTON/BUTTON_JUMP.png differ diff --git a/DATA/assets_global_en/BUTTON/BUTTON_NOT_JUMP.png b/DATA/assets_global_en/BUTTON/BUTTON_NOT_JUMP.png index c245ac58..a1f6ed10 100644 Binary files a/DATA/assets_global_en/BUTTON/BUTTON_NOT_JUMP.png and b/DATA/assets_global_en/BUTTON/BUTTON_NOT_JUMP.png differ diff --git a/DATA/assets_global_en/PAGE/PAGE_CRAFT_FINISH.png b/DATA/assets_global_en/PAGE/PAGE_CRAFT_FINISH.png deleted file mode 100644 index 2cbd3672..00000000 Binary files a/DATA/assets_global_en/PAGE/PAGE_CRAFT_FINISH.png and /dev/null differ diff --git a/DATA/assets_global_en/PAGE/PAGE_CRAFT_SELECT.png b/DATA/assets_global_en/PAGE/PAGE_CRAFT_SELECT.png deleted file mode 100644 index aa0dac89..00000000 Binary files a/DATA/assets_global_en/PAGE/PAGE_CRAFT_SELECT.png and /dev/null differ diff --git a/DATA/assets_global_en/PAGE/PAGE_FIGHT_CENTER.png b/DATA/assets_global_en/PAGE/PAGE_FIGHT_CENTER.png index 8556ed2f..984ba748 100644 Binary files a/DATA/assets_global_en/PAGE/PAGE_FIGHT_CENTER.png and b/DATA/assets_global_en/PAGE/PAGE_FIGHT_CENTER.png differ diff --git a/DATA/assets_jp/PAGE/PAGE_CRAFT_FINISH.png b/DATA/assets_jp/PAGE/PAGE_CRAFT_FINISH.png deleted file mode 100644 index e0f43051..00000000 Binary files a/DATA/assets_jp/PAGE/PAGE_CRAFT_FINISH.png and /dev/null differ diff --git a/DATA/assets_jp/PAGE/PAGE_CRAFT_SELECT.png b/DATA/assets_jp/PAGE/PAGE_CRAFT_SELECT.png deleted file mode 100644 index 7c276459..00000000 Binary files a/DATA/assets_jp/PAGE/PAGE_CRAFT_SELECT.png and /dev/null differ diff --git a/DATA/i18n/en_US.json b/DATA/i18n/en_US.json index f09491a7..94fa8d42 100644 --- a/DATA/i18n/en_US.json +++ b/DATA/i18n/en_US.json @@ -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", diff --git a/DATA/i18n/jp_JP.json b/DATA/i18n/jp_JP.json index c574844f..0d1cad11 100644 --- a/DATA/i18n/jp_JP.json +++ b/DATA/i18n/jp_JP.json @@ -20,6 +20,7 @@ "push_hard": "難関ステージの攻略", "push_main_story": "メインストーリーの進行", "task_assault": "総力戦", + "task_user_def_task": "ユーザー定義タスク", "setting_emulator": "エミュレータ設定", "setting_server": "サーバー設定", diff --git a/DATA/i18n/zh_CN.json b/DATA/i18n/zh_CN.json index b9cef41f..3dd7002b 100644 --- a/DATA/i18n/zh_CN.json +++ b/DATA/i18n/zh_CN.json @@ -20,6 +20,7 @@ "push_hard":"困难图推图", "push_main_story":"推主线剧情", "task_assault":"总力战", + "task_user_def_task": "自定义任务", "setting_emulator":"模拟器配置", "setting_server":"服务器配置", diff --git a/README.md b/README.md index 1f467873..83f3be9b 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/docs/README_dev.md b/docs/README_dev.md index 2dc10830..21694222 100644 --- a/docs/README_dev.md +++ b/docs/README_dev.md @@ -27,6 +27,14 @@ 自动脚本项目从main.py作为入口,从命令行读取用户指定的用户配置文件,然后通过AllTask下的myAllTask类解析此用户配置文件的每日任务,为每个任务创建相应的Task实例为一个列表,在BAAH.py里按序运行这些Task实例。 +# 项目打包 + +使用pyinstaller打包,打包命令为 + +```python +python package.py +``` + # 关键类 ## modules/configs/Configger类 diff --git a/docs/README_dev_en.md b/docs/README_dev_en.md index d51cce1d..72522947 100644 --- a/docs/README_dev_en.md +++ b/docs/README_dev_en.md @@ -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 diff --git a/gui/__init__.py b/gui/__init__.py index 13f064d3..34f7d35c 100644 --- a/gui/__init__.py +++ b/gui/__init__.py @@ -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 @@ -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"), } # ============================================= @@ -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') @@ -139,6 +142,9 @@ def show_GUI(load_jsonname, config, shared_softwareconfig): # 普通关卡 set_normal(config) + # 用户定义任务 + set_usertask(config) + # 其他设置 set_other(config, load_jsonname) diff --git a/gui/components/check_update.py b/gui/components/check_update.py new file mode 100644 index 00000000..a8f51248 --- /dev/null +++ b/gui/components/check_update.py @@ -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文件夹内的文件解压到当前目录 \ No newline at end of file diff --git a/gui/components/run_baah_in_gui.py b/gui/components/run_baah_in_gui.py index 4ce02f2c..d0d28da7 100644 --- a/gui/components/run_baah_in_gui.py +++ b/gui/components/run_baah_in_gui.py @@ -3,6 +3,7 @@ import subprocess import threading import queue +import locale from nicegui import ui, run # 显示命令行输出的地方 @@ -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) @@ -31,7 +33,9 @@ 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() @@ -39,6 +43,10 @@ def enqueue_output(pipe, 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中获取数据 @@ -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() diff --git a/gui/pages/Setting_BAAH.py b/gui/pages/Setting_BAAH.py index 22d40dd5..e1985104 100644 --- a/gui/pages/Setting_BAAH.py +++ b/gui/pages/Setting_BAAH.py @@ -1,8 +1,5 @@ -from nicegui import ui, run -import time -import requests -import os -import zipfile +from nicegui import ui +from gui.components.check_update import get_newest_version def set_BAAH(config, shared_softwareconfig): @@ -14,79 +11,6 @@ def select_language(value): else: ui.notify("Language has been changed, restart to take effect") - # 检查更新 - async def check_newest_version(): - ui.notify(config.get_text("button_check_version")) - # 比较访问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) - # 如果两个网站都访问失败 - if len(eachtime) == 0: - ui.notify(config.get_text("notice_fail")) - return - # 找到访问时间最短的网站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})') - else: - ui.notify(config.get_text("notice_no_new_version")) - return - # 下载 - ui.notify(config.get_text("notice_download_version")) - target_urls = eachdowloadurl[fastestkey] - # 找到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文件夹内的文件解压到当前目录 - - - with ui.column(): ui.link_target("BAAH") @@ -98,7 +22,7 @@ async def check_newest_version(): ui.label(config.get_text("BAAH_get_version")) - ui.button(config.get_text("button_check_version"), on_click=check_newest_version) + ui.button(config.get_text("button_check_version"), on_click=lambda e, c=config:get_newest_version(c)) web_url = { "github": "https://github.com/sanmusen214/BAAH", diff --git a/gui/pages/Setting_UserTask.py b/gui/pages/Setting_UserTask.py new file mode 100644 index 00000000..5ec5326d --- /dev/null +++ b/gui/pages/Setting_UserTask.py @@ -0,0 +1,9 @@ +from nicegui import ui + +def set_usertask(config): + with ui.row(): + ui.link_target("USER_DEF_TASK") + ui.label(config.get_text("task_user_def_task")).style('font-size: x-large') + + with ui.row(): + ui.textarea(label = config.get_text("task_user_def_task")).bind_value(config.userconfigdict, "USER_DEF_TASKS").style('width: 40vw;') \ No newline at end of file diff --git a/gui/pages/Setting_notification.py b/gui/pages/Setting_notification.py index 3430b066..418967ac 100644 --- a/gui/pages/Setting_notification.py +++ b/gui/pages/Setting_notification.py @@ -56,4 +56,4 @@ def set_api_noti_type(type): # 官网 ui.link("PushPlus", "http://www.pushplus.plus/", new_tab=True) - ui.link("ServerChan", "http://sc.ftqq.com/3.version", new_tab=True) \ No newline at end of file + ui.link("ServerChan", "https://sct.ftqq.com/r/13283", new_tab=True) \ No newline at end of file diff --git a/gui/pages/Setting_task_order.py b/gui/pages/Setting_task_order.py index 49018930..dc8fa6ac 100644 --- a/gui/pages/Setting_task_order.py +++ b/gui/pages/Setting_task_order.py @@ -49,13 +49,13 @@ def del_task(i): # pre-run command with ui.row(): - ui.input(config.get_text("config_pre_command"), placeholder='start cmd /c "BAAH.exe config2.json"').bind_value(config.userconfigdict, 'PRE_COMMAND').style('width: 300px') + ui.input(config.get_text("config_pre_command"), placeholder='start cmd /c "BAAH.exe config1.json"').bind_value(config.userconfigdict, 'PRE_COMMAND').style('width: 300px') task_order() # post-run command with ui.row(): - ui.input(config.get_text("config_post_command")).bind_value(config.userconfigdict, 'POST_COMMAND').style('width: 300px') + ui.input(config.get_text("config_post_command"), placeholder='start cmd /c "BAAH.exe config2.json"').bind_value(config.userconfigdict, 'POST_COMMAND').style('width: 300px') # with ui.row(): # ui.link_target("NEXT_CONFIG") diff --git a/jsoneditor.py b/jsoneditor.py index 9601d07d..3e12abd2 100644 --- a/jsoneditor.py +++ b/jsoneditor.py @@ -17,7 +17,8 @@ def get_json_list(): return [i for i in os.listdir(MyConfigger.USER_CONFIG_FOLDER) if i.endswith(".json")] from gui import show_GUI - from nicegui import native, ui, run + from gui.components.check_update import only_check_version + from nicegui import native, ui, run, app alljson_list = get_json_list() alljson_tab_list = [None for i in alljson_list] @@ -65,7 +66,24 @@ def tab_area(): for i,tab_panel in enumerate(alljson_tab_list): with ui.tab_panel(tab_panel).style("height: 88vh; overflow: auto;"): show_GUI(alljson_list[i], MyConfigger(), shared_softwareconfig) - + check_times = 0 + async def check_version(): + """check the version, show the update message""" + global check_times + # if users have opened multi pages, this function will be called multi times + if check_times > 0: + return + check_times = 1 + result = await only_check_version(shared_softwareconfig) + if not result["status"]: + return + ui.notify(result["msg"], close_button=True, type="info") + with updateTextBox: + ui.link(result["msg"], "https://github.com/sanmusen214/BAAH/releases", new_tab=True).style("color: red; border: 1px solid blue; border-radius: 5px; font-size: 20px;z-index: 9999;") + + # 更新提示 + app.on_connect(check_version) + updateTextBox = ui.row().style("position: fixed;z-index: 9999;") # Tab栏区域 tab_area() @@ -79,4 +97,4 @@ def tab_area(): except Exception as e: import traceback traceback.print_exc() - input("按任意键退出") \ No newline at end of file + input("Press Enter to quit...") \ No newline at end of file diff --git a/main.py b/main.py index 648bac07..744ace64 100644 --- a/main.py +++ b/main.py @@ -14,14 +14,20 @@ # 从命令行参数获取要运行的config文件名,并将config实例parse为那个config文件 from modules.configs.MyConfig import config + logging.info({"zh_CN": f"当前运行目录: {os.getcwd()}", "en_US": f"Current running directory: {os.getcwd()}"}) + now_config_files = config.get_all_user_config_names() + logging.info({"zh_CN": "BAAH_CONFIGS可用的配置文件: " + ", ".join(now_config_files), "en_US": "Available BAAH_CONFIGS config files: " + ", ".join(now_config_files)}) + if len(sys.argv) > 1: config_name = sys.argv[1] logging.info({"zh_CN": f"读取指定的配置文件: {config_name}", "en_US": f"loading config from {config_name}"}) + if config_name not in now_config_files: + logging.error({"zh_CN": "输入的配置文件名不在可用配置文件列表中", "en_US": "The entered config file name is not in the list of available config files"}) + raise FileNotFoundError(f"config file {config_name} not found") + config.parse_user_config(config_name) else: logging.warn({"zh_CN": "启动程序时没有指定配置文件", "en_US": "No config file specified when starting the program"}) - now_config_files = config.get_all_user_config_names() - logging.info({"zh_CN": "可用的配置文件: " + ", ".join(now_config_files), "en_US": "Available config files: " + ", ".join(now_config_files)}) if len(now_config_files) == 1: logging.info({"zh_CN": "自动读取唯一的配置文件", "en_US": "Automatically read the only config file"}) config_name = now_config_files[0] diff --git a/modules/AllTask/InClub/InClub.py b/modules/AllTask/InClub/InClub.py index 23dbb5ea..5b9be21a 100644 --- a/modules/AllTask/InClub/InClub.py +++ b/modules/AllTask/InClub/InClub.py @@ -21,8 +21,8 @@ def pre_condition(self) -> bool: def on_run(self) -> None: - if config.userconfigdict["SERVER_TYPE"]=="JP": - # 日服适配新界面 + if config.userconfigdict["SERVER_TYPE"] in ["JP", "GLOBAL", "GLOBAL_EN"]: + # 日服, 国际服适配新界面 click((565, 669), sleeptime=3) click((299, 330), sleeptime=3) else: diff --git a/modules/AllTask/InCraft/InCraft.py b/modules/AllTask/InCraft/InCraft.py new file mode 100644 index 00000000..9f510e0f --- /dev/null +++ b/modules/AllTask/InCraft/InCraft.py @@ -0,0 +1,141 @@ + +from DATA.assets.PageName import PageName +from DATA.assets.ButtonName import ButtonName +from DATA.assets.PopupName import PopupName + +from modules.AllPage.Page import Page +from modules.AllTask.Task import Task + +from modules.utils import click, swipe, match, page_pic, button_pic, popup_pic, sleep, ocr_area, config, screenshot, match_pixel, istr, CN, EN, JP +from modules.utils.log_utils import logging + +import numpy as np + +class InCraft(Task): + STATUS_CRAFT_NOTHING = 0 + STATUS_CRAFT_DOING = 1 + STATUS_CRAFT_DONE = 2 + def __init__(self, name="InCraft") -> None: + super().__init__(name) + self.COLOR_CRAFT_NOTHING = ((226, 228, 228), (235, 235, 235)) + self.COLOR_CRAFT_DOING = ((250, 215, 110), (255, 222, 115)) + self.COLOR_CRAFT_DONE = ((60, 220, 240), (77, 236, 250)) + self.BUTTON_CRAFT = (1029, 678) + self.COLOR_BUTTON_CRAFT_YELLOW = self.COLOR_CRAFT_DONE + # 制造材料清单从上到下三个点的位置 + # 国服下方没有一键收集按钮,因此三个点偏下 + offsetY = 20 if "CN" in config.userconfigdict["SERVER_TYPE"] else 0 + items_ys = np.linspace(285, 530, 3, dtype=int) + self.items_pos = [(1130, y+offsetY) for y in items_ys] + + def pre_condition(self) -> bool: + return self.back_to_home() + + def getNowCraftStatus(self): + reslist = [] + for item in self.items_pos: + res = match_pixel(item, self.COLOR_CRAFT_NOTHING, printit=True) + if res: + reslist.append(self.STATUS_CRAFT_NOTHING) + continue + res = match_pixel(item, self.COLOR_CRAFT_DONE, printit=True) + if res: + reslist.append(self.STATUS_CRAFT_DONE) + continue + reslist.append(self.STATUS_CRAFT_DOING) + return reslist + + def dealing_with_craft(self): + """ + 进入到添加制造石头的页面 + """ + # 点击一号位添加直到匹配到开放按钮亮起来 + button_light = self.run_until( + lambda: click((767, 204)), + lambda: match_pixel(self.BUTTON_CRAFT, self.COLOR_BUTTON_CRAFT_YELLOW) + ) + if not button_light: + logging.warn(istr({ + CN: "点击制造失败", + EN: "Failed to click craft button" + })) + return + # 点击开放按钮 + click(self.BUTTON_CRAFT) + self.dealing_with_craft_details() + + def dealing_with_craft_details(self): + """ + 选择制造内容,确定制造 + """ + #! 点击开放节点按钮后,如果没有走到最后一步,那么下次进入制造页面时,会直接跳转到这里 + # 点左下角节点,使节点左移 + COLOR_W_CIRCLE = ((252, 252, 245), (255, 255, 252)) + POS_W_LEFT = (156, 109) + self.run_until( + lambda: click((444, 554)), + lambda: match_pixel(POS_W_LEFT, COLOR_W_CIRCLE), + times=3 + ) + # 选择具体节点 并确定 + # 第一个制造节点结束 + # 点击右下角按钮, 直到出现弹窗 + self.run_until( + lambda: click(self.BUTTON_CRAFT), + lambda: self.has_popup(), + sleeptime = 0.5 + ) + # 点击确认按钮,直到返回制造页面 + self.run_until( + lambda: click(button_pic(ButtonName.BUTTON_CONFIRMB)), + lambda: not match(button_pic(ButtonName.BUTTON_CONFIRMB)) + ) + self.run_until( + lambda: click(Page.MAGICPOINT), + lambda: Page.is_page(PageName.PAGE_CRAFT) + ) + + + + + + def on_run(self) -> None: + # 进入制造页面 + enter_page = self.run_until( + lambda: click((678, 667)), + lambda: Page.is_page(PageName.PAGE_CRAFT) + ) + if not enter_page: + logging.warn(istr({ + CN: "进入制造页面失败", + EN: "Failed to enter craft page" + })) + self.dealing_with_craft_details() + # 获取当前制造状态 + status_list = self.getNowCraftStatus() + logging.info(status_list) + for ind, item in enumerate(status_list): + # 处理每一个位置 + if item == self.STATUS_CRAFT_DOING: + # 正在制造:不管跳过 + continue + elif item == self.STATUS_CRAFT_DONE: + # 制造完成:点击领取 + self.run_until( + lambda: click(self.items_pos[ind]), + lambda: self.has_popup(), + sleeptime = 1.5 + ) + self.clear_popup() + # 随后制造 + # 尚未制造:开始制造 + self.run_until( + lambda: click(self.items_pos[ind]), + lambda: not Page.is_page(PageName.PAGE_CRAFT) + ) + self.dealing_with_craft() + + + + def post_condition(self) -> bool: + return self.back_to_home() \ No newline at end of file diff --git a/modules/AllTask/InQuest/PushQuest.py b/modules/AllTask/InQuest/PushQuest.py index cb63ce3e..6f47646c 100644 --- a/modules/AllTask/InQuest/PushQuest.py +++ b/modules/AllTask/InQuest/PushQuest.py @@ -14,8 +14,7 @@ from modules.utils import (click, swipe, match, page_pic, button_pic, popup_pic, sleep, ocr_area, config, screenshot, match_pixel) from modules.utils.grid_analyze import GridAnalyzer -from .Questhelper import (jump_to_page, close_popup_until_see, judge_whether_3star, quest_has_easy_tab, easy_tab_pos_R, - center_tab_pos_L) +from .Questhelper import (jump_to_page, close_popup_until_see, judge_whether_3star, quest_has_easy_tab, easy_tab_pos_R, center_tab_pos_L) class PushQuest(Task): @@ -203,6 +202,7 @@ def on_run(self) -> None: self.level_ind += 1 logging.info({"zh_CN": f"一个战斗完成,更新关卡下标为{self.level_ind}", "en_US": f"One battle completed, update level subscript to {self.level_ind}"}) + sleep(6) # 等待6秒:可能的新章节解锁动画 def post_condition(self) -> bool: return Page.is_page(PageName.PAGE_QUEST_SEL) \ No newline at end of file diff --git a/modules/AllTask/InQuest/Questhelper.py b/modules/AllTask/InQuest/Questhelper.py index 6eb9de38..5cc06a06 100644 --- a/modules/AllTask/InQuest/Questhelper.py +++ b/modules/AllTask/InQuest/Questhelper.py @@ -12,7 +12,7 @@ def jump_to_page(to_num: int) -> bool: return Task.run_until( lambda: jump_to_neighbour_page(to_num), lambda: ocr_area((122, 179), (165, 211))[0] == str(to_num), - sleeptime=0.5 + sleeptime=0.6 ) def jump_to_neighbour_page(to_num: int) -> bool: diff --git a/modules/AllTask/InShop/InShop.py b/modules/AllTask/InShop/InShop.py index 2df141bf..ca6846d9 100644 --- a/modules/AllTask/InShop/InShop.py +++ b/modules/AllTask/InShop/InShop.py @@ -29,6 +29,7 @@ def pre_condition(self) -> bool: def on_run(self) -> None: # 进入商店 + # 可能这边不需要区分服务器 if config.userconfigdict["SERVER_TYPE"]=="JP": # 适配日服新界面 self.run_until( diff --git a/modules/AllTask/InWanted/InWanted.py b/modules/AllTask/InWanted/InWanted.py index 2f544751..795911ae 100644 --- a/modules/AllTask/InWanted/InWanted.py +++ b/modules/AllTask/InWanted/InWanted.py @@ -48,8 +48,16 @@ def on_run(self) -> None: # 进入悬赏通缉页面 caninwanted = self.run_until( lambda: click((741, 440)), - lambda: Page.is_page(PageName.PAGE_WANTED), + lambda: Page.is_page(PageName.PAGE_WANTED) or Page.is_page(PageName.PAGE_WANTED_SUB), ) + if Page.is_page(PageName.PAGE_WANTED_SUB): + # 点多了,进入到了子页面,此时点击左上角返回一次 + click(Page.TOPLEFTBACK, 1) + caninwanted = self.run_until( + lambda: click(Page.MAGICPOINT), + lambda: Page.is_page(PageName.PAGE_WANTED) + ) + if not caninwanted: logging.warn({"zh_CN": "无法打开通缉页面,任务退出", "en_US": "Can't open wanted page, task quit"}) self.back_to_home() diff --git a/modules/AllTask/README.md b/modules/AllTask/README.md index 8a2dee2d..24a16972 100644 --- a/modules/AllTask/README.md +++ b/modules/AllTask/README.md @@ -10,4 +10,4 @@ And write the relationship of it in task_dict in `myAllTask.py` 模板文件ataskformat.py All task modules named as a folder are all designed to run from the main page. -所有文件夹命名的任务模块都默认从主页开始运行 \ No newline at end of file +所有文件夹命名的任务模块应当都默认从主页开始运行 \ No newline at end of file diff --git a/modules/AllTask/SubTask/ExecCode.py b/modules/AllTask/SubTask/ExecCode.py new file mode 100644 index 00000000..2603ea5f --- /dev/null +++ b/modules/AllTask/SubTask/ExecCode.py @@ -0,0 +1,41 @@ + +from DATA.assets.PageName import PageName +from DATA.assets.ButtonName import ButtonName +from DATA.assets.PopupName import PopupName + +from modules.AllPage.Page import Page +from modules.AllTask.Task import Task + +from modules.utils import click, swipe, match, page_pic, button_pic, popup_pic, sleep, ocr_area, config, screenshot, match_pixel, istr, CN, EN, JP +from modules.utils.log_utils import logging + +class ExecCode(Task): + def __init__(self, content, name="ExecCode") -> None: + super().__init__(name) + self.content = content + + + def pre_condition(self) -> bool: + return True + + + def on_run(self) -> None: + if not self.content or len(self.content)==0: + logging.warn(istr({ + CN: "自定义任务为空", + EN: "Defined task is empty", + })) + try: + exec(self.content) + self.status = self.STATUS_SUCCESS + except Exception as e: + logging.error(istr({ + CN: "自定义任务执行错误", + EN: "Defined task error", + })) + logging.error(e) + self.status = self.STATUS_ERROR + + + def post_condition(self) -> bool: + return True \ No newline at end of file diff --git a/modules/AllTask/Task.py b/modules/AllTask/Task.py index 4ae4516f..d1087ac4 100644 --- a/modules/AllTask/Task.py +++ b/modules/AllTask/Task.py @@ -10,6 +10,9 @@ class Task: + STATUS_SUCCESS = 0 + STATUS_ERROR = 1 + STATUS_SKIP = 2 # 父类 def __init__(self, name, pre_times = 2, post_times = 4) -> None: self.name = name @@ -17,6 +20,7 @@ def __init__(self, name, pre_times = 2, post_times = 4) -> None: self.post_times = post_times self.click_magic_when_run = True """运行时是否点击魔法点重置窗口状态到Page级别""" + self.status = self.STATUS_SUCCESS def pre_condition(self) -> bool: """ @@ -214,4 +218,11 @@ def clear_popup(): lambda: click(Page.MAGICPOINT), lambda: match_pixel(Page.MAGICPOINT, Page.COLOR_WHITE), times=15, - ) \ No newline at end of file + ) + + @staticmethod + def has_popup(): + """ + 判断是否有弹窗 + """ + return not match_pixel(Page.MAGICPOINT, Page.COLOR_WHITE) \ No newline at end of file diff --git a/modules/AllTask/UserTask/UserTask.py b/modules/AllTask/UserTask/UserTask.py new file mode 100644 index 00000000..873ce7e9 --- /dev/null +++ b/modules/AllTask/UserTask/UserTask.py @@ -0,0 +1,40 @@ + +from DATA.assets.PageName import PageName +from DATA.assets.ButtonName import ButtonName +from DATA.assets.PopupName import PopupName + +from modules.AllPage.Page import Page +from modules.AllTask.Task import Task +from modules.AllTask.SubTask.ExecCode import ExecCode + +from modules.utils import click, swipe, match, page_pic, button_pic, popup_pic, sleep, ocr_area, config, screenshot, match_pixel, istr, CN, EN, JP +from modules.utils.log_utils import logging + +class UserTask(Task): + def __init__(self, name="UserTask") -> None: + super().__init__(name) + + + def pre_condition(self) -> bool: + return True + + + def on_run(self) -> None: + content = config.userconfigdict["USER_DEF_TASKS"] + runCode = ExecCode(content) + runCode.run() + if runCode.status == Task.STATUS_SUCCESS: + logging.info(istr({ + CN: "自定义任务执行成功", + EN: "Defined task success", + })) + elif runCode.status == Task.STATUS_ERROR: + logging.error(istr({ + CN: "自定义任务执行错误,尝试返回游戏主页", + EN: "Defined task error, try to return to the game homepage", + })) + self.back_to_home() + + + def post_condition(self) -> bool: + return True \ No newline at end of file diff --git a/modules/AllTask/__init__.py b/modules/AllTask/__init__.py index 83312056..ea2aa425 100644 --- a/modules/AllTask/__init__.py +++ b/modules/AllTask/__init__.py @@ -22,4 +22,8 @@ from .BuyAP.BuyAP import BuyAP +from .InCraft.InCraft import InCraft + +from .UserTask.UserTask import UserTask + from .PostAllTask.PostAllTask import PostAllTask \ No newline at end of file diff --git a/modules/AllTask/myAllTask.py b/modules/AllTask/myAllTask.py index a40a5b07..122f4112 100644 --- a/modules/AllTask/myAllTask.py +++ b/modules/AllTask/myAllTask.py @@ -14,6 +14,7 @@ "咖啡馆只摸头":[InCafe,{}], # 此方法弃用,现在所有咖啡馆参数通过config调整 "课程表":[InTimeTable,{}], "社团":[InClub,{}], + "制造":[InCraft,{}], "商店":[InShop,{}], "悬赏通缉":[InWanted,{}], "特殊任务":[InSpecial,{}], @@ -29,6 +30,7 @@ "困难推图":[InQuest, {'types':["push-hard"]}], "主线剧情":[AutoStory,{}], "购买AP":[BuyAP,{}], + "自定义任务":[UserTask,{}], } class AllTask: diff --git a/modules/configs/MyConfig.py b/modules/configs/MyConfig.py index 24aad263..1398ecf9 100644 --- a/modules/configs/MyConfig.py +++ b/modules/configs/MyConfig.py @@ -10,7 +10,7 @@ class MyConfigger: """ 维护config字典,包含软件config,用户任务config,语言包 """ - NOWVERSION="1.5.2" + NOWVERSION="1.5.3" USER_CONFIG_FOLDER="./BAAH_CONFIGS" SOFTWARE_CONFIG_FOLDER="./DATA/CONFIGS" LANGUAGE_PACKAGE_FOLDER="./DATA/i18n" @@ -86,7 +86,11 @@ def get_all_user_config_names()->list[str]: """ 获取所有用户配置文件名 """ - return [f for f in os.listdir(os.path.join(os.getcwd(), MyConfigger.USER_CONFIG_FOLDER)) if f.endswith(".json")] + user_config_folder = os.path.join(os.getcwd(), MyConfigger.USER_CONFIG_FOLDER) + whetherHasFolder = os.path.exists(user_config_folder) + if not whetherHasFolder: + return [] + return [f for f in os.listdir(user_config_folder) if f.endswith(".json")] def _read_config_file(self, file_path): """ @@ -109,8 +113,8 @@ def _read_config_file(self, file_path): # os.makedirs(path, exist_ok=True) # with open(file_path, 'w', encoding="utf8") as f: # json.dump({}, f, indent=4, ensure_ascii=False) - print(f'试图读取的配置文件不存在,这里使用预设的默认值代替') - print(f'请传入正确的配置文件名') + print(f'试图读取的配置文件 {file_path} 不存在,这里使用预设的默认值代替') + print(f'no such file: {file_path}, use default value instead') return {} else: raise Exception(f'文件不存在: {file_path}') diff --git a/modules/configs/defaultSettings.py b/modules/configs/defaultSettings.py index f38ce553..b02351f1 100644 --- a/modules/configs/defaultSettings.py +++ b/modules/configs/defaultSettings.py @@ -150,6 +150,9 @@ # 任务运行前后的命令 "PRE_COMMAND":{"d":""}, "POST_COMMAND":{"d":""}, + + # 自定义任务 + "USER_DEF_TASKS":{"d":""}, } # 软件的config里的默认值 diff --git a/modules/utils/__init__.py b/modules/utils/__init__.py index 33b71f52..5114ada3 100644 --- a/modules/utils/__init__.py +++ b/modules/utils/__init__.py @@ -166,7 +166,8 @@ def page_pic(picname): """ 给定页面的图片名称,得到图片的路径 """ - return get_config_pic_path() + "/PAGE" + f"/{picname}.png" + # get_config_pic_path() + "/PAGE" + f"/{picname}.png" + return os.path.join(get_config_pic_path(), "PAGE", f"{picname}.png") def button_pic(buttonname): """ @@ -175,7 +176,8 @@ def button_pic(buttonname): # 如果是反和谐,就把按钮名称改成反和谐的 if config.userconfigdict["FANHEXIE"] and buttonname == "BUTTON_CFIGHT_START": buttonname = "BUTTON_CFIGHT_START_FANHEXIE" - return get_config_pic_path() + "/BUTTON" + f"/{buttonname}.png" + # get_config_pic_path() + "/BUTTON" + f"/{buttonname}.png" + return os.path.join(get_config_pic_path(), "BUTTON", f"{buttonname}.png") def popup_pic(popupname): """ @@ -184,7 +186,8 @@ def popup_pic(popupname): # 如果是反和谐,就把名称改成反和谐的 if config.userconfigdict["FANHEXIE"] and popupname == "POPUP_MOMOTALK": popupname = "POPUP_MOMOTALK_FANHEXIE" - return get_config_pic_path() + "/POPUP" + f"/{popupname}.png" + # get_config_pic_path() + "/POPUP" + f"/{popupname}.png" + return os.path.join(get_config_pic_path(), "POPUP", f"{popupname}.png") def get_grid_solution_json(location, level, ishard=False): # 读取DATA/grid_config/quest/里的文件 diff --git a/modules/utils/image_processing.py b/modules/utils/image_processing.py index 98ae15be..7ab978c7 100644 --- a/modules/utils/image_processing.py +++ b/modules/utils/image_processing.py @@ -160,6 +160,10 @@ def ocr_pic_area(imageurl, fromx, fromy, tox, toy, multi_lines = False): axis in image is x: from left to right, y: from top to bottom """ + fromx = int(fromx) + fromy = int(fromy) + tox = int(tox) + toy = int(toy) def replace_mis(ocr_text): """ 替换容易识别错误的字符 @@ -196,6 +200,8 @@ def match_pixel_color_range(imageurl, x, y, low_range, high_range, printit = Fal return True if the color is between the range """ img = cv2.imread(imageurl) + x = int(x) + y = int(y) pixel = img[y, x][:3] if printit: print("Pixel color at ({}, {}): {}".format(x, y, pixel)) @@ -214,16 +220,16 @@ def compare_diff(img1, img2, xfocus, yfocus): 图片1 img2 : np.ndarray 图片2 - xignore : List[int] + xfocus : List[int] 关注的x范围, 图片坐标 - yignore : List[int] + yfocus : List[int] 关注的y范围, 图片坐标 """ # 忽略UI部分 # xs = [1, 1279] # ys = [124, 568] - xs=xfocus - ys=yfocus + xs=[int(each) for each in xfocus] + ys=[int(each) for each in yfocus] img1 = img1[ys[0]:ys[1], xs[0]:xs[1]] img2 = img2[ys[0]:ys[1], xs[0]:xs[1]] diff --git a/package.py b/package.py index e3591e43..ffd1f380 100644 --- a/package.py +++ b/package.py @@ -6,6 +6,41 @@ from pathlib import Path import nicegui import time +import pponnxcr +import platform +import requests + +def package_download_adb(platformstr = None): + + target_adb_path = os.path.join(os.getcwd(), "tools", "adb") + downloadurls = { + "Windows": "https://dl.google.com/android/repository/platform-tools-latest-windows.zip", + "Darwin": "https://dl.google.com/android/repository/platform-tools-latest-darwin.zip", + "Linux": "https://dl.google.com/android/repository/platform-tools-latest-linux.zip" + } + if not os.path.exists(target_adb_path): + if platformstr and platformstr in downloadurls.keys(): + url = downloadurls[platformstr] + elif platform.system() in downloadurls.keys(): + url = downloadurls[platform.system()] + else: + print(f"Unknown platform: {platform.system()}") + return + + # download zip + r = requests.get(url) + with open("platform-tools-latest.zip", "wb") as f: + f.write(r.content) + target_adb_path_parent_folder = os.path.dirname(target_adb_path) + # unzip to target_adb_path, rename the upper folder "playform-tools" to "adb" + with zipfile.ZipFile("platform-tools-latest.zip", 'r') as z: + z.extractall(target_adb_path_parent_folder) + print(f"adb downloaded to: {target_adb_path_parent_folder}") + package_rename(os.path.join(target_adb_path_parent_folder, "platform-tools"), target_adb_path) + + + else: + print(f"adb already exists: {target_adb_path}") def package_copyfolder(src, dst): try: @@ -50,6 +85,9 @@ def package_remove_folder(path): config_version = config.NOWVERSION +# mainly for windows, download adb +package_download_adb(platformstr="Windows") + package_remove_folder("./dist") # 打包main.py,名字为BAAH @@ -58,6 +96,7 @@ def package_remove_folder(path): 'main.py', '-n', 'BAAH', '--icon', './DATA/assets/kei.ico', + '--add-data', f'{Path(pponnxcr.__file__).parent}{os.pathsep}pponnxcr', '-y' ] subprocess.call(baahcmd)