Seregon/PkgToolBox

Toolbox for analyzing and editing pkg application files for psp,ps3, ps4 and ps5, includes the most useful functions you might need.

Python/57.3 KB/No license
Utilities/Settings/SettingsManager.py
PkgToolBox / Utilities / Settings / SettingsManager.py
1import os
2import json
3from PyQt5.QtWidgets import QMessageBox
4from Utilities.PS4PKGToolHelper.Helper import Helper
5from Utilities.PS4PKGToolHelper.MessageBoxHelper import MessageBoxHelper
6from Utilities.Settings.AppSettings import AppSettings
7
8class SettingsManager:
9 app_settings = AppSettings()
10 setting_file_path = os.path.join(Helper.ps4pkg_tool_temp_directory, "Settings.conf")
11
12 @staticmethod
13 def save_settings(settings, file_path):
14 try:
15 os.makedirs(os.path.dirname(file_path), exist_ok=True)
16 with open(file_path, 'w') as f:
17 json.dump(settings.__dict__, f, indent=4)
18 except Exception as ex:
19 MessageBoxHelper.show_error(f"Error in saving settings: {ex}", True)
20
21 @staticmethod
22 def load_settings(file_path):
23 try:
24 if os.path.exists(file_path):
25 with open(file_path, 'r') as f:
26 settings = json.load(f)
27 SettingsManager.app_settings.__dict__.update(settings)
28 except Exception as ex:
29 MessageBoxHelper.show_error(f"Error in loading settings: {ex}", True)
30 return SettingsManager.app_settings