Esempio n. 1
0
    def get_library(self):
        if not self.active_token:
            return

        games = []
        current_page = 1
        all_pages_processed = False
        url = "https://embed.gog.com/account/getFilteredProducts"

        tags = {}

        while not all_pages_processed:
            params = {
                'mediaType': 1,  # 1 means game
                'page': current_page,
            }
            response = self.__request(url, params=params)
            total_pages = response["totalPages"]

            if response["tags"]:
                for tag in response["tags"]:
                    tags[tag["id"]] = tag["name"]

            for product in response["products"]:
                try:
                    if product["id"] not in IGNORE_GAME_IDS:
                        if not product["url"]:
                            print("{} ({}) has no store page url".format(
                                product["title"], product['id']))
                        supported_platforms = []
                        if product["worksOn"]["Linux"]:
                            supported_platforms.append("linux")
                        if product["worksOn"]["Windows"]:
                            supported_platforms.append("windows")
                        if product["worksOn"]["Mac"]:
                            supported_platforms.append("mac")
                        ptags = []
                        if product["tags"]:
                            for tag in product["tags"]:
                                ptags.append(tags[tag])
                        release_date = None
                        if "releaseDate" in product:
                            release_date = product["releaseDate"]
                        game = Game(name=product["title"],
                                    url=product["url"],
                                    game_id=product["id"])
                        game.updates = 0
                        game.image_url = product["image"]
                        game.installed = 0
                        game.tags = ptags if len(ptags) > 0 else None
                        game.set_main_genre(product["category"])
                        game.supported_platforms = supported_platforms
                        game.release_date = release_date
                        games.append(game)
                except Exception as e:
                    print(e)
            if current_page == total_pages:
                all_pages_processed = True
            current_page += 1
        return games
Esempio n. 2
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)
Esempio n. 3
0
 def test_strip_within_comparison(self):
     game1 = Game("!@#$%^&*(){}[]\"'_-<>.,;:")
     game2 = Game("")
     game3 = Game("hallo")
     game4 = Game("Hallo")
     game5 = Game("Hallo!")
     self.assertEqual(game1, game2)
     self.assertNotEqual(game2, game3)
     self.assertEqual(game3, game4)
     self.assertEqual(game3, game5)
Esempio n. 4
0
    def test_local_comparison(self):
        larry1_local_gog = Game(
            "Leisure Suit Larry",
            install_dir="/home/user/Games/Leisure Suit Larry",
            game_id=1207662033)
        larry1_vga_local_gog = Game(
            "Leisure Suit Larry VGA",
            install_dir="/home/user/Games/Leisure Suit Larry VGA",
            game_id=1207662043)

        self.assertNotEqual(larry1_local_gog, larry1_vga_local_gog)
Esempio n. 5
0
 def test3_get_dlc_status(self, mock_isfile):
     mock_isfile.side_effect = [False, False]
     json_content = '[{"Neverwinter Nights: Wyvern Crown of Cormyr": "not-installed", ' \
                    '"Neverwinter Nights: Infinite Dungeons": "updatable", "Neverwinter Nights: Pirates of ' \
                    'the Sword Coast": "installed"}, {}]'
     with patch("builtins.open", mock_open(read_data=json_content)):
         game = Game("Game Name test2")
         game.read_installed_version = MagicMock()
         game.installed_version = "1"
         dlc_status = game.get_dlc_status(
             "Neverwinter Nights: Infinite Dungeons", "")
     expected = "not-installed"
     observed = dlc_status
     self.assertEqual(expected, observed)
Esempio n. 6
0
 def test1_add_games_from_api(self):
     self_games = []
     for game in SELF_GAMES:
         self_games.append(Game(name=game, game_id=int(SELF_GAMES[game]),))
     api_games = []
     for game in API_GAMES:
         api_games.append(Game(name=game, game_id=int(API_GAMES[game]),))
     api_mock = MagicMock()
     api_mock.get_library.return_value = api_games
     test_library = Library(MagicMock(), api_mock)
     test_library.games = self_games
     test_library._Library__add_games_from_api()
     exp = len(API_GAMES)
     obs = len(test_library.games)
     self.assertEqual(exp, obs)
