Nattiden 1 год назад
Родитель
Сommit
6167eb7b65

+ 26 - 15
Actions/check_mcv.py

@@ -2,6 +2,7 @@ import json
 import requests
 import re
 import os
+from pathlib import Path
 
 LAUNCHER_MANIFSET_URL = 'https://piston-meta.mojang.com/mc/game/version_manifest.json'
 
@@ -26,23 +27,35 @@ def get_version_type(vid:str):
         return 'Release'
     return 'Others'
 
-def update_library(version_mainfest,version_libloc:str,ver_type:str,ver_id:str):
+def generate_filepath(ver_type:str, ver_id:str):
+    if ver_type == 'Snapshot':
+        return Path(f'Snapshot/20{ver_id[:2]}/{ver_id}.md')
+    if ver_type == 'Pre-Release':
+        return Path(f'Pre-Release/{ver_id[:4]}/{ver_id}.md')
+    if ver_type == 'Release-Candidate':
+        return Path(f'Release-Candidate/{ver_id}.md')
+    if ver_type == 'Release':
+        return Path(f'Release/{ver_id}.md')
+
+def update_library(version_mainfest, version_libloc:str, ver_type:str, ver_id:str):
     #gen content
     content = '---\n'
     content += 'version-image-link: null\n'
     content += 'not_finished: true\n'
-    content += f'server-jar: {get_server_jar(version_mainfest,ver_id)}\n'
+    content += f'server-jar: {get_server_jar(version_mainfest, ver_id)}\n'
     content += 'translator: null\n'
     content += f"cats: ['{CURRENT_MAJOR_DEVELOPING_VERSION}','{CURRENT_MINOR_DEVELOPING_VERSION}']\n"
     content += '---\n'
     #write file
-    filepath = f'{version_libloc}{ver_type}{os.sep}{ver_id}.md'
+    filepath = Path(version_libloc) / generate_filepath(ver_type, ver_id)
     if os.path.exists(filepath):
-        return False,'存在于版本库,无需更改'
+        print(f'版本库内已存在 {ver_type} 版 {ver_id} 的文件,跳过添加')
+        return False
     else:
-        with open(filepath, "w") as file:
+        with open(filepath.absolute(), "w", encoding='UTF-8') as file:
             file.write(content)
-        return True,'版本库内未找到,已添加'
+        print(f'已添加 {ver_type} 版 {ver_id} 的文件到版本库')
+        return True
 
 def get_server_jar(version_mainfest,version_id):
     versions = version_mainfest.get('versions')
@@ -54,14 +67,14 @@ def get_server_jar(version_mainfest,version_id):
 
 try:
     response = requests.get(LAUNCHER_MANIFSET_URL)
-    version_mainfest = json.loads(response.content)
+    VERSION_MAINFEST = json.loads(response.content)
 except Exception as e:
     print(f'error_log={e.with_traceback()}')
     exit(1)
 
 def main():
-    latest_snapshot_id = version_mainfest['latest']['snapshot']
-    latest_release_id = version_mainfest['latest']['release']
+    latest_snapshot_id = VERSION_MAINFEST['latest']['snapshot']
+    latest_release_id = VERSION_MAINFEST['latest']['release']
 
     latest_snapshot_type = get_version_type(latest_snapshot_id)
     latest_release_type = get_version_type(latest_release_id)
@@ -72,19 +85,17 @@ def main():
     dir_location = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     version_lib_location = f'{dir_location}{os.sep}Project{os.sep}libraries{os.sep}Versions{os.sep}'
 
-    release_require_update,latest_release_act = \
-    update_library(version_mainfest,version_lib_location,
+    release_require_update = \
+    update_library(VERSION_MAINFEST,version_lib_location,
                 latest_release_type,latest_release_id)
-    snapshot_require_update,latest_snapshot_act = \
-    update_library(version_mainfest,version_lib_location,
+    snapshot_require_update = \
+    update_library(VERSION_MAINFEST,version_lib_location,
                 latest_snapshot_type,latest_snapshot_id)
 
     print(f'latest_release_type={latest_release_type}')
     print(f'latest_snapshot_type={latest_snapshot_type}')
     print(f'latest_release_id={latest_release_id}')
     print(f'latest_snapshot_id={latest_snapshot_id}')
-    print(f'latest_release_act={latest_release_act}')
-    print(f'latest_snapshot_act={latest_snapshot_act}')
     print(f'require_update={release_require_update or snapshot_require_update}')
 
 if __name__ == '__main__':

+ 0 - 0
Project/libraries/Versions/Pre-Release/1.21.6-pre3.md → Project/libraries/Versions/Pre-Release/1.21/1.21.6-pre3.md


+ 0 - 0
Project/libraries/Versions/Snapshot/25w15a.md → Project/libraries/Versions/Snapshot/2025/25w15a.md


+ 0 - 0
Project/libraries/Versions/Snapshot/25w16a.md → Project/libraries/Versions/Snapshot/2025/25w16a.md


+ 0 - 0
Project/libraries/Versions/Snapshot/25w17a.md → Project/libraries/Versions/Snapshot/2025/25w17a.md


+ 0 - 0
Project/libraries/Versions/Snapshot/25w18a.md → Project/libraries/Versions/Snapshot/2025/25w18a.md


+ 0 - 0
Project/libraries/Versions/Snapshot/25w19a.md → Project/libraries/Versions/Snapshot/2025/25w19a.md


+ 0 - 0
Project/libraries/Versions/Snapshot/25w20a.md → Project/libraries/Versions/Snapshot/2025/25w20a.md


+ 0 - 0
Project/libraries/Versions/Snapshot/25w21a.md → Project/libraries/Versions/Snapshot/2025/25w21a.md