perf: shared_preferences加载失败时自动删除无效文件

This commit is contained in:
Raven95676
2025-04-12 19:31:45 +08:00
parent d6239822db
commit 489784104e
+3 -1
View File
@@ -8,9 +8,11 @@ class SharedPreferences:
self._data = self._load_preferences()
def _load_preferences(self):
if os.path.exists(self.path):
try:
with open(self.path, "r") as f:
return json.load(f)
except json.JSONDecodeError:
os.remove(self.path)
return {}
def _save_preferences(self):