mirror of
https://github.com/lutris/lutris
synced 2024-09-04 23:13:35 +00:00
Do not offer to cache user-supplied files if there's more than one file.
We aren't clever enough to find the other files after the initial one, so we just won't offer this option if there's more than one file.
This commit is contained in:
parent
d41bc263ea
commit
8888d73e61
|
@ -161,7 +161,7 @@ class InstallerFileBox(Gtk.VBox):
|
|||
location_entry.connect("changed", self.on_location_changed)
|
||||
location_entry.show()
|
||||
box.pack_start(location_entry, False, False, 0)
|
||||
if self.installer_file.uses_pga_cache(create=True):
|
||||
if self.installer_file.is_user_pga_caching_allowed:
|
||||
cache_option = Gtk.CheckButton(_("Cache file for future installations"))
|
||||
cache_option.set_active(self.cache_to_pga)
|
||||
cache_option.connect("toggled", self.on_user_file_cached)
|
||||
|
|
|
@ -167,11 +167,9 @@ class InstallerFile:
|
|||
"""Return True if the file can be downloaded (even from the local filesystem)"""
|
||||
return self.url.startswith(("http", "file"))
|
||||
|
||||
def uses_pga_cache(self, create=False):
|
||||
def uses_pga_cache(self):
|
||||
"""Determines whether the installer files are stored in a PGA cache
|
||||
|
||||
Params:
|
||||
create (bool): If a cache is active, auto create directories if needed
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
|
@ -180,17 +178,16 @@ class InstallerFile:
|
|||
return False
|
||||
if system.path_exists(cache_path):
|
||||
return True
|
||||
if create:
|
||||
try:
|
||||
logger.debug("Creating cache path %s", self.cache_path)
|
||||
os.makedirs(self.cache_path)
|
||||
except (OSError, PermissionError) as ex:
|
||||
logger.error("Failed to created cache path: %s", ex)
|
||||
return False
|
||||
return True
|
||||
|
||||
logger.warning("Cache path %s does not exist", cache_path)
|
||||
return False
|
||||
|
||||
@property
|
||||
def is_user_pga_caching_allowed(self):
|
||||
"""Returns true if this file can be transferred to the cache, if
|
||||
the user provides it."""
|
||||
return self.uses_pga_cache()
|
||||
|
||||
@property
|
||||
def cache_path(self):
|
||||
"""Return the directory used as a cache for the duration of the installation"""
|
||||
|
@ -205,8 +202,8 @@ class InstallerFile:
|
|||
return os.path.join(_cache_path, self.game_slug, folder)
|
||||
|
||||
def prepare(self):
|
||||
"""Prepare the file for download"""
|
||||
if not system.path_exists(self.cache_path):
|
||||
"""Prepare the file for download, if we've not been redirected to an existing file."""
|
||||
if not self._dest_file and not system.path_exists(self.cache_path):
|
||||
os.makedirs(self.cache_path)
|
||||
|
||||
def create_download_progress_box(self):
|
||||
|
@ -251,13 +248,23 @@ class InstallerFile:
|
|||
|
||||
def save_to_cache(self):
|
||||
"""Copy the file into the PGA cache."""
|
||||
save_to_cache(self.dest_file, self.cache_path)
|
||||
|
||||
cache_path = self.cache_path
|
||||
try:
|
||||
if not os.path.isdir(cache_path):
|
||||
logger.debug("Creating cache path %s", self.cache_path)
|
||||
os.makedirs(cache_path)
|
||||
except (OSError, PermissionError) as ex:
|
||||
logger.error("Failed to created cache path: %s", ex)
|
||||
return
|
||||
|
||||
save_to_cache(self.dest_file, cache_path)
|
||||
|
||||
def remove_previous(self):
|
||||
"""Remove file at already at destination, prior to starting the download."""
|
||||
if (
|
||||
not self.uses_pga_cache()
|
||||
and system.path_exists(self.dest_file)
|
||||
not self.uses_pga_cache()
|
||||
and system.path_exists(self.dest_file)
|
||||
):
|
||||
# If we've previously downloaded a directory, we'll need to get rid of it
|
||||
# to download a file now. Since we are not using the cache, we don't keep
|
||||
|
|
|
@ -55,10 +55,13 @@ class InstallerFileCollection:
|
|||
we'll special case GOG here too."""
|
||||
self._dest_file = new_dest_file
|
||||
|
||||
# try to set main gog file to dest_file
|
||||
for installer_file in self.files_list:
|
||||
if installer_file.id == "goginstaller":
|
||||
installer_file.dest_file = new_dest_file
|
||||
if len(self.files_list) == 1:
|
||||
self.files_list[0].override_dest_file(new_dest_file)
|
||||
else:
|
||||
# try to set main gog file to dest_file
|
||||
for installer_file in self.files_list:
|
||||
if installer_file.id == "goginstaller":
|
||||
installer_file.dest_file = new_dest_file
|
||||
|
||||
def get_dest_files_by_id(self):
|
||||
files = {}
|
||||
|
@ -102,11 +105,9 @@ class InstallerFileCollection:
|
|||
_providers.add("download")
|
||||
return _providers
|
||||
|
||||
def uses_pga_cache(self, create=False):
|
||||
def uses_pga_cache(self):
|
||||
"""Determines whether the installer files are stored in a PGA cache
|
||||
|
||||
Params:
|
||||
create (bool): If a cache is active, auto create directories if needed
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
|
@ -115,19 +116,14 @@ class InstallerFileCollection:
|
|||
return False
|
||||
if system.path_exists(cache_path):
|
||||
return True
|
||||
if create:
|
||||
try:
|
||||
logger.debug("Creating cache path %s", self.cache_path)
|
||||
# make dirs to all files
|
||||
for installer_file in self.files_list:
|
||||
os.makedirs(installer_file.cache_path)
|
||||
except (OSError, PermissionError) as ex:
|
||||
logger.error("Failed to created cache path: %s", ex)
|
||||
return False
|
||||
return True
|
||||
|
||||
logger.warning("Cache path %s does not exist", cache_path)
|
||||
return False
|
||||
|
||||
@property
|
||||
def is_user_pga_caching_allowed(self):
|
||||
return len(self.files_list) == 1 and self.files_list[0].is_user_pga_caching_allowed
|
||||
|
||||
@property
|
||||
def cache_path(self):
|
||||
"""Return the directory used as a cache for the duration of the installation"""
|
||||
|
@ -137,10 +133,10 @@ class InstallerFileCollection:
|
|||
return os.path.join(_cache_path, self.game_slug)
|
||||
|
||||
def prepare(self):
|
||||
"""Prepare all files for download"""
|
||||
# File Collection do not need to prepare, only the files_list
|
||||
for installer_file in self.files_list:
|
||||
installer_file.prepare()
|
||||
"""Prepare the file for download, if we've not been redirected to an existing file."""
|
||||
if not self._dest_file or len(self.files_list) == 1:
|
||||
for installer_file in self.files_list:
|
||||
installer_file.prepare()
|
||||
|
||||
def create_download_progress_box(self):
|
||||
return DownloadCollectionProgressBox(self)
|
||||
|
|
Loading…
Reference in a new issue