- 移除了不必要的导入和冗余代码- 新增了从文件读取版本号和路径的功能 - 实现了将新版本复制到指定路径的逻辑 - 添加了重命名旧版本和删除源文件的功能 - 新增了运行新版本的函数
39 lines
753 B
Python
39 lines
753 B
Python
import os
|
|
import subprocess
|
|
import time
|
|
|
|
appdata = os.getenv("APPDATA")
|
|
update_path = appdata + "/.NFLmusic/update/"
|
|
|
|
with open(f"{update_path}file_path", "r") as f:
|
|
data = f.read()
|
|
version = data.split("\n")[0]
|
|
path = data.split("\n")[1]
|
|
|
|
source_file = f"{update_path}NFLmusicv{version}.exe"
|
|
|
|
new_path = path.rsplit("\\", 1)[0]
|
|
|
|
while True:
|
|
try:
|
|
with open(source_file, "rb") as f:
|
|
content = f.read()
|
|
with open(path, "wb") as f:
|
|
f.write(content)
|
|
break
|
|
except:
|
|
pass
|
|
time.sleep(0.05)
|
|
|
|
try:
|
|
os.rename(path, f"NFLmusicv{version}.exe")
|
|
except:
|
|
pass
|
|
os.remove(source_file)
|
|
|
|
|
|
def run_NFLmusic():
|
|
subprocess.Popen(new_path + f"/NFLmusicv{version}.exe")
|
|
|
|
|
|
run_NFLmusic() |