Exemplo n.º 1
0
    def __install(self, game: Game = None):
        GLib.idle_add(self.__update_to_state, game.state.INSTALLING, game)
        game.install_dir = game.get_install_dir()
        try:
            if os.path.exists(game.keep_path):
                install_game(game, game.keep_path, main_window=self)
            else:
                install_game(game, game.download_path, main_window=self)
        except (FileNotFoundError, BadZipFile):
            GLib.idle_add(self.__update_to_state, game.state.DOWNLOADABLE,
                          game)
            return
        GLib.idle_add(self.__update_to_state, game.state.INSTALLED, game)
        GLib.idle_add(self.__reload_state, game)
        # make user to add the game to the side bar

        # check if DLCs should also be installed
        if game.type == "game" and Config.get("install_dlcs"):
            # first ensure we know about game dlcs
            self.library.update_dlcs_for_game(game)
            if len(game.dlcs) == 0:
                return
            # now grab DLCs that can be installed
            downloads = []
            for dlc in game.dlcs:
                try:
                    download_info = self.api.get_download_info(
                        dlc, game.platform, True, dlc.get_installers())
                except Exception:
                    # could not find a valid target, ignore it
                    continue
                # set dlc information now, otherwise this will break later
                dlc.platform = game.platform
                dlc.language = game.language
                # add download
                # Start the download for all files
                for key, file_info in enumerate(download_info['files']):
                    if key > 0:
                        download_path = "{}-{}.bin".format(
                            dlc.download_path, key)
                    else:
                        download_path = dlc.download_path
                    download = Download(url=self.api.get_real_download_link(
                        file_info["downlink"]),
                                        title=dlc.name,
                                        associated_object=dlc,
                                        save_location=download_path,
                                        number=key + 1,
                                        file_size=download_info["total_size"],
                                        out_of_amount=len(
                                            download_info['files']))
                    download.register_finish_function(self.__dlc_finish_func,
                                                      [game, dlc])
                    download.register_progress_function(
                        self.set_progress, game)
                    download.register_cancel_function(self.__cancel_download,
                                                      game)
                    downloads.append(download)
            DownloadManager.download(downloads)
Exemplo n.º 2
0
 def test_cancel(self):
     mock_cancel_function = MagicMock()
     download = Download("test_url", "test_save_location")
     download.register_cancel_function(mock_cancel_function)
     download.cancel()
     exp = 2
     obs = len(mock_cancel_function.mock_calls)
     self.assertEqual(exp, obs)
Exemplo n.º 3
0
 def test2_finish(self):
     mock_finish_function = MagicMock()
     mock_finish_function.side_effect = FileNotFoundError(
         Mock(status="Connection Error"))
     mock_cancel_function = MagicMock()
     download = Download("test_url", "test_save_location")
     download.register_finish_function(mock_finish_function)
     download.register_cancel_function(mock_cancel_function)
     download.finish()
     exp = 2
     obs = len(mock_cancel_function.mock_calls)
     self.assertEqual(exp, obs)
Exemplo n.º 4
0
    def __download_file(self, game: Game, operating_system=None) -> None:
        Config.set("current_download", game.id)
        GLib.idle_add(self.__update_to_state, game.state.QUEUED, game)

        current_os = platform.system()
        if current_os == "Linux":
            current_os = "linux"
        elif current_os == "Windows":
            current_os = "windows"
        elif current_os == "Darwin":
            current_os = "mac"
        # pick current os if none was passed
        if operating_system is None:
            operating_system = current_os
        if game.platform is None:
            game.platform = operating_system

        download_info = self.api.get_download_info(
            game, operating_system=operating_system)

        # Start the download for all files
        game.downloads = []
        download_path = game.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"]),
                                title=download_info["name"],
                                associated_object=game,
                                save_location=download_path,
                                number=key + 1,
                                file_size=download_info["total_size"],
                                out_of_amount=len(download_info['files']))
            download.register_finish_function(finish_func, game)
            download.register_progress_function(self.set_progress, game)
            download.register_cancel_function(self.__cancel_download, game)
            game.downloads.append(download)

        DownloadManager.download(game.downloads)