From 82cc49a5ad3ec7053a4317bedcf2d7df26e86d54 Mon Sep 17 00:00:00 2001 From: Adentent <96329894+Adentent@users.noreply.github.com> Date: Sun, 9 Jun 2024 21:48:21 +0800 Subject: [PATCH 01/11] textDiffiultyList -> textDifficultyList --- MCSL2Lib/ServerControllers/windowCreator.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MCSL2Lib/ServerControllers/windowCreator.py b/MCSL2Lib/ServerControllers/windowCreator.py index 4111f23..a6e75da 100644 --- a/MCSL2Lib/ServerControllers/windowCreator.py +++ b/MCSL2Lib/ServerControllers/windowCreator.py @@ -1332,7 +1332,7 @@ def getKnownServerPlayers(self) -> str: def initQuickMenu_Difficulty(self): """快捷菜单-服务器游戏难度""" - textDiffiultyList = ["peaceful", "easy", "normal", "hard"] + textDifficultyList = ["peaceful", "easy", "normal", "hard"] if self.getRunningStatus(): try: self.difficulty.setCurrentIndex( @@ -1340,7 +1340,7 @@ def initQuickMenu_Difficulty(self): ) except ValueError: self.difficulty.setCurrentIndex( - int(textDiffiultyList.index(self.serverConfig.serverProperties["difficulty"])) + int(textDifficultyList.index(self.serverConfig.serverProperties["difficulty"])) ) except Exception: pass @@ -1349,8 +1349,8 @@ def initQuickMenu_Difficulty(self): self.showServerNotOpenMsg() def runQuickMenu_Difficulty(self): - textDiffiultyList = ["peaceful", "easy", "normal", "hard"] - self.sendCommand(f"difficulty {textDiffiultyList[self.difficulty.currentIndex()]}") + textDifficultyList = ["peaceful", "easy", "normal", "hard"] + self.sendCommand(f"difficulty {textDifficultyList[self.difficulty.currentIndex()]}") def initQuickMenu_GameMode(self): """快捷菜单-游戏模式""" From 4c7ec54637f353524b6749341dcf67060867506b Mon Sep 17 00:00:00 2001 From: Adentent <96329894+Adentent@users.noreply.github.com> Date: Sun, 9 Jun 2024 21:48:45 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E6=9B=B4=E6=94=B9=20utils.checkSHA1=20?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=87=BD=E6=95=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MCSL2Lib/utils.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/MCSL2Lib/utils.py b/MCSL2Lib/utils.py index 3b4e0e1..54b115f 100644 --- a/MCSL2Lib/utils.py +++ b/MCSL2Lib/utils.py @@ -235,15 +235,12 @@ def checkSHA1( 检查文件的SHA1值是否正确 """ rv = [] - if _filter is None: - def _filter(a, b): - return True for file, sha1 in fileAndSha1: if not osp.exists(file): rv.append({"file": file, "result": False}) continue - if _filter(file, sha1): + if _filter is None or _filter(file, sha1): # check sha1 fileSha1 = hashlib.sha1(readBytesFile(file)).hexdigest() rv.append({"file": file, "result": fileSha1 == sha1}) From 362aea51c4c7381bc396902e51056f5408d19b5f Mon Sep 17 00:00:00 2001 From: Adentent <96329894+Adentent@users.noreply.github.com> Date: Sun, 9 Jun 2024 22:32:57 +0800 Subject: [PATCH 03/11] format code --- MCSL2Lib/ServerControllers/forge/installer/json/artifact.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCSL2Lib/ServerControllers/forge/installer/json/artifact.py b/MCSL2Lib/ServerControllers/forge/installer/json/artifact.py index 90025b1..550ed68 100644 --- a/MCSL2Lib/ServerControllers/forge/installer/json/artifact.py +++ b/MCSL2Lib/ServerControllers/forge/installer/json/artifact.py @@ -30,7 +30,7 @@ def from_(descriptor: str) -> "Artifact": idx = pts[last].find("@") if idx != -1: - ext = pts[last][idx + 1 :] + ext = pts[last][idx + 1:] pts[last] = pts[last][:idx] else: ext = "jar" From a9386e56c57ee95350ac7baa33a3c80aa30bd5c7 Mon Sep 17 00:00:00 2001 From: Adentent <96329894+Adentent@users.noreply.github.com> Date: Sun, 9 Jun 2024 22:33:17 +0800 Subject: [PATCH 04/11] add TODO comment --- Adapters/Event/BaseEvent.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Adapters/Event/BaseEvent.py b/Adapters/Event/BaseEvent.py index 521680f..b91b38e 100644 --- a/Adapters/Event/BaseEvent.py +++ b/Adapters/Event/BaseEvent.py @@ -45,6 +45,8 @@ def __init__(self): self.handlers.append() """ + # TODO: 不可否认的是这个方法并未起到效果, 并且作为 abstract method 也未被子类实现, 其及其子类在实际应用场景中也无用处. + # 并且该段代码已经存在近一年时间. @abstractmethod def registerHandle(self, func, priority: int): pass From 20ea48c9b842e964af4892116acf90c9e08bd916 Mon Sep 17 00:00:00 2001 From: Adentent <96329894+Adentent@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:11:40 +0800 Subject: [PATCH 05/11] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=BC=80?= =?UTF-8?q?=E6=9C=BA=E8=87=AA=E5=90=AF=E5=8A=A8=E9=80=89=E9=A1=B9=20(=20?= =?UTF-8?q?=E4=BB=85=E9=99=90=E4=BA=8E=20Windows=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MCSL2Lib/Pages/settingsPage.py | 19 +++++++++++--- MCSL2Lib/utils.py | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/MCSL2Lib/Pages/settingsPage.py b/MCSL2Lib/Pages/settingsPage.py index cc9a57a..85c0adb 100644 --- a/MCSL2Lib/Pages/settingsPage.py +++ b/MCSL2Lib/Pages/settingsPage.py @@ -13,7 +13,7 @@ """ Settings page. """ - +import os from datetime import datetime from PyQt5.QtCore import QSize, Qt, QRect, pyqtSignal, pyqtSlot @@ -49,7 +49,7 @@ setThemeColor, ) -from MCSL2Lib import MCSL2VERSION +from MCSL2Lib import MCSL2VERSION, utils from MCSL2Lib.ProgramControllers.aria2ClientController import ( Aria2BootThread, Aria2Controller, @@ -335,14 +335,18 @@ def __init__(self, parent=None): self.startOnStartup = SwitchSettingCard( icon=FIF.POWER_BUTTON, title=self.tr("开机自启动"), - content=self.tr("好像还做不到啊。"), + content=self.tr("好像还做不到啊。仅限 Windows。( WIP )"), configItem=cfg.startOnStartup, parent=self.consoleSettingsGroup, ) self.alwaysRunAsAdministrator.setEnabled(False) - self.startOnStartup.setEnabled(False) + if os.name == 'nt': + self.startOnStartup.setEnabled(True) + else: + self.startOnStartup.setEnabled(False) self.themeColor.colorChanged.connect(lambda cl: setThemeColor(color=cl, lazy=True)) self.themeMode.optionChanged.connect(lambda ci: setTheme(cfg.get(ci), lazy=True)) + self.startOnStartup.checkedChanged.connect(self.setStartup) # self.themeMode.optionChanged.connect(self.showNeedRestartMsg) self.programSettingsGroup.addSettingCard(self.themeMode) self.programSettingsGroup.addSettingCard(self.themeColor) @@ -690,3 +694,10 @@ def generateSystemReport(self): ) ) w.exec() + + @staticmethod + def setStartup(state: bool): + if state: + utils.setStartOnStartup() + else: + utils.removeStartOnStartup() diff --git a/MCSL2Lib/utils.py b/MCSL2Lib/utils.py index 54b115f..903d6f1 100644 --- a/MCSL2Lib/utils.py +++ b/MCSL2Lib/utils.py @@ -18,6 +18,8 @@ import functools import hashlib import inspect +import os.path +import sys from json import dumps, loads from os import makedirs, path as osp from types import TracebackType @@ -25,9 +27,11 @@ import aria2p import psutil +import pythoncom import requests from PyQt5.QtCore import QUrl, QThread, QThreadPool, QFile from PyQt5.QtGui import QDesktopServices +from win32comext.shell import shell from MCSL2Lib.ProgramControllers.logController import _MCSL2Logger @@ -322,3 +326,44 @@ def getAvailableAuthorServer() -> Optional[str]: except ConnectionError: continue return None + + +def getCurrentMainFile() -> str: + """ + 返回可执行文件 / 脚本的路径 + """ + return sys.argv[0] + + +def setStartOnStartup(): + """ + 在相应位置创建一个快捷方式, 使得本应用能够开机自启动 + 仅限于 Windows 操作系统 + """ + # Refs: + # - https://github.com/pearu/iocbio/blob/master/installer/utils.py + # - https://blog.csdn.net/thundor/article/details/5968581 + targetDirectory = os.getenv('USERPROFILE') + r'\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup' + shortcut = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, + pythoncom.CLSCTX_INPROC_SERVER, + shell.IID_IShellLink) + pythonPath = sys.executable # 可执行文件全路径 + shortcut.SetPath(pythonPath) + shortcut.SetArguments(getCurrentMainFile()) + shortcut.SetDescription(pythonPath) + shortcut.SetIconLocation(sys.executable, 0) + shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save(targetDirectory + r"\MCSL2.lnk", 0) # 保存快捷方式文件 + + +def removeStartOnStartup(): + """ + 移除先前创建的开机自启动快捷方式 + """ + shortcut = (os.getenv('USERPROFILE') + + r"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\MCSL2.lnk") + print(shortcut) + if not os.path.exists(shortcut): + print(123) + raise FileNotFoundError(f"{shortcut} not found! Check again or ask others for help") + os.remove(shortcut) + print(12) From d73ce2980f1b6ab1435fff757900918763e8b3d8 Mon Sep 17 00:00:00 2001 From: Adentent <96329894+Adentent@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:39:37 +0800 Subject: [PATCH 06/11] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E4=BD=BF=E7=94=A8=E5=8E=9F=E6=9C=AC=20config?= =?UTF-8?q?=20=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MCSL2.py | 5 ++++- MCSL2Lib/Pages/settingsPage.py | 2 +- MCSL2Lib/utils.py | 7 +++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/MCSL2.py b/MCSL2.py index d74038a..ca330bb 100644 --- a/MCSL2.py +++ b/MCSL2.py @@ -13,7 +13,7 @@ """ Main entry. """ - +import os import sys from PyQt5.QtCore import Qt, QLocale, QObject, QEvent from PyQt5.QtWidgets import QApplication @@ -36,6 +36,9 @@ def notify(self, a0: QObject, a1: QEvent) -> bool: if __name__ == "__main__": + # Override cwd + os.chdir(os.path.dirname(os.path.abspath(__file__))) + # Debug # tracer = VizTracer() # tracer.enable_thread_tracing() diff --git a/MCSL2Lib/Pages/settingsPage.py b/MCSL2Lib/Pages/settingsPage.py index 85c0adb..79f91cf 100644 --- a/MCSL2Lib/Pages/settingsPage.py +++ b/MCSL2Lib/Pages/settingsPage.py @@ -335,7 +335,7 @@ def __init__(self, parent=None): self.startOnStartup = SwitchSettingCard( icon=FIF.POWER_BUTTON, title=self.tr("开机自启动"), - content=self.tr("好像还做不到啊。仅限 Windows。( WIP )"), + content=self.tr("仅限 Windows。"), configItem=cfg.startOnStartup, parent=self.consoleSettingsGroup, ) diff --git a/MCSL2Lib/utils.py b/MCSL2Lib/utils.py index 903d6f1..a2f6847 100644 --- a/MCSL2Lib/utils.py +++ b/MCSL2Lib/utils.py @@ -347,7 +347,9 @@ def setStartOnStartup(): shortcut = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink) - pythonPath = sys.executable # 可执行文件全路径 + pythonPath = sys.executable.replace("python.exe", "pythonw.exe") # 可执行文件全路径 + if not os.path.exists(pythonPath): + pythonPath = sys.executable shortcut.SetPath(pythonPath) shortcut.SetArguments(getCurrentMainFile()) shortcut.SetDescription(pythonPath) @@ -361,9 +363,6 @@ def removeStartOnStartup(): """ shortcut = (os.getenv('USERPROFILE') + r"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\MCSL2.lnk") - print(shortcut) if not os.path.exists(shortcut): - print(123) raise FileNotFoundError(f"{shortcut} not found! Check again or ask others for help") os.remove(shortcut) - print(12) From 41dcae538ea328b395b4b06b277cd9bca0cf0a39 Mon Sep 17 00:00:00 2001 From: Adentent <96329894+Adentent@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:49:22 +0800 Subject: [PATCH 07/11] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86=20log?= =?UTF-8?q?=20=E4=BD=8D=E7=BD=AE=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MCSL2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MCSL2.py b/MCSL2.py index ca330bb..a034041 100644 --- a/MCSL2.py +++ b/MCSL2.py @@ -19,7 +19,6 @@ from PyQt5.QtWidgets import QApplication # from viztracer import VizTracer -from MCSL2Lib.utils import MCSL2Logger class MCSL2Application(QApplication): @@ -39,6 +38,9 @@ def notify(self, a0: QObject, a1: QEvent) -> bool: # Override cwd os.chdir(os.path.dirname(os.path.abspath(__file__))) + # Import after overriding cwd to export the logs to the correct place + from MCSL2Lib.utils import MCSL2Logger + # Debug # tracer = VizTracer() # tracer.enable_thread_tracing() From 4820543fa468ec9893d1a71e2fe189085c48941d Mon Sep 17 00:00:00 2001 From: Adentent <96329894+Adentent@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:54:37 +0800 Subject: [PATCH 08/11] remove todo tag --- Adapters/Event/BaseEvent.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Adapters/Event/BaseEvent.py b/Adapters/Event/BaseEvent.py index b91b38e..521680f 100644 --- a/Adapters/Event/BaseEvent.py +++ b/Adapters/Event/BaseEvent.py @@ -45,8 +45,6 @@ def __init__(self): self.handlers.append() """ - # TODO: 不可否认的是这个方法并未起到效果, 并且作为 abstract method 也未被子类实现, 其及其子类在实际应用场景中也无用处. - # 并且该段代码已经存在近一年时间. @abstractmethod def registerHandle(self, func, priority: int): pass From 9dfe00736794ec276dea225e5dbb939078e0ae45 Mon Sep 17 00:00:00 2001 From: Adentent <96329894+Adentent@users.noreply.github.com> Date: Mon, 10 Jun 2024 14:00:23 +0800 Subject: [PATCH 09/11] format import --- MCSL2.py | 11 +++++++---- MCSL2Lib/variables.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/MCSL2.py b/MCSL2.py index a034041..48f6647 100644 --- a/MCSL2.py +++ b/MCSL2.py @@ -13,11 +13,14 @@ """ Main entry. """ + import os import sys + from PyQt5.QtCore import Qt, QLocale, QObject, QEvent from PyQt5.QtWidgets import QApplication + # from viztracer import VizTracer @@ -63,10 +66,10 @@ def notify(self, a0: QObject, a1: QEvent) -> bool: from MCSL2Lib.variables import GlobalMCSL2Variables if ( - cfg.get(cfg.oldExecuteable) == "python" - or cfg.get(cfg.oldExecuteable) == "python.exe" - or cfg.get(cfg.oldExecuteable) == "py" - or cfg.get(cfg.oldExecuteable) == "py.exe" + cfg.get(cfg.oldExecuteable) == "python" + or cfg.get(cfg.oldExecuteable) == "python.exe" + or cfg.get(cfg.oldExecuteable) == "py" + or cfg.get(cfg.oldExecuteable) == "py.exe" ): GlobalMCSL2Variables.devMode = True else: diff --git a/MCSL2Lib/variables.py b/MCSL2Lib/variables.py index c4df59d..4003e4a 100644 --- a/MCSL2Lib/variables.py +++ b/MCSL2Lib/variables.py @@ -15,8 +15,8 @@ """ from MCSL2Lib.ProgramControllers.settingsController import cfg -from MCSL2Lib.utils import readGlobalServerConfig from MCSL2Lib.singleton import Singleton +from MCSL2Lib.utils import readGlobalServerConfig class BaseServerVariables: From b6d52cd3b53f53216ab838680eff9e5d65a8edab Mon Sep 17 00:00:00 2001 From: Adentent <96329894+Adentent@users.noreply.github.com> Date: Mon, 10 Jun 2024 14:14:38 +0800 Subject: [PATCH 10/11] =?UTF-8?q?(=20=E5=8F=AF=E8=83=BD=20)=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=BA=86=E6=89=93=E5=8C=85=E5=90=8E=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MCSL2Lib/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MCSL2Lib/utils.py b/MCSL2Lib/utils.py index a2f6847..fe3292a 100644 --- a/MCSL2Lib/utils.py +++ b/MCSL2Lib/utils.py @@ -350,6 +350,8 @@ def setStartOnStartup(): pythonPath = sys.executable.replace("python.exe", "pythonw.exe") # 可执行文件全路径 if not os.path.exists(pythonPath): pythonPath = sys.executable + if getCurrentMainFile().endswith(".exe"): + pythonPath = "" shortcut.SetPath(pythonPath) shortcut.SetArguments(getCurrentMainFile()) shortcut.SetDescription(pythonPath) From 40b725351eec3106ab9de546a96d97b80ad8fb7a Mon Sep 17 00:00:00 2001 From: Adentent Date: Sat, 15 Jun 2024 08:05:40 +0800 Subject: [PATCH 11/11] Cross-platform support --- MCSL2Lib/Pages/settingsPage.py | 14 +++++----- MCSL2Lib/utils.py | 48 +++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/MCSL2Lib/Pages/settingsPage.py b/MCSL2Lib/Pages/settingsPage.py index 79f91cf..26e6d05 100644 --- a/MCSL2Lib/Pages/settingsPage.py +++ b/MCSL2Lib/Pages/settingsPage.py @@ -14,6 +14,7 @@ Settings page. """ import os +import platform from datetime import datetime from PyQt5.QtCore import QSize, Qt, QRect, pyqtSignal, pyqtSlot @@ -340,7 +341,7 @@ def __init__(self, parent=None): parent=self.consoleSettingsGroup, ) self.alwaysRunAsAdministrator.setEnabled(False) - if os.name == 'nt': + if platform.system() == 'Linux' or 'Windows': self.startOnStartup.setEnabled(True) else: self.startOnStartup.setEnabled(False) @@ -524,7 +525,8 @@ def __init__(self, parent=None): self.subTitleLabel.setText(self.tr("自定义你的 MCSL2。")) self.aboutContent.setText( self.tr( - "MCServerLauncher 2 是一个开源非营利性项目,遵循 GNU General Public License 3.0 开源协议。\n任何人皆可使用 MCSL2 的源码进行再编译、修改以及发行,\n但必须在相关源代码中以及软件中给出声明,并且二次分发版本的项目名称应与 “MCSL2” 有明显辨识度。\n“MCServerLauncher 2 软件” 已进行中华人民共和国计算机软件著作权登记,一切侵权行为将依法追究。\n计算机软件著作权登记号: 2024SR0343868\n\n© 2022 - 2024 MCSL开发组 保留所有权利。\n" # noqa : E501 + "MCServerLauncher 2 是一个开源非营利性项目,遵循 GNU General Public License 3.0 开源协议。\n任何人皆可使用 MCSL2 的源码进行再编译、修改以及发行,\n但必须在相关源代码中以及软件中给出声明,并且二次分发版本的项目名称应与 “MCSL2” 有明显辨识度。\n“MCServerLauncher 2 软件” 已进行中华人民共和国计算机软件著作权登记,一切侵权行为将依法追究。\n计算机软件著作权登记号: 2024SR0343868\n\n© 2022 - 2024 MCSL开发组 保留所有权利。\n" + # noqa : E501 ) ) self.aboutTitle.setText(self.tr("关于")) @@ -667,10 +669,10 @@ def showUpdateMsg(self, latestVerInfo): def generateSystemReport(self): """创建系统报告""" report = ( - self.tr("生成时间: ") - + str(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) - + "\n" - + genSysReport() + self.tr("生成时间: ") + + str(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + + "\n" + + genSysReport() ) title = self.tr("MCServerLauncher 2 系统报告") diff --git a/MCSL2Lib/utils.py b/MCSL2Lib/utils.py index fe3292a..bacf2f0 100644 --- a/MCSL2Lib/utils.py +++ b/MCSL2Lib/utils.py @@ -19,6 +19,8 @@ import hashlib import inspect import os.path +import platform +import subprocess import sys from json import dumps, loads from os import makedirs, path as osp @@ -27,12 +29,10 @@ import aria2p import psutil -import pythoncom import requests from PyQt5.QtCore import QUrl, QThread, QThreadPool, QFile from PyQt5.QtGui import QDesktopServices -from win32comext.shell import shell - +from platform import system from MCSL2Lib.ProgramControllers.logController import _MCSL2Logger MCSL2Logger = _MCSL2Logger() @@ -336,6 +336,24 @@ def getCurrentMainFile() -> str: def setStartOnStartup(): + """ + Decide which method to run according to the operating system + """ + if system() == "Windows": + setStartOnStartupWindows() + elif system() == "Linux": + setStartOnStartupLinux() + + +def setStartOnStartupLinux(): + """ + 在相应位置创建一个快捷方式, 使得本应用能够开机自启动 + 仅限于 Linux 操作系统 + """ + raise NotImplementedError("You cannot currently do this.") + + +def setStartOnStartupWindows(): """ 在相应位置创建一个快捷方式, 使得本应用能够开机自启动 仅限于 Windows 操作系统 @@ -343,6 +361,11 @@ def setStartOnStartup(): # Refs: # - https://github.com/pearu/iocbio/blob/master/installer/utils.py # - https://blog.csdn.net/thundor/article/details/5968581 + + # Operating system import check + from win32comext.shell import shell + import pythoncom + targetDirectory = os.getenv('USERPROFILE') + r'\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup' shortcut = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, @@ -363,6 +386,25 @@ def removeStartOnStartup(): """ 移除先前创建的开机自启动快捷方式 """ + if system() == "Windows": + removeStartOnStartupWindows() + elif system() == "Linux": + removeStartOnStartupLinux() + + +def removeStartOnStartupLinux(): + """ + 移除先前创建的开机自启动快捷方式 + 仅限于 Linux 操作系统 + """ + raise NotImplementedError("You cannot currently do this.") + + +def removeStartOnStartupWindows(): + """ + 移除先前创建的开机自启动快捷方式 + 仅限于 Windows 操作系统 + """ shortcut = (os.getenv('USERPROFILE') + r"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\MCSL2.lnk") if not os.path.exists(shortcut):