Skip to content

Commit dbdaca9

Browse files
committed
- 修复了在无/MCSL2/的目录或没有AutoDetectJavaHistory.txt的情况下无法打开MCSL2的问题。
1 parent 9955338 commit dbdaca9

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

MCSL2.py

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -669,13 +669,13 @@ def SaveMinecraftServer(self):
669669
print(type(GlobalServerList))
670670
ServerCount = len(GlobalServerList)
671671
print(ServerCount)
672-
GlobalServerList[ServerCount+1] = {
672+
GlobalServerList['MCSLServerList'].append({
673673
"name": ServerName,
674674
"core_file_name": CoreFileName,
675675
"java_path": JavaPath,
676676
"min_memory": MinMemory,
677677
"max_memory": MaxMemory,
678-
}
678+
})
679679
ReadGlobalServerListFile.close()
680680
with open(r'MCSL2/MCSL2_ServerList.json', "w", encoding='utf-8') as WriteGlobalServerListFile:
681681
WriteGlobalServerListFile.write(dumps(GlobalServerList))
@@ -710,9 +710,20 @@ def AutoDetectJava(self):
710710
def JavaDetectFinished(self, _JavaPaths: list):
711711
global JavaPaths
712712
JavaPaths = _JavaPaths
713-
with open(r"./MCSL2/AutoDetectJavaHistory.txt", 'w', encoding='utf-8') as SaveFoundedJava:
714-
SaveFoundedJava.writelines([p + '\n' for p in JavaPaths])
715-
713+
if not ospath.exists(r"./MCSL2"):
714+
pass
715+
else:
716+
if ospath.exists(r"./MCSL2/AutoDetectJavaHistory.txt"):
717+
with open(r"./MCSL2/AutoDetectJavaHistory.txt", 'w', encoding='utf-8') as SaveFoundedJava:
718+
SaveFoundedJava.writelines([p + '\n' for p in JavaPaths])
719+
SaveFoundedJava.close()
720+
else:
721+
with open(r"./MCSL2/AutoDetectJavaHistory.txt", 'w+', encoding='utf-8') as InitFoundedJava:
722+
InitFoundedJava.write("")
723+
InitFoundedJava.close()
724+
with open(r"./MCSL2/AutoDetectJavaHistory.txt", 'w', encoding='utf-8') as SaveFoundedJava:
725+
SaveFoundedJava.writelines([p + '\n' for p in JavaPaths])
726+
SaveFoundedJava.close()
716727
@pyqtSlot(int)
717728
def OnJavaFindWorkThreadFinished(self, sequenceNumber):
718729

@@ -1229,7 +1240,13 @@ def InitSelectJavaSubWidget(self):
12291240
# 清空self.ChooseJavaScrollAreaVerticalLayout下的所有子控件
12301241
for i in reversed(range(self.ChooseJavaScrollAreaVerticalLayout.count())):
12311242
self.ChooseJavaScrollAreaVerticalLayout.itemAt(i).widget().setParent(None)
1232-
1243+
if ospath.exists(r"./MCSL2/AutoDetectJavaHistory.txt"):
1244+
with open(r"./MCSL2/AutoDetectJavaHistory.txt", 'w+', encoding='utf-8') as InitFoundedJava:
1245+
InitFoundedJava.write("")
1246+
InitFoundedJava.close()
1247+
with open(r"./MCSL2/AutoDetectJavaHistory.txt", 'w', encoding='utf-8') as SaveFoundedJava:
1248+
SaveFoundedJava.writelines([p + '\n' for p in JavaPaths])
1249+
SaveFoundedJava.close()
12331250
# 重新添加子控件
12341251
if len(JavaPaths) == 0:
12351252
if ospath.exists(r"MCSL2/AutoDetectJavaHistory.txt"):
@@ -1389,25 +1406,25 @@ def CallMCSL2Dialog(Tip, isNeededTwoButtons):
13891406

13901407
def InitMCSL(isFirstLaunch):
13911408
if isFirstLaunch == 1:
1392-
CallMCSL2Dialog(Tip="请注意:\n\n本程序无法在125%的\n\nDPI缩放比下正常运行。\n(本提示仅在首次启动出现)",
1409+
CallMCSL2Dialog(Tip="请注意:\n\n本程序无法在125%的\n\nDPI缩放比下正常运行。\n\n(本提示仅在首次启动出现)",
13931410
isNeededTwoButtons=0)
1394-
mkdir(r"MCSL2")
1395-
mkdir(r"MCSL2/Aria2")
1396-
with open(r"./MCSL2/MCSL2_Config.json", "w+", encoding="utf-8") as InitConfig:
1397-
ConfigTemplate = ""
1398-
InitConfig.write(ConfigTemplate)
1399-
InitConfig.close()
1400-
with open(
1401-
r"./MCSL2/MCSL2_ServerList.json", "w+", encoding="utf-8"
1402-
) as InitServerList:
1403-
ServerListTemplate = '{\n "MCSLServerList": [\n {\n "name": "MCSLReplacer",\n ' \
1404-
'"core_file_name": "MCSLReplacer",\n "java_path": "MCSLReplacer",' \
1405-
'\n "min_memory": "MCSLReplacer",\n "max_memory": "MCSLReplacer"\n }\n ' \
1406-
']\n} '
1407-
InitServerList.write(ServerListTemplate)
1408-
InitServerList.close()
1411+
if not ospath.exists(r"MCSL2"):
1412+
mkdir(r"MCSL2")
1413+
mkdir(r"MCSL2/Aria2")
1414+
with open(r"./MCSL2/MCSL2_Config.json", "w+", encoding="utf-8") as InitConfig:
1415+
ConfigTemplate = ""
1416+
InitConfig.write(ConfigTemplate)
1417+
InitConfig.close()
1418+
with open(r"./MCSL2/MCSL2_ServerList.json", "w+", encoding="utf-8") as InitServerList:
1419+
ServerListTemplate = '{\n "MCSLServerList": [\n\n ]\n}'
1420+
InitServerList.write(ServerListTemplate)
1421+
InitServerList.close()
1422+
with open(r"./MCSL2/AutoDetectJavaHistory.txt", 'w+', encoding='utf-8') as InitFoundedJava:
1423+
InitFoundedJava.write("")
1424+
InitFoundedJava.close()
14091425
if not ospath.exists(r"Servers"):
14101426
mkdir(r"./Servers")
1427+
14111428
pass
14121429
else:
14131430
if not ospath.exists(r"Servers"):

0 commit comments

Comments
 (0)