From b2e9f6ae81e1393ec30cd257740f3a06fb7bb3b4 Mon Sep 17 00:00:00 2001
From: toxic-recker <62395124+toxicrecker@users.noreply.github.com>
Date: Mon, 9 Jan 2023 23:55:34 +0530
Subject: [PATCH] Handled user interruption during the process of moving a game

---
 legendary/cli.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/legendary/cli.py b/legendary/cli.py
index 7f0fabc..4c9176a 100644
--- a/legendary/cli.py
+++ b/legendary/cli.py
@@ -2515,6 +2515,10 @@ class LegendaryCLI:
                 logger.error(f'The target path already contains a folder called "{game_folder}", '
                              f'please remove or rename it first.')
                 return
+            logger.info('This process could be cancelled and reverted by interrupting it with CTRL-C')
+            if not get_boolean_choice(f'Are you sure you wish to move "{igame.title}" from "{old_base}" to "{args.new_path}"?'):
+                print('Aborting...')
+                exit(0)
             try:
                 total_files, total_chunks = scan_dir(igame.install_path)
                 copied_files = 0
@@ -2567,6 +2571,11 @@ class LegendaryCLI:
                     logger.info(f'Try moving the folder manually to "{new_path}" and running '
                                 f'"legendary move {app_name} "{args.new_path}" --skip-move"')
                 return
+            except KeyboardInterrupt:
+                # TODO: Make it resumable
+                shutil.rmtree(new_path)
+                logger.info("The process has been cancelled.")
+                return
         else:
             logger.info(f'Not moving, just rewriting legendary metadata...')