fix: 修复文件不存在的情况

This commit is contained in:
Raven95676
2025-04-13 11:36:06 +08:00
parent fc146d3d00
commit 9470ca6bc5
+6 -5
View File
@@ -8,11 +8,12 @@ class SharedPreferences:
self._data = self._load_preferences()
def _load_preferences(self):
try:
with open(self.path, "r") as f:
return json.load(f)
except json.JSONDecodeError:
os.remove(self.path)
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):