Exemplo n.º 1
0
    def on_login_activated(self):
        email = self.username_field.get_text().strip()
        password = self.password_field.get_text().strip()
        if not email or not password:
            return
        self.username_field.set_enabled(False)
        self.password_field.set_enabled(False)
        self.login_button.set_enabled(False)

        task = OGDClient().login_task(email, password)
        # task.progressed.connect(self.progress)
        task.succeeded.connect(self.on_success)
        # task.failed.connect(fsui.error_function(gettext("Login Failed")))
        task.failed.connect(self.on_failure)
        task.start()
Exemplo n.º 2
0
    def main(self):
        self.setProgress("Logging out from openretro.org...")
        OGDClient().deauth(self.authToken)

        Settings.set("error_report_user_id", "")
        Settings.set("database_username", "")
        Settings.set("database_auth", "")

        # Clear legacy key
        Settings.set("database_password", "")
        return

        print("LogoutTask.main")
        self.setProgress("Starting logout process...")
        time.sleep(1)
        if self.isCancelled():
            return
        self.setProgress("Logging out...")
        time.sleep(1)
        if self.isCancelled():
            return
        raise Exception("Fail")
        self.setProgress("Completing...")
        time.sleep(1)
        if self.isCancelled():
            return
        self.setProgress("Done...")
 def set_rating_for_variant(variant_uuid, rating):
     # FIXME: Do asynchronously, add to queue
     client = OGDClient()
     result = client.rate_variant(variant_uuid, like=rating)
     like_rating = result.get("like", 0)
     work_rating = result.get("work", 0)
     database = Database.instance()
     cursor = database.cursor()
     cursor.execute("DELETE FROM rating WHERE game_uuid = ?",
                    (variant_uuid, ))
     cursor.execute(
         "INSERT INTO rating (game_uuid, work_rating, like_rating) "
         "VALUES (?, ?, ?)",
         (variant_uuid, work_rating, like_rating),
     )
     database.commit()
     LauncherSettings.set("__variant_rating", str(like_rating))
Exemplo n.º 4
0
 def __logout_activated(self):
     auth_token = app.settings["database_auth"]
     if auth_token:
         task = OGDClient().logout_task(auth_token)
         # task.progressed.connect(self.progress)
         task.succeeded.connect(self.close)
         # task.failed.connect(fsui.error_function(gettext("Login Failed")))
         task.failed.connect(self.on_failure)
         task.start()
     else:
         # this is not a normal case, no auth token stored, but clear
         # all auth-related settings just in case
         app.settings["database_auth"] = ""
         app.settings["database_username"] = ""
         # app.settings["database_email"] = ""
         app.settings["database_password"] = ""
         self.on_close()
Exemplo n.º 5
0
    def addEventListener(self, eventName, listener):
        if eventName == "destroy":
            self.destroyed.connect(listener)

        # def onLogoutActivated(self):
        #     self.setRunning(True)
        #     authToken = app.settings["database_auth"]

        #     def onResult(result):
        #         print(result)
        #         self.setRunning(False)

        #     def onError(error):
        #         print(error)

        #     def onProgress(progress):
        #         print(progress)
        #         self.errorLabel.set_text(progress.value)

        #     self.addEventListener(
        #         "destroy",
        #         AsyncTaskRunner(onResult, onError, onProgress)
        #         .run(LogoutTask(authToken))
        #         .cancel,
        #     )

        # with AsyncTaskRunner(onResult, onError, onProgress):
        #     LogoutTask(authToken)

        # import time
        # time.sleep(3)
        # self.close()

        # LogoutTask(authToken).start()
        # LogoutTask(authToken).runAsync()

        # AsyncTaskRunner(onResult, onError, onProgress).run(
        #     LogoutTask(authToken)
        # ).cancelOn(self.destroy)

        # self.runTask(LogoutTask(authToken), onProgress, onError, onComplete)

        # self.disposable = (
        #     logoutTask(auth_token)
        #     .pipe(
        #         # rx.operators.subscribe_on(rx.scheduler.EventLoopScheduler()),
        #         rx.operators.subscribe_on(rx.scheduler.NewThreadScheduler()),
        #         rx.operators.observe_on(MainLoopScheduler()),
        #     )
        #     .subscribe(self.onNext, self.onError, self.onCompleted)
        # )
        # #  ).subscribe(self, scheduler=qtScheduler)

        return
        if auth_token:
            task = OGDClient().logout_task(auth_token)
            # task.progressed.connect(self.progress)
            task.succeeded.connect(self.close)
            # task.failed.connect(fsui.error_function(gettext("Login Failed")))
            task.failed.connect(self.on_failure)
            task.start()
        else:
            # this is not a normal case, no auth token stored, but clear
            # all auth-related settings just in case
            app.settings["database_auth"] = ""
            app.settings["database_username"] = ""
            # app.settings["database_email"] = ""
            app.settings["database_password"] = ""
            self.on_close()
 def __init__(self):
     Task.__init__(self, "Locker Uploader Task")
     self.client = OGDClient()
