Example #1
0
 def load_description(self):
     description = ""
     lang = Config.get("lang")
     if self.gamesdb_info["summary"]:
         desc_lang = "*"
         for summary_key in self.gamesdb_info["summary"].keys():
             if lang in summary_key:
                 desc_lang = summary_key
         description_len = 470
         if len(self.gamesdb_info["summary"][desc_lang]) > description_len:
             description = "{}...".format(
                 self.gamesdb_info["summary"][desc_lang][:description_len])
         else:
             description = self.gamesdb_info["summary"][desc_lang]
         if "*" in self.gamesdb_info["genre"]:
             genre = self.gamesdb_info["genre"]["*"]
         else:
             genre = _("unknown")
         for genre_key, genre_value in self.gamesdb_info["genre"].items():
             if lang in genre_key:
                 genre = genre_value
         description = "{}: {}\n{}".format(_("Genre"), genre, description)
     if self.game.is_installed():
         description = "{}: {}\n{}".format(_("Version"),
                                           self.game.get_info("version"),
                                           description)
     GLib.idle_add(self.label_game_description.set_text, description)
Example #2
0
 def __download_update(self) -> None:
     finish_func = self.__update
     cancel_to_state = self.state.UPDATABLE
     result, download_info = self.get_download_info(self.game.platform)
     if result:
         result = self.__download(download_info, finish_func, cancel_to_state)
     if not result:
         GLib.idle_add(self.update_to_state, cancel_to_state)
Example #3
0
 def __download_game(self) -> None:
     finish_func = self.__install_game
     cancel_to_state = self.state.DOWNLOADABLE
     result, download_info = self.get_download_info()
     if result:
         result = self.__download(download_info, finish_func, cancel_to_state)
     if not result:
         GLib.idle_add(self.update_to_state, cancel_to_state)
Example #4
0
 def __check_for_update_dlc(self):
     if self.game.is_installed() and self.game.id and not self.offline:
         game_info = self.api.get_info(self.game)
         game_version = self.api.get_version(self.game, gameinfo=game_info)
         update_available = self.game.is_update_available(game_version)
         if update_available:
             GLib.idle_add(self.update_to_state, self.state.UPDATABLE)
         self.__check_for_dlc(game_info)
     if self.offline:
         GLib.idle_add(self.menu_button_dlc.hide)
Example #5
0
 def get_async_image_dlc_icon(self, dlc_id, image, icon, title):
     dlc_icon_path = os.path.join(ICON_DIR, "{}.jpg".format(dlc_id))
     if icon:
         if os.path.isfile(dlc_icon_path):
             GLib.idle_add(image.set_from_file, dlc_icon_path)
         else:
             url = "http:{}".format(icon)
             dlc_icon = os.path.join(ICON_DIR, "{}.jpg".format(dlc_id))
             download = Download(url, dlc_icon)
             DownloadManager.download_now(download)
             GLib.idle_add(image.set_from_file, dlc_icon_path)
Example #6
0
 def __check_for_dlc(self, game_info):
     dlcs = game_info["expanded_dlcs"]
     for dlc in dlcs:
         if dlc["is_installable"] and dlc["id"] in self.parent.owned_products_ids:
             d_installer = dlc["downloads"]["installers"]
             d_icon = dlc["images"]["sidebarIcon"]
             d_name = dlc["title"]
             GLib.idle_add(self.update_gtk_box_for_dlc, d_icon, d_name, d_installer)
             if dlc not in self.game.dlcs:
                 self.game.dlcs.append(dlc)
     if self.game.dlcs:
         GLib.idle_add(self.menu_button_dlc.show)
Example #7
0
 def get_download_info(self, platform="linux"):
     try:
         download_info = self.api.get_download_info(self.game, platform)
         result = True
     except NoDownloadLinkFound as e:
         print(e)
         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!\n{}".format(e)))
         download_info = False
         result = False
     return result, download_info
Example #8
0
    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)
        dlc_title = self.game.name
        for dlc in self.game.dlcs:
            if dlc["downloads"]["installers"] == dlc_installers:
                dlc_title = dlc["title"]
        cancel_to_state = self.state.INSTALLED
        result = self.__download(download_info, finish_func, cancel_to_state)
        if not result:
            GLib.idle_add(self.update_to_state, cancel_to_state)
Example #9
0
 def __install(self, save_location, update=False, dlc_title=""):
     if update:
         processing_state = self.state.UPDATING
         failed_state = self.state.INSTALLED
     else:
         processing_state = self.state.INSTALLING
         failed_state = self.state.DOWNLOADABLE
     success_state = self.state.INSTALLED
     GLib.idle_add(self.update_to_state, processing_state)
     err_msg = install_game(self.game, save_location)
     if not err_msg:
         GLib.idle_add(self.update_to_state, success_state)
         install_success = True
         if dlc_title:
             self.game.set_dlc_info(
                 "version",
                 self.api.get_version(self.game, dlc_name=dlc_title),
                 dlc_title)
         else:
             self.game.set_info("version", self.api.get_version(self.game))
     else:
         GLib.idle_add(self.parent.parent.show_error,
                       _("Failed to install {}").format(self.game.name),
                       err_msg)
         GLib.idle_add(self.update_to_state, failed_state)
         install_success = False
     return install_success
