Skip to content

Commit

Permalink
v0.7-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Hikari16665 committed Jun 27, 2024
1 parent e4cde6b commit 925b2b5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
12 changes: 5 additions & 7 deletions hsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
27 changes: 18 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,'请选择服务器类型:')
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 925b2b5

Please sign in to comment.