Repository: lutris/lutris

Issue:
Lutris will delete game folder when instructed not to
### Bug description

When doing an install (Cyberpunk 2077, GOG galaxy, in my case), if the installation is interrupted, Lutris will delete the game folder for said installation, even when you uncheck the checkbox for deleting game files.

It should be possible to resume an install or, at the very least, stop Lutris from deleting the entire Wine directory when canceling an install, so that you can recover downloads that are not put in the cache (downloads done by Wine applications, as part of the install, for example).

### How to Reproduce

Steps to reproduce the behavior:
Install Cyberpunk 2077 (GOG Galaxy) and cancel the install if/when it fails and the games folder will be deleted, even though you uncheck the option to delete the games folder

### Expected behavior

When unchecking the option for deleting the game's files, when canceling an installation, the application should leave the Wine folder intact

### Log output

```shell
2021-12-17 17:21:09,188: Starting Lutris 0.5.9.1
2021-12-17 17:21:09,259: No cores found
2021-12-17 17:21:11,129: Startup complete
INFO     2021-12-17 17:21:11,131 [startup.check_driver:61]:Running AMD Mesa driver 21.2.2 on AMD Radeon(TM) Vega 8 Graphics (RAVEN, DRM 3.41.0, 5.13.0-22-generic, LLVM 12.0.1) (0x15d8)
INFO     2021-12-17 17:21:11,132 [startup.check_driver:73]:GPU: 1002:15D8 17AA:5124 (amdgpu drivers)
DEBUG    2021-12-17 17:21:11,879 [lutriswindow.update_store:451]:Showing 3 games
```


### System Information

```shell
AMD Ryzen 5 3500U, Vega 8, 16GB
```


### Media (optional)

_No response_

### Checklist:

- [X] I'm not asking for support with a game or the wine runner.
- [X] I have followed the above mentioned guides and have all the graphics and wine dependencies installed.
- [X] I have checked for existing issues that describe my problem prior to opening this one.
- [X] I understand that improperly formatted bug reports may be closed without explanation.


Discussion:

Resolving patch:
diff --git a/lutris/gui/installerwindow.py b/lutris/gui/installerwindow.py
--- a/lutris/gui/installerwindow.py
+++ b/lutris/gui/installerwindow.py
@@ -491,7 +491,7 @@ def create_shortcut(self, desktop=False):
     def cancel_installation(self, _widget=None):
         """Ask a confirmation before cancelling the install"""
         remove_checkbox = Gtk.CheckButton.new_with_label(_("Remove game files"))
-        if self.interpreter:
+        if self.interpreter and self.interpreter.target_path:
             remove_checkbox.set_active(self.interpreter.game_dir_created)
             remove_checkbox.show()
         confirm_cancel_dialog = QuestionDialog(
@@ -507,8 +507,8 @@ def cancel_installation(self, _widget=None):
         if self._cancel_files_func:
             self._cancel_files_func()
         if self.interpreter:
-            self.interpreter.revert()
-            self.interpreter.cleanup()
+            self.interpreter.revert(remove_game_dir=remove_checkbox.get_active())
+            self.interpreter.cleanup()  # still remove temporary downloads in any case
         self.destroy()
 
     def on_source_clicked(self, _button):
diff --git a/lutris/installer/interpreter.py b/lutris/installer/interpreter.py
--- a/lutris/installer/interpreter.py
+++ b/lutris/installer/interpreter.py
@@ -354,7 +354,7 @@ def cleanup(self):
         os.chdir(os.path.expanduser("~"))
         system.remove_folder(self.cache_path)
 
-    def revert(self):
+    def revert(self, remove_game_dir=True):
         """Revert installation in case of an error"""
         logger.info("Cancelling installation of %s", self.installer.game_name)
         if self.installer.runner.startswith("wine"):
@@ -365,7 +365,7 @@ def revert(self):
         if self.abort_current_task:
             self.abort_current_task()
 
-        if self.game_dir_created:
+        if self.target_path and remove_game_dir:
             system.remove_folder(self.target_path)
 
     def _substitute(self, template_string):


Test patch: