From eee098860ff961a337064611c5fb9471c5fae133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=A1=E7=94=A8=E7=9A=84=E5=B0=8F=E5=BA=9F=E9=BC=A0?= <107793048+ymh0000123@users.noreply.github.com> Date: Mon, 19 Feb 2024 15:55:15 +0800 Subject: [PATCH] 1 --- source code/XPMSL.py | 104 +++++++++++++++++- source code/{ => old}/app.py | 0 source code/requirements.txt | 6 +- .../public/announcement/announcement.txt | 4 +- vuepress/src/.vuepress/public/releases.json | 8 +- vuepress/src/zh-cn/historicalversion.md | 5 + 6 files changed, 114 insertions(+), 13 deletions(-) rename source code/{ => old}/app.py (100%) diff --git a/source code/XPMSL.py b/source code/XPMSL.py index 2bff7e8..e3d9f9a 100644 --- a/source code/XPMSL.py +++ b/source code/XPMSL.py @@ -10,15 +10,64 @@ import http.client import json from tkinter import simpledialog +import argparse +import sys +import subprocess -version = "V1.1.0" -Build = "20240212" +version = "V1.1.1" +Build = "20240219" current_build = Build api_url = "https://xpmsl.pages.dev/" api_releases = "releases.json" api_download_button = "announcement/list.txt" api_announcement = "announcement/announcement.txt" +Update_module = 'XPMSL-Update-module.exe' +github_url = "https://slink.ltd/https://github.com/" +Update_module_github = "ymh0000123/XPMSL-Update-module" + +def update_or_create_releases_json(build_value, directory_path="XPMSL"): + # 构造releases.json文件的路径 + releases_json_path = os.path.join(directory_path, "releases.json") + + # 确保directory_path目录存在 + os.makedirs(directory_path, exist_ok=True) + + # 检查文件是否存在 + if not os.path.exists(releases_json_path): + print(f"文件{releases_json_path}不存在,将创建一个新的文件。") + # 创建带有Build值的初始字典 + data = {"Build": build_value} + else: + # 如果文件存在,读取现有的JSON数据 + with open(releases_json_path, 'r', encoding='utf-8') as file: + try: + data = json.load(file) + except json.JSONDecodeError: + # 如果文件存在但是为空或格式不正确,创建一个新的字典 + print(f"文件{releases_json_path}格式不正确,将创建一个新的文件。") + data = {} + + # 修改数据 + data["Build"] = build_value + + # 写回文件 + with open(releases_json_path, 'w', encoding='utf-8') as file: + json.dump(data, file, indent=4, ensure_ascii=False) + + print(f"已成功将Build更新为{build_value}在{releases_json_path}") + +def update_tool(): + # 获取当前脚本的目录路径 + current_dir = os.path.dirname(os.path.abspath(__file__)) + # 构造XPMSL-Update-module.exe的完整路径 + exe_path = os.path.join(current_dir, "XPMSL-Update-module.exe") + + # 使用subprocess模块启动程序 + subprocess.run([exe_path]) + +# 示例调用函数 +update_or_create_releases_json(Build) def check_for_updates(current_build): try: @@ -29,10 +78,18 @@ def check_for_updates(current_build): # 获取远程build值并转换为整数 remote_build = data['build'] - + up_releases = data['up_releases'] + Update_download(up_releases) # 比较build值 if remote_build > current_build: - messagebox.showinfo("更新提醒", "有新的程序版本可用,请更新!") + if messagebox.askyesno("更新提醒", "有新的程序版本可用,请更新!"): + try: + update_tool() + except: + messagebox.showerror("更新失败", "无法更新程序。") + + else: + messagebox.showinfo("提示", "注意!你正在使用的可能是测试版。") except Exception as e: messagebox.showerror("更新检查失败", f"无法检查更新:{e}") @@ -41,6 +98,45 @@ def check_updates_in_thread(current_build): update_thread.start() + +def open_announcement(): + # 创建解析器 + parser = argparse.ArgumentParser(description='处理命令行参数的示例。') + + # 添加 '-v' 或 '--verbose' 选项 + parser.add_argument('-b', '--Build', action='store_true', help='查看版本号') + + # 解析命令行参数 + args = parser.parse_args() + + # 根据 '-v' 或 '--verbose' 选项是否存在来决定程序行为 + if args.Build: + print('Build') + # 执行一些操作后,退出程序 + sys.exit() + +open_announcement() + + +def Update_download(up_releases): + filename = Update_module + if not os.path.exists(filename): + download_file_Update(up_releases) + +def download_file_Update(up_releases): + url = github_url + Update_module_github +"/releases/download/V"+ up_releases +"/"+ Update_module + print (url) + filename = Update_module + try: + response = requests.get(url) + with open(filename, 'wb') as f: + f.write(response.content) + print("文件下载成功!") + except Exception as e: + print(f"文件下载失败:{e}") + + + # 在程序启动时自动检查更新(在单独的线程中) check_updates_in_thread(current_build) diff --git a/source code/app.py b/source code/old/app.py similarity index 100% rename from source code/app.py rename to source code/old/app.py diff --git a/source code/requirements.txt b/source code/requirements.txt index 2239cd3..d157a64 100644 --- a/source code/requirements.txt +++ b/source code/requirements.txt @@ -1,3 +1,3 @@ -requests -PyYAML -pyinstaller \ No newline at end of file +PyYAML==6.0.1 +PyYAML==6.0.1 +Requests==2.31.0 diff --git a/vuepress/src/.vuepress/public/announcement/announcement.txt b/vuepress/src/.vuepress/public/announcement/announcement.txt index 0180e7f..7c63bd1 100644 --- a/vuepress/src/.vuepress/public/announcement/announcement.txt +++ b/vuepress/src/.vuepress/public/announcement/announcement.txt @@ -1,3 +1,3 @@ 欢迎使用 Hi~ o(* ̄▽ ̄*)ブ -目前最新版是 V1.0.5 -更新日志在GitHub查看 +目前最新版是 V1.1.0 +更新日志在https://xpmsl.pages.dev/zh-cn/historicalversion.html diff --git a/vuepress/src/.vuepress/public/releases.json b/vuepress/src/.vuepress/public/releases.json index 93c4634..2a7520e 100644 --- a/vuepress/src/.vuepress/public/releases.json +++ b/vuepress/src/.vuepress/public/releases.json @@ -1,6 +1,6 @@ { - "releases": "1.1.0", - "build": "20240212", - "up_releases": "1.0.0", - "up_build": "20240218" + "releases": "1.1.1", + "build": "20240219", + "up_releases": "1.0.1", + "up_build": "20240219" } \ No newline at end of file diff --git a/vuepress/src/zh-cn/historicalversion.md b/vuepress/src/zh-cn/historicalversion.md index 0d6fbe7..6d0f7aa 100644 --- a/vuepress/src/zh-cn/historicalversion.md +++ b/vuepress/src/zh-cn/historicalversion.md @@ -1,5 +1,10 @@ # 历史版本 +## 20240219 + 1. 添加自动下载更新模块 +[Github](https://github.com/ymh0000123/XPMSL/releases/download/V1.1.1/XPMSL.exe) | +[加速下载](https://slink.ltd/https://github.com/ymh0000123/XPMSL/releases/download/V1.1.1/XPMSL.exe) + ## 20240212 1. 修改所有需要调用的API接口 [Github](https://github.com/ymh0000123/XPMSL/releases/download/V1.1.0/XPMSL.exe) |