Пример #1
0
def open_locker_uri(uri):
    sha1 = uri[9:]
    assert len(sha1) == 40
    context = SynchronizerContext()
    url = "{0}/api/locker/{1}".format(openretro_url_prefix(), sha1)
    path = Downloader.cache_file_from_url(url,
                                          auth=(context.username,
                                                context.password))
    return path
    def prepare_hard_drive(self, index):
        key = "hard_drive_{}".format(index)
        src = self.config.get(key, "")
        dummy, ext = os.path.splitext(src)
        ext = ext.lower()

        if is_http_url(src):
            name = src.rsplit("/", 1)[-1]
            name = unquote(name)
            self.on_progress(gettext("Downloading {0}...".format(name)))
            dest = os.path.join(self.temp_dir, name)
            Downloader.install_file_from_url(src, dest)
            src = dest
        elif src.startswith("hd://game/"):
            self.unpack_game_hard_drive(index, src)
            self.disable_save_states()
            return
        elif src.startswith("file_list:"):
            self.unpack_game_hard_drive(index, src)
            self.disable_save_states()
            return
        elif src.startswith("hd://template/workbench/"):
            self.prepare_workbench_hard_drive(index, src)
            self.disable_save_states()
            return
        elif src.startswith("hd://template/empty/"):
            self.prepare_empty_hard_drive(index, src)
            self.disable_save_states()
            return

        if ext in Archive.extensions:
            print("zipped hard drive", src)
            self.unpack_hard_drive(index, src)
            self.disable_save_states()

        elif src.endswith("HardDrive"):
            print("XML-described hard drive", src)
            self.unpack_hard_drive(index, src)
            self.disable_save_states()
        else:
            src = Paths.expand_path(src)
            self.config[key] = src
 def download_game_file_archive(self, url):
     print("\ndownload_game_file_archive", url)
     archive_path = Downloader.cache_file_from_url(url)
     archive = Archive(archive_path)
     archive_files = archive.list_files()
     print(archive_files)
     for name in archive_files:
         print(name)
         ifs = archive.open(name)
         data = ifs.read()
         Downloader.cache_data(data)
     if len(archive_files) == 0:
         # might not be an archive then
         with open(archive_path, "rb") as f:
             data = f.read()
         Downloader.cache_data(data)
     # the downloaded archive is no longer needed, now that we have
     # extracted all the files
     os.remove(archive_path)
     print("\n")
    def open_url(cls, url):
        original_url = url
        hash_part = ""
        parts = url.split("#", 1)
        if len(parts) > 1:
            url = parts[0]
            hash_part = "#" + parts[1]
        if not Downloader.cache_file_from_url(url, download=False):
            # license_code = cls.get_license_code_for_url(original_url)
            # license_status = {"accepted": False, "done": False}

            # def show_license_code():
            #     try:
            #         try:
            #             license_status["accepted"] = cls.show_license_code(
            #                 license_code
            #             )
            #         except Exception:
            #             traceback.print_exc()
            #     finally:
            #         license_status["done"] = True

            # if license_code:
            #     print("URL", url, "has license code", license_code)
            #     # FIXME: remove direct dependency on fsui
            #     import fsui as fsui

            #     fsui.call_after(show_license_code)
            #     while not license_status["done"]:
            #         time.sleep(0.1)
            #     if not license_status["accepted"]:
            #         # FIXME: custom exception here
            #         raise Exception(
            #             'Usage terms "{0}" was not '
            #             "accepted".format(license_code)
            #         )
            pass
        path = Downloader.cache_file_from_url(url)
        return path + hash_part
 def find_by_sha1(cls, sha1):
     # FIXME: check_sha1 should check with PluginManager directly?
     database = FileDatabase.instance()
     result = database.find_file(sha1=sha1)["path"]
     if not result:
         path = Downloader.get_cache_path(sha1)
         if os.path.exists(path):
             result = path
     #    result = self.context.get_game_database().find_file_by_sha1(sha1)
     # print("find by sha1", sha1, "in file database - result", result)
     if not result and is_locker_enabled() and not offline_mode():
         database = LockerDatabase.instance()
         if database.check_sha1(sha1):
             result = "locker://" + sha1
         # print("find by sha1", sha1, "in locker database - result",
         # result)
     return result
Пример #6
0
    def start_local_game(cls, dialog=True, *, gscontext):
        config = gscontext.config
        print("START LOCAL GAME")
        print("x_missing_files", config.get("x_missing_files"))

        if config.get("x_missing_files"):
            if config.get("download_file"):
                if config.get("download_terms"
                              ) and not Downloader.check_terms_accepted(
                                  config.get("download_file"),
                                  config.get("download_terms"),
                              ):
                    from .ui.launcherwindow import LauncherWindow

                    terms_dialog = DownloadTermsDialog(
                        LauncherWindow.current(), fsgs)
                    if not terms_dialog.show_modal():
                        return

            elif config.get("download_page"):
                from .ui.launcherwindow import LauncherWindow

                # fsui.show_error(_("This game must be downloaded first."))
                DownloadGameWindow(LauncherWindow.current(), fsgs).show()
                return
            else:
                fsui.show_error(
                    gettext("This game variant cannot be started "
                            "because you don't have all required files."))
                return

        # platform_id = config.get(Option.PLATFORM).lower()
        # if platform_id in AMIGA_PLATFORMS:
        #     cls.start_local_game_amiga()
        # else:
        #     cls.start_local_game_other()
        cls.start_local_game_other(dialog=dialog, gscontext=gscontext)
Пример #7
0
def install_whdload_file(sha1, dest_dir, rel_path):
    abs_path = os.path.join(dest_dir, rel_path)
    name = os.path.basename(rel_path)
    # self.on_progress(gettext("Downloading {0}...".format(name)))
    Downloader.install_file_by_sha1(sha1, name, abs_path)
Пример #8
0
 def on_accept_button(self):
     self.end_modal(True)
     Downloader.set_terms_accepted(self.download_file, self.download_terms)