コード例 #1
0
ファイル: gametile.py プロジェクト: kibun1/minigalaxy
    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 += int(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
            self.game.md5sum[os.path.basename(download_path)] = self.api.get_download_file_md5(file_info["downlink"])
            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
コード例 #2
0
 def on_button_cancel(self, widget):
     question = _("Are you sure you want to cancel downloading {}?").format(
         self.game.name)
     if self.parent.parent.show_question(question):
         self.prevent_resume_on_startup()
         DownloadManager.cancel_download(self.download)
         try:
             for filename in os.listdir(self.download_dir):
                 if self.game.get_install_directory_name() in filename:
                     os.remove(os.path.join(self.download_dir, filename))
         except FileNotFoundError:
             pass
コード例 #3
0
    def on_button_cancel(self, widget):
        message_dialog = Gtk.MessageDialog(parent=self.parent.parent,
                                           flags=Gtk.DialogFlags.MODAL,
                                           message_type=Gtk.MessageType.WARNING,
                                           buttons=Gtk.ButtonsType.OK_CANCEL,
                                           message_format=_("Are you sure you want to cancel downloading {}?").format(self.game.name))
        response = message_dialog.run()

        if response == Gtk.ResponseType.OK:
            self.prevent_resume_on_startup()
            DownloadManager.cancel_download(self.download)
        message_dialog.destroy()
コード例 #4
0
    def load_thumbnail(self):
        if self.__set_image():
            return True
        if not self.game.image_url or not self.game.id:
            return False

        # Download the thumbnail
        image_url = "https:{}_196.jpg".format(self.game.image_url)
        thumbnail = os.path.join(THUMBNAIL_DIR, "{}.jpg".format(self.game.id))

        download = Download(image_url, thumbnail, finish_func=self.__set_image)
        DownloadManager.download_now(download)
        return True
コード例 #5
0
ファイル: gametile.py プロジェクト: rscmbbng/minigalaxy
    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)
コード例 #6
0
ファイル: gametile.py プロジェクト: heidiwenger/minigalaxy
    def load_thumbnail(self):
        set_result = self.__set_image()
        if not set_result:
            tries = 10
            performed_try = 0
            while performed_try < tries:
                if self.game.image_url and self.game.id:
                    # Download the thumbnail
                    image_url = "https:{}_196.jpg".format(self.game.image_url)
                    thumbnail = os.path.join(THUMBNAIL_DIR, "{}.jpg".format(self.game.id))

                    download = Download(image_url, thumbnail, finish_func=self.__set_image)
                    DownloadManager.download_now(download)
                    set_result = True
                    break
                performed_try += 1
                time.sleep(1)
        return set_result
コード例 #7
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
コード例 #8
0
    def save_pressed(self, button):
        self.__save_language_choice()
        Config.set("keep_installers", self.switch_keep_installers.get_active())
        Config.set("stay_logged_in", self.switch_stay_logged_in.get_active())
        Config.set("show_fps", self.switch_show_fps.get_active())

        if self.switch_show_windows_games.get_active() != Config.get("show_windows_games"):
            if self.switch_show_windows_games.get_active() and not shutil.which("wine"):
                self.parent.show_error(_("Wine wasn't found. Showing Windows games cannot be enabled."))
                Config.set("show_windows_games", False)
            else:
                Config.set("show_windows_games", self.switch_show_windows_games.get_active())
                self.parent.reset_library()

        # Only change the install_dir is it was actually changed
        if self.button_file_chooser.get_filename() != Config.get("install_dir"):
            if self.__save_install_dir_choice():
                DownloadManager.cancel_all_downloads()
                self.parent.reset_library()
            else:
                self.parent.show_error(_("{} isn't a usable path").format(self.button_file_chooser.get_filename()))
        self.destroy()
コード例 #9
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)
コード例 #10
0
ファイル: gametile.py プロジェクト: SvdB-nonp/minigalaxy
 def on_button_cancel(self, widget):
     question = _("Are you sure you want to cancel downloading {}?").format(
         self.game.name)
     if self.parent.parent.show_question(question):
         self.prevent_resume_on_startup()
         DownloadManager.cancel_download(self.download)