Example #10
0
 def __set_image(self, save_location):
     set_result = False
     self.game.set_install_dir()
     thumbnail_install_dir = os.path.join(self.game.install_dir, "thumbnail.jpg")
     if os.path.isfile(thumbnail_install_dir):
         GLib.idle_add(self.image.set_from_file, thumbnail_install_dir)
         set_result = True
     elif save_location and os.path.isfile(save_location):
         GLib.idle_add(self.image.set_from_file, save_location)
         # Copy image to
         if os.path.isdir(os.path.dirname(thumbnail_install_dir)):
             shutil.copy2(save_location, thumbnail_install_dir)
         set_result = True
     return set_result
Example #11
0
 def load_thumbnail(self):
     if self.gamesdb_info["cover"]:
         response = urllib.request.urlopen(self.gamesdb_info["cover"])
         input_stream = Gio.MemoryInputStream.new_from_data(
             response.read(), None)
         pixbuf = GdkPixbuf.Pixbuf.new_from_stream(input_stream, None)
         pixbuf = pixbuf.scale_simple(340, 480,
                                      GdkPixbuf.InterpType.BILINEAR)
         GLib.idle_add(self.image.set_from_pixbuf, pixbuf)
     else:
         thumbnail_path = os.path.join(THUMBNAIL_DIR,
                                       "{}.jpg".format(self.game.id))
         if not os.path.isfile(thumbnail_path) and self.game.is_installed:
             thumbnail_path = os.path.join(self.game.install_dir,
                                           "thumbnail.jpg")
         GLib.idle_add(self.image.set_from_file, thumbnail_path)
Example #12
0
 def __add_games_from_api(self):
     retrieved_games, err_msg = self.api.get_library()
     if not err_msg:
         self.offline = False
     else:
         self.offline = True
         GLib.idle_add(self.parent.show_error,
                       _("Failed to retrieve library"), _(err_msg))
     for game in retrieved_games:
         if game not in self.games:
             self.games.append(game)
         elif self.games[self.games.index(game)].id == 0 or self.games[
                 self.games.index(game)].name != game.name:
             self.games[self.games.index(game)].id = game.id
             self.games[self.games.index(game)].name = game.name
         self.games[self.games.index(game)].image_url = game.image_url
         self.games[self.games.index(game)].url = game.url
Example #13
0
    def __update_library(self):
        GLib.idle_add(self.__load_tile_states)
        self.owned_products_ids = self.api.get_owned_products_ids()
        # Get already installed games first
        self.games = self.__get_installed_games()
        GLib.idle_add(self.__create_gametiles)

        # Get games from the API
        self.__add_games_from_api()
        GLib.idle_add(self.__create_gametiles)
        GLib.idle_add(self.filter_library)
Example #14
0
 def set_progress(self, percentage: int):
     if self.current_state in [self.state.QUEUED, self.state.INSTALLED]:
         GLib.idle_add(self.update_to_state, self.state.DOWNLOADING)
         self.__create_progress_bar()
     if self.progress_bar:
         GLib.idle_add(self.progress_bar.set_fraction, percentage / 100)
         GLib.idle_add(self.progress_bar.set_tooltip_text, "{}%".format(percentage))
Example #15
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
Example #16
0
 def __uninstall_game(self):
     GLib.idle_add(self.update_to_state, self.state.UNINSTALLING)
     uninstall_game(self.game)
     GLib.idle_add(self.update_to_state, self.state.DOWNLOADABLE)
     GLib.idle_add(self.reload_state)
Example #17
0
 def __install_dlc(self, save_location, dlc_title):
     install_success = self.__install(save_location, dlc_title=dlc_title)
     if not install_success:
         GLib.idle_add(self.update_to_state, self.state.INSTALLED)
     self.__check_for_update_dlc()
Example #18
0
 def __cancel(self, to_state):
     self.download_list = []
     GLib.idle_add(self.update_to_state, to_state)
     GLib.idle_add(self.reload_state)
Example #19
0
 def __cancel(self, to_state):
     GLib.idle_add(self.update_to_state, to_state)
     GLib.idle_add(self.reload_state)
Example #20
0
 def set_progress(self, percentage: int):
     if self.current_state == self.state.QUEUED:
         GLib.idle_add(self.update_to_state, self.state.DOWNLOADING)
     if self.progress_bar:
         GLib.idle_add(self.progress_bar.set_fraction, percentage / 100)