Skip to content

Commit

Permalink
Fix | update
Browse files Browse the repository at this point in the history
  • Loading branch information
LxHTT committed Apr 4, 2024
1 parent d8401f0 commit 6c76469
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
3 changes: 2 additions & 1 deletion MCSL2Lib/ProgramControllers/updateController.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ def downloadVerification(self):
"""下载MCSL2验证模块,在下载主程序之后调用"""
if GlobalMCSL2Variables.devMode:
return
if not osp.exists(f"MCSL2/Downloads/MCSL2{self.updateProcessExt}"):
if not osp.exists(f"MCSL2/Downloads/{self.updateVerificationFileName}"):
self.downloadUpdate(showInfoBar=False)
return
else:
Aria2Controller.download(
uri=self.verificationUpdateLink,
watch=False,
interval=0.2,
stopped=self.renameUpdate,
)

Expand Down
55 changes: 37 additions & 18 deletions MCSL2Lib/ServerControllers/serverUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from psutil import NoSuchProcess, Process, AccessDenied
from MCSL2Lib.ServerControllers.processCreator import _ServerProcessBridge
from MCSL2Lib.variables import ServerVariables
# from MCSL2Lib.ProgramControllers.networkController import MCSLNetworkSession
from os import path as osp, mkdir
from os.path import isdir, exists
from qfluentwidgets import InfoBar, InfoBarPosition
Expand Down Expand Up @@ -50,9 +51,7 @@ def getServerMem(self):
try:
if self.bridge.isServerRunning():
serverMem = (
Process(self.bridge.handledServer.process.processId())
.memory_full_info()
.uss
Process(self.bridge.handledServer.process.processId()).memory_full_info().uss
/ divisionNum
)
self.memPercent.emit(float("{:.4f}".format(serverMem)))
Expand All @@ -68,9 +67,9 @@ def getServerMem(self):
def getServerCPU(self):
try:
if self.bridge.isServerRunning():
serverCPU = Process(
self.bridge.handledServer.process.processId()
).cpu_percent(interval=0.01)
serverCPU = Process(self.bridge.handledServer.process.processId()).cpu_percent(
interval=0.01
)
self.cpuPercent.emit(float("{:.4f}".format(serverCPU / 10)))
else:
self.cpuPercent.emit(0.0000)
Expand Down Expand Up @@ -106,6 +105,32 @@ def readServerProperties(serverConfig: ServerVariables):
serverConfig.serverProperties.update({"msg": "File not found"})


# class CrashMCAnalyzerThread(QThread):
# resSignal = pyqtSignal(str)

# def __init__(self, log: str, parent=None):
# super().__init__(parent)
# self.log = log

# def run(self):
# headers = MCSLNetworkSession.MCSLNetworkHeaders
# headers["Content-Type"] = "text/plain"
# headers["Accept"] = "application/json"

# apiResult = MCSLNetworkSession().post(
# url="https://api.crashmc.com/v0/analyze/",
# data=self.log,
# headers=headers,
# )
# if apiResult.status_code == 200:
# if apiResult.json().get("res"):
# error = ""
# for matchError in apiResult.json().get("res"):
# pass
# else:
# self.resSignal.emit(f"CrashMC接口请求失败,HTTP Status Code: {apiResult.status_code}")


class MakeArchiveThread(QThread):
successSignal = pyqtSignal()
errorSignal = pyqtSignal()
Expand Down Expand Up @@ -206,9 +231,7 @@ def backupSaves(serverConfig: ServerVariables, parent):
try:
copytree(
osp.abspath(f"Servers/{serverConfig.serverName}/{dir}/"),
osp.abspath(
f"MCSL2/BackupTemp_{serverConfig.serverName}/{dir}/"
),
osp.abspath(f"MCSL2/BackupTemp_{serverConfig.serverName}/{dir}/"),
)
except FileNotFoundError:
levelNameList.remove(dir)
Expand All @@ -223,9 +246,9 @@ def backupSaves(serverConfig: ServerVariables, parent):
tmpArchiveThread.successSignal.connect(
lambda: InfoBar.success(
title=parent.tr("备份完毕"),
content=parent.tr(
"已保存至 {s}。\n备份了以下文件夹:\n{existsDir}"
).format(s=s, existsDir=existsDir),
content=parent.tr("已保存至 {s}。\n备份了以下文件夹:\n{existsDir}").format(
s=s, existsDir=existsDir
),
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP,
Expand All @@ -234,14 +257,10 @@ def backupSaves(serverConfig: ServerVariables, parent):
)
)
tmpArchiveThread.successSignal.connect(
lambda: rmtree(
osp.abspath(f"MCSL2/BackupTemp_{serverConfig.serverName}/")
)
lambda: rmtree(osp.abspath(f"MCSL2/BackupTemp_{serverConfig.serverName}/"))
)
tmpArchiveThread.errorSignal.connect(
lambda: rmtree(
osp.abspath(f"MCSL2/BackupTemp_{serverConfig.serverName}/")
)
lambda: rmtree(osp.abspath(f"MCSL2/BackupTemp_{serverConfig.serverName}/"))
)
tmpArchiveThread.start()
else:
Expand Down
1 change: 0 additions & 1 deletion MCSL2Lib/Widgets/serverManagerWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
QWidget,
QSizePolicy,
QGridLayout,
QSpacerItem,
QVBoxLayout,
QHBoxLayout,
QSpacerItem,
Expand Down

0 comments on commit 6c76469

Please sign in to comment.