|
1 | 1 | import os |
| 2 | +import datetime |
2 | 3 | import json |
3 | 4 | import colorama |
4 | 5 | from colorama import Fore, Back, Style |
@@ -95,7 +96,8 @@ def main(): |
95 | 96 | print("3) Edit Money") |
96 | 97 | print("4) Edit Difficulty") |
97 | 98 | print("5) Change Life/Death Symbol") |
98 | | - print("6) Exit") |
| 99 | + print("6) Load/Backup Current Save File") |
| 100 | + print("7) Exit") |
99 | 101 |
|
100 | 102 | choice = input("Enter your choice: ") |
101 | 103 |
|
@@ -169,6 +171,33 @@ def main(): |
169 | 171 | print_status(save_data) |
170 | 172 |
|
171 | 173 | elif choice == "6": |
| 174 | + backup_file_path = save_file_path.replace('.save', '.bak') |
| 175 | + |
| 176 | + if os.path.exists(backup_file_path): |
| 177 | + creation_time = os.path.getctime(backup_file_path) |
| 178 | + creation_date = datetime.datetime.fromtimestamp(creation_time).strftime("%Y-%m-%d %I:%M:%S %p") |
| 179 | + print(Fore.YELLOW + f"Backup file created on {creation_date}" + Style.RESET_ALL) |
| 180 | + |
| 181 | + print("\nSave File Operations:") |
| 182 | + print(Fore.GREEN + "1) Backup current save file" + Style.RESET_ALL) |
| 183 | + print(Fore.RED + "2) Load from backup" + Style.RESET_ALL) |
| 184 | + print("3) Go back to main menu") |
| 185 | + |
| 186 | + operation_choice = input("Enter your choice: ") |
| 187 | + |
| 188 | + if operation_choice == "1": |
| 189 | + with open(save_file_path, 'r') as original: data = original.read() |
| 190 | + with open(backup_file_path, 'w') as backup: backup.write(data) |
| 191 | + print("Backup created.") |
| 192 | + elif operation_choice == "2": |
| 193 | + with open(backup_file_path, 'r') as backup: data = backup.read() |
| 194 | + with open(save_file_path, 'w') as original: original.write(data) |
| 195 | + print("Backup loaded.") |
| 196 | + else: |
| 197 | + clear_console() |
| 198 | + print_status(save_data) |
| 199 | + |
| 200 | + elif choice == "7": |
172 | 201 | break |
173 | 202 |
|
174 | 203 | else: |
|
0 commit comments