-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsave_manager.py
More file actions
35 lines (33 loc) · 909 Bytes
/
Copy pathsave_manager.py
File metadata and controls
35 lines (33 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import pickle
from settings import SAVE_FILE
def load_progress():
"""
Loads progress from SAVE_FILE if it exists and is a valid dict.
Returns an empty dict otherwise.
Expected structure:
{
"chapter1.yml": {"last_page": 0, "completed": False},
...
}
"""
if os.path.exists(SAVE_FILE):
try:
with open(SAVE_FILE, "rb") as f:
data = pickle.load(f)
if isinstance(data, dict):
return data
else:
return {}
except Exception:
return {}
return {}
def save_progress(progress_data):
"""
Saves the given progress dict to SAVE_FILE.
"""
try:
with open(SAVE_FILE, "wb") as f:
pickle.dump(progress_data, f)
except Exception as e:
print(f"[save_manager] Error saving progress: {e}")