Skip to content

Commit 6ba5b7f

Browse files
committed
Add ability to delete backups
1 parent 898dc48 commit 6ba5b7f

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/inject.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,24 @@ def restore_backup(backup, spotify_path):
216216
print_pink("Backup restored!")
217217
wait()
218218

219+
def delete_backup(backup):
220+
utils.clear()
221+
print_blue(f"Deleting backup...")
222+
223+
print("Removing files...")
224+
match backup["type"]:
225+
case "simple":
226+
os.remove(os.path.join(utils.backdir, f"{backup['uuid']}.spa.bak"))
227+
case "full":
228+
os.remove(os.path.join(utils.backdir, f"{backup['uuid']}.bak"))
229+
230+
print("Updating backups.json...")
231+
backups = json.load(open(utils.backupdata))
232+
backups.remove(backup)
233+
json.dump(backups, open(utils.backupdata, "w"))
234+
print_pink("Backup deleted!")
235+
wait()
236+
219237
def get_spotmod_version(spotify_path):
220238
if os.path.exists(f"{spotify_path}/SpotMod.txt"):
221239
return 0.2

src/main.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def manage_backup(backup):
103103
spotify_ver = utils.get_file_version(os.path.join(spotify_path, "Spotify.exe"))
104104
old = int(backup["sver"].replace(".", "")) < int(spotify_ver.replace(".", ""))
105105
print(f"Spotify version: {backup['sver']} {f"{Fore.RED}(OLD | CURRENT VERSION: {spotify_ver}){Fore.GREEN}" if old else ""}\n")
106-
option_list(["Restore", "Delete", "SPACER", "Cancel"], [partial(restore_backup, backup, old), None, manage_backups])
106+
option_list(["Restore", "Delete", "SPACER", "Cancel"], [partial(restore_backup, backup, old), partial(delete_backup, backup), manage_backups])
107107

108108
def restore_backup(backup, old):
109109
utils.clear()
@@ -120,6 +120,15 @@ def restore_backup(backup, old):
120120
f"Are you sure? {Fore.RED}This will overwrite your existing Spotify installation!{Fore.GREEN}"
121121
)
122122

123+
def delete_backup(backup):
124+
utils.clear()
125+
option_list(
126+
["I'm sure", "Cancel"],
127+
[partial(inject.delete_backup, backup), partial(manage_backup, backup)],
128+
f"Are you sure? {Fore.RED}You will no longer be able to restore this backup!{Fore.GREEN}"
129+
)
130+
manage_backups()
131+
123132
def not_detected():
124133
print("SpotMod is not detected on this system.\n")
125134
option_list(["Patch Spotify", "Quit"], [None, quit])

0 commit comments

Comments
 (0)