tretrauit
a5659f7ff3
chore: rename gui.py to cli.py fix: internal downloader can resume download now. feat: add verify_game, verify_from_pkg_version, clear_cache to installer.py. feat: add clear_cache to patcher.py. fix: linux now check for pkexec before executing it. fix: add get_name to voicepack.py, latest.py, diff.py to get name from path (since the developer didn't set a name to these files in the sdk url) chore: remove deprecation message in read_version_from_config in installer.py misc: use chunk from self._download_chunk instead of being hardcoded to 8192. fix: is_telemetry_blocked will only wait 15s for a connection. chore: move appdirs to constants.py This commit refactor almost all functions to be compatible with asyncio, also restructured CLI to use asyncio.run on main function instead of executing it randomly. Also prioritize the use of asyncio.gather, sometimes making tasks faster
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
from configparser import ConfigParser
|
|
from pathlib import Path
|
|
|
|
from aiopath import AsyncPath
|
|
|
|
|
|
class LauncherConfig:
|
|
"""
|
|
Provides config.ini for official launcher compatibility
|
|
"""
|
|
|
|
@staticmethod
|
|
def create_config(game_version, overseas=True):
|
|
"""
|
|
Creates config.ini
|
|
"""
|
|
sub_channel = "0" if overseas else "1"
|
|
config = ConfigParser()
|
|
config.add_section("General")
|
|
config.set("General", "channel", "1")
|
|
config.set("General", "cps", "mihoyo")
|
|
config.set("General", "game_version", game_version)
|
|
config.set("General", "sdk_version", "")
|
|
config.set("General", "sub_channel", sub_channel)
|
|
return config
|
|
|
|
def __init__(self, config_path, game_version=None, overseas=True):
|
|
if isinstance(config_path, str | AsyncPath):
|
|
config_path = Path(config_path)
|
|
if not game_version:
|
|
game_version = "0.0.0"
|
|
self.config_path = config_path
|
|
self.config = ConfigParser()
|
|
if self.config_path.exists():
|
|
self.config.read(self.config_path)
|
|
else:
|
|
self.config = self.create_config(game_version, overseas)
|
|
|
|
def set_game_version(self, game_version):
|
|
self.config.set("General", "game_version", game_version)
|
|
|
|
def set_overseas(self, overseas=True):
|
|
sub_channel = "0" if overseas else "1"
|
|
self.config.set("General", "sub_channel", sub_channel)
|
|
|
|
def save(self):
|
|
"""
|
|
Saves config.ini
|
|
"""
|
|
with self.config_path.open("w") as config_file:
|
|
self.config.write(config_file)
|