Esempio n. 7
0
 def test2_add_games_from_api(self):
     self_games = []
     for game in SELF_GAMES:
         self_games.append(Game(name=game, game_id=int(SELF_GAMES[game]),))
     api_games = []
     for game in API_GAMES:
         api_games.append(Game(name=game, game_id=int(API_GAMES[game]),))
     api_mock = MagicMock()
     api_mock.get_library.return_value = api_games
     test_library = Library(MagicMock(), api_mock)
     test_library.games = self_games
     test_library._Library__add_games_from_api()
     exp = True
     obs = Game(name="Stellaris (English)", game_id=1508702879,) in test_library.games
     self.assertEqual(exp, obs)
Esempio n. 8
0
    def __download_update(self, game: Game = None) -> None:
        Config.set("current_download", game.id)
        GLib.idle_add(self.__update_to_state, game.state.UPDATE_QUEUED, game)
        download_info = self.api.get_download_info(game)

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

        DownloadManager.download(game.downloads)
Esempio n. 9
0
 def test1_check_if_game_started_correctly(self, mock_check_game):
     mock_process = MagicMock()
     mock_process.wait.side_effect = subprocess.TimeoutExpired("cmd", 1)
     game = Game("Test Game", install_dir="/test/install/dir")
     exp = ""
     obs = launcher.check_if_game_started_correctly(mock_process, game)
     self.assertEqual(exp, obs)
Esempio n. 10
0
 def test2_run_game_subprocess(self, launcher_mock, mock_popen,
                               mock_os_chdir, mock_os_getcwd):
     mock_popen.side_effect = FileNotFoundError()
     game = Game("Test Game", install_dir="/test/install/dir")
     exp = ('No executable was found in /test/install/dir', None)
     obs = launcher.run_game_subprocess(game)
     self.assertEqual(exp, obs)
Esempio n. 11
0
 def test1_run_game_subprocess(self, launcher_mock, mock_popen,
                               mock_os_chdir, mock_os_getcwd):
     mock_process = "Mock Process"
     mock_popen.return_value = mock_process
     game = Game("Test Game", install_dir="/test/install/dir")
     exp = ("", mock_process)
     obs = launcher.run_game_subprocess(game)
     self.assertEqual(exp, obs)
Esempio n. 12
0
 def test2_check_if_game_started_correctly(self, mock_check_game):
     mock_process = MagicMock()
     mock_process.communicate.return_value = (b"Output message",
                                              b"Error message")
     game = Game("Test Game", install_dir="/test/install/dir")
     exp = "Error message"
     obs = launcher.check_if_game_started_correctly(mock_process, game)
     self.assertEqual(exp, obs)
Esempio n. 13
0
 def test2_validate_if_installed_is_latest(self):
     game = Game("Version Test game")
     game.installed_version = "91.8193.16"
     game.read_installed_version = MagicMock()
     installers = [{
         'os': 'windows',
         'version': '81.8193.16'
     }, {
         'os': 'mac',
         'version': '81.8193.16'
     }, {
         'os': 'linux',
         'version': '81.8193.16'
     }]
     expected = False
     observed = game.validate_if_installed_is_latest(installers)
     self.assertEqual(expected, observed)
Esempio n. 14
0
 def __uninstall_game(self, game: Game = None):
     GLib.idle_add(self.__update_to_state, game.state.UNINSTALLING, game)
     # Remove game from sidebar if it is there
     if game.sidebar_tile is not None:
         self.installed_list.remove(game.sidebar_tile.get_parent())
         game.sidebar_tile = None
     uninstall_game(game)
     GLib.idle_add(self.__update_to_state, game.state.DOWNLOADABLE, game)
Esempio n. 15
0
 def download_update(self, game: Game):
     if game.sidebar_tile is None:
         game.sidebar_tile = InstalledRow(self, game, self.api)
         GLib.idle_add(self.installed_list.prepend, game.sidebar_tile)
     # start download
     download_thread = threading.Thread(target=self.__download_update,
                                        args=[game])
     download_thread.start()
