def _download_file(self, game_file): """Download a file referenced in the installer script. Game files can be either a string, containing the location of the file to fetch or a dict with the following keys: - url : location of file, if not present, filename will be used this should be the case for local files. - filename : force destination filename when url is present or path of local file. """ # Setup file_id, file_uri and local filename file_id = list(game_file.keys())[0] if isinstance(game_file[file_id], dict): filename = game_file[file_id]['filename'] file_uri = game_file[file_id]['url'] referer = game_file[file_id].get('referer') else: file_uri = game_file[file_id] filename = os.path.basename(file_uri) referer = None if file_uri.startswith("/"): file_uri = "file://" + file_uri elif file_uri.startswith(("$WINESTEAM", "$STEAM")): # Download Steam data self._download_steam_data(file_uri, file_id) return if not filename: raise ScriptingError("No filename provided, please provide 'url' and 'filename' parameters in the script") # Check for file availability in PGA pga_uri = pga.check_for_file(self.game_slug, file_id) if pga_uri: file_uri = pga_uri # Setup destination path dest_file = os.path.join(self.cache_path, filename) logger.debug("Downloading [%s]: %s to %s", file_id, file_uri, dest_file) if file_uri.startswith("N/A"): # Ask the user where the file is located parts = file_uri.split(":", 1) if len(parts) == 2: message = parts[1] else: message = "Please select file '%s'" % file_id self.current_file_id = file_id self.parent.ask_user_for_file(message) return if os.path.exists(dest_file): os.remove(dest_file) # Change parent's status self.parent.set_status('') self.game_files[file_id] = dest_file self.parent.start_download(file_uri, dest_file, referer=referer)
def _download_file(self, game_file): """Download a file referenced in the installer script. Game files can be either a string, containing the location of the file to fetch or a dict with the following keys: - url : location of file, if not present, filename will be used this should be the case for local files. - filename : force destination filename when url is present or path of local file. """ # Setup file_id, file_uri and local filename file_id = game_file.keys()[0] if isinstance(game_file[file_id], dict): filename = game_file[file_id]['filename'] file_uri = game_file[file_id]['url'] else: file_uri = game_file[file_id] filename = os.path.basename(file_uri) if file_uri.startswith("/"): file_uri = "file://" + file_uri elif file_uri.startswith(("$WINESTEAM", "$STEAM")): # Download Steam data self._download_steam_data(file_uri, file_id) return logger.debug("Fetching [%s]: %s" % (file_id, file_uri)) # Check for file availability in PGA pga_uri = pga.check_for_file(self.game_slug, file_id) if pga_uri: file_uri = pga_uri # Setup destination path dest_file = os.path.join(self.download_cache_path, filename) if file_uri.startswith("N/A"): # Ask the user where the file is located parts = file_uri.split(":", 1) if len(parts) == 2: message = parts[1] else: message = "Please select file '%s'" % file_id self.current_file_id = file_id self.parent.ask_user_for_file(message) return if os.path.exists(dest_file): logger.debug("Destination file exists") if settings.KEEP_CACHED_ASSETS: self.game_files[file_id] = dest_file self.iter_game_files() return else: os.remove(dest_file) # Change parent's status self.parent.set_status('') self.game_files[file_id] = dest_file self.parent.start_download(file_uri, dest_file)
def _download_file(self, game_file): """Download a file referenced in the installer script Game files can be either a string, containing the location of the file to fetch or a dict with the following keys: - url : location of file, if not present, filename will be used this should be the case for local files - filename : force destination filename when url is present or path of local file """ # Setup file_id, file_uri and local filename file_id = game_file.keys()[0] if isinstance(game_file[file_id], dict): filename = game_file[file_id]['filename'] file_uri = game_file[file_id]['url'] else: file_uri = game_file[file_id] filename = os.path.basename(file_uri) if file_uri.startswith("/"): file_uri = "file://" + file_uri elif file_uri.startswith(("$WINESTEAM", "$STEAM")): # Download Steam data if self._download_steam_data(file_uri, file_id): return logger.debug("Fetching [%s]: %s" % (file_id, file_uri)) # Check for file availability in PGA pga_uri = pga.check_for_file(self.game_slug, file_id) if pga_uri: file_uri = pga_uri # Setup destination path dest_file = os.path.join(self.download_cache_path, filename) if file_uri.startswith("N/A"): # Ask the user where is the file located parts = file_uri.split(":", 1) if len(parts) == 2: message = parts[1] else: message = "Please select file '%s'" % file_id self.current_file_id = file_id self.parent.ask_user_for_file(message) return if os.path.exists(dest_file): logger.debug("Destination file exists") if settings.KEEP_CACHED_ASSETS: self.game_files[file_id] = dest_file self.iter_game_files() return else: os.remove(dest_file) # Change parent's status self.parent.set_status('Fetching %s' % file_uri) self.game_files[file_id] = dest_file self.parent.start_download(file_uri, dest_file)
def get_download_info(self): """Retrieve the file locally""" if self.url.startswith(("$WINESTEAM", "$STEAM", "N/A")): raise FileNotAvailable() # Check for file availability in PGA pga_uri = pga.check_for_file(self.game_slug, self.id) if pga_uri: self.url = pga_uri dest_file = os.path.join(self.cache_path, self.filename) logger.debug("Downloading [%s]: %s to %s", self.id, self.url, dest_file) if not self.uses_pga_cache() and os.path.exists(dest_file): os.remove(dest_file) self.dest_file = dest_file return self.dest_file
def _download_file(self, game_file): """Download a file referenced in the installer script Game files can be either a string, containing the location of the file to fetch or a dict with the following keys: - url : location of file, if not present, filename will be used this should be the case for local files - filename : force destination filename when url is present or path of local file """ # Setup file_id, file_uri and local filename file_id = game_file.keys()[0] if isinstance(game_file[file_id], dict): filename = game_file[file_id]['filename'] file_uri = game_file[file_id]['url'] else: file_uri = game_file[file_id] filename = os.path.basename(file_uri) if file_uri.startswith("/"): file_uri = "file://" + file_uri elif file_uri.startswith(("$WINESTEAM", "$STEAM")): # Download Steam data try: parts = file_uri.split(":", 2) steam_rel_path = parts[2].strip() except IndexError: raise ScriptingError("Malformed steam path: %s" % file_uri) if steam_rel_path == "/": steam_rel_path = "." self.steam_data = { 'appid': parts[1], 'steam_rel_path': steam_rel_path, 'file_id': file_id } if parts[0] == '$WINESTEAM': appid = self.steam_data['appid'] logger.debug("Getting Wine Steam data for appid %s" % appid) self.parent.set_status('Getting Wine Steam game data') self.steam_data['platform'] = "windows" # Check that wine is installed wine_runner = wine.wine() if not wine_runner.is_installed(): wine_runner.install() # Getting data from Wine Steam steam_runner = winesteam.winesteam() if not steam_runner.is_installed(): winesteam.download_steam( downloader=self.parent.start_download, callback=self.parent.on_steam_downloaded ) else: self.install_steam_game(winesteam.winesteam) return else: # Getting data from Linux Steam self.parent.set_status('Getting Steam game data') self.steam_data['platform'] = "linux" self.install_steam_game(steam.steam) return logger.debug("Fetching [%s]: %s" % (file_id, file_uri)) # Check for file availability in PGA pga_uri = pga.check_for_file(self.game_slug, file_id) if pga_uri: file_uri = pga_uri # Setup destination path dest_file = os.path.join(self.download_cache_path, filename) if file_uri.startswith("N/A"): # Ask the user where is the file located parts = file_uri.split(":", 1) if len(parts) == 2: message = parts[1] else: message = "Please select file '%s'" % file_id self.current_file_id = file_id self.parent.ask_user_for_file(message) return if os.path.exists(dest_file): logger.debug("Destination file exists") if settings.KEEP_CACHED_ASSETS: self.game_files[file_id] = dest_file self.iter_game_files() return else: os.remove(dest_file) # Change parent's status self.parent.set_status('Fetching %s' % file_uri) self.game_files[file_id] = dest_file self.parent.start_download(file_uri, dest_file)
def _download_file(self, game_file): """Download a file referenced in the installer script Game files can be either a string, containing the location of the file to fetch or a dict with the following keys: - url : location of file, if not present, filename will be used this should be the case for local files - filename : force destination filename when url is present or path of local file """ # Setup file_id, file_uri and local filename file_id = game_file.keys()[0] if isinstance(game_file[file_id], dict): filename = game_file[file_id]['filename'] file_uri = game_file[file_id]['url'] else: file_uri = game_file[file_id] filename = os.path.basename(file_uri) if file_uri.startswith("/"): file_uri = "file://" + file_uri elif file_uri.startswith(("$WINESTEAM", "$STEAM")): # Download Steam data try: parts = file_uri.split(":", 2) steam_rel_path = parts[2].strip() except IndexError: raise ScriptingError("Malformed steam path: %s" % file_uri) if steam_rel_path == "/": steam_rel_path = "." self.steam_data = { 'appid': parts[1], 'steam_rel_path': steam_rel_path, 'file_id': file_id } if parts[0] == '$WINESTEAM': self.steam_data['platform'] = "windows" # Getting data from Wine Steam steam_runner = winesteam.winesteam() if not steam_runner.is_installed(): # Downoad Steam for Windows steam_installer_path = os.path.join( settings.TMP_PATH, "SteamInstall.msi" ) self.parent.start_download( winesteam.winesteam.installer_url, steam_installer_path, self.parent.on_steam_downloaded, self.steam_data['appid'] ) else: self.install_steam_game(winesteam.winesteam) return else: # Getting data from Linux Steam self.steam_data['platform'] = "linux" self.install_steam_game(steam.steam) return logger.debug("Fetching [%s]: %s" % (file_id, file_uri)) # Check for file availability in PGA pga_uri = pga.check_for_file(self.game_slug, file_id) if pga_uri: file_uri = pga_uri # Setup destination path dest_file = os.path.join(self.download_cache_path, filename) if file_uri.startswith("N/A"): # Ask the user where is the file located parts = file_uri.split(":", 1) if len(parts) == 2: message = parts[1] else: message = "Please select file '%s'" % file_id self.current_file_id = file_id self.parent.ask_user_for_file(message) return if os.path.exists(dest_file): logger.debug("Destination file exists") if settings.KEEP_CACHED_ASSETS: self.game_files[file_id] = dest_file self.iter_game_files() return else: os.remove(dest_file) # Change parent's status self.parent.set_status('Fetching %s' % file_uri) self.game_files[file_id] = dest_file self.parent.start_download(file_uri, dest_file)
def pga_uri(self): """Return the URI of the file stored in the PGA This isn't used yet, it looks in the PGA sources """ return pga.check_for_file(self.game_slug, self.id)
def _download_file(self, game_file): """Download a file referenced in the installer script. KILL IT WITH FIRE!!! This method is a mess. Game files can be either a string, containing the location of the file to fetch or a dict with the following keys: - url : location of file, if not present, filename will be used this should be the case for local files. - filename : force destination filename when url is present or path of local file. """ if not isinstance(game_file, dict): raise ScriptingError("Invalid file, check the installer script", game_file) # Setup file_id, file_uri and local filename file_id = list(game_file.keys())[0] file_meta = game_file[file_id] if isinstance(file_meta, dict): for field in ("url", "filename"): if field not in file_meta: raise ScriptingError("missing field `%s` for file `%s`" % (field, file_id)) file_uri = file_meta["url"] filename = file_meta["filename"] referer = file_meta.get("referer") checksum = file_meta.get("checksum") else: file_uri = file_meta filename = os.path.basename(file_uri) referer = None checksum = None if file_uri.startswith("/"): file_uri = "file://" + file_uri elif file_uri.startswith(("$WINESTEAM", "$STEAM")): # Download Steam data self._download_steam_data(file_uri, file_id) return if not filename: raise ScriptingError( "No filename provided, please provide 'url' and 'filename' parameters in the script" ) # Check for file availability in PGA pga_uri = pga.check_for_file(self.game_slug, file_id) if pga_uri: file_uri = pga_uri # Setup destination path dest_file = os.path.join(self.cache_path, filename) logger.debug("Downloading [%s]: %s to %s", file_id, file_uri, dest_file) if file_uri.startswith("N/A"): # Ask the user where the file is located parts = file_uri.split(":", 1) if len(parts) == 2: message = parts[1] else: message = "Please select file '%s'" % file_id self.current_file_id = file_id self.parent.ask_user_for_file(message) return if os.path.exists(dest_file): os.remove(dest_file) # Change parent's status self.parent.set_status("") self.game_files[file_id] = dest_file if checksum: self.parent.start_download( file_uri, dest_file, lambda *args: self.check_hash(checksum, dest_file, file_uri), referer=referer) else: self.parent.start_download(file_uri, dest_file, referer=referer)