Ejemplo n.º 1
0
    def __download(self, download_info, finish_func, cancel_to_state):
        download_success = True
        GLib.idle_add(self.update_to_state, self.state.QUEUED)
        Config.set("current_download", self.game.id)
        # Start the download for all files
        self.download_list = []
        number_of_files = len(download_info['files'])
        total_file_size = 0
        executable_path = None
        download_files = []
        for key, file_info in enumerate(download_info['files']):
            try:
                download_url = self.api.get_real_download_link(
                    file_info["downlink"])
            except ValueError as e:
                print(e)
                GLib.idle_add(self.parent.parent.show_error,
                              _("Download error"), _(str(e)))
                download_success = False
                break
            total_file_size += self.api.get_file_size(file_info["downlink"])
            try:
                # Extract the filename from the download url (filename is between %2F and &token)
                filename = urllib.parse.unquote(
                    re.search('%2F(((?!%2F).)*)&t', download_url).group(1))
            except AttributeError:
                filename = "{}-{}.bin".format(self.game.get_stripped_name(),
                                              key)
            download_path = os.path.join(self.download_dir, filename)
            if key == 0:
                # If key = 0, denote the file as the executable's path
                executable_path = download_path
            md5sum = self.api.get_download_file_md5(file_info["downlink"])
            if md5sum:
                self.game.md5sum[os.path.basename(download_path)] = md5sum
            download = Download(
                url=download_url,
                save_location=download_path,
                finish_func=finish_func
                if download_path == executable_path else None,
                progress_func=self.set_progress,
                cancel_func=lambda: self.__cancel(to_state=cancel_to_state),
                number=number_of_files - key,
                out_of_amount=number_of_files,
                game=self.game)
            download_files.insert(0, download)
        self.download_list.extend(download_files)

        if check_diskspace(total_file_size, Config.get("install_dir")):
            DownloadManager.download(download_files)
            ds_msg_title = ""
            ds_msg_text = ""
        else:
            ds_msg_title = "Download error"
            ds_msg_text = "Not enough disk space to install game."
            download_success = False
        if ds_msg_title:
            GLib.idle_add(self.parent.parent.show_error, _(ds_msg_title),
                          _(ds_msg_text))
        return download_success
Ejemplo n.º 2
0
 def __download_file(self) -> None:
     Config.set("current_download", self.game.id)
     GLib.idle_add(self.update_to_state, self.state.QUEUED)
     download_info = self.api.get_download_info(self.game)
     file_url = download_info["downlink"]
     self.download = Download(file_url,
                              self.download_path,
                              self.__install,
                              progress_func=self.set_progress,
                              cancel_func=self.__cancel_download)
     DownloadManager.download(self.download)
Ejemplo n.º 3
0
    def __download_file(self) -> None:
        GLib.idle_add(self.update_to_state, self.state.QUEUED)
        try:
            download_info = self.api.get_download_info(self.game)
        except NoDownloadLinkFound:
            if Config.get("current_download") == self.game.id:
                Config.unset("current_download")
            GLib.idle_add(
                self.parent.parent.show_error, _("Download error"),
                _("There was an error when trying to fetch the download link!")
            )
            GLib.idle_add(self.update_to_state, self.state.DOWNLOADABLE)
            return

        Config.set("current_download", self.game.id)
        # Start the download for all files
        self.download = []
        download_path = self.download_path
        finish_func = self.__install
        number_of_files = len(download_info['files'])
        for key, file_info in enumerate(download_info['files']):
            download_url = self.api.get_real_download_link(
                file_info["downlink"])
            try:
                # Extract the filename from the download url (filename is between %2F and &token)
                download_path = os.path.join(
                    self.download_dir,
                    urllib.parse.unquote(
                        re.search('%2F(((?!%2F).)*)&t',
                                  download_url).group(1)))
                if key == 0:
                    # If key = 0, denote the file as the executable's path
                    self.download_path = download_path
            except AttributeError:
                if key > 0:
                    download_path = "{}-{}.bin".format(self.download_path, key)
            download = Download(url=download_url,
                                save_location=download_path,
                                finish_func=finish_func,
                                progress_func=self.set_progress,
                                cancel_func=self.__cancel_download,
                                number=key + 1,
                                out_of_amount=number_of_files)
            self.download.append(download)

        DownloadManager.download(self.download)
Ejemplo n.º 4
0
    def __download(self, download_info, finish_func, cancel_to_state):
        download_success = True
        GLib.idle_add(self.update_to_state, self.state.QUEUED)
        Config.set("current_download", self.game.id)
        # Start the download for all files
        self.download = []
        number_of_files = len(download_info['files'])
        for key, file_info in enumerate(download_info['files']):
            try:
                download_url = self.api.get_real_download_link(
                    file_info["downlink"])
                self.game.md5sum = self.api.get_download_file_md5(
                    file_info["downlink"])
            except ValueError as e:
                print(e)
                GLib.idle_add(self.parent.parent.show_error,
                              _("Download error"), _(str(e)))
                download_success = False
                break
            try:
                # Extract the filename from the download url (filename is between %2F and &token)
                download_path = os.path.join(
                    self.download_dir,
                    urllib.parse.unquote(
                        re.search('%2F(((?!%2F).)*)&t',
                                  download_url).group(1)))
                if key == 0:
                    # If key = 0, denote the file as the executable's path
                    self.download_path = download_path
            except AttributeError:
                if key > 0:
                    download_path = "{}-{}.bin".format(self.download_path, key)
            download = Download(
                url=download_url,
                save_location=download_path,
                finish_func=finish_func,
                progress_func=self.set_progress,
                cancel_func=lambda: self.__cancel(to_state=cancel_to_state),
                number=key + 1,
                out_of_amount=number_of_files)
            self.download.append(download)

        DownloadManager.download(self.download)
        return download_success
Ejemplo n.º 5
0
    def __download_file(self) -> None:
        Config.set("current_download", self.game.id)
        GLib.idle_add(self.update_to_state, self.state.QUEUED)
        download_info = self.api.get_download_info(self.game)

        # Start the download for all files
        self.download = []
        download_path = self.download_path
        finish_func = self.__install
        for key, file_info in enumerate(download_info['files']):
            if key > 0:
                download_path = "{}-{}.bin".format(self.download_path, key)
            download = Download(url=self.api.get_real_download_link(
                file_info["downlink"]),
                                save_location=download_path,
                                finish_func=finish_func,
                                progress_func=self.set_progress,
                                cancel_func=self.__cancel_download,
                                number=key + 1,
                                out_of_amount=len(download_info['files']))
            self.download.append(download)

        DownloadManager.download(self.download)