Esempio n. 16
0
 def test4_add_games_from_api(self):
     self_games = []
     for game in SELF_GAMES:
         self_games.append(Game(name=game, game_id=int(SELF_GAMES[game]),))
     api_games = []
     url_nr = 1
     for game in API_GAMES:
         api_games.append(Game(name=game, game_id=int(API_GAMES[game]), url="http://test_url{}".format(str(url_nr))))
         url_nr += 1
     api_mock = MagicMock()
     api_mock.get_library.return_value = api_games
     test_library = Library(MagicMock(), api_mock)
     test_library.games = self_games
     test_library._Library__add_games_from_api()
     exp = "http://test_url1"
     obs = test_library.games[0].url
     self.assertEqual(exp, obs)
Esempio n. 17
0
 def test1_validate_if_installed_is_latest(self):
     game = Game("Version Test game")
     game.installed_version = "gog-2"
     game.read_installed_version = MagicMock()
     installers = [{
         'os': 'windows',
         'version': '1.0'
     }, {
         'os': 'mac',
         'version': '1.0'
     }, {
         'os': 'linux',
         'version': 'gog-2'
     }]
     expected = True
     observed = game.validate_if_installed_is_latest(installers)
     self.assertEqual(expected, observed)
Esempio n. 18
0
 def __update(self, game: Game = None):
     GLib.idle_add(self.__update_to_state, game.state.UPDATING, game)
     game.install_dir = self.__get_install_dir(game)
     try:
         if os.path.exists(game.keep_path):
             install_game(self.game,
                          self.keep_path,
                          parent_window=self.parent)
         else:
             install_game(self.game,
                          self.update_path,
                          parent_window=self.parent)
     except (FileNotFoundError, BadZipFile):
         GLib.idle_add(self.__update_to_state, game.state.UPDATABLE, game)
         return
     # reset updates count flag
     game.updates = 0
     GLib.idle_add(self.__update_to_state, game.state.INSTALLED, game)
Esempio n. 19
0
 def test_get_start_script_exe_cmd(self):
     files = [
         'thumbnail.jpg', 'docs', 'support', 'game', 'start.sh',
         'goodoldgalaxy-dlc.json', 'gameinfo'
     ]
     game = Game("Test Game", install_dir="/test/install/dir")
     exp = ["/test/install/dir/start.sh"]
     obs = launcher.get_start_script_exe_cmd(game, files)
     self.assertEqual(exp, obs)
Esempio n. 20
0
 def test_get_scummvm_exe_cmd(self):
     files = [
         'thumbnail.jpg', 'data', 'docs', 'support', 'beneath.ini',
         'scummvm', 'start.sh', 'gameinfo'
     ]
     game = Game("Test Game", install_dir="/test/install/dir")
     exp = ["scummvm", "-c", "beneath.ini"]
     obs = launcher.get_scummvm_exe_cmd(game, files)
     self.assertEqual(exp, obs)
Esempio n. 21
0
 def install_game(self, game: Game):
     # used to say that a game was installed
     # add to the sidebar
     if game.sidebar_tile is not None:
         return
     # add it to the sidebar
     game.sidebar_tile = InstalledRow(self, game, self.api)
     GLib.idle_add(self.installed_list.prepend, game.sidebar_tile)
     install_thread = threading.Thread(target=self.__install, args=[game])
     install_thread.start()
Esempio n. 22
0
 def __update_to_state(self, state, game: Game):
     game.state = state
     if game.list_tile is not None:
         game.list_tile.update_to_state(state)
     if game.grid_tile is not None:
         game.grid_tile.update_to_state(state)
     if game.sidebar_tile is not None:
         game.sidebar_tile.update_to_state(state)
     if self.details is not None and self.details.game == game:
         self.details.update_to_state(state)
Esempio n. 23
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)
Esempio n. 24
0
 def test_get_dosbox_exe_cmd(self):
     files = [
         'thumbnail.jpg', 'docs', 'support', 'dosbox_bbb_single.conf',
         'dosbox_aaa.conf', 'dosbox'
     ]
     game = Game("Test Game", install_dir="/test/install/dir")
     exp = [
         "dosbox", "-conf", "dosbox_aaa.conf", "-conf",
         "dosbox_bbb_single.conf", "-no-console", "-c", "exit"
     ]
     obs = launcher.get_dosbox_exe_cmd(game, files)
     self.assertEqual(exp, obs)
