diff --git a/CHANGELOG.md b/CHANGELOG.md index 21f5b55e..496fc206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ **1.2.6** - Fix changing the install path causing an exception +- Allow Windows versions of games with Linux versions to be installed (thanks to makson96 and Kzimir) - Fix error detection & reporting on wineprefix creation failure (thanks to LeXofLeviafan) **1.2.5** diff --git a/data/ui/properties.ui b/data/ui/properties.ui old mode 100644 new mode 100755 index 1eb8f5b4..3f4fc356 --- a/data/ui/properties.ui +++ b/data/ui/properties.ui @@ -15,8 +15,8 @@ False - True - True + False + False 0 @@ -35,13 +35,12 @@ 6 True - True False + 18 6 12 - True True @@ -297,7 +296,7 @@ 1 - 10 + 11 @@ -311,7 +310,7 @@ 0 - 9 + 10 @@ -323,11 +322,65 @@ 1 + 10 + + + + + True + False + end + Game platform: + fill + + + 0 9 - + + True + False + start + vertical + center + + + Linux (native) + True + True + False + True + True + + + True + True + 0 + + + + + Windows (wine) + True + True + False + True + True + radiobutton_linux_type + + + True + True + 1 + + + + + 1 + 9 + diff --git a/minigalaxy/api.py b/minigalaxy/api.py old mode 100644 new mode 100755 index 7c0a0f39..49d9c1bb --- a/minigalaxy/api.py +++ b/minigalaxy/api.py @@ -100,14 +100,17 @@ def get_library(self): # Only support Linux unless the show_windows_games setting is enabled if product["worksOn"]["Linux"]: platform = "linux" + supported_platforms = [platform, "windows"] elif self.config.show_windows_games: platform = "windows" + supported_platforms = [platform] else: continue if not product["url"]: logger.warn("{} ({}) has no store page url".format(product["title"], product['id'])) game = Game(name=product["title"], url=product["url"], game_id=product["id"], - image_url=product["image"], platform=platform, category=product["category"]) + image_url=product["image"], platform=platform, + category=product["category"], supported_platforms=supported_platforms) games.append(game) if current_page == total_pages: all_pages_processed = True @@ -144,7 +147,7 @@ def get_info(self, game: Game) -> dict: return response # This returns a unique download url and a link to the checksum of the download - def get_download_info(self, game: Game, operating_system="linux", dlc_installers="") -> dict: + def get_download_info(self, game: Game, operating_system="", dlc_installers="") -> dict: if dlc_installers: installers = dlc_installers else: @@ -227,6 +230,15 @@ def get_user_info(self) -> str: self.config.username = username return username + def get_download_version(self, game: Game): + if not game.get_info("platform"): + platform_version = game.platform + else: + platform_version = game.get_info("platform") + if not platform_version: + platform_version = "linux" + return platform_version + def get_version(self, game: Game, gameinfo=None, dlc_name="") -> str: if gameinfo is None: gameinfo = self.get_info(game) diff --git a/minigalaxy/game.py b/minigalaxy/game.py old mode 100644 new mode 100755 index 7069b6d8..da8b0760 --- a/minigalaxy/game.py +++ b/minigalaxy/game.py @@ -7,17 +7,18 @@ class Game: def __init__(self, name: str, url: str = "", md5sum=None, game_id: int = 0, install_dir: str = "", - image_url="", platform="linux", dlcs=None, category=""): + image_url="", platform=None, supported_platforms: list = None, dlcs=None, category=""): self.name = name self.url = url self.md5sum = {} if md5sum is None else md5sum self.id = game_id self.install_dir = install_dir self.image_url = image_url - self.platform = platform self.dlcs = [] if dlcs is None else dlcs self.category = category self.status_file_path = self.get_status_file_path() + self.platform = platform if platform else self.get_info("platform") + self.supported_platforms = [platform] if supported_platforms is None else supported_platforms def get_stripped_name(self): return self.__strip_string(self.name) @@ -144,6 +145,10 @@ def set_install_dir(self, install_dir) -> None: if not self.install_dir: self.install_dir = os.path.join(install_dir, self.get_install_directory_name()) + def set_platform(self, platform): + self.platform = platform + self.set_info("platform", platform) + def __str__(self): return self.name diff --git a/minigalaxy/installer.py b/minigalaxy/installer.py index b6154233..32d27372 100644 --- a/minigalaxy/installer.py +++ b/minigalaxy/installer.py @@ -125,7 +125,7 @@ def make_tmp_dir(game): def extract_installer(game: Game, installer: str, temp_dir: str, language: str, use_innoextract: bool): # Extract the installer - if game.platform in ["linux"]: + if game.platform in ["linux"] and not game.get_info("platform") or game.get_info("platform") == "linux": err_msg = extract_linux(installer, temp_dir) else: err_msg = extract_windows(game, installer, temp_dir, language, use_innoextract) diff --git a/minigalaxy/ui/gametile.py b/minigalaxy/ui/gametile.py index 0f378eaa..fc0cf84f 100644 --- a/minigalaxy/ui/gametile.py +++ b/minigalaxy/ui/gametile.py @@ -213,9 +213,9 @@ def get_keep_executable_path(self): break return keep_path - def get_download_info(self, platform="linux"): + def get_download_info(self): try: - download_info = self.api.get_download_info(self.game, platform) + download_info = self.api.get_download_info(self.game, self.api.get_download_version(self.game)) result = True except NoDownloadLinkFound as e: logger.error("No download link found", exc_info=1) @@ -358,7 +358,7 @@ def __cancel(self, to_state): def __download_update(self) -> None: finish_func = self.__update cancel_to_state = State.UPDATABLE - result, download_info = self.get_download_info(self.game.platform) + result, download_info = self.get_download_info() if result: result = self.__download(download_info, DownloadType.GAME_UPDATE, finish_func, cancel_to_state) @@ -387,7 +387,8 @@ def __update(self, save_location): else: self.image.set_tooltip_text(self.game.name) for dlc in self.game.dlcs: - download_info = self.api.get_download_info(self.game, dlc_installers=dlc["downloads"]["installers"]) + download_info = self.api.get_download_info(self.game, self.api.get_download_version(self.game), + dlc_installers=dlc["downloads"]["installers"]) if self.game.is_update_available(version_from_api=download_info["version"], dlc_title=dlc["title"]): self.__download_dlc(dlc["downloads"]["installers"]) @@ -395,7 +396,8 @@ def __download_dlc(self, dlc_installers) -> None: def finish_func(save_location): self.__install_dlc(save_location, dlc_title=dlc_title) - download_info = self.api.get_download_info(self.game, dlc_installers=dlc_installers) + download_info = self.api.get_download_info(self.game, self.api.get_download_version(self.game), + dlc_installers=dlc_installers) dlc_title = self.game.name for dlc in self.game.dlcs: if dlc["downloads"]["installers"] == dlc_installers: @@ -442,7 +444,8 @@ def update_gtk_box_for_dlc(self, dlc_id, icon, title, installer): self.dlc_horizontal_box.pack_start(dlc_box, False, True, 0) dlc_box.show_all() self.get_async_image_dlc_icon(dlc_id, image, icon, title) - download_info = self.api.get_download_info(self.game, dlc_installers=installer) + download_info = self.api.get_download_info(self.game, operating_system=self.api.get_download_version(self.game), + dlc_installers=installer) if self.game.is_update_available(version_from_api=download_info["version"], dlc_title=title): icon_name = "emblem-synchronizing" self.dlc_dict[title][0].set_sensitive(True) diff --git a/minigalaxy/ui/gametilelist.py b/minigalaxy/ui/gametilelist.py index 542d4be9..f8303beb 100644 --- a/minigalaxy/ui/gametilelist.py +++ b/minigalaxy/ui/gametilelist.py @@ -219,9 +219,9 @@ def get_keep_executable_path(self): break return keep_path - def get_download_info(self, platform="linux"): + def get_download_info(self): try: - download_info = self.api.get_download_info(self.game, platform) + download_info = self.api.get_download_info(self.game, self.api.get_download_version(self.game)) result = True except NoDownloadLinkFound as e: logger.error("No download link found", exc_info=1) @@ -393,7 +393,8 @@ def __update(self, save_location): else: self.image.set_tooltip_text(self.game.name) for dlc in self.game.dlcs: - download_info = self.api.get_download_info(self.game, dlc_installers=dlc["downloads"]["installers"]) + download_info = self.api.get_download_info(self.game, self.api.get_download_version(self.game), + dlc_installers=dlc["downloads"]["installers"]) if self.game.is_update_available(version_from_api=download_info["version"], dlc_title=dlc["title"]): self.__download_dlc(dlc["downloads"]["installers"]) @@ -401,7 +402,8 @@ def __download_dlc(self, dlc_installers) -> None: def finish_func(save_location): self.__install_dlc(save_location, dlc_title=dlc_title) - download_info = self.api.get_download_info(self.game, dlc_installers=dlc_installers) + download_info = self.api.get_download_info(self.game, self.api.get_download_version(self.game), + dlc_installers=dlc_installers) dlc_title = self.game.name for dlc in self.game.dlcs: if dlc["downloads"]["installers"] == dlc_installers: @@ -448,7 +450,8 @@ def update_gtk_box_for_dlc(self, dlc_id, icon, title, installer): self.dlc_horizontal_box.pack_start(dlc_box, False, True, 0) dlc_box.show_all() self.get_async_image_dlc_icon(dlc_id, image, icon, title) - download_info = self.api.get_download_info(self.game, dlc_installers=installer) + download_info = self.api.get_download_info(self.game, operating_system=self.api.get_download_version(self.game), + dlc_installers=installer) if self.game.is_update_available(version_from_api=download_info["version"], dlc_title=title): icon_name = "emblem-synchronizing" self.dlc_dict[title][0].set_sensitive(True) diff --git a/minigalaxy/ui/properties.py b/minigalaxy/ui/properties.py old mode 100644 new mode 100755 index ec8eacac..868cdd95 --- a/minigalaxy/ui/properties.py +++ b/minigalaxy/ui/properties.py @@ -29,6 +29,9 @@ class Properties(Gtk.Dialog): button_properties_cancel = Gtk.Template.Child() button_properties_ok = Gtk.Template.Child() label_wine_custom = Gtk.Template.Child() + radiobutton_linux_type = Gtk.Template.Child() + radiobutton_windows_type = Gtk.Template.Child() + label_properties_platform = Gtk.Template.Child() def __init__(self, parent, game, api): Gtk.Dialog.__init__(self, title=_("Properties of {}").format(game.name), parent=parent.parent.parent, @@ -93,6 +96,10 @@ def ok_pressed(self, button): self.game.set_info("hide_game", self.switch_properties_hide_game.get_active()) self.game.set_info("custom_wine", str(self.button_properties_wine.get_filename())) self.parent.parent.filter_library() + if self.radiobutton_linux_type.get_active(): + self.game.set_platform("linux") + elif self.radiobutton_windows_type.get_active(): + self.game.set_platform("windows") self.destroy() @Gtk.Template.Callback("on_button_properties_regedit_clicked") @@ -134,10 +141,18 @@ def button_sensitive(self, game): self.entry_properties_variable.set_sensitive(False) self.entry_properties_command.set_sensitive(False) - if game.platform == 'linux': + if game.platform in ["linux"]: self.button_properties_regedit.hide() self.button_properties_winecfg.hide() self.button_properties_winetricks.hide() self.button_properties_wine.hide() self.button_properties_reset.hide() self.label_wine_custom.hide() + self.radiobutton_linux_type.set_active(True) + elif game.platform in ["windows"]: + self.radiobutton_windows_type.set_active(True) + + if "linux" not in self.game.supported_platforms or game.is_installed(): + self.radiobutton_linux_type.hide() + self.radiobutton_windows_type.hide() + self.label_properties_platform.hide() diff --git a/tests/test_api.py b/tests/test_api.py index ef394efb..087ac13e 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -63,9 +63,9 @@ def test1_get_download_info(self): api.get_info = MagicMock() api.get_info.return_value = API_GET_INFO_TOONSTRUCK config.lang = "pl" - test_game = Game("Test Game") + test_game = Game("Test Game", platform="linux") exp = {'id': 'installer_linux_en', 'name': 'Toonstruck', 'os': 'linux', 'language': 'en', 'language_full': 'English', 'version': 'gog-2', 'total_size': 963641344, 'files': [{'id': 'en3installer0', 'size': 963641344, 'downlink': 'https://api.gog.com/products/1207666633/downlink/installer/en3installer0'}]} - obs = api.get_download_info(test_game) + obs = api.get_download_info(test_game, operating_system="linux") self.assertEqual(exp, obs) def test2_get_download_info(self): @@ -75,9 +75,9 @@ def test2_get_download_info(self): api.get_info = MagicMock() api.get_info.return_value = API_GET_INFO_TOONSTRUCK config.lang = "fr" - test_game = Game("Test Game") + test_game = Game("Test Game", platform="linux") exp = {'id': 'installer_linux_fr', 'name': 'Toonstruck', 'os': 'linux', 'language': 'fr', 'language_full': 'français', 'version': 'gog-2', 'total_size': 1011875840, 'files': [{'id': 'fr3installer0', 'size': 1011875840, 'downlink': 'https://api.gog.com/products/1207666633/downlink/installer/fr3installer0'}]} - obs = api.get_download_info(test_game) + obs = api.get_download_info(test_game, operating_system="linux") self.assertEqual(exp, obs) def test3_get_download_info(self): @@ -94,7 +94,7 @@ def test3_get_download_info(self): config.lang = "en" test_game = Game("Test Game") exp = {'id': 'installer_windows_en', 'name': 'Toonstruck', 'os': 'windows', 'language': 'en', 'language_full': 'English', 'version': '1.0', 'total_size': 939524096, 'files': [{'id': 'en1installer0', 'size': 1048576, 'downlink': 'https://api.gog.com/products/1207666633/downlink/installer/en1installer0'}, {'id': 'en1installer1', 'size': 938475520, 'downlink': 'https://api.gog.com/products/1207666633/downlink/installer/en1installer1'}]} - obs = api.get_download_info(test_game) + obs = api.get_download_info(test_game, operating_system="linux") self.assertEqual(exp, obs) def test4_get_download_info(self): @@ -105,7 +105,7 @@ def test4_get_download_info(self): config.lang = "en" test_game = Game("Test Game") exp = {'id': 'installer_linux_en', 'name': 'Toonstruck', 'os': 'linux', 'language': 'en', 'language_full': 'English', 'version': 'gog-2', 'total_size': 963641344, 'files': [{'id': 'en3installer0', 'size': 963641344, 'downlink': 'https://api.gog.com/products/1207666633/downlink/installer/en3installer0'}]} - obs = api.get_download_info(test_game, dlc_installers=dlc_test_installer) + obs = api.get_download_info(test_game, operating_system="linux", dlc_installers=dlc_test_installer) self.assertEqual(exp, obs) def test1_get_library(self): diff --git a/tests/test_game.py b/tests/test_game.py index 4e495c00..f0725e38 100644 --- a/tests/test_game.py +++ b/tests/test_game.py @@ -6,23 +6,23 @@ class TestGame(unittest.TestCase): def test_strip_within_comparison(self): - game1 = Game("!@#$%^&*(){}[]\"'_-<>.,;:") - game2 = Game("") - game3 = Game("hallo") - game4 = Game("Hallo") - game5 = Game("Hallo!") + game1 = Game("!@#$%^&*(){}[]\"'_-<>.,;:", platform="linux") + game2 = Game("", platform="linux") + game3 = Game("hallo", platform="linux") + game4 = Game("Hallo", platform="linux") + game5 = Game("Hallo!", platform="linux") self.assertEqual(game1, game2) self.assertNotEqual(game2, game3) self.assertEqual(game3, game4) self.assertEqual(game3, game5) def test_local_and_api_comparison(self): - larry1_api = Game("Leisure Suit Larry 1 - In the Land of the Lounge Lizards", game_id=1207662033) + larry1_api = Game("Leisure Suit Larry 1 - In the Land of the Lounge Lizards", platform="linux", game_id=1207662033) larry1_local_gog = Game("Leisure Suit Larry", install_dir="/home/user/Games/Leisure Suit Larry", - game_id=1207662033) + game_id=1207662033, platform="linux") larry1_local_minigalaxy = Game("Leisure Suit Larry", install_dir="/home/wouter/Games/Leisure Suit Larry 1 - In the Land of the Lounge Lizards", - game_id=1207662033) + game_id=1207662033, platform="linux") self.assertEqual(larry1_local_gog, larry1_local_minigalaxy) self.assertEqual(larry1_local_minigalaxy, larry1_api) @@ -31,9 +31,9 @@ def test_local_and_api_comparison(self): larry2_api = Game("Leisure Suit Larry 2 - Looking For Love (In Several Wrong Places)", game_id=1207662053) larry2_local_minigalaxy = Game("Leisure Suit Larry 2", install_dir="/home/user/Games/Leisure Suit Larry 2 - Looking For Love (In Several Wrong Places)", - game_id=1207662053) + game_id=1207662053, platform="linux") larry2_local_gog = Game("Leisure Suit Larry 2", install_dir="/home/user/Games/Leisure Suit Larry 2", - game_id=1207662053) + game_id=1207662053, platform="linux") self.assertNotEqual(larry1_api, larry2_api) self.assertNotEqual(larry2_local_gog, larry1_api) @@ -44,14 +44,14 @@ def test_local_and_api_comparison(self): def test_local_comparison(self): larry1_local_gog = Game("Leisure Suit Larry", install_dir="/home/user/Games/Leisure Suit Larry", - game_id=1207662033) + game_id=1207662033, platform="linux") larry1_vga_local_gog = Game("Leisure Suit Larry VGA", install_dir="/home/user/Games/Leisure Suit Larry VGA", - game_id=1207662043) + game_id=1207662043, platform="linux") self.assertNotEqual(larry1_local_gog, larry1_vga_local_gog) def test1_is_update_available(self): - game = Game("Version Test game") + game = Game("Version Test game", platform="linux") game.load_minigalaxy_info_json = MagicMock() game.load_minigalaxy_info_json.return_value = {'version': 'gog-2'} expected = True @@ -59,7 +59,7 @@ def test1_is_update_available(self): self.assertEqual(expected, observed) def test2_is_update_available(self): - game = Game("Version Test game") + game = Game("Version Test game", platform="linux") game.load_minigalaxy_info_json = MagicMock() game.load_minigalaxy_info_json.return_value = {'version': "91.8193.16"} expected = False @@ -67,7 +67,7 @@ def test2_is_update_available(self): self.assertEqual(expected, observed) def test3_is_update_available(self): - game = Game("Version Test game") + game = Game("Version Test game", platform="linux") game.load_minigalaxy_info_json = MagicMock() game.load_minigalaxy_info_json.return_value = {'version': "91.8193.16", "dlcs": {"Neverwinter Nights: Wyvern Crown of Cormyr": {"version": "82.8193.20.1"}}} expected = True @@ -75,7 +75,7 @@ def test3_is_update_available(self): self.assertEqual(expected, observed) def test4_is_update_available(self): - game = Game("Version Test game") + game = Game("Version Test game", platform="linux") game.load_minigalaxy_info_json = MagicMock() game.load_minigalaxy_info_json.return_value = {'version': "91.8193.16", "dlcs": {"Neverwinter Nights: Wyvern Crown of Cormyr": {"version": "82.8193.20.1"}}} expected = False @@ -83,13 +83,13 @@ def test4_is_update_available(self): self.assertEqual(expected, observed) def test1_get_install_directory_name(self): - game = Game("Get Install Directory Test1") + game = Game("Get Install Directory Test1", platform="linux") expected = "Get Install Directory Test1" observed = game.get_install_directory_name() self.assertEqual(expected, observed) def test2_get_install_directory_name(self): - game = Game("Get\r Install\n Directory Test2!@#$%") + game = Game("Get\r Install\n Directory Test2!@#$%", platform="linux") expected = "Get Install Directory Test2" observed = game.get_install_directory_name() self.assertEqual(expected, observed) @@ -104,7 +104,7 @@ def test1_fallback_read_installed_version(self, mock_isfile): 1207658695 1207658695 664777434""" - game = Game("Game Name test1") + game = Game("Game Name test1", platform="linux") expected = "gog-2" with patch("builtins.open", mock_open(read_data=gameinfo)): observed = game.fallback_read_installed_version() @@ -120,7 +120,7 @@ def test2_fallback_read_installed_version(self, mock_isfile): 1207658695 1207658695 664777434""" - game = Game("Game Name test2") + game = Game("Game Name test2", platform="linux") expected = "0" with patch("builtins.open", mock_open(read_data=gameinfo)): observed = game.fallback_read_installed_version() @@ -131,7 +131,7 @@ def test1_set_info(self, mock_exists): mock_exists.return_value = True json_content = '{"version": "gog-2"}' with patch("builtins.open", mock_open(read_data=json_content)) as m: - game = Game("Game Name test2") + game = Game("Game Name test2", platform="linux") game.set_info("version", "gog-3") mock_c = m.mock_calls write_string = "" @@ -149,7 +149,7 @@ def test2_set_dlc_info(self, mock_makedirs, mock_exists): mock_exists.return_value = False dlc_name = "Neverwinter Nights: Wyvern Crown of Cormyr" with patch("builtins.open", mock_open()) as m: - game = Game("Neverwinter Nights") + game = Game("Neverwinter Nights", platform="linux") game.set_dlc_info("version", "82.8193.20.1", dlc_name) mock_c = m.mock_calls write_string = "" @@ -163,7 +163,7 @@ def test2_set_dlc_info(self, mock_makedirs, mock_exists): def test_get_stripped_name(self): name_string = "Beneath A Steel Sky" - game = Game(name_string) + game = Game(name_string, platform="linux") expected = "BeneathASteelSky" observed = game.get_stripped_name() self.assertEqual(expected, observed) @@ -173,7 +173,7 @@ def test1_load_minigalaxy_info_json(self, mock_isfile): mock_isfile.side_effect = [True] json_content = '{"version": "gog-2"}' with patch("builtins.open", mock_open(read_data=json_content)): - game = Game("Game Name test2") + game = Game("Game Name test2", platform="linux") jscon_dict = game.load_minigalaxy_info_json() expected = {"version": "gog-2"} observed = jscon_dict @@ -184,7 +184,7 @@ def test2_load_minigalaxy_info_json(self, mock_isfile): mock_isfile.side_effect = [False] json_content = '{"version": "gog-2"}' with patch("builtins.open", mock_open(read_data=json_content)): - game = Game("Game Name test2") + game = Game("Game Name test2", platform="linux") jscon_dict = game.load_minigalaxy_info_json() expected = {} observed = jscon_dict @@ -195,7 +195,7 @@ def test2_load_minigalaxy_info_json(self, mock_isfile): def test_save_minigalaxy_info_json(self, mock_makedirs, mock_config): json_dict = {"version": "gog-2"} with patch("builtins.open", mock_open()) as m: - game = Game("Neverwinter Nights") + game = Game("Neverwinter Nights", platform="linux") game.save_minigalaxy_info_json(json_dict) mock_c = m.mock_calls write_string = "" @@ -210,7 +210,7 @@ def test_save_minigalaxy_info_json(self, mock_makedirs, mock_config): @unittest.mock.patch('os.path.exists') def test1_is_installed(self, mock_isfile): mock_isfile.side_effect = [False] - game = Game("Game Name Test") + game = Game("Game Name Test", platform="linux") game.load_minigalaxy_info_json = MagicMock() exp = False obs = game.is_installed() @@ -219,7 +219,7 @@ def test1_is_installed(self, mock_isfile): @unittest.mock.patch('os.path.exists') def test2_is_installed(self, mock_isfile): mock_isfile.side_effect = [True] - game = Game("Game Name Test", install_dir="Test Install Dir") + game = Game("Game Name Test", install_dir="Test Install Dir", platform="linux") game.load_minigalaxy_info_json = MagicMock() game.load_minigalaxy_info_json.return_value = {"dlcs": {"Neverwinter Nights: Wyvern Crown of Cormyr": {"version": "82.8193.20.1"}}} exp = True @@ -229,7 +229,7 @@ def test2_is_installed(self, mock_isfile): @unittest.mock.patch('os.path.exists') def test3_is_installed(self, mock_isfile): mock_isfile.side_effect = [True] - game = Game("Game Name Test", install_dir="Test Install Dir") + game = Game("Game Name Test", install_dir="Test Install Dir", platform="linux") game.load_minigalaxy_info_json = MagicMock() game.load_minigalaxy_info_json.return_value = {"dlcs": {"Neverwinter Nights: Wyvern Crown of Cormyr": {"version": "82.8193.20.1"}}} game.legacy_get_dlc_status = MagicMock() @@ -243,7 +243,7 @@ def test_get_info(self, mock_isfile): mock_isfile.side_effect = [True] json_content = '{"example_key": "example_value"}' with patch("builtins.open", mock_open(read_data=json_content)): - game = Game("Game Name test") + game = Game("Game Name test", platform="linux") game_get_status = game.get_info("example_key") expected = "example_value" observed = game_get_status @@ -254,7 +254,7 @@ def test_get_dlc_info(self, mock_isfile): mock_isfile.side_effect = [True, False] json_content = '{"dlcs": {"example_dlc" : {"example_key": "example_value"}}}' with patch("builtins.open", mock_open(read_data=json_content)): - game = Game("Game Name test") + game = Game("Game Name test", platform="linux") game_get_status = game.get_dlc_info("example_key", "example_dlc") expected = "example_value" observed = game_get_status @@ -263,7 +263,7 @@ def test_get_dlc_info(self, mock_isfile): def test_set_install_dir(self): install_directory = "/home/user/GOG Games" install_game_name = "Neverwinter Nights" - game = Game(install_game_name) + game = Game(install_game_name, platform="linux") game.set_install_dir(install_directory) exp = os.path.join(install_directory, install_game_name) obs = game.install_dir @@ -274,7 +274,7 @@ def test1_get_info_legacy(self, mock_isfile): mock_isfile.side_effect = [False, True] json_content = '{"example_key": "example_value"}' with patch("builtins.open", mock_open(read_data=json_content)): - game = Game("Game Name test") + game = Game("Game Name test", platform="linux") game.set_info = MagicMock() game_get_status = game.get_info("example_key") expected = "example_value" @@ -286,7 +286,7 @@ def test2_get_info_legacy(self, mock_isfile): mock_isfile.side_effect = [True, True] json_content = '{"example_key": "example_value"}' with patch("builtins.open", mock_open(read_data=json_content)): - game = Game("Game Name test") + game = Game("Game Name test", platform="linux") game.set_info = MagicMock() game.load_minigalaxy_info_json = MagicMock() game.load_minigalaxy_info_json.return_value = {} @@ -300,7 +300,7 @@ def test3_get_info_legacy(self, mock_isfile): mock_isfile.side_effect = [True, True] json_content = '{"example_key": "example_value_legacy"}' with patch("builtins.open", mock_open(read_data=json_content)): - game = Game("Game Name test") + game = Game("Game Name test", platform="linux") game.load_minigalaxy_info_json = MagicMock() game.load_minigalaxy_info_json.return_value = {"example_key": "example_value"} game_get_status = game.get_info("example_key") @@ -313,7 +313,7 @@ def test1_get_dlc_info_legacy(self, mock_isfile): mock_isfile.side_effect = [False, True] json_content = '{"dlcs": {"example_dlc" : {"example_key": "example_value"}}}' with patch("builtins.open", mock_open(read_data=json_content)): - game = Game("Game Name test") + game = Game("Game Name test", platform="linux") game.set_dlc_info = MagicMock() game_get_status = game.get_dlc_info("example_key", "example_dlc") expected = "example_value" @@ -325,7 +325,7 @@ def test2_get_dlc_info_legacy(self, mock_isfile): mock_isfile.side_effect = [True, True] json_content = '{"dlcs": {"example_dlc" : {"example_key": "example_value"}}}' with patch("builtins.open", mock_open(read_data=json_content)): - game = Game("Game Name test") + game = Game("Game Name test", platform="linux") game.set_dlc_info = MagicMock() game.load_minigalaxy_info_json = MagicMock() game.load_minigalaxy_info_json.return_value = {} @@ -339,7 +339,7 @@ def test3_get_dlc_info_legacy(self, mock_isfile): mock_isfile.side_effect = [True, True] json_content = '{"dlcs": {"example_dlc" : {"example_key": "example_value_legacy"}}}' with patch("builtins.open", mock_open(read_data=json_content)): - game = Game("Game Name test") + game = Game("Game Name test", platform="linux") game.load_minigalaxy_info_json = MagicMock() game.load_minigalaxy_info_json.return_value = {"dlcs": {"example_dlc": {"example_key": "example_value"}}} game_get_status = game.get_dlc_info("example_key", "example_dlc") @@ -348,13 +348,13 @@ def test3_get_dlc_info_legacy(self, mock_isfile): self.assertEqual(expected, observed) def test1_get_status_file_path(self): - game = Game(name="Europa Universalis 2") + game = Game(name="Europa Universalis 2", platform="linux") expected = os.path.expanduser("~/.config/minigalaxy/games/Europa Universalis 2.json") observed = game.get_status_file_path() self.assertEqual(expected, observed) def test2_get_status_file_path(self): - game = Game(name="Europa Universalis 2", install_dir="/home/user/GoG Games//Europa Universalis II") + game = Game(name="Europa Universalis 2", platform="linux", install_dir="/home/user/GoG Games//Europa Universalis II") expected = os.path.expanduser("~/.config/minigalaxy/games/Europa Universalis II.json") observed = game.get_status_file_path() self.assertEqual(expected, observed) diff --git a/tests/test_installer.py b/tests/test_installer.py index 8e6cb769..3ef0ce86 100644 --- a/tests/test_installer.py +++ b/tests/test_installer.py @@ -63,7 +63,7 @@ def test1_extract_installer(self, mock_subprocess, mock_listdir, mock_is_file): mock_subprocess().returncode = 0 mock_subprocess().communicate.return_value = [b"stdout", b"stderr"] mock_listdir.return_value = ["object1", "object2"] - game = Game("Beneath A Steel Sky", install_dir="/home/makson/GOG Games/Beneath a Steel Sky") + game = Game("Beneath A Steel Sky", platform="linux", install_dir="/home/makson/GOG Games/Beneath a Steel Sky") installer_path = "/home/makson/.cache/minigalaxy/download/Beneath a Steel Sky/beneath_a_steel_sky_en_gog_2_20150.sh" temp_dir = "/home/makson/.cache/minigalaxy/extract/1207658695" exp = "" @@ -79,7 +79,7 @@ def test2_extract_installer(self, mock_subprocess, mock_listdir, mock_is_file): mock_subprocess().returncode = 2 mock_subprocess().communicate.return_value = [b"stdout", b"stderr"] mock_listdir.return_value = ["object1", "object2"] - game = Game("Beneath A Steel Sky", install_dir="/home/makson/GOG Games/Beneath a Steel Sky") + game = Game("Beneath A Steel Sky", platform="linux", install_dir="/home/makson/GOG Games/Beneath a Steel Sky") installer_path = "/home/makson/.cache/minigalaxy/download/Beneath a Steel Sky/beneath_a_steel_sky_en_gog_2_20150.sh" temp_dir = "/home/makson/.cache/minigalaxy/extract/1207658695" exp = "The installation of /home/makson/.cache/minigalaxy/download/Beneath a Steel Sky/beneath_a_steel_sky_en_gog_2_20150.sh failed. Please try again." @@ -206,7 +206,7 @@ def test2_postinstaller(self, mock_chmod, mock_path_isfile, mock_subprocess): mock_path_isfile.return_value = True mock_subprocess().returncode = 0 mock_subprocess().communicate.return_value = [b"stdout", b"stderr"] - game = Game("Absolute Drift", install_dir="/home/makson/GOG Games/Absolute Drift") + game = Game("Absolute Drift", platform="linux", install_dir="/home/makson/GOG Games/Absolute Drift") exp = "" obs = installer.postinstaller(game) self.assertEqual(exp, obs) @@ -218,7 +218,7 @@ def test3_postinstaller(self, mock_chmod, mock_path_isfile, mock_subprocess): mock_path_isfile.return_value = True mock_subprocess().returncode = 1 mock_subprocess().communicate.return_value = [b"stdout", b"stderr"] - game = Game("Absolute Drift", install_dir="/home/makson/GOG Games/Absolute Drift") + game = Game("Absolute Drift", platform="linux", install_dir="/home/makson/GOG Games/Absolute Drift") exp = "Postinstallation script failed: /home/makson/GOG Games/Absolute Drift/support/postinst.sh" obs = installer.postinstaller(game) self.assertEqual(exp, obs)