def reread_config(self) -> None: #TODO: Only the broken GUI calls this outside of init calling it once right up there, do I care enough for this to be a separate function parser = configparser.ConfigParser(interpolation=None) parser.optionxform = str #type: ignore[assignment] self.parser = parser ensure_exist(_main_config_path) self.parser.read(_main_config_path) self.ignored_directories = _load_ignored_directories()
def __init__(self) -> None: parser = configparser.ConfigParser(interpolation=None, delimiters='=', allow_no_value=True) parser.optionxform = str #type: ignore[assignment] ensure_exist(_platform_config_path) parser.read(_platform_config_path) self.configs = { platform_name: _get_config(section, platform_name) for platform_name, section in parser.items() }
def __init__(self) -> None: parser = configparser.ConfigParser(interpolation=None, delimiters='=', allow_no_value=True) parser.optionxform = str #type: ignore[assignment] ensure_exist(_emulator_config_path) parser.read(_emulator_config_path) self.configs = { emulator.config_name: _get_config(parser, emulator.config_name, emulator.default_exe_name, emulator.configs) for emulator in all_emulators }
def _write_new_config(new_config: Mapping[str, Mapping[str, TypeOfConfigValue]], config_file_path: Path) -> None: parser = configparser.ConfigParser(interpolation=None) parser.optionxform = str #type: ignore[assignment] ensure_exist(config_file_path) parser.read(config_file_path) for section, configs in new_config.items(): if section not in parser: parser.add_section(section) for name, value in configs.items(): parser[section][name] = _convert_value_for_ini(value) try: with config_file_path.open('wt', encoding='utf-8') as ini_file: parser.write(ini_file) except OSError as ex: print('Oh no!!! Failed to write', config_file_path, '!!!!11!!eleven!!', ex)
def _make_linux_desktop(command: 'LaunchCommand', display_name: str, metadata: 'Metadata', filename_tags: Collection[str], game_type: str, game_id: str): path = pick_new_path(main_config.output_folder, sanitize_name(display_name, no_janky_chars=True), 'desktop') configwriter = configparser.ConfigParser(interpolation=None) configwriter.optionxform = str #type: ignore[assignment] configwriter.add_section('Desktop Entry') desktop_entry = configwriter['Desktop Entry'] #Necessary for this thing to even be recognized desktop_entry['Type'] = 'Application' desktop_entry['Encoding'] = 'UTF-8' desktop_entry['Name'] = clean_string(display_name) desktop_entry['Exec'] = command.make_linux_command_string() if command.working_directory: desktop_entry['Path'] = command.working_directory fields = metadata.to_launcher_fields() if filename_tags: fields[junk_section_name]['Filename Tags'] = filename_tags fields[junk_section_name][ 'Original Name'] = display_name #Will be most likely touched by disambiguate later fields[id_section_name] = {} fields[id_section_name]['Type'] = game_type fields[id_section_name]['Unique ID'] = game_id for section_name, section in fields.items(): if not section: continue configwriter.add_section(section_prefix + section_name) for k, v in section.items(): if v is None: continue if have_pillow: if isinstance(v, Image.Image): this_image_folder = main_config.image_folder.joinpath(k) this_image_folder.mkdir(exist_ok=True, parents=True) image_path = this_image_folder.joinpath(path.stem + '.png') v.save(image_path, 'png') #v = image_path _write_field(configwriter, section_name, k, image_path) continue _write_field(configwriter, section_name, k, v) if section_prefix + image_section_name in configwriter: keys_to_try = ('Icon', ) + main_config.use_other_images_as_icons for k in keys_to_try: if k in configwriter[section_prefix + image_section_name]: desktop_entry['Icon'] = configwriter[section_prefix + image_section_name][k] break ensure_exist(path) with path.open('wt', encoding='utf-8') as f: configwriter.write(f) #Set executable, but also set everything else because whatever, partially because I can't remember what I would need to do to get the original mode and | it with executable path.chmod(0o7777)