def __init__(self, parent): Gtk.Dialog.__init__(self, title=_("Preferences"), parent=parent, modal=True) self.parent = parent self.__set_language_list() self.button_file_chooser.set_filename(Config.get("install_dir")) self.switch_keep_installers.set_active(Config.get("keep_installers")) self.switch_stay_logged_in.set_active(Config.get("stay_logged_in")) self.switch_show_fps.set_active(Config.get("show_fps")) self.switch_show_windows_games.set_active(Config.get("show_windows_games")) self.switch_create_shortcuts.set_active(Config.get("create_shortcuts")) self.switch_install_dlcs.set_active(Config.get("install_dlcs")) self.switch_automatic_updates.set_active(Config.get("automatic_updates")) self.switch_do_not_show_backgrounds.set_active(Config.get("do_not_show_backgrounds")) self.switch_do_not_show_media_tab.set_active(Config.get("do_not_show_media_tab")) # Set tooltip for keep installers label installer_dir = os.path.join(self.button_file_chooser.get_filename(), "installer") self.label_keep_installers.set_tooltip_text( _("Keep installers after downloading a game.\nInstallers are stored in: {}").format(installer_dir) ) # Only allow showing Windows games if wine is available if not shutil.which("wine"): self.switch_show_windows_games.set_sensitive(False) self.switch_show_windows_games.set_tooltip_text( _("Install Wine to enable this feature") )
def __init__(self, parent, library: Library, api: Api): Gtk.Viewport.__init__(self) self.parent = parent self.api = api self.library = library self.library_mode = "list" self.show_installed_only = None # Set library view mode if (Config.get("viewas") == "list"): self.library_mode = "list" self.library_mode_button.set_image(self.image_view_as_grid) self.library_mode_button.set_tooltip_text(_("View as Grid")) self.library_viewport.add(self.listbox) else: self.library_mode = "grid" self.library_mode_button.set_image(self.image_view_as_list) self.library_mode_button.set_tooltip_text(_("View as List")) self.library_viewport.add(self.flowbox) # load library in background current_os = platform.system() if current_os == "Linux": self.ck_os_linux.set_active(True) elif current_os == "Windows": self.ck_os_windows.set_active(True) elif current_os == "Darwin": self.ck_os_mac.set_active(True)
def __finish_download(self, args): treeiter: Gtk.TreeIter = args[0] if len(args) > 0 else None dlc = args[1] if len(args) > 1 else None if treeiter is None or dlc is None: self.downloadstree.get_model().set_value(treeiter, 6, _("Installable")) return self.downloadstree.get_model().set_value(treeiter, 6, _("Installing")) if dlc is not None: # install DLC try: if os.path.exists(dlc.keep_path): install_game(dlc, dlc.keep_path, main_window=self.parent) else: install_game(dlc, dlc.download_path, main_window=self.parent) except (FileNotFoundError, BadZipFile): # error, revert state self.downloadstree.get_model().set_value( treeiter, 6, _("Installable")) return # No error, install was successful, as such update information self.game.set_dlc_status(dlc.name, "installed", dlc.available_version) self.downloadstree.get_model().set_value(treeiter, 6, _("Installed"))
def on_menu_button_support(self, widget): try: webbrowser.open(self.api.get_info(self.game)['links']['support'], new=2) except: self.parent.parent.show_eror( _("Couldn't open support page"), _("Please check your internet connection"))
def update_options(self): # hide all menu buttons self.menu_button_update.hide() self.menu_button_store.show() self.menu_button_support.show() self.menu_button_settings.hide() self.menu_button_open.hide() self.menu_button_uninstall.hide() self.menu_button_cancel.hide() self.menu_button.hide() # configure button label and available options if (self.current_state == self.game.state.INSTALLED or self.current_state == self.game.state.UPDATABLE): self.button.set_label(_("play")) self.menu_button_uninstall.show() self.menu_button_open.show() self.menu_button.show() elif (self.current_state == self.game.state.DOWNLOADABLE): self.button.set_label(_("download")) elif (self.current_state == self.game.state.DOWNLOADING or self.current_state == self.game.state.UPDATE_DOWNLOADING): self.button.set_label(_("downloading..")) self.menu_button_cancel.show() elif (self.current_state == self.game.state.QUEUED): self.button.set_label(_("in queue..")) self.menu_button_cancel.show() elif (self.current_state == self.game.state.UPDATE_QUEUED): self.menu_button_cancel.show() elif (self.current_state == self.game.state.INSTALLING): self.button.set_label(_("installing..")) elif (self.current_state == self.game.state.UNINSTALLING): self.button.set_label(_("uninstalling..")) elif (self.current_state == self.game.state.UPDATING): self.button.set_label(_("updating..")) self.menu_button_uninstall.show() self.menu_button_open.show() # special cases if self.game.installed > 0 and self.game.updates is not None and self.game.updates > 0: self.update_icon.show() else: self.update_icon.hide() if self.game.installed == 1 and self.game.updates is not None and self.game.updates > 0: # figure out if we should fetch or install the update if (self.current_state == self.game.state.UPDATABLE or self.current_state == self.game.state.INSTALLED): self.menu_button_update.set_label(_("Download Update")) elif (self.current_state == self.game.state.UPDATE_INSTALLABLE): self.menu_button_update.set_label(_("Install Update")) else: self.menu_button_update.set_label(_("Update")) self.menu_button_update.show() if not self.game.url: self.menu_button_store.hide() if self.game.platform == "windows": self.menu_button_settings.show()
def on_menu_button_uninstall(self, widget): if not self.parent.uninstall_game(self.game): return # user clicked on OK self.update_options() # reset status for downloads table for row in self.downloadstree.get_model(): if row[3] == _("Installer"): row[6] = _("Install") else: row[6] = _("N/A")
def set_state(self, state): if state == state.DOWNLOADING: self.download_action_image.set_from_icon_name("media-playback-pause",4) self.download_action_image.set_tooltip_text(_("Pause")) elif state == state.QUEUED: self.download_action_image.set_from_icon_name("image-loading",4) self.download_action_image.set_tooltip_text(_("Queued")) elif state == state.PAUSED: self.download_action_image.set_from_icon_name("media-playback-start",4) self.download_action_image.set_tooltip_text(_("Resume")) else: self.download_action_image.set_from_icon_name("dialog-cancel",4) self.download_action_image.set_tooltip_text(_("Remove"))
def on_menu_button_support(self, widget): try: webbrowser.open(self.api.get_info(self.game)['links']['support'], new=2) except: dialog = Gtk.MessageDialog(message_type=Gtk.MessageType.ERROR, parent=self.parent, modal=True, buttons=Gtk.ButtonsType.OK, text=_("Couldn't open support page")) dialog.format_secondary_text( _("Please check your internet connection")) dialog.run() dialog.destroy()
def on_goodies_button_pressed(self, widget: Gtk.Widget, event: Gdk.EventButton): if event.get_event_type( ) == Gdk.EventType.BUTTON_PRESS and event.get_button( ).button == Gdk.BUTTON_SECONDARY: # find out what was selected res = self.goodiestree.get_path_at_pos(event.x, event.y) link = None fname = None if res is not None: path = res[0] treeiter: Gtk.TreeIter = self.goodiestree.get_model().get_iter( path) link = self.goodiestree.get_model().get_value(treeiter, 5) fname = self.goodiestree.get_model().get_value(treeiter, 0) # find out what was selected menu: Gtk.Menu = Gtk.Menu() download_item: Gtk.MenuItem = Gtk.MenuItem.new_with_label( _("Download")) download_item.connect("activate", self.__download_file, link, fname) menu.add(download_item) menu.attach_to_widget(self.goodiestree) menu.show_all() menu.popup(None, None, None, None, event.button, event.time) return False
def __state_func(self, state, treeiter: Gtk.TreeIter = None): if treeiter is None: return val = self.downloadstree.get_model().get_value(treeiter, 6) if state == state.DOWNLOADING: val = _("Downloading") elif state == state.QUEUED: val = _("Queued") elif state == state.PAUSED: val = _("Paused") elif state == state.FINISHED: val = _("Installable") elif state == state.ERROR or state == state.CANCELED: val = _("Install") self.downloadstree.get_model().set_value(treeiter, 6, val)
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()) Config.set("create_shortcuts", self.switch_create_shortcuts.get_active()) Config.set("install_dlcs", self.switch_install_dlcs.get_active()) Config.set("automatic_updates", self.switch_automatic_updates.get_active()) Config.set("do_not_show_backgrounds",self.switch_do_not_show_backgrounds.get_active()) Config.set("do_not_show_media_tab",self.switch_do_not_show_media_tab.get_active()) if self.switch_show_windows_games.get_active() != Config.get("show_windows_games"): 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: dialog = Gtk.MessageDialog( parent=self, modal=True, destroy_with_parent=True, message_type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, text=_("{} isn't a usable path").format(self.button_file_chooser.get_filename()) ) dialog.run() dialog.destroy() self.destroy()
def change_view_mode(self, button): iconname = self.library_mode_button.get_image().get_icon_name( ).icon_name if (iconname == "view-list-symbolic"): Config.set("viewas", "list") self.library_mode = "list" self.library_mode_button.set_image(self.image_view_as_grid) self.library_mode_button.set_tooltip_text(_("View as Grid")) self.view_as_list() else: Config.set("viewas", "grid") self.library_mode = "grid" self.library_mode_button.set_image(self.image_view_as_list) self.library_mode_button.set_tooltip_text(_("View as List")) self.view_as_grid() self.sync_library()
def __init__(self, parent): Gtk.AboutDialog.__init__(self, title=_("About"), parent=parent, modal=True) self.set_version(VERSION) new_image = GdkPixbuf.Pixbuf().new_from_file(LOGO_IMAGE_PATH) self.set_logo(new_image)
def __show_library(self): self.selection_button.hide() self.selection_label.set_text(_("Library")) # first remove any existing child if len(self.selection_window.get_children()) > 0: self.selection_window.remove( self.selection_window.get_children()[0]) self.details = None self.selection_window.add(self.library_view)
def __install_file(self, widget, link: str, ftype: str = None, product_id: int = None, fsize: int = 0, treeiter: Gtk.TreeIter = None): if (ftype == _("Installer")): # just follow the default path self.parent.download_game(self.game) elif ftype == "DLC " + _("Installer"): dlc = None if product_id is not None: for i in self.game.dlcs: if i.id == product_id: dlc = i break if dlc is not None: dlc.platform = self.downloadstree.get_model().get_value( treeiter, 10) dlc.language = DOWNLOAD_LANGUAGES_TO_GOG_CODE[ self.downloadstree.get_model().get_value(treeiter, 2)] dlc.available_version = self.downloadstree.get_model( ).get_value(treeiter, 5) download = Download(url=self.api.get_real_download_link(link), save_location=dlc.download_path, title=dlc.name, associated_object=dlc, file_size=fsize) else: # fallback to game as source of generic information download = Download(url=self.api.get_real_download_link(link), save_location=self.game.download_path, title=self.game.name, associated_object=self.game, file_size=fsize) download.register_finish_function(self.__finish_download, [treeiter, dlc]) download.register_state_function(self.__state_func, treeiter) DownloadManager.download(download) print("Downloading: \"{}\"".format(link))
def start_game(game, parent_window=None): error_message = "" process = None if not error_message: error_message = set_fps_display() if not error_message: error_message, process = run_game_subprocess(game) if not error_message: error_message = check_if_game_started_correctly(process, game) if error_message: print(_("Failed to start {}:").format(game.name)) print(error_message) return error_message
def __show_installation_error(game, message, parent_window=None, main_window=None): error_message = [_("Failed to install {}").format(game.name), message] print("{}: {}".format(error_message[0], error_message[1])) parent = main_window if main_window is not None else parent_window.parent dialog = Gtk.MessageDialog(message_type=Gtk.MessageType.ERROR, parent=parent, modal=True, buttons=Gtk.ButtonsType.CLOSE, text=error_message[0]) dialog.format_secondary_text(error_message[1]) dialog.run() dialog.destroy()
def __init__(self, name): Gtk.ApplicationWindow.__init__(self, title=name) self.api = Api() self.offline = False self.library = Library(self.api) self.games = [] self.library_view = LibraryView(self, library=self.library, api=self.api) self.details = None res = self.get_screen_resolution() # we got resolution if res[0] > 0 and res[0] <= 1368: self.set_default_size(1024, 700) # Set the icon icon = GdkPixbuf.Pixbuf.new_from_file(LOGO_IMAGE_PATH) self.set_default_icon_list([icon]) self.installed_search.connect("search-changed", self.filter_installed) self.selection_button.hide() # Show the window self.show_all() self.selection_button.hide() self.selection_label.set_text(_("Library")) if not os.path.exists(CACHE_DIR): os.makedirs(CACHE_DIR) # Create the thumbnails directory if not os.path.exists(THUMBNAIL_DIR): os.makedirs(THUMBNAIL_DIR) # Interact with the API self.__authenticate() self.user_photo.set_tooltip_text( self.api.get_user_info(self.__set_avatar)) self.sync_library() # Check what was the last view if Config.get("last_view") == "Game": print("last view as game..") else: self.__show_library() # Register self as a download manager listener DownloadManager.register_listener(self.__download_listener_func)
def __init__(self, login_url=None, redirect_url=None, parent=None): Gtk.Dialog.__init__(self, title=_("Login"), parent=parent, flags=0, buttons=()) self.redirect_url = redirect_url context = WebKit2.WebContext.new() webview = WebKit2.WebView.new_with_context(context) webview.load_uri(login_url) webview.connect('load-changed', self.on_navigation) self.box.pack_start(webview, True, True, 0) self.show_all()
def __init__(self, parent, game, api): Gtk.Frame.__init__(self) self.parent = parent self.game = game self.api = api self.progress_bar = None self.thumbnail_set = False self.title_label.set_text(self.game.name) self.current_state = self.game.state self.last_played_label.set_text(_("Not yet played")) self.load_icon() # Icon if update is available self.update_options()
def run_game_subprocess(game): # Change the directory to the install dir working_dir = os.getcwd() os.chdir(game.install_dir) try: process = subprocess.Popen(get_execute_command(game), stdout=subprocess.PIPE, stderr=subprocess.PIPE) error_message = "" except FileNotFoundError: process = None error_message = _("No executable was found in {}").format( game.install_dir) # restore the working directory os.chdir(working_dir) return error_message, process
def cancel_download(self, game: Game = None): message_dialog = Gtk.MessageDialog( parent=self, 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( game.name)) response = message_dialog.run() if response == Gtk.ResponseType.OK: self.prevent_resume_on_startup(game) cancel_thread = threading.Thread(target=self.__cancel_download, args=[game]) cancel_thread.start() message_dialog.destroy()
def __download_file(self, widget, link: str, fname: str = None): dialog: Gtk.FileChooserDialog = Gtk.FileChooserDialog( _("Download"), self.parent, action=Gtk.FileChooserAction.SAVE, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.ACCEPT)) file_name = link[link.rfind("/") + 1:] if fname is None else fname dialog.set_current_name(file_name) response = dialog.run() if response == Gtk.ResponseType.ACCEPT: download = Download(url=self.api.get_real_download_link(link), save_location=dialog.get_filename()) DownloadManager.download(download) print("Downloading: \"{}\" to \"{}\"".format( link, dialog.get_filename())) dialog.destroy()
def uninstall_game(self, game: Game) -> bool: message_dialog = Gtk.MessageDialog( parent=self, flags=Gtk.DialogFlags.MODAL, message_type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.OK_CANCEL, message_format=_("Are you sure you want to uninstall %s?" % game.name)) response = message_dialog.run() if response == Gtk.ResponseType.OK: uninstall_thread = threading.Thread(target=self.__uninstall_game, args=[game]) uninstall_thread.start() message_dialog.destroy() return True elif response == Gtk.ResponseType.CANCEL: message_dialog.destroy() return False
import requests import platform from goodoldgalaxy.translation import _ from goodoldgalaxy.version import VERSION from goodoldgalaxy.paths import DEFAULT_INSTALL_DIR SUPPORTED_DOWNLOAD_LANGUAGES = [["br", _("Brazilian Portuguese")], ["cn", _("Chinese")], ["da", _("Danish")], ["nl", _("Dutch")], ["en", _("English")], ["fi", _("Finnish")], ["fr", _("French")], ["de", _("German")], ["hu", _("Hungarian")], ["it", _("Italian")], ["jp", _("Japanese")], ["ko", _("Korean")], ["no", _("Norwegian")], ["pl", _("Polish")], ["pt", _("Portuguese")], ["ru", _("Russian")], ["es", _("Spanish")], ["sv", _("Swedish")], ["tr", _("Turkish")]] DOWNLOAD_LANGUAGES_TO_GOG_CODE = { _("Brazilian Portuguese"): "br", _("Chinese"): "cn", _("Danish"): "da", _("Dutch"): "nl", _("English"): "en", _("Finnish"): "fi", _("French"): "fr",
def set_game(self, game: Game = None): """ Sets the game to display Parameters: ----------- game: Game -> Game instance to display """ # bail out if game was not set or we are doing the same game if game is None or self.game == game: return self.game = game self.progress_bar = None self.download = None self.current_state = self.game.state # Update paths for current game # Set folder for download installer self.download_path = os.path.join(self.download_dir, self.game.name) # Set folder for update installer self.update_path = os.path.join(self.update_dir, self.game.name) # Set folder if user wants to keep installer (disabled by default) self.keep_path = os.path.join(self.keep_dir, self.game.name) # reload game state self.reload_state() # Icon if update is available self.update_icon.hide() if self.game.installed == 1 and self.game.updates is not None and self.game.updates > 0: self.update_icon.show() # Hide the store icon if there is no game URL if not self.game.url: self.menu_button_store.hide() # Show platform icons that match supported platforms if ("linux" in game.supported_platforms): self.image_os_linux.show() if ("windows" in game.supported_platforms): self.image_os_windows.show() if ("mac" in game.supported_platforms): self.image_os_mac.show() # Handle game genres genres = "" idx = 0 glen = len(game.genres) for genre in game.genres: if len(genre.strip()) == 0: continue genres += genre if idx < glen - 1: genres += ", " idx += 1 if idx > 0: self.genres_label.show() self.genres_header.show() self.genres_label.set_text(genres) else: self.genres_label.hide() self.genres_header.hide() # Set game installed version if game.installed_version and game.installed_version is not None and game.installed_version != "": self.installed_version_label.show() self.installed_version_label.set_text(game.installed_version) else: self.installed_version_label.hide() # Handle game languages languages = "" idx = 0 glen = len(game.supported_languages) for language in game.supported_languages: languages += language if idx < glen - 1: languages += ", " idx += 1 if idx > 0: self.languages_header.show() self.languages_label.show() self.languages_label.set_text(languages) else: self.languages_header.hide() self.languages_label.hide() # Set game release date if game.release_date is not None and game.release_date != "": dt = None if isinstance(game.release_date, str): dt = datetime.datetime.strptime(game.release_date, '%Y-%m-%dT%H:%M:%S%z') elif isinstance(game.release_date, dict): dt = datetime.datetime.strptime(game.release_date["date"], '%Y-%m-%d %H:%M:%S.%f') if dt is not None: self.release_date_header.show() self.release_date_label.show() self.release_date_label.set_text(dt.strftime('%Y-%m-%d')) else: self.release_date_header.hide() self.release_date_label.hide() # grab game details from api self.response = self.api.get_info(game) # Game description if "description" in self.response: # note this is self.description_header.show() self.description_label.show() self.description_label.set_property("use-markup", True) #self.description_lead_label.set_text(self.response["description"]["lead"]) try: desc = self.__cleanup_html( self.response["description"]["full"]) self.description_label.set_markup(desc) except Exception as e: print(e) else: self.description_header.hide() self.description_label.hide() # changelog if "changelog" in self.response: try: text = self.__cleanup_html(self.response["changelog"]) self.changelog.get_buffer().set_text(text) # show the tab self.notebook.get_nth_page(1).show() except Exception as e: print(e) else: # hide the tab self.notebook.get_nth_page(1).hide() self.changelog.get_buffer().set_text("") # first remove existing media while len(self.media_flowbox.get_children()) > 0: child = self.media_flowbox.get_children()[0] self.media_flowbox.remove(child) # destroy child which is a gtk image to see if we can get back some memory child.destroy() # screenshots sidx = 0 # Only handle the media tab if requested if Config.get("do_not_show_media_tab") == False: if "screenshots" in self.response: for screenshot in self.response["screenshots"]: sidx += 1 image_id = screenshot["image_id"] template = screenshot["formatter_template_url"] image_url = template.replace("{formatter}", "ggvgt_2x").replace( ".png", ".jpg") self.__add_screenshot(image_id, image_url) # videos vidx = 0 if "videos" in self.response: for video in self.response["videos"]: thumbnail_url = video["thumbnail_url"] video_url = video["video_url"] self.__add_video(vidx, video_url, thumbnail_url) sidx += 1 if sidx == 0: self.media_bar.hide() self.media_flowbox.hide() else: self.media_bar.show() self.media_flowbox.show() # first remove any existing downloads if self.downloadstree is not None and self.downloadstree.get_model( ) is not None: # clear the store self.downloadstree.get_model().get_model().clear() # remove columns while len(self.downloadstree.get_columns()) > 0: self.downloadstree.remove_column( self.downloadstree.get_columns()[0]) if self.goodiestree is not None and self.goodiestree.get_model( ) is not None: # clear the store self.goodiestree.get_model().clear() # remove columns while len(self.goodiestree.get_columns()) > 0: self.goodiestree.remove_column( self.goodiestree.get_columns()[0]) # downloads didx = 0 gidx = 0 #GdkPixbuf.Pixbuf downloads_store = Gtk.ListStore(str, str, str, str, str, str, str, str, int, str, str) downloads_cols = [ _("Name"), _("OS"), _("Language"), _("Type"), _("Size"), _("Version"), _("State"), "Location", "Id", "File Size", "Operating System" ] goodies_store = Gtk.ListStore(str, str, str, str, str, str) goodies_cols = [ _("Name"), _("Category"), _("Type"), _("Size"), _("Count"), _("Location") ] self.downloads_languages = set() self.downloads_os = [] self.download_links = [] self.goodies_links = [] if "downloads" in self.response: downloads = self.response["downloads"] for dltype in downloads: is_goodies = True if dltype == "bonus_content" else False items = downloads[dltype] download_type = DL_TYPES[dltype] for item in items: if is_goodies: gidx += 1 links = self.__append_to_list_store_for_download( goodies_store, item, download_type, is_goodies) for link in links: self.goodies_links.append(link) else: didx += 1 state = "N/A" if self.game.installed == 1: if self.game.installed_version == item["version"]: state = _("Installed") else: state = _("Update Available") links = self.__append_to_list_store_for_download( downloads_store, item, download_type, state=state, product_id=self.game.id, file_size=item["total_size"]) for link in links: self.download_links.append(link) if "expanded_dlcs" in self.response: dlcs = self.response["expanded_dlcs"] for dlc in dlcs: downloads = dlc["downloads"] for dltype in downloads: is_goodies = True if dltype == "bonus_content" else False items = downloads[dltype] download_type = DL_TYPES[dltype] for item in items: if is_goodies: gidx += 1 links = self.__append_to_list_store_for_download( goodies_store, item, "DLC " + download_type, is_goodies) for link in links: self.goodies_links.append(link) else: didx += 1 state = self.game.get_dlc_status( item["name"], item["version"] ) if self.game.installed > 0 else "N/A" if state == "installed": state = _("Installed") elif state == "updatable": state = _("Update Available") elif state == "not-installed": state = _("Install") links = self.__append_to_list_store_for_download( downloads_store, item, "DLC " + download_type, state=state, product_id=dlc["id"], file_size=item["total_size"]) # add game to dlc list self.game.add_dlc_from_json(dlc) for link in links: self.download_links.append(link) if (didx > 0): self.downloads_filter = downloads_store.filter_new() self.downloads_filter.set_visible_func(self.__downloads_filter, data=None) self.downloadstree.set_model(self.downloads_filter) self.__create_tree_columns(self.downloadstree, downloads_cols) for lang in self.downloads_languages: ck = Gtk.CheckButton(lang) ck.set_active( lang == IETF_DOWNLOAD_LANGUAGES[Config.get("lang")]) ck.connect("toggled", self.downloads_filter_changed) self.languagebox.pack_start(ck, False, True, 10) self.languagebox.show_all() self.downloads_header_box.show_all() self.downloadstree.show_all() # re-filter downloads self.downloads_filter.refilter() else: self.languagebox.hide() self.downloads_header_box.hide() self.downloadstree.hide() if (gidx > 0): self.goodiestree.set_model(goodies_store) self.__create_tree_columns(self.goodiestree, goodies_cols, True) self.goodies_header.show() self.goodiestree.show_all() else: self.goodies_header.hide() self.goodiestree.hide() # handle achievements self.load_achievements() # load the background image self.__background_width = None if self.background_image is not None: self.background_image.clear() if Config.get("do_not_show_backgrounds") == False: self.background_image.show() self.__load_background_image() else: self.background_image.hide()
def on_downloads_button_pressed(self, widget: Gtk.Widget, event: Gdk.EventButton): if event.get_event_type( ) == Gdk.EventType.BUTTON_PRESS and event.get_button( ).button == Gdk.BUTTON_SECONDARY: # find out what was selected res = self.downloadstree.get_path_at_pos(event.x, event.y) state = None link = None fname = None ftype = None fsize = -1 if res is not None: path = res[0] treeiter: Gtk.TreeIter = self.downloadstree.get_model( ).get_iter(path) fname = self.downloadstree.get_model().get_value(treeiter, 0) ftype = self.downloadstree.get_model().get_value(treeiter, 3) state = self.downloadstree.get_model().get_value(treeiter, 6) link = self.downloadstree.get_model().get_value(treeiter, 7) pid = self.downloadstree.get_model().get_value(treeiter, 8) fsize = self.downloadstree.get_model().get_value(treeiter, 9) # find out what was selected menu: Gtk.Menu = Gtk.Menu() if state == _("Update Available"): update_item: Gtk.MenuItem = Gtk.MenuItem.new_with_label( _("Update")) menu.add(update_item) if ftype == _("Installer") and (state == _("Update Available") or state == _("Installed")): uninstall_item: Gtk.MenuItem = Gtk.MenuItem.new_with_label( _("Uninstall")) uninstall_item.connect("activate", self.on_menu_button_uninstall) menu.add(uninstall_item) if (ftype == _("Installer") or (ftype != _("Installer") and self.game.installed == 1)) and ( state == None or state == _("N/A") or state == "" or state == "Install"): install_item: Gtk.MenuItem = Gtk.MenuItem.new_with_label( _("Install")) install_item.connect("activate", self.__install_file, link, ftype, pid, fsize, treeiter) menu.add(install_item) download_item: Gtk.MenuItem = Gtk.MenuItem.new_with_label( _("Download")) download_item.connect("activate", self.__download_file, link, fname) menu.add(download_item) menu.attach_to_widget(self.downloadstree) menu.show_all() menu.popup(None, None, None, None, event.button, event.time) return False
def install_game(game, installer, parent_window=None, main_window=None) -> None: if not os.path.exists(installer): GLib.idle_add(__show_installation_error, game, _("{} failed to download.").format(installer), parent_window, main_window) raise FileNotFoundError( "The installer {} does not exist".format(installer)) if game.platform == "linux": if not __verify_installer_integrity(installer): GLib.idle_add( __show_installation_error, game, _("{} was corrupted. Please download it again.").format( installer), parent_window, main_window) os.remove(installer) raise FileNotFoundError( "The installer {} was corrupted".format(installer)) # Make sure the install directory exists library_dir = Config.get("install_dir") if not os.path.exists(library_dir): os.makedirs(library_dir) # Make a temporary empty directory for extracting the installer extract_dir = os.path.join(CACHE_DIR, "extract") temp_dir = os.path.join(extract_dir, str(game.id)) if os.path.exists(extract_dir): shutil.rmtree(extract_dir, ignore_errors=True) os.makedirs(temp_dir, mode=0o755) # Extract the installer subprocess.call(["unzip", "-qq", installer, "-d", temp_dir]) if len(os.listdir(temp_dir)) == 0: GLib.idle_add(__show_installation_error, game, _("{} could not be unzipped.").format(installer), parent_window, main_window) raise CannotOpenZipContent( "{} could not be unzipped.".format(installer)) # Make sure the install directory exists library_dir = Config.get("install_dir") if not os.path.exists(library_dir): os.makedirs(library_dir, mode=0o755) # Copy the game files into the correct directory tmp_noarch_dir = os.path.join(temp_dir, "data/noarch") copytree(tmp_noarch_dir, game.install_dir) if game.type == "game" and Config.get("create_shortcuts") == True: create_shortcuts(game) # Remove the temporary directory shutil.rmtree(temp_dir, ignore_errors=True) elif game.platform == "windows": # Set the prefix for Windows games prefix_dir = os.path.join(game.install_dir, "prefix") if not os.path.exists(prefix_dir): os.makedirs(prefix_dir, mode=0o755) os.environ["WINEPREFIX"] = prefix_dir # It's possible to set install dir as argument before installation command = ["wine", installer, "/dir=" + game.install_dir] process = subprocess.Popen(command) process.wait() if process.returncode != 0: GLib.idle_add( __show_installation_error, game, _("The installation of {} failed. Please try again.").format( installer), main_window) return else: GLib.idle_add(__show_installation_error, game, _("{} platform not supported.").format(installer), parent_window, main_window) raise Exception("Platform not supported") thumbnail_small = os.path.join(THUMBNAIL_DIR, "{}_100.jpg".format(game.id)) thumbnail_medium = os.path.join(THUMBNAIL_DIR, "{}_196.jpg".format(game.id)) if os.path.exists(thumbnail_small): shutil.copyfile(thumbnail_small, os.path.join(game.install_dir, "thumbnail_100.jpg")) if os.path.exists(thumbnail_medium): shutil.copyfile(thumbnail_medium, os.path.join(game.install_dir, "thumbnail_196.jpg")) if Config.get("keep_installers"): keep_dir = os.path.join(Config.get("install_dir"), "installer") download_dir = os.path.join(CACHE_DIR, "download") update_dir = os.path.join(CACHE_DIR, "update") if not os.path.exists(keep_dir): os.makedirs(keep_dir, mode=0o755) try: # It's needed for multiple files for file in os.listdir(download_dir): shutil.move(download_dir + '/' + file, keep_dir + '/' + file) except Exception as ex: print("Encountered error while copying {} to {}. Got error: {}". format(installer, keep_dir, ex)) try: # It's needed for multiple files for file in os.listdir(update_dir): shutil.move(update_dir + '/' + file, keep_dir + '/' + file) except Exception as ex: print("Encountered error while copying {} to {}. Got error: {}". format(installer, keep_dir, ex)) else: os.remove(installer) # finish up game.istalled = 1 game.updates = 0