diff --git a/rare/commands/launcher/console_dialog.py b/rare/commands/launcher/console_dialog.py index ee83b657b..8b07e9737 100644 --- a/rare/commands/launcher/console_dialog.py +++ b/rare/commands/launcher/console_dialog.py @@ -102,7 +102,7 @@ def save(self): if ok: if "." not in file: file += ".log" - with open(file, "w") as f: + with open(file, "w", encoding="utf-8") as f: f.write(self.console_edit.toPlainText()) f.close() self.save_button.setText(self.tr("Saved")) diff --git a/rare/models/game.py b/rare/models/game.py index 6c4e28ba7..a2c35d9f4 100644 --- a/rare/models/game.py +++ b/rare/models/game.py @@ -152,7 +152,7 @@ def __load_metadata_json() -> Dict: metadata = {} file = os.path.join(data_dir(), "game_meta.json") try: - with open(file, "r") as f: + with open(file, "r", encoding="utf-8") as f: metadata = json.load(f) except FileNotFoundError: logger.info("%s does not exist", file) @@ -175,7 +175,7 @@ def __save_metadata(self): metadata: Dict = self.__load_metadata_json() # pylint: disable=unsupported-assignment-operation metadata[self.app_name] = vars(self.metadata) - with open(os.path.join(data_dir(), "game_meta.json"), "w+") as file: + with open(os.path.join(data_dir(), "game_meta.json"), "w+", encoding="utf-8") as file: json.dump(metadata, file, indent=2) def update_game(self): diff --git a/rare/resources/static_css/stylesheet.py b/rare/resources/static_css/stylesheet.py index e7f3f3f14..384024d95 100644 --- a/rare/resources/static_css/stylesheet.py +++ b/rare/resources/static_css/stylesheet.py @@ -172,7 +172,7 @@ def css_name(widget: Union[wrappertype, QObject, Type], subwidget: str = ""): if __name__ == "__main__": - with open("stylesheet.qss", "w") as qss: + with open("stylesheet.qss", "w", encoding="utf-8") as qss: qss.write(f'\n/* This file is auto-generated from "{os.path.basename(__file__)}". DO NOT EDIT!!! */\n\n') qss.write(css.toString()) diff --git a/rare/shared/image_manager.py b/rare/shared/image_manager.py index 40db6b212..8ab0e8468 100644 --- a/rare/shared/image_manager.py +++ b/rare/shared/image_manager.py @@ -237,7 +237,7 @@ def __download(self, updates: List, json_data: Dict, game: Game, use_async: bool json_data["size"] = {"w": ImageSize.Tall.size.width(), "h": ImageSize.Tall.size.height()} # write image.json - with open(self.__img_json(game.app_name), "w") as file: + with open(self.__img_json(game.app_name), "w", encoding="utf-8") as file: json.dump(json_data, file) return bool(updates) diff --git a/rare/shared/rare_core.py b/rare/shared/rare_core.py index 87a430e7c..a9b3a710d 100644 --- a/rare/shared/rare_core.py +++ b/rare/shared/rare_core.py @@ -156,7 +156,7 @@ def core(self, init: bool = False) -> LegendaryCore: else: path = os.path.expanduser('~/.config/legendary') logger.info("Creating config in path: %s", config_path) - with open(os.path.join(path, "config.ini"), "w") as config_file: + with open(os.path.join(path, "config.ini"), "w", encoding="utf-8") as config_file: config_file.write("[Legendary]") self.__core = LegendaryCore() diff --git a/rare/shared/wrappers.py b/rare/shared/wrappers.py index d99b40d2b..d6eaca9ee 100644 --- a/rare/shared/wrappers.py +++ b/rare/shared/wrappers.py @@ -19,7 +19,7 @@ def __init__(self): self.__file = os.path.join(config_dir(), "wrappers.json") self.__wrappers_dict = {} try: - with open(self.__file) as f: + with open(self.__file, "r", encoding="utf-8") as f: self.__wrappers_dict = json.load(f) except FileNotFoundError: logger.info("%s does not exist", self.__file) @@ -114,7 +114,7 @@ def __save_wrappers(self): self.__wrappers_dict["wrappers"] = self.__wrappers self.__wrappers_dict["applists"] = self.__applists - with open(os.path.join(self.__file), "w+") as f: + with open(os.path.join(self.__file), "w+", encoding="utf-8") as f: json.dump(self.__wrappers_dict, f, default=lambda o: vars(o), indent=2) diff --git a/rare/utils/compat/steam.py b/rare/utils/compat/steam.py index 0bcc59b00..c159442eb 100644 --- a/rare/utils/compat/steam.py +++ b/rare/utils/compat/steam.py @@ -23,7 +23,7 @@ def find_steam() -> Optional[str]: def find_libraries(steam_path: str) -> Set[str]: vdf_path = os.path.join(steam_path, "config", "libraryfolders.vdf") - with open(vdf_path, "r") as f: + with open(vdf_path, "r", encoding="utf-8") as f: libraryfolders = vdf.load(f)["libraryfolders"] # libraries = [os.path.join(folder["path"], "steamapps") for key, folder in libraryfolders.items()] libraries = {os.path.join(folder["path"], "steamapps") for key, folder in libraryfolders.items()} @@ -165,7 +165,7 @@ def find_appmanifests(library: str) -> List[dict]: appmanifests = [] for entry in os.scandir(library): if entry.is_file() and entry.name.endswith(".acf"): - with open(os.path.join(library, entry.name), "r") as f: + with open(os.path.join(library, entry.name), "r", encoding="utf-8") as f: appmanifest = vdf.load(f) appmanifests.append(appmanifest) return appmanifests @@ -206,7 +206,7 @@ def find_runtimes(steam_path: str, library: str) -> Dict[str, SteamRuntime]: folder = appmanifest["AppState"]["installdir"] tool_path = os.path.join(common, folder) if os.path.isfile(vdf_file := os.path.join(tool_path, "toolmanifest.vdf")): - with open(vdf_file, "r") as f: + with open(vdf_file, "r", encoding="utf-8") as f: toolmanifest = vdf.load(f) if toolmanifest["manifest"]["compatmanager_layer_name"] == "container-runtime": runtimes.update( @@ -231,7 +231,7 @@ def find_protons(steam_path: str, library: str) -> List[ProtonTool]: folder = appmanifest["AppState"]["installdir"] tool_path = os.path.join(common, folder) if os.path.isfile(vdf_file := os.path.join(tool_path, "toolmanifest.vdf")): - with open(vdf_file, "r") as f: + with open(vdf_file, "r", encoding="utf-8") as f: toolmanifest = vdf.load(f) if toolmanifest["manifest"]["compatmanager_layer_name"] == "proton": protons.append( @@ -270,7 +270,7 @@ def find_compatibility_tools(steam_path: str) -> List[CompatibilityTool]: if not os.path.isfile(tool_vdf): continue - with open(tool_vdf, "r") as f: + with open(tool_vdf, "r", encoding="utf-8") as f: compatibilitytool = vdf.load(f) entry_tools = compatibilitytool["compatibilitytools"]["compat_tools"] @@ -285,7 +285,7 @@ def find_compatibility_tools(steam_path: str) -> List[CompatibilityTool]: if not os.path.isfile(manifest_vdf): continue - with open(manifest_vdf, "r") as f: + with open(manifest_vdf, "r", encoding="utf-8") as f: manifest = vdf.load(f) tools.append( diff --git a/rare/utils/steam_grades.py b/rare/utils/steam_grades.py index 49b60289d..e79b173e6 100644 --- a/rare/utils/steam_grades.py +++ b/rare/utils/steam_grades.py @@ -93,7 +93,7 @@ def load_json() -> dict: ids = {} for app in apps: ids[app["name"]] = app["appid"] - with open(file, "w") as f: + with open(file, "w", encoding="utf-8") as f: f.write(orjson.dumps(ids).decode("utf-8")) return ids else: diff --git a/rare/utils/steam_shortcuts.py b/rare/utils/steam_shortcuts.py index 6fee380cd..d38a4c7aa 100644 --- a/rare/utils/steam_shortcuts.py +++ b/rare/utils/steam_shortcuts.py @@ -44,7 +44,7 @@ def find_steam_users(steam_path: str) -> List[SteamUser]: vdf_path = os.path.join(steam_path, "config", "loginusers.vdf") if not os.path.exists(vdf_path): return _users - with open(vdf_path, 'r') as f: + with open(vdf_path, "r", encoding="utf-8") as f: users = vdf.load(f).get("users", {}) for long_id, user in users.items(): _users.append(SteamUser(long_id, user)) @@ -56,7 +56,7 @@ def _load_shortcuts(steam_path: str, user: SteamUser) -> Dict[str, SteamShortcut vdf_path = os.path.join(steam_path, "userdata", str(user.short_id), "config", "shortcuts.vdf") if not os.path.exists(vdf_path): return _shortcuts - with open(vdf_path, 'rb') as f: + with open(vdf_path, "rb") as f: shortcuts = vdf.binary_load(f).get("shortcuts", {}) for idx, shortcut in shortcuts.items(): _shortcuts[idx] = SteamShortcut.from_dict(shortcut) @@ -66,7 +66,7 @@ def _load_shortcuts(steam_path: str, user: SteamUser) -> Dict[str, SteamShortcut def _save_shortcuts(steam_path: str, user: SteamUser, shortcuts: Dict[str, SteamShortcut]) -> None: _shortcuts = {k: asdict(v) for k, v in shortcuts.items()} vdf_path = os.path.join(steam_path, "userdata", str(user.short_id), "config", "shortcuts.vdf") - with open(vdf_path, 'wb') as f: + with open(vdf_path, "wb") as f: vdf.binary_dump({"shortcuts": _shortcuts}, f)