mirror of
https://github.com/TriM-Organization/Linglun-Converter.git
synced 2024-11-28 16:15:25 +08:00
提供检查更新模块,非常人性化
This commit is contained in:
parent
68d93068bb
commit
5c2a56dd50
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,6 +11,7 @@ __pycache__/
|
|||||||
*.bdx
|
*.bdx
|
||||||
*.json
|
*.json
|
||||||
/Musicreater
|
/Musicreater
|
||||||
|
/TrimLog
|
||||||
/logs
|
/logs
|
||||||
|
|
||||||
# C extensions
|
# C extensions
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
伶伦转换器
|
伶伦转换器 命令行
|
||||||
Linglun Converter
|
Linglun Converter CLI
|
||||||
|
|
||||||
版权所有 © 2023 金羿 & 睿穆开发组
|
版权所有 © 2023 金羿 & 睿穆开发组
|
||||||
Copyright © 2023 EillesWan & TriM Org.
|
Copyright © 2023 EillesWan & TriM Org.
|
||||||
|
@ -1,5 +1,17 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
伶伦转换器 WXGUI
|
||||||
|
Linglun Converter WxPython GUI
|
||||||
|
|
||||||
|
版权所有 © 2023 金羿 & 睿穆开发组
|
||||||
|
Copyright © 2023 EillesWan & TriM Org.
|
||||||
|
|
||||||
|
开源相关声明请见 ./License.md
|
||||||
|
Terms & Conditions: ./Lisense.md
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
# 导入所需库
|
# 导入所需库
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
@ -19,49 +31,35 @@ from Musicreater.plugin.addonpack import (
|
|||||||
)
|
)
|
||||||
from Musicreater.plugin.bdxfile import to_BDX_file_in_delay, to_BDX_file_in_score
|
from Musicreater.plugin.bdxfile import to_BDX_file_in_delay, to_BDX_file_in_score
|
||||||
|
|
||||||
# import TrimLog
|
|
||||||
import wx
|
import wx
|
||||||
|
|
||||||
# from TrimLog import Console, object_constants
|
from utils.io import myWords, osc, logger, object_constants, TrimLog, is_logging
|
||||||
|
from utils.update_check import check_update
|
||||||
|
|
||||||
# from utils.io import prt
|
|
||||||
|
|
||||||
# is_logging: bool = True
|
|
||||||
|
|
||||||
# osc = object_constants.ObjectStateConstant()
|
|
||||||
# logger = TrimLog.Logger(
|
|
||||||
# is_logging=is_logging,
|
|
||||||
# printing=not osc.isRelease,
|
|
||||||
# in_suffix=".llc",
|
|
||||||
# )
|
|
||||||
|
|
||||||
WHITE = (242, 244, 246) # F2F4F6
|
WHITE = (242, 244, 246) # F2F4F6
|
||||||
BLACK = (18, 17, 16) # 121110
|
BLACK = (18, 17, 16) # 121110
|
||||||
|
|
||||||
try:
|
|
||||||
myWords = (
|
|
||||||
urllib.request.urlopen(
|
|
||||||
"https://gitee.com/TriM-Organization/LinglunStudio/raw/master/resources/myWords.txt"
|
|
||||||
)
|
|
||||||
.read()
|
|
||||||
.decode("utf-8")
|
|
||||||
.strip("\n")
|
|
||||||
.split("\n")
|
|
||||||
)
|
|
||||||
except (ConnectionError, urllib.error.HTTPError) as E:
|
|
||||||
# logger.warning(f"读取言·论信息发生 互联网连接 错误:\n{E}")
|
|
||||||
myWords = ["以梦想为驱使 创造属于自己的未来"]
|
|
||||||
# noinspection PyBroadException
|
|
||||||
except BaseException as E:
|
|
||||||
# logger.warning(f"读取言·论信息发生 未知 错误:\n{E}")
|
|
||||||
myWords = ["灵光焕发 深艺献心"]
|
|
||||||
|
|
||||||
__appname__ = "伶伦转换器"
|
__appname__ = "伶伦转换器"
|
||||||
__version__ = "WXGUI 0.0.2"
|
__version__ = "WXGUI 0.0.3"
|
||||||
|
__zhver__ = "WX图形界面 预代预版第三次修订"
|
||||||
|
|
||||||
|
osc.project_name = __appname__
|
||||||
|
osc.version = __version__
|
||||||
|
|
||||||
|
|
||||||
|
# osc = object_constants.ObjectStateConstant(
|
||||||
|
# logging_project_name=__appname__,
|
||||||
|
# logging_project_version=__version__,
|
||||||
|
# logging_exit_exec=lambda x: None,
|
||||||
|
# )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
yanlun_length = len(myWords)
|
yanlun_length = len(myWords)
|
||||||
|
|
||||||
|
logger.info("加载窗口布局……")
|
||||||
|
|
||||||
# 创建应用程序类
|
# 创建应用程序类
|
||||||
class LinglunConverterApp(wx.App):
|
class LinglunConverterApp(wx.App):
|
||||||
@ -82,7 +80,7 @@ class LingLunMainFrame(wx.Frame):
|
|||||||
self,
|
self,
|
||||||
parent,
|
parent,
|
||||||
id=wx.ID_ANY,
|
id=wx.ID_ANY,
|
||||||
title="{} {}".format(__appname__, __version__),
|
title="{} {}".format(__appname__, __zhver__),
|
||||||
pos=wx.DefaultPosition,
|
pos=wx.DefaultPosition,
|
||||||
size=wx.Size(660, 780),
|
size=wx.Size(660, 780),
|
||||||
style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL,
|
style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL,
|
||||||
@ -955,9 +953,14 @@ class LingLunMainFrame(wx.Frame):
|
|||||||
).ShowModal()
|
).ShowModal()
|
||||||
|
|
||||||
|
|
||||||
|
logger.info("执行应用。")
|
||||||
|
|
||||||
# 启动应用程序
|
# 启动应用程序
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = LinglunConverterApp()
|
app = LinglunConverterApp()
|
||||||
|
|
||||||
|
check_update(__appname__,"https://gitee.com/TriM-Organization/Linglun-Converter/raw/master/llc_win_wxPython.py",__version__,lambda text:wx.MessageDialog(None,text,"软件更新",wx.ICON_INFORMATION | wx.YES_DEFAULT,).ShowModal(),logger,__zhver__)
|
||||||
|
|
||||||
app.MainLoop()
|
app.MainLoop()
|
||||||
|
|
||||||
# input("按下回车退出……")
|
# input("按下回车退出……")
|
||||||
|
18
utils/io.py
18
utils/io.py
@ -1,6 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
伶伦转换器 命令行组件
|
||||||
|
Linglun Converter Command Line IO Component
|
||||||
|
|
||||||
|
版权所有 © 2023 金羿 & 睿穆开发组
|
||||||
|
Copyright © 2023 EillesWan & TriM Org.
|
||||||
|
|
||||||
|
开源相关声明请见 ./License.md
|
||||||
|
Terms & Conditions: ./Lisense.md
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
import urllib.error
|
import urllib.error
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from typing import Any, Callable, Dict, List, Literal, Optional, Set, TextIO, Tuple
|
from typing import Any, Callable, Dict, List, Literal, Optional, Set, TextIO, Tuple, Iterable, Sequence
|
||||||
|
|
||||||
import TrimLog
|
import TrimLog
|
||||||
from TrimLog import Console, object_constants
|
from TrimLog import Console, object_constants
|
||||||
@ -11,7 +25,7 @@ MainConsole = Console()
|
|||||||
osc = object_constants.ObjectStateConstant()
|
osc = object_constants.ObjectStateConstant()
|
||||||
logger = TrimLog.Logger(
|
logger = TrimLog.Logger(
|
||||||
is_logging=is_logging,
|
is_logging=is_logging,
|
||||||
printing=not osc.isRelease,
|
# printing=not osc.is_release,
|
||||||
in_suffix=".llc",
|
in_suffix=".llc",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
118
utils/update_check.py
Normal file
118
utils/update_check.py
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
伶伦转换器 版本检查组件
|
||||||
|
Linglun Converter Version Checking Component
|
||||||
|
|
||||||
|
版权所有 © 2023 金羿 & 睿穆开发组
|
||||||
|
Copyright © 2023 EillesWan & TriM Org.
|
||||||
|
|
||||||
|
开源相关声明请见 ./License.md
|
||||||
|
Terms & Conditions: ./Lisense.md
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .io import TrimLog, urllib, Sequence, Iterable, Callable, Optional
|
||||||
|
|
||||||
|
|
||||||
|
def is_ver_char(text: str) -> bool:
|
||||||
|
return text.isnumeric() or text == "."
|
||||||
|
|
||||||
|
|
||||||
|
def cut_ver_str(text: str) -> str:
|
||||||
|
text += " "
|
||||||
|
len_of_text = len(text) - 1
|
||||||
|
i = 0
|
||||||
|
while i <= len_of_text:
|
||||||
|
if is_ver_char(text[i]) and (text[i + 1] if i < len_of_text else False):
|
||||||
|
j = i
|
||||||
|
while is_ver_char(text[j]) and j < len_of_text:
|
||||||
|
j += 1
|
||||||
|
temp_str = text[i:j].strip()
|
||||||
|
if ("." in temp_str) and (temp_str[0] != ".") and (temp_str[-1] != "."):
|
||||||
|
return temp_str
|
||||||
|
i = j
|
||||||
|
i += 1
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
def get_ver_str(text: str) -> Iterable[str]:
|
||||||
|
text += " "
|
||||||
|
all_ver_str = []
|
||||||
|
len_of_text = len(text) - 1
|
||||||
|
i = 0
|
||||||
|
while i <= len_of_text:
|
||||||
|
if is_ver_char(text[i]) and (text[i + 1] if i < len_of_text else False):
|
||||||
|
j = i
|
||||||
|
while is_ver_char(text[j]) and j < len_of_text:
|
||||||
|
j += 1
|
||||||
|
temp_str = text[i:j].strip()
|
||||||
|
if ("." in temp_str) and (temp_str[0] != ".") and (temp_str[-1] != "."):
|
||||||
|
all_ver_str.append(temp_str)
|
||||||
|
i = j
|
||||||
|
i += 1
|
||||||
|
return all_ver_str
|
||||||
|
|
||||||
|
|
||||||
|
def is_ver_bigger(ver_1: Sequence[int], ver_2: Sequence[int]) -> bool:
|
||||||
|
len_v1 = len(ver_1)
|
||||||
|
len_v2 = len(ver_2)
|
||||||
|
for i in range(min(len_v1, len_v2)):
|
||||||
|
if ver_1[i] == ver_2[i]:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
return ver_1[i] > ver_2[i]
|
||||||
|
return len_v1 > len_v2
|
||||||
|
|
||||||
|
|
||||||
|
def check_update(
|
||||||
|
appname: str,
|
||||||
|
get_text_url: str,
|
||||||
|
version_now: str,
|
||||||
|
message_show_fun: Callable,
|
||||||
|
logger: TrimLog.Logger,
|
||||||
|
version_disp: Optional[str] = None,
|
||||||
|
):
|
||||||
|
if not version_disp:
|
||||||
|
version_disp = version_now
|
||||||
|
|
||||||
|
logger.info("当前版本信息:{}".format(version_now))
|
||||||
|
try:
|
||||||
|
code_content: str = urllib.request.urlopen(get_text_url).read().decode("utf-8")
|
||||||
|
except Exception as E: # noinspection PyBroadException
|
||||||
|
logger.warning("无法获取更新版本信息:{}".format(E))
|
||||||
|
return
|
||||||
|
|
||||||
|
code_content = code_content[code_content.find("__version__") :]
|
||||||
|
code_content = code_content[code_content.find('"') + 1 :]
|
||||||
|
version_content = code_content[: code_content.find('"')]
|
||||||
|
|
||||||
|
logger.info("已获取更新版本信息:{}".format(version_content))
|
||||||
|
|
||||||
|
if is_ver_bigger(
|
||||||
|
[int(v) for v in cut_ver_str(version_content).split(".")],
|
||||||
|
[int(v) for v in cut_ver_str(version_now).split(".")],
|
||||||
|
):
|
||||||
|
if "__zhver__" in code_content:
|
||||||
|
code_content = code_content[code_content.find("__zhver__") :]
|
||||||
|
code_content = code_content[code_content.find('"') + 1 :]
|
||||||
|
version_content = code_content[: code_content.find('"')]
|
||||||
|
|
||||||
|
message_show_fun(
|
||||||
|
"!有新版本!\n最新的 {app} 已经是 {latest} 版本,当前您正在使用的仍是 {current} 版本,您可以前往下载地址更新。".format(
|
||||||
|
app=appname, latest=version_content, current=version_disp
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# code_content = code_content[code_content.find('"')+1:]
|
||||||
|
|
||||||
|
# version_content = code_content[:code_content.find('"')]
|
||||||
|
|
||||||
|
# version_content_len = len(version_content)
|
||||||
|
|
||||||
|
# for i in range(version_content_len):
|
||||||
|
# if is_ver_char(version_content[i]) and (version_content[i+1] if i < version_content.__len__() else False):
|
||||||
|
# j = i
|
||||||
|
# while is_ver_char(version_content[j]):j+=1
|
||||||
|
# return version_content[i:j]
|
||||||
|
|
||||||
|
# "".join([version_content[i] for i in range(version_content.__len__()) if is_ver_char(version_content[i]) and ((version_content[i-1] if i > 0 else False) or (version_content[i+1] if i < version_content.__len__() else False))]).split('.')
|
Loading…
Reference in New Issue
Block a user