diff --git a/cddagl/constants.py b/cddagl/constants.py index 0081994..9b78aeb 100644 --- a/cddagl/constants.py +++ b/cddagl/constants.py @@ -21,6 +21,9 @@ CDDA_RELEASE_BY_TAG = lambda tag: f'/repos/CleverRaven/Cataclysm-DDA/releases/tags/{tag}' CDDAGL_LATEST_RELEASE = '/repos/DoiiarX/CDDA-Game-Launcher/releases/latest' +REMOTE_MODS_URL = '/DoiiarX/CDDA-Game-Launcher/master/data/mods.yaml' +REMOTE_SOUNDPACKS_URL = '/DoiiarX/CDDA-Game-Launcher/master/data/soundpacks.yaml' + CHANGELOG_URL = 'https://api.github.com/search/issues?q=repo%3Acleverraven/Cataclysm-DDA+is%3Apr+is%3Amerged&per_page=' NEW_ISSUE_URL = 'https://github.com/DoiiarX/CDDA-Game-Launcher/issues/new' diff --git a/cddagl/ui/views/mods.py b/cddagl/ui/views/mods.py index e16c74b..6de37d9 100644 --- a/cddagl/ui/views/mods.py +++ b/cddagl/ui/views/mods.py @@ -362,6 +362,18 @@ def enable_tab(self): repository_selected = repository_selection.hasSelection() self.install_new_button.setEnabled(repository_selected) + + def get_mods_yaml_file(self): + """尝试从远程获取 mods.yaml 文件,失败则使用本地文件""" + try: + response = requests.get(cons.GITHUB_REST_API_URL + cons.REMOTE_MODS_URL) + response.raise_for_status() + with open(get_data_path('mods.yaml'), 'wb') as f: + f.write(response.content) + return get_data_path('mods.yaml') + except requests.RequestException: + logger.warning("无法从远程获取 mods.yaml 文件,使用本地文件") + return get_data_path('mods.yaml') def load_repository(self): """加载存储库。""" @@ -375,7 +387,7 @@ def load_repository(self): self.repository_lv.selectionModel().currentChanged.connect( self.repository_selection) - yaml_file = get_data_path('mods.yaml') # 获取mods.yaml文件的路径 + yaml_file = self.get_mods_yaml_file() # 获取mods.yaml文件的路径 if os.path.isfile(yaml_file): # 检查文件是否存在 with open(yaml_file, 'r', encoding='utf8') as f: # 打开YAML文件 diff --git a/cddagl/ui/views/soundpacks.py b/cddagl/ui/views/soundpacks.py index 6730aea..a83f6ae 100644 --- a/cddagl/ui/views/soundpacks.py +++ b/cddagl/ui/views/soundpacks.py @@ -302,6 +302,18 @@ def enable_tab(self): repository_selected = repository_selection.hasSelection() self.install_new_button.setEnabled(repository_selected) + + def get_soundpacks_yaml_file(self): + """尝试从远程获取 mods.yaml 文件,失败则使用本地文件""" + try: + response = requests.get(cons.GITHUB_REST_API_URL + cons.REMOTE_SOUNDPACKS_URL) + response.raise_for_status() + with open(get_data_path('soundpacks.yaml'), 'wb') as f: + f.write(response.content) + return get_data_path('soundpacks.yaml') + except requests.RequestException: + logger.warning("无法从远程获取 soundpacks.yaml 文件,使用本地文件") + return get_data_path('soundpacks.yaml') def load_repository(self): self.repo_soundpacks = [] @@ -313,7 +325,7 @@ def load_repository(self): self.repository_lv.selectionModel().currentChanged.connect( self.repository_selection) - yaml_file = get_data_path('soundpacks.yaml') + yaml_file = self.get_soundpacks_yaml_file() if os.path.isfile(yaml_file): with open(yaml_file, 'r', encoding='utf8') as f: