예제 #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.disable()
        self.password_field.disable()
        self.login_button.disable()

        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()
예제 #2
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.disable()
        self.password_field.disable()
        self.login_button.disable()

        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()
예제 #3
0
 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()
     LauncherConfig.set("variant_rating", str(like_rating))
예제 #4
0
 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()
     LauncherConfig.set("variant_rating", str(like_rating))
예제 #5
0
 def on_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()
예제 #6
0
 def __init__(self):
     Task.__init__(self, "Locker Uploader Task")
     self.client = OGDClient()
예제 #7
0
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("OAGD.net 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)
                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 OAGD.net 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("OAGD.net 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
예제 #8
0
 def __init__(self):
     Task.__init__(self, "Locker Uploader Task")
     self.client = OGDClient()
예제 #9
0
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("OAGD.net 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)
                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 OAGD.net 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("OAGD.net 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