Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

云端取代本地mods和soundpacks配置 #8

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cddagl/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
14 changes: 13 additions & 1 deletion cddagl/ui/views/mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""加载存储库。"""
Expand All @@ -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文件
Expand Down
14 changes: 13 additions & 1 deletion cddagl/ui/views/soundpacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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:
Expand Down
Loading