class LockerUploaderTask(Task):
    def __init__(self):
        Task.__init__(self, "Locker Uploader Task")
        self.client = OGDClient()

    def run(self):
        for i in range(16):
            self.upload_prefix(i)
        self.progressed(gettext("Locker upload task completed successfully"))

    def upload_prefix(self, prefix):
        self.stop_check()
        result = self.upload_check(prefix)
        print(len(result))
        for k in range(0, len(result), 20):
            self.stop_check()

            sha1 = result[k:k + 20]
            path = fsgs.file.find_by_sha1(bytes_to_hex(sha1))
            if not path:
                continue
            try:
                # this is done to properly handle encrypted ROMs
                archive = Archive(path)
                # FIXME: Use Archive.open to get support for filter functions
                # FIXME: Also use stream api, do not buffer entire file
                data = ROMManager.decrypt_archive_rom(archive, path)["data"]
            except Exception:
                traceback.print_exc()
                uri = "sha1://{0}".format(bytes_to_hex(sha1))
                print(uri)
                try:
                    input_stream = fsgs.file.open(uri)
                    data = input_stream.read()
                except Exception:
                    continue
                assert not input_stream.read()

            print("uploading file of size ", len(data))

            # self.progressed(gettext("Verifying {name}").format(
            #                 name=bytes_to_hex(sha1)))
            self.progressed(
                gettext("Uploading {name}").format(name=bytes_to_hex(sha1)))
            import hashlib

            new_hash = hashlib.sha1(data).hexdigest()
            print(new_hash, "vs", bytes_to_hex(sha1))
            if hashlib.sha1(data).hexdigest() != bytes_to_hex(sha1):
                print("hash mismatch, probably Cloanto ROM...")
                continue

            retry_seconds = 1
            while True:
                try:
                    self.client.post("/api/locker-upload-file", data=data)
                except OGDClient.NonRetryableHTTPError as e:
                    raise e
                except Exception:
                    traceback.print_exc()
                    self.progressed(
                        gettext("Re-trying in {0} seconds...").format(
                            retry_seconds))
                    for _ in range(retry_seconds):
                        self.stop_check()
                        time.sleep(1.0)
                    retry_seconds = min(retry_seconds * 2, 60 * 10)
                else:
                    break

    def upload_check(self, prefix):
        self.progressed(
            gettext("Finding files eligible for OpenRetro Locker") +
            " ({:0.0%})".format((prefix / 16.0)))
        file_database = FileDatabase.instance()
        cursor = file_database.cursor()
        # FIXME: prefix
        p = "0123456789ABCDEF"[prefix]
        cursor.execute(
            "SELECT DISTINCT sha1 FROM file "
            "WHERE hex(sha1) LIKE ?",
            (p + "%", ),
        )
        string_io = StringIO()
        for row in cursor:
            string_io.write(row[0])
        # print(prefix, len(string_io.getvalue()))
        self.stop_check()

        retry_seconds = 1
        while True:
            try:
                result = self.client.post("/api/locker-upload-check",
                                          data=string_io.getvalue())
            except OGDClient.ForbiddenError:
                raise Task.Failure(
                    gettext("OpenRetro Locker is not enabled for your user. "
                            "It may be available only to a few select beta "
                            "users."))
            except OGDClient.NonRetryableHTTPError as e:
                raise e
            except Exception:
                traceback.print_exc()
                self.progressed(
                    gettext("Re-trying in {0} seconds...").format(
                        retry_seconds))
                for _ in range(retry_seconds):
                    self.stop_check()
                    time.sleep(1.0)
                retry_seconds = min(retry_seconds * 2, 60 * 10)
            else:
                return result