Exemple #1
0
    def __save_install_dir_choice(self) -> bool:
        choice = self.button_file_chooser.get_filename()
        old_dir = Config.get("install_dir")
        if choice == old_dir:
            return True

        if not os.path.exists(choice):
            try:
                os.makedirs(choice)
            except:
                return False
        else:
            write_test_file = os.path.join(choice, "write_test.txt")
            try:
                with open(write_test_file, "w") as file:
                    file.write("test")
                    file.close()
                os.remove(write_test_file)
            except:
                return False
        # Remove the old directory if it is empty
        try:
            os.rmdir(old_dir)
        except OSError:
            pass

        Config.set("install_dir", choice)
        return True
Exemple #2
0
 def get_user_info(self, finish_fn=None) -> str:
     username = Config.get("username")
     userid = Config.get("user_id")
     avatar = None
     if userid is not None:
         user_dir = os.path.join(CACHE_DIR, "user/{}".format(userid))
         if os.path.exists(user_dir) == False:
             os.makedirs(user_dir)
         avatar = os.path.join(user_dir, "avatar_menu_user_av_small.jpg")
         if not (os.path.isfile(avatar) and os.path.exists(avatar)):
             avatar = None
         if (avatar is not None and finish_fn is not None):
             finish_fn()
     if not username or not avatar:
         url = "https://embed.gog.com/userData.json"
         response = self.__request(url)
         username = response["username"]
         userid = response["userId"]
         Config.set("user_id", userid)
         Config.set("username", username)
         user_dir = os.path.join(CACHE_DIR, "user/{}".format(userid))
         if os.path.exists(user_dir) == False:
             os.makedirs(user_dir)
         avatar = os.path.join(user_dir, "avatar_menu_user_av_small.jpg")
         download = Download(response["avatar"] + "_menu_user_av_small.jpg",
                             avatar)
         download.register_finish_function(finish_fn)
         DownloadManager.download_now(download)
     return username
Exemple #3
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)
Exemple #4
0
 def test_set(self, mock_isfile):
     mock_isfile.return_value = True
     config = JSON_DEFAULT_CONFIGURATION
     with patch("builtins.open", mock_open(read_data=config)):
         from goodoldgalaxy.config import Config
         Config.set("lang", "pl")
         lang = Config.get("lang")
     exp = "pl"
     obs = lang
     self.assertEqual(exp, obs)
Exemple #5
0
 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()
Exemple #6
0
    def __request(self, url: str = None, params: dict = None) -> tuple:
        # Refresh the token if needed
        if self.active_token_expiration_time < time.time():
            print("Refreshing token")
            refresh_token = Config.get("refresh_token")
            Config.set("refresh_token", self.__refresh_token(refresh_token))

        # Make the request
        headers = {
            'Authorization': "Bearer " + self.active_token,
        }
        response = SESSION.get(url, headers=headers, params=params)
        if self.debug:
            print("Request: {}".format(url))
            print("Return code: {}".format(response.status_code))
            print("Response body: {}".format(response.text))
            print("")
        return response.json()
Exemple #7
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)
Exemple #8
0
    def __authenticate(self):
        url = None
        if Config.get("stay_logged_in"):
            token = Config.get("refresh_token")
        else:
            Config.unset("username")
            Config.unset("user_id")
            Config.unset("refresh_token")
            token = None

        # Make sure there is an internet connection
        if not self.api.can_connect():
            return

        try:
            authenticated = self.api.authenticate(refresh_token=token,
                                                  login_code=url)
        except Exception as ex:
            print("Could not authenticate with GOG. Cause: {}".format(ex))
            return

        while not authenticated:
            login_url = self.api.get_login_url()
            redirect_url = self.api.get_redirect_url()
            login = Login(login_url=login_url,
                          redirect_url=redirect_url,
                          parent=self)
            response = login.run()
            login.hide()
            if response == Gtk.ResponseType.DELETE_EVENT:
                Gtk.main_quit()
                exit(0)
            if response == Gtk.ResponseType.NONE:
                result = login.get_result()
                authenticated = self.api.authenticate(refresh_token=token,
                                                      login_code=result)

        Config.set("refresh_token", authenticated)
Exemple #9
0
 def __save_language_choice(self) -> None:
     lang_choice = self.combobox_language.get_active_iter()
     if lang_choice is not None:
         model = self.combobox_language.get_model()
         lang, _ = model[lang_choice][:2]
         Config.set("lang", lang)
Exemple #10
0
    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()