From 925b2b5771213c12b6d5163927d3c294ab7dbb2a Mon Sep 17 00:00:00 2001 From: ikunsz666 <3279642466@qq.com> Date: Thu, 27 Jun 2024 16:45:05 +0800 Subject: [PATCH] v0.7-1 --- hsl.py | 12 +++++------- main.py | 27 ++++++++++++++++++--------- workspace.py | 5 ++++- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/hsl.py b/hsl.py index 37f1464..3e100c7 100644 --- a/hsl.py +++ b/hsl.py @@ -6,7 +6,7 @@ def check_update(version: int) -> tuple: console.print('正在检查更新...') try: - r = requests.get(VERSION,timeout=1) + r = requests.get(VERSION,timeout=3) if r.status_code == 200: latest: int = r.json()['version'] if version < latest: @@ -21,17 +21,15 @@ def check_update(version: int) -> tuple: return False, version def get_source() -> dict: console.print('正在获取下载源信息...') - with open('source.json','r',encoding='utf-8') as f: - return json.loads(f.read()) r = requests.get(DOWNLOAD_SOURCE,timeout=3) if r.status_code == 200: return r.json() else: - return {} + raise Exception -HSL_VERSION = 6 -DOWNLOAD_SOURCE = r'http://mirror.hikari.bond:12345/source.json' -VERSION = r'http://mirror.hikari.bond:12345/hsl.json' +HSL_VERSION = 7 +DOWNLOAD_SOURCE = r'http://hsl.hikari.bond/source.json' +VERSION = r'http://hsl.hikari.bond/hsl.json' try: SOURCE = get_source() except: diff --git a/main.py b/main.py index 3743694..b785d7c 100644 --- a/main.py +++ b/main.py @@ -27,9 +27,9 @@ from java import Java OPTIONS_YN = ['是', '否'] -OPTIONS_GAMETYPE = ['原版','Paper','Forge','Fabric'] +OPTIONS_GAMETYPE = ['原版','Paper','Forge','Fabric','取消'] OPTIONS_MENU = ['创建服务器', '管理服务器', '删除服务器','退出'] -OPTIONS_MANAGE = ['启动服务器'] +OPTIONS_MANAGE = ['启动服务器','打开服务器目录',] MAXRAM_PATTERN = re.compile(r'^\d+(\.\d+)?(M|G)$') HSL_NAME = f'Hikari Server Launcher' @@ -105,21 +105,22 @@ async def create(self): serverPath=serverPath ) if server_setting == False: - console.print('[bold magenta]安装失败。') + console.print('[bold magenta]未安装服务器。') return serverName, serverType, serverPath, javaPath = server_setting maxRam = await promptInput(f'你的主机最大内存为:{OS_MAXRAM}MB 请输入服务器最大内存(示例:1024M 或 1G):') #check regex while not MAXRAM_PATTERN.match(maxRam): - maxRam = await promptInput('[bold magenta]输入错误,请重新输入:') - Server = Server( + maxRam = await promptInput('输入错误,请重新输入:') + server = None + server = Server( name=serverName, type=serverType, path=serverPath, javaPath=javaPath, maxRam=maxRam ) - await self.Workspace.add(Server) + await self.Workspace.add(server) async def install(self,*,serverName: str,serverPath: str): serverJarPath = os.path.join(serverPath,'server.jar') gameType = await promptSelect(OPTIONS_GAMETYPE,'请选择服务器类型:') @@ -172,6 +173,8 @@ async def install(self,*,serverName: str,serverPath: str): console.print('Fabric 服务端下载失败。') return False console.print('Fabric 服务端下载完成。') + case 4: + return False return serverName, serverType, serverPath, javaPath async def manage(self): workspaces = self.Workspace.workspaces @@ -181,9 +184,15 @@ async def manage(self): index = await promptSelect([x['name'] for x in workspaces],'选择服务器:') serverName = workspaces[index]['name'] choice = await promptSelect(OPTIONS_MANAGE,f'{serverName} - 请选择操作:') - if choice == 0: - Server = await self.Workspace.get(index) - Server.run() + server = await self.Workspace.get(index) + match choice: + case 0: + server.run() + case 1: + try: + os.startfile(server.path) + except: + console.print('[bold magenta]无法打开服务器目录。') async def delete(self): console.rule('服务器删除') if not self.Workspace.workspaces: diff --git a/workspace.py b/workspace.py index b53cae5..8372aaf 100644 --- a/workspace.py +++ b/workspace.py @@ -50,6 +50,9 @@ async def get(self, index: int): maxRam = server["maxRam"] ) async def delete(self, index: int): - shutil.rmtree(self.workspaces[index]["path"]) + try: + shutil.rmtree(self.workspaces[index]["path"]) + except: + pass del self.workspaces[index] self.save()