Esempio n. 25
0
 def test1_get_windows_exe_cmd(self, mock_glob):
     mock_glob.return_value = [
         "/test/install/dir/start.exe", "/test/install/dir/unins000.exe"
     ]
     files = [
         'thumbnail.jpg', 'docs', 'support', 'game',
         'goodoldgalaxy-dlc.json', 'start.exe', 'unins000.exe'
     ]
     game = Game("Test Game", install_dir="/test/install/dir")
     exp = ["wine", "start.exe"]
     obs = launcher.get_windows_exe_cmd(game, files)
     self.assertEqual(exp, obs)
Esempio n. 26
0
 def test3_add_games_from_api(self):
     self_games = []
     for game in SELF_GAMES:
         self_games.append(Game(name=game, game_id=int(SELF_GAMES[game]),))
     self_games.append(Game(name="Game without ID", game_id=0))
     api_games = []
     for game in API_GAMES:
         api_games.append(Game(name=game, game_id=int(API_GAMES[game]),))
     api_gmae_with_id = Game(name="Game without ID", game_id=1234567890)
     api_games.append(api_gmae_with_id)
     api_mock = MagicMock()
     api_mock.get_library.return_value = api_games
     test_library = Library(MagicMock(), api_mock)
     test_library.games = self_games
     test_library._Library__add_games_from_api()
     exp = True
     obs = api_gmae_with_id in test_library.games
     self.assertEqual(exp, obs)
     exp = len(api_games)
     obs = len(test_library.games)
     self.assertEqual(exp, obs)
Esempio n. 27
0
 def __cancel_download(self, game: Game = None):
     DownloadManager.cancel_download(game.downloads)
     GLib.idle_add(self.__reload_state, game)
     if game.state == game.state.DOWNLOADING:
         ## remove sidebar tile
         if game.sidebar_tile is not None:
             game.sidebar_tile.get_parent().get_parent().remove(
                 game.sidebar_tile.get_parent())
             game.sidebar_tile = None
         GLib.idle_add(self.__update_to_state, game.state.DOWNLOADABLE,
                       game)
     elif game.state == game.state.UPDATE_DOWNLOADING:
         GLib.idle_add(self.__update_to_state, game.state.INSTALLED, game)
Esempio n. 28
0
 def update_dlcs_for_game(self, game: Game):
     """
     Update DLCs for a given game.
     
     Parameters:
     -----------
         game: Game -> Game for which we want to know about dlc's
     """
     if game is None:
         return
     response = self.api.get_info(game)
     if "expanded_dlcs" in response:
         dlcs = response["expanded_dlcs"]
         for dlc in dlcs:
             downloads = dlc["downloads"]
             for dltype in downloads:
                 if dltype == "bonus_content":
                     continue
                 items = downloads[dltype]
                 for item in items:
                     # add game to dlc list
                     game.add_dlc_from_json(dlc)
Esempio n. 29
0
 def test2_read_installed_version(self, mock_isfile):
     mock_isfile.return_value = False
     gameinfo = """Beneath A Steel Sky
 gog-2
 20150
 en-US
 1207658695
 1207658695
 664777434"""
     with patch("builtins.open", mock_open(read_data=gameinfo)):
         game = Game("Game Name test2")
     expected = ""
     observed = game.installed_version
     self.assertEqual(expected, observed)
Esempio n. 30
0
    def test1_check_if_game_start_process_spawned_final_process(
            self, mock_check_output, mock_getpid):
        mock_check_output.return_value = b"""UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 lis24 ?        00:00:02 /sbin/init splash
root         2     0  0 lis24 ?        00:00:00 [kthreadd]
root         3     2  0 lis24 ?        00:00:00 [rcu_gp]
root         4     2  0 lis24 ?        00:00:00 [rcu_par_gp]
root         6     2  0 lis24 ?        00:00:00 [kworker/0:0H-kblockd]
"""
        mock_getpid.return_value = 1000
        err_msg = "Error Message"
        game = Game("Test Game", install_dir="/test/install/dir")
        exp = err_msg
        obs = launcher.check_if_game_start_process_spawned_final_process(
            err_msg, game)
        self.assertEqual(exp, obs)