""" Handles loading and saving of radar configuration profiles from a JSON file. """ import json import os # Use a file in the user's home directory to persist profiles # across different project locations or versions. PROFILES_FILE = os.path.join(os.path.expanduser("~"), ".radar_simulator_profiles.json") def load_profiles(): """ Loads radar configuration profiles from the JSON file. If the file doesn't exist or is corrupted, returns an empty dictionary. """ if not os.path.exists(PROFILES_FILE): return {} try: with open(PROFILES_FILE, 'r') as f: profiles = json.load(f) # Basic validation if isinstance(profiles, dict): return profiles return {} except (IOError, json.JSONDecodeError): return {} def save_profiles(profiles): """ Saves the given profiles dictionary to the JSON file. Returns True on success, False on failure. """ try: with open(PROFILES_FILE, 'w') as f: json.dump(profiles, f, indent=4) return True except IOError: return False