Пример #1
0
    def get_settings_path(self):
        settings_ini = os.path.join(FSGSDirectories.get_data_dir(),
                                    "Settings.ini")
        if not os.path.exists(settings_ini):
            migrate_list = [
                os.path.join(FSGSDirectories.get_data_dir(),
                             "FS-UAE Launcher.ini")
            ]
            portable_ini = os.path.join(FSGSDirectories.get_base_dir(),
                                        "Portable.ini")
            if not os.path.exists(portable_ini):
                # not portable, can migrate settings from old
                # launcher.settings file
                migrate_list.append(
                    os.path.join(get_data_dir(), "fs-uae",
                                 "launcher.settings"))
            # move the highest-priority settings file if present
            for migrate in migrate_list:
                if os.path.exists(migrate):
                    shutil.move(migrate, settings_ini)
                    break
            # remove all old settings files
            for migrate in migrate_list:
                if os.path.exists(migrate):
                    os.remove(migrate)

        return settings_ini
Пример #2
0
    def _get_state_dir(self):
        config_name = self.config_name
        if not config_name:
            config_name = "Default"

        # use a temporary state dir, for now, to avoid problems with
        # floppy overlays etc interfering with net play
        from .netplay.netplay import Netplay

        if Netplay.current():
            # it is possible to manually specify the state dir
            config_name = LauncherConfig.get("__netplay_state_dir_name")
            if not config_name:
                # this is the default behavior, create a clean state
                # dir for the net play session
                netplay_game = LauncherConfig.get("__netplay_game")
                if netplay_game:
                    config_name = "Net Play ({0})".format(netplay_game)

        letter = self.get_letter(config_name)
        if not letter:
            config_name = "Default"
            letter = self.get_letter(config_name)
        # we use an existing state dir in a "letter" dir if it exists
        # (legacy support).
        path = os.path.join(FSGSDirectories.get_save_states_dir(), letter,
                            config_name)
        if os.path.exists(path):
            return path
        # if not, we use a direct sub-folder of save states dir
        path = os.path.join(FSGSDirectories.get_save_states_dir(), config_name)
        return path
Пример #3
0
 def plugin_path(cls):
     result = []
     plugins_dir = FSGSDirectories.get_plugins_dir()
     if plugins_dir and os.path.isdir(plugins_dir):
         result.append(plugins_dir)
     expansion_dir = os.path.join(
         FSGSDirectories.get_base_dir(), "Workspace", "Expansion"
     )
     if expansion_dir and os.path.isdir(expansion_dir):
         result.append(expansion_dir)
     if System.macos:
         system_plugins_dir = os.path.join(
             fsboot.executable_dir(),
             "..",
             "..",
             "..",
             "..",
             "..",
             "..",
             "Plugins",
         )
     else:
         system_plugins_dir = os.path.join(
             fsboot.executable_dir(), "..", "..", "..", "Plugins"
         )
     if os.path.isdir(system_plugins_dir):
         result.append(system_plugins_dir)
     return result
Пример #4
0
    def _get_state_dir(self):
        config_name = self.config_name
        if not config_name:
            config_name = "Default"

        # Use a temporary state dir, for now, to avoid problems with
        # floppy overlays etc interfering with net play.
        if self.fsgc.netplay.enabled:
            # It is possible to manually specify the state dir.
            config_name = self.fsgc.config.get("__netplay_state_dir_name")
            if not config_name:
                # This is the default behavior, create a clean state
                # dir for the net play session.
                netplay_game = self.fsgc.config.get("__netplay_game")
                if netplay_game:
                    config_name = "Net Play ({0})".format(netplay_game)

        # Convert the config name to a name which can be represented on
        # the file system (really all/most filesystems).
        config_name = GameNameUtil.create_fs_name(config_name)

        letter = self.get_letter(config_name)
        if not letter:
            config_name = "Default"
            letter = self.get_letter(config_name)
        # We use an existing state dir in a "letter" dir if it already
        # exists (legacy support).
        path = os.path.join(FSGSDirectories.get_save_states_dir(), letter,
                            config_name)
        if os.path.exists(path):
            return path
        # If not, we use a direct sub-folder of save states dir.
        path = os.path.join(FSGSDirectories.get_save_states_dir(), config_name)
        return path
Пример #5
0
    def _get_state_dir(self):
        config_name = self.config_name
        if not config_name:
            config_name = "Default"

        # use a temporary state dir, for now, to avoid problems with
        # floppy overlays etc interfering with net play
        from .netplay.netplay import Netplay
        if Netplay.current():
            # it is possible to manually specify the state dir
            config_name = LauncherConfig.get("__netplay_state_dir_name")
            if not config_name:
                # this is the default behavior, create a clean state
                # dir for the net play session
                netplay_game = LauncherConfig.get("__netplay_game")
                if netplay_game:
                    config_name = "Net Play ({0})".format(netplay_game)

        letter = self.get_letter(config_name)
        if not letter:
            config_name = "Default"
            letter = self.get_letter(config_name)
        # we use an existing state dir in a "letter" dir if it exists
        # (legacy support).
        path = os.path.join(FSGSDirectories.get_save_states_dir(), letter,
                            config_name)
        if os.path.exists(path):
            return path
        # if not, we use a direct sub-folder of save states dir
        path = os.path.join(FSGSDirectories.get_save_states_dir(),
                            config_name)
        return path
Пример #6
0
    def _get_state_dir(self):
        config_name = self.config_name
        if not config_name:
            config_name = "Default"

        # Use a temporary state dir, for now, to avoid problems with
        # floppy overlays etc interfering with net play.
        if self.fsgc.netplay.enabled:
            # It is possible to manually specify the state dir.
            config_name = self.fsgc.config.get("__netplay_state_dir_name")
            if not config_name:
                # This is the default behavior, create a clean state
                # dir for the net play session.
                netplay_game = self.fsgc.config.get("__netplay_game")
                if netplay_game:
                    config_name = "Net Play ({0})".format(netplay_game)

        # Convert the config name to a name which can be represented on
        # the file system (really all/most filesystems).
        config_name = GameNameUtil.create_fs_name(config_name)

        letter = self.get_letter(config_name)
        if not letter:
            config_name = "Default"
            letter = self.get_letter(config_name)
        # We use an existing state dir in a "letter" dir if it already
        # exists (legacy support).
        path = os.path.join(
            FSGSDirectories.get_save_states_dir(), letter, config_name
        )
        if os.path.exists(path):
            return path
        # If not, we use a direct sub-folder of save states dir.
        path = os.path.join(FSGSDirectories.get_save_states_dir(), config_name)
        return path
Пример #7
0
 def plugin_path(cls):
     result = []
     plugins_dir = FSGSDirectories.get_plugins_dir()
     if plugins_dir and os.path.isdir(plugins_dir):
         result.append(plugins_dir)
     expansion_dir = os.path.join(
             FSGSDirectories.get_base_dir(), "Workspace", "Expansion")
     if expansion_dir and os.path.isdir(expansion_dir):
         result.append(expansion_dir)
     return result
 def get_default_directory(self, type):
     if type == "floppy":
         return FSGSDirectories.get_floppies_dir()
     elif type == "cd":
         return FSGSDirectories.get_cdroms_dir()
     elif type == "hd":
         return FSGSDirectories.get_hard_drives_dir()
     elif type == "rom":
         return FSGSDirectories.get_kickstarts_dir()
     raise Exception("unknown file dialog type")
Пример #9
0
 def get_default_directory(media_type):
     if media_type == "floppy":
         return FSGSDirectories.get_floppies_dir()
     elif media_type == "cd":
         return FSGSDirectories.get_cdroms_dir()
     elif media_type == "hd":
         return FSGSDirectories.get_hard_drives_dir()
     elif media_type == "rom":
         return FSGSDirectories.get_kickstarts_dir()
     # FIXME: Return new Media directory instead
     return FSGSDirectories.get_base_dir()
Пример #10
0
 def get_default_directory(media_type):
     if media_type == "floppy":
         return FSGSDirectories.get_floppies_dir()
     elif media_type == "cd":
         return FSGSDirectories.get_cdroms_dir()
     elif media_type == "hd":
         return FSGSDirectories.get_hard_drives_dir()
     elif media_type == "rom":
         return FSGSDirectories.get_kickstarts_dir()
     # FIXME: Return new Media directory instead
     return FSGSDirectories.get_base_dir()
Пример #11
0
    def get_cover_path(self):
        sha1 = LauncherConfig.get("front_sha1")
        if sha1:
            return "sha1:" + sha1

        path = self.get_override_path("cover_image")
        if path and os.path.exists(path):
            return path
        if self.uuid:
            paths = FSGSDirectories.get_images_dirs()
            for dir_ in paths:
                p = os.path.join(
                    dir_,
                    self.platform,
                    "Images",
                    self.uuid[:2],
                    self.uuid,
                    "front.png",
                )
                if os.path.exists(p):
                    return p
                p = os.path.join(
                    dir_,
                    self.platform,
                    "Thumbnails",
                    self.uuid[:2],
                    self.uuid,
                    "front.png",
                )
                if os.path.exists(p):
                    return p
        letter = self.get_letter(self.name)
        if not letter:
            return None
        name = self.name
        override_dir = LauncherConfig.get("covers_dir")
        if override_dir:
            paths = [Paths.expand_path(override_dir)]
        else:
            paths = FSGSDirectories.get_covers_dirs()
        for dir_ in paths:
            path = os.path.join(dir_, letter, name + ".jpg")
            if os.path.exists(path):
                return path
            path = os.path.join(dir_, letter, name + ".png")
            if os.path.exists(path):
                return path
            path = os.path.join(dir_, name + ".jpg")
            if os.path.exists(path):
                return path
            path = os.path.join(dir_, name + ".png")
            if os.path.exists(path):
                return path
        return None
Пример #12
0
 def custom_database_names():
     custom_dir = os.path.join(FSGSDirectories.databases_dir(), "Custom")
     custom_databases = []
     if os.path.exists(custom_dir):
         for item in os.listdir(custom_dir):
             if item.endswith(".sqlite"):
                 custom_databases.append("Custom/" + item[:-7])
     custom_dir = os.path.join(FSGSDirectories.databases_dir(), "User")
     custom_databases = []
     if os.path.exists(custom_dir):
         for item in os.listdir(custom_dir):
             if item.endswith(".sqlite"):
                 custom_databases.append("User/" + item[:-7])
     return custom_databases
Пример #13
0
 def custom_database_names():
     custom_dir = os.path.join(FSGSDirectories.databases_dir(), "Custom")
     custom_databases = []
     if os.path.exists(custom_dir):
         for item in os.listdir(custom_dir):
             if item.endswith(".sqlite"):
                 custom_databases.append("Custom/" + item[:-7])
     custom_dir = os.path.join(FSGSDirectories.databases_dir(), "User")
     custom_databases = []
     if os.path.exists(custom_dir):
         for item in os.listdir(custom_dir):
             if item.endswith(".sqlite"):
                 custom_databases.append("User/" + item[:-7])
     return custom_databases
Пример #14
0
 def insert_floppy(self, drive, path, sha1=None):
     if sha1 is None:
         sha1 = ChecksumTool().checksum(path)
     default_dir = FSGSDirectories.get_floppies_dir()
     path = Paths.contract_path(path, default_dir)
     self.set_config([("floppy_drive_{0}".format(drive), path),
                      ("x_floppy_drive_{0}_sha1".format(drive), sha1)])
Пример #15
0
def find_font_path_or_stream(name):
    path = os.path.join(
        FSGSDirectories.get_base_dir(), "Workspace", "Fonts", name)
    if os.path.exists(path):
        return path
    stream = resources.resource_stream(name)
    return stream
Пример #16
0
    def on_add_button(self):
        existing_items = self.create_list()

        default_dir = FSGSDirectories.get_floppies_dir()
        if self.cd_mode:
            dialog = LauncherFilePicker(
                self.get_window(), gettext("Select Multiple CD-ROMs"),
                "cd", multiple=True)
        else:
            dialog = LauncherFilePicker(
                self.get_window(), gettext("Select Multiple Floppies"),
                "floppy", multiple=True)
        if not dialog.show_modal():
            print("dialog.show returned false")
            return
        print("dialog.show returned true")
        paths = dialog.get_paths()
        paths.sort()
        print(paths)

        checksum_tool = ChecksumTool(self.get_window())
        for i, path in enumerate(paths):
            sha1 = checksum_tool.checksum(path)
            path = Paths.contract_path(path, default_dir)

            dir, file = os.path.split(path)
            if os.path.normcase(os.path.normpath(dir)) == \
                    os.path.normcase(os.path.normpath(default_dir)):
                path = file

            existing_items.append((path, sha1))
        self.set_new_config(existing_items)
Пример #17
0
def get_cache_zip_for_sha1(sha1):
    zip_path = os.path.join(
        FSGSDirectories.images_dir(), sha1[:2] + ".zip")
    try:
        return ZipFile(zip_path, "r")
    except Exception:
        return None
Пример #18
0
    def on_add_button(self):
        existing_items = self.create_list()

        default_dir = FSGSDirectories.get_floppies_dir()
        if self.cd_mode:
            dialog = LauncherFilePicker(self.get_window(),
                                        gettext("Select Multiple CD-ROMs"),
                                        "cd",
                                        multiple=True)
        else:
            dialog = LauncherFilePicker(self.get_window(),
                                        gettext("Select Multiple Floppies"),
                                        "floppy",
                                        multiple=True)
        if not dialog.show_modal():
            print("dialog.show returned false")
            return
        print("dialog.show returned true")
        paths = dialog.get_paths()
        paths.sort()
        print(paths)

        checksum_tool = ChecksumTool(self.get_window())
        for i, path in enumerate(paths):
            sha1 = checksum_tool.checksum(path)
            path = Paths.contract_path(path, default_dir)

            dir, file = os.path.split(path)
            if os.path.normcase(os.path.normpath(dir)) == \
                    os.path.normcase(os.path.normpath(default_dir)):
                path = file

            existing_items.append((path, sha1))
        self.set_new_config(existing_items)
Пример #19
0
 def decode_path(self, path):
     if not path or path[0] != "$":
         return path
     base_dir = FSGSDirectories.get_base_dir() + "/"
     if path.startswith("$/"):
         path = base_dir + path[2:]
     return path
Пример #20
0
    def on_browse_button(self, extended=False):
        default_dir = FSGSDirectories.get_kickstarts_dir()
        if extended:
            title = gettext("Choose Extended ROM")
            key = "kickstart_ext_file"
        else:
            title = gettext("Choose Kickstart ROM")
            key = "kickstart_file"
        dialog = LauncherFilePicker(self.get_window(), title, "rom",
                                    LauncherConfig.get(key))
        if not dialog.show_modal():
            return
        path = dialog.get_path()

        checksum_tool = ChecksumTool(self.get_window())
        sha1 = checksum_tool.checksum_rom(path)

        dir_path, file = os.path.split(path)
        if extended:
            self.ext_text_field.set_text(file)
        else:
            self.text_field.set_text(file)
        if os.path.normcase(os.path.normpath(dir_path)) == \
                os.path.normcase(os.path.normpath(default_dir)):
            path = file

        if extended:
            LauncherConfig.set_multiple([("kickstart_ext_file", path),
                                         ("x_kickstart_ext_file", path),
                                         ("x_kickstart_ext_file_sha1", sha1)])
        else:
            LauncherConfig.set_multiple([("kickstart_file", path),
                                         ("x_kickstart_file", path),
                                         ("x_kickstart_file_sha1", sha1)])
Пример #21
0
def setup_logging(log_name):
    if sys.platform == "win32" and "FS_FORCE_STDOUT" not in os.environ:
        # noinspection PyUnresolvedReferences
        # import win32console
        if hasattr(sys, "frozen"):
            # or win32console.GetConsoleWindow() == 0:
            sys.stdout = NullOutput()
            sys.stderr = NullOutput()

    # FIXME: remove dependency on fsgs here!
    from fsgs.FSGSDirectories import FSGSDirectories
    logs_dir = FSGSDirectories.get_logs_dir()
    log_file = os.path.join(logs_dir, log_name)
    print("[LOGGING] Logging to", log_file)
    try:
        f = open(log_file, "wb")
    except Exception:
        print("[LOGGING] Could not open log file")
        # use MultiplexedOutput here too, for the mutex handling
        sys.stdout = MultiplexedOutput(sys.stdout)
        sys.stderr = MultiplexedOutput(sys.stderr)
    else:
        sys.stdout = MultiplexedOutput(FileOutput(f), sys.stdout)
        sys.stderr = MultiplexedOutput(FileOutput(f), sys.stderr)

    logging.basicConfig(stream=sys.stdout, level=logging.NOTSET)
Пример #22
0
 def get_cache_path(cls, sha1_or_uuid):
     path = os.path.join(
         FSGSDirectories.get_cache_dir(), "Downloads", sha1_or_uuid[:3]
     )
     if not os.path.exists(path):
         os.makedirs(path)
     return os.path.join(path, sha1_or_uuid)
Пример #23
0
def get_file_for_sha1_cached(sha1, size_arg, cache_ext):
    cache_zip = get_cache_zip_for_sha1(sha1)
    if cache_zip is not None:
        try:
            return cache_zip.open("{}/{}{}".format(sha1[:2], sha1, cache_ext))
        except KeyError:
            pass
    cache_dir = FSGSDirectories.images_dir_for_sha1(sha1)
    cache_file = os.path.join(cache_dir, sha1 + cache_ext)
    if os.path.exists(cache_file):
        # An old bug made it possible for 0-byte files to exist, so
        # we check for that here...
        if os.path.getsize(cache_file) > 0:
            return cache_file

    url = "{}/image/{}{}".format(openretro_url_prefix(), sha1, size_arg)
    print("[IMAGES]", url)

    r = requests.get(url, stream=True)
    try:
        r.raise_for_status()
        cache_file_partial = "{}.{}.partial".format(
            cache_file, str(uuid4())[:8]
        )
        if not os.path.exists(os.path.dirname(cache_file_partial)):
            os.makedirs(os.path.dirname(cache_file_partial))
        with open(cache_file_partial, "wb") as f:
            for chunk in r.iter_content(chunk_size=65536):
                f.write(chunk)
    finally:
        r.close()
    os.rename(cache_file_partial, cache_file)
    return cache_file
Пример #24
0
    def __init__(self, parent):
        super().__init__(parent)
        icon = fsui.Icon("settings", "pkg:workspace")
        # gettext("WHDLoad Settings")
        title = gettext("WHDLoad")
        subtitle = gettext("Options for WHDLoad support in FS-UAE Launcher")
        self.add_header(icon, title, subtitle)

        label = fsui.MultiLineLabel(self, gettext(
            "The following options only apply when you use the automatic "
            "WHDLoad support in FS-UAE Launcher, for example in relation with "
            "the online game database."), 640)
        self.layout.add(label, fill=True, margin_top=0)

        self.add_option("whdload_splash_delay")

        label = fsui.Label(
            self, gettext("Directory for WHDLoad.key file (if you have it):"))
        self.layout.add(label, margin_top=10)
        hor_layout = fsui.HorizontalLayout()
        self.layout.add(hor_layout, margin_top=4, fill=True)
        label = fsui.Label(
            self, FSGSDirectories.get_base_dir())
        hor_layout.add_spacer(0, expand=True)
        hor_layout.add(label)
Пример #25
0
def setup_logging(log_name):
    if sys.platform == "win32" and "FS_FORCE_STDOUT" not in os.environ:
        # noinspection PyUnresolvedReferences
        # import win32console
        if hasattr(sys, "frozen"):
            # or win32console.GetConsoleWindow() == 0:
            sys.stdout = NullOutput()
            sys.stderr = NullOutput()

    # FIXME: remove dependency on fsgs here!
    from fsgs.FSGSDirectories import FSGSDirectories
    logs_dir = FSGSDirectories.get_logs_dir()
    log_file = os.path.join(logs_dir, log_name)
    try:
        f = open(log_file, "wb")
    except Exception:
        print("could not open log file")
        # use MultiplexedOutput here too, for the mutex handling
        sys.stdout = MultiplexedOutput(sys.stdout)
        sys.stderr = MultiplexedOutput(sys.stderr)
    else:
        sys.stdout = MultiplexedOutput(FileOutput(f), sys.stdout)
        sys.stderr = MultiplexedOutput(FileOutput(f), sys.stderr)

    logging.basicConfig(stream=sys.stdout, level=logging.NOTSET)
Пример #26
0
    def __init__(self, fsgc):
        self.fsgc = fsgc
        self.files = GameFiles(fsgc)
        self.logger = GameDriverLogger()
        self.emulator = Emulator("no-emulator")

        self.options = defaultdict(str)
        self.init_options()

        self.ports = []
        self.init_ports()

        self._allow_gsync = True
        self._model_name = ""
        self._emulator_skin_prepared = {}
        self.__vsync = False
        self.__game_temp_file = None

        self.temp_root = TemporaryItem(root=None,
                                       prefix="fsgs-",
                                       suffix="tmp",
                                       directory=True)
        # # Default current working directory for the emulator.
        self.cwd = self.temp_dir("cwd")
        # # Fake home directory for the emulator.
        self.home = self.temp_dir("home")
        self.home._path = os.path.join(FSGSDirectories.get_cache_dir(), "Home")
        if not os.path.exists(self.home.path):
            os.makedirs(self.home.path)
        # noinspection PyProtectedMember
        self.cwd._path = self.home._path
Пример #27
0
 def decode_path(self, path):
     if not path or path[0] != "$":
         return path
     base_dir = FSGSDirectories.get_base_dir() + "/"
     if path.startswith("$/"):
         path = base_dir + path[2:]
     return path
Пример #28
0
def get_file_for_sha1_cached(sha1, size_arg, cache_ext):
    cache_zip = get_cache_zip_for_sha1(sha1)
    if cache_zip is not None:
        try:
            return cache_zip.open("{}/{}{}".format(
                sha1[:2], sha1, cache_ext))
        except KeyError:
            pass
    cache_dir = FSGSDirectories.images_dir_for_sha1(sha1)
    cache_file = os.path.join(cache_dir, sha1 + cache_ext)
    if os.path.exists(cache_file):
        # An old bug made it possible for 0-byte files to exist, so
        # we check for that here...
        if os.path.getsize(cache_file) > 0:
            return cache_file

    url = "{}/image/{}{}".format(openretro_url_prefix(), sha1, size_arg)
    print("[IMAGES]", url)
    r = urlopen(url)
    data = r.read()
    cache_file_partial = "{}.{}.partial".format(
        cache_file, str(uuid4())[:8])
    if not os.path.exists(os.path.dirname(cache_file_partial)):
        os.makedirs(os.path.dirname(cache_file_partial))
    with open(cache_file_partial, "wb") as f:
        f.write(data)
    os.rename(cache_file_partial, cache_file)
    return cache_file
Пример #29
0
    def __init__(self, fsgc):
        self.fsgc = fsgc
        self.files = GameFiles(fsgc)
        self.logger = GameDriverLogger()
        self.emulator = Emulator("no-emulator")

        self.options = defaultdict(str)
        self.init_options()

        self.ports = []
        self.init_ports()

        self._allow_gsync = True
        self._model_name = ""
        self._emulator_skin_prepared = {}
        self.__vsync = False
        self.__game_temp_file = None

        self.temp_root = TemporaryItem(
            root=None, prefix="fsgs-", suffix="tmp", directory=True
        )
        # # Default current working directory for the emulator.
        self.cwd = self.temp_dir("cwd")
        # # Fake home directory for the emulator.
        self.home = self.temp_dir("home")
        self.home._path = os.path.join(FSGSDirectories.get_cache_dir(), "Home")
        if not os.path.exists(self.home.path):
            os.makedirs(self.home.path)
        # noinspection PyProtectedMember
        self.cwd._path = self.home._path
Пример #30
0
    def config_startup_scan(cls):
        if cls._config_scanned:
            return
        cls._config_scanned = True

        configs_dir = FSGSDirectories.get_configurations_dir()
        print("config_startup_scan", configs_dir)
        print(LauncherSettings.settings)

        settings_mtime = LauncherSettings.get("configurations_dir_mtime")
        dir_mtime = cls.get_dir_mtime_str(configs_dir)
        if settings_mtime == dir_mtime + "+" + str(Database.VERSION):
            print("... mtime not changed", settings_mtime, dir_mtime)
            return

        database = Database.get_instance()
        file_database = FileDatabase.get_instance()

        print("... database.find_local_configurations")
        local_configs = Database.get_instance().find_local_configurations()
        print("... walk configs_dir")
        for dir_path, dir_names, file_names in os.walk(configs_dir):
            for file_name in file_names:
                if not file_name.endswith(".fs-uae"):
                    continue
                path = Paths.join(dir_path, file_name)
                if path in local_configs:
                    local_configs[path] = None
                    # already exists in database
                    continue
                name, ext = os.path.splitext(file_name)
                # search = ConfigurationScanner.create_configuration_search(
                # name)
                scanner = ConfigurationScanner()
                print("[startup] adding config", path)
                file_database.delete_file(path=path)
                with open(path, "rb") as f:
                    sha1 = hashlib.sha1(f.read()).hexdigest()
                file_database.add_file(path=path, sha1=sha1)

                game_id = database.add_configuration(
                    path=path, name=scanner.create_configuration_name(name)
                )
                database.update_game_search_terms(
                    game_id, scanner.create_search_terms(name)
                )

        for path, config_id in local_configs.items():
            if config_id is not None:
                print("[startup] removing configuration", path)
                database.delete_game(id=config_id)
                file_database.delete_file(path=path)
        print("... commit")
        database.commit()

        LauncherSettings.set(
            "configurations_dir_mtime",
            cls.get_dir_mtime_str(configs_dir) + "+" + str(Database.VERSION),
        )
Пример #31
0
 def save_dir_path(self):
     save_dir = self.uuid_save_dir_path()
     if save_dir:
         return save_dir
     # assert False, "save_dir_path not implemented for this case"
     print("[SAVES] Unsupported save dir FIXME")
     saves_dir = FSGSDirectories.saves_dir()
     return os.path.join(saves_dir, "Unsupported")
Пример #32
0
 def insert_floppy(self, drive, path, sha1=None):
     if sha1 is None:
         sha1 = ChecksumTool().checksum(path)
     default_dir = FSGSDirectories.get_floppies_dir()
     path = Paths.contract_path(path, default_dir)
     self.set_config([
         ("floppy_drive_{0}".format(drive), path),
         ("x_floppy_drive_{0}_sha1".format(drive), sha1)])
Пример #33
0
def default_openretro_server_from_file():
    server = None
    p = os.path.join(
        FSGSDirectories.get_data_dir(), "Settings", "database-server")
    if os.path.exists(p):
        with open(p, "r", encoding="UTF-8") as f:
            server = f.read().strip()
    return server
Пример #34
0
def default_openretro_server_from_file():
    server = None
    p = os.path.join(FSGSDirectories.get_data_dir(), "Settings",
                     "database-server")
    if os.path.exists(p):
        with open(p, "r", encoding="UTF-8") as f:
            server = f.read().strip()
    return server
Пример #35
0
 def insert_cd(self, drive, path, sha1=None):
     if sha1 is None:
         sha1 = ""
         print("FIXME: not calculating CD checksum just yet")
     default_dir = FSGSDirectories.get_cdroms_dir()
     path = Paths.contract_path(path, default_dir)
     self.set_config([("cdrom_drive_{0}".format(drive), path),
                      ("x_cdrom_drive_{0}_sha1".format(drive), sha1)])
Пример #36
0
    def insert_multiple_floppies(self, insert_paths):
        paths = []
        for path in insert_paths:
            embedded_files = []
            if path.endswith(".zip"):
                archive = Archive(path)
                files = archive.list_files()
                for file in files:
                    name, ext = os.path.splitext(file)
                    # FIXME: get list of floppy extensions from a central
                    # place
                    if ext in [".adf", ".ipf"]:
                        embedded_files.append(file)
            if len(embedded_files) > 0:
                embedded_files.sort()
                print("found embedded floppy images:")
                print(embedded_files)
                for file in embedded_files:
                    paths.append(file)
            else:
                paths.append(path)

        default_dir = FSGSDirectories.get_floppies_dir()
        checksum_tool = ChecksumTool()
        for i, path in enumerate(paths):
            sha1 = checksum_tool.checksum(path)
            path = Paths.contract_path(path, default_dir)

            if i < 4:
                self.set_config(
                    [
                        ("floppy_drive_{0}".format(i), path),
                        ("x_floppy_drive_{0}_sha1".format(i), sha1),
                    ]
                )
            self.set_config(
                [
                    ("floppy_image_{0}".format(i), path),
                    ("x_floppy_image_{0}_sha1".format(i), sha1),
                ]
            )

        # blank the rest of the drives
        for i in range(len(paths), 4):
            self.set_config(
                [
                    ("floppy_drive_{0}".format(i), ""),
                    ("x_floppy_drive_{0}_sha1".format(i), ""),
                ]
            )
        # blank the rest of the image list
        for i in range(len(paths), 20):
            self.set_config(
                [
                    ("floppy_image_{0}".format(i), ""),
                    ("x_floppy_image_{0}_sha1".format(i), ""),
                ]
            )
Пример #37
0
    def multi_select(cls, parent=None):
        default_dir = FSGSDirectories.get_floppies_dir()
        dialog = LauncherFilePicker(parent,
                                    gettext("Select Multiple Floppies"),
                                    "floppy",
                                    multiple=True)
        if not dialog.show_modal():
            return
        original_paths = dialog.get_paths()
        original_paths.sort()
        paths = []
        for path in original_paths:
            path = Paths.get_real_case(path)
            embedded_files = []
            if path.endswith(".zip"):
                archive = Archive(path)
                files = archive.list_files()
                for file in files:
                    name, ext = os.path.splitext(file)
                    # FIXME: get list of floppy extensions from a central
                    # place
                    if ext in [".adf", ".ipf"]:
                        embedded_files.append(file)
            if len(embedded_files) > 0:
                embedded_files.sort()
                print("found embedded floppy images:")
                print(embedded_files)
                for file in embedded_files:
                    paths.append(file)
            else:
                paths.append(path)

        checksum_tool = ChecksumTool(parent)
        for i, path in enumerate(paths):
            sha1 = checksum_tool.checksum(path)
            path = Paths.contract_path(path,
                                       default_dir,
                                       force_real_case=False)

            if i < 4:
                LauncherConfig.set_multiple([
                    ("floppy_drive_{0}".format(i), path),
                    ("x_floppy_drive_{0}_sha1".format(i), sha1)
                ])
            LauncherConfig.set_multiple([("floppy_image_{0}".format(i), path),
                                         ("x_floppy_image_{0}_sha1".format(i),
                                          sha1)])

        # blank the rest of the drives
        for i in range(len(paths), 4):
            LauncherConfig.set_multiple([("floppy_drive_{0}".format(i), ""),
                                         ("x_floppy_drive_{0}_sha1".format(i),
                                          "")])
        # blank the rest of the image list
        for i in range(len(paths), 20):
            LauncherConfig.set_multiple([("floppy_image_{0}".format(i), ""),
                                         ("x_floppy_image_{0}_sha1".format(i),
                                          "")])
Пример #38
0
    def plugin_path(cls):
        # Plugins dir location has changed, add several old and new paths here
        # to find plugins in both places (FS-UAE and OpenRetro style).

        result = []

        # $BASE/Plugins/ or $BASE/Data/Plugins/
        plugins_dir = FSGSDirectories.get_plugins_dir()
        result.append(plugins_dir)

        # $BASE/Plugins/
        plugins_dir = os.path.join(FSGSDirectories.get_base_dir(), "Plugins")
        if plugins_dir not in result:
            result.append(plugins_dir)

        # $BASE/Data/Plugins/
        plugins_dir = os.path.join(FSGSDirectories.get_data_dir(), "Plugins")
        if plugins_dir not in result:
            result.append(plugins_dir)

        # # $BASE/Workspace/Expansion/
        # plugins_dir = os.path.join(
        #     FSGSDirectories.get_base_dir(), "Workspace", "Expansion"
        # )
        # if plugins_dir and os.path.isdir(plugins_dir):
        #     result.append(plugins_dir)

        if System.macos:
            escape_exe_dir = "../../../../../.."
        else:
            escape_exe_dir = "../../.."

        # System/
        plugins_dir = os.path.normpath(
            os.path.join(fsboot.executable_dir(), escape_exe_dir)
        )
        result.append(plugins_dir)

        # System/Plugins/
        plugins_dir = os.path.normpath(
            os.path.join(fsboot.executable_dir(), escape_exe_dir, "Plugins")
        )
        result.append(plugins_dir)

        return result
Пример #39
0
 def insert_cd(self, drive, path, sha1=None):
     if sha1 is None:
         sha1 = ""
         print("FIXME: not calculating CD checksum just yet")
     default_dir = FSGSDirectories.get_cdroms_dir()
     path = Paths.contract_path(path, default_dir)
     self.set_config([
         ("cdrom_drive_{0}".format(drive), path),
         ("x_cdrom_drive_{0}_sha1".format(drive), sha1)])
Пример #40
0
 def uuid_save_dir_path(self):
     saves_dir = FSGSDirectories.saves_dir()
     # FIXME: Correct?
     variant_uuid = self.get("variant_uuid")
     if variant_uuid:
         save_dir = os.path.join(saves_dir, "UUID", variant_uuid[:2],
                                 variant_uuid)
         return save_dir
     return None
Пример #41
0
    def config_startup_scan(cls):
        if cls._config_scanned:
            return
        cls._config_scanned = True

        configs_dir = FSGSDirectories.get_configurations_dir()
        print("config_startup_scan", configs_dir)
        print(LauncherSettings.settings)

        settings_mtime = LauncherSettings.get("configurations_dir_mtime")
        dir_mtime = cls.get_dir_mtime_str(configs_dir)
        if settings_mtime == dir_mtime + "+" + str(Database.VERSION):
            print("... mtime not changed", settings_mtime, dir_mtime)
            return

        database = Database.get_instance()
        file_database = FileDatabase.get_instance()

        print("... database.find_local_configurations")
        local_configs = Database.get_instance().find_local_configurations()
        print("... walk configs_dir")
        for dir_path, dir_names, file_names in os.walk(configs_dir):
            for file_name in file_names:
                if not file_name.endswith(".fs-uae"):
                    continue
                path = Paths.join(dir_path, file_name)
                if path in local_configs:
                    local_configs[path] = None
                    # already exists in database
                    continue
                name, ext = os.path.splitext(file_name)
                # search = ConfigurationScanner.create_configuration_search(
                # name)
                scanner = ConfigurationScanner()
                print("[startup] adding config", path)
                file_database.delete_file(path=path)
                with open(path, "rb") as f:
                    sha1 = hashlib.sha1(f.read()).hexdigest()
                file_database.add_file(path=path, sha1=sha1)

                game_id = database.add_configuration(
                    path=path, name=scanner.create_configuration_name(name))
                database.update_game_search_terms(
                    game_id, scanner.create_search_terms(name))

        for path, config_id in local_configs.items():
            if config_id is not None:
                print("[startup] removing configuration", path)
                database.delete_game(id=config_id)
                file_database.delete_file(path=path)
        print("... commit")
        database.commit()

        LauncherSettings.set(
            "configurations_dir_mtime",
            cls.get_dir_mtime_str(configs_dir) + "+" + str(Database.VERSION),
        )
Пример #42
0
 def on_item_selected(self, index):
     self.set_path(FSGSDirectories.get_hard_drives_dir())
     if index == 0:
         size = "256"
     elif index == 1:
         size = "1024"
     else:
         raise Exception("Unexpected index " + repr(index))
     self.size_field.set_text(size)
     self.size_field.enable(True)
Пример #43
0
 def uuid_save_dir_path(self):
     saves_dir = FSGSDirectories.saves_dir()
     # FIXME: Correct?
     variant_uuid = self.get("variant_uuid")
     if variant_uuid:
         save_dir = os.path.join(
             saves_dir, "UUID", variant_uuid[:2], variant_uuid
         )
         return save_dir
     return None
Пример #44
0
 def get_theme_path(self):
     letter = self.get_letter(self.name)
     if not letter:
         return None
     paths = FSGSDirectories.get_themes_dirs()
     for dir_ in paths:
         path = os.path.join(dir_, letter, self.name)
         if os.path.exists(path):
             return path
     return None
Пример #45
0
 def on_item_selected(self, index):
     self.set_path(FSGSDirectories.get_hard_drives_dir())
     if index == 0:
         size = "256"
     elif index == 1:
         size = "1024"
     else:
         raise Exception("Unexpected index " + repr(index))
     self.size_field.set_text(size)
     self.size_field.enable(True)
Пример #46
0
 def on_item_selected(self, index):
     self.set_path(FSGSDirectories.get_floppies_dir())
     if index == 0:
         size = "0.86"
     elif index == 1:
         size = "2.00"
     else:
         raise Exception("Unexpected index " + repr(index))
     self.size_field.set_text(size)
     self.size_field.enable(False)
Пример #47
0
 def get_theme_path(self):
     letter = self.get_letter(self.name)
     if not letter:
         return None
     paths = FSGSDirectories.get_themes_dirs()
     for dir_ in paths:
         path = os.path.join(dir_, letter, self.name)
         if os.path.exists(path):
             return path
     return None
Пример #48
0
    def plugin_path(cls):
        result = []
        plugins_dir = FSGSDirectories.get_plugins_dir()
        result.append(plugins_dir)

        # Plugins dir location has changed, add several old and new paths here
        # to find plugins in both places (FS-UAE and OpenRetro style).
        plugins_dir = os.path.join(FSGSDirectories.get_base_dir(), "Plugins")
        if plugins_dir not in result:
            result.append(plugins_dir)
        plugins_dir = os.path.join(FSGSDirectories.get_data_dir(), "Plugins")
        if plugins_dir not in result:
            result.append(plugins_dir)

        # if plugins_dir and os.path.isdir(plugins_dir):
        #     result.append(plugins_dir)
        expansion_dir = os.path.join(FSGSDirectories.get_base_dir(),
                                     "Workspace", "Expansion")
        if expansion_dir and os.path.isdir(expansion_dir):
            result.append(expansion_dir)

        if System.macos:
            system_plugins_dir = os.path.normpath(
                os.path.join(
                    fsboot.executable_dir(),
                    "..",
                    "..",
                    "..",
                    "..",
                    "..",
                    "..",
                    "Plugins",
                ))
            result.append(system_plugins_dir)
        else:
            system_plugins_dir = os.path.normpath(
                os.path.join(fsboot.executable_dir(), "..", "..", "..",
                             "Plugins"))
            result.append(system_plugins_dir)
        # if os.path.isdir(system_plugins_dir):
        #     result.append(system_plugins_dir)

        return result
Пример #49
0
 def on_item_selected(self, index):
     self.set_path(FSGSDirectories.get_floppies_dir())
     if index == 0:
         size = "0.86"
     elif index == 1:
         size = "2.00"
     else:
         raise Exception("Unexpected index " + repr(index))
     self.size_field.set_text(size)
     self.size_field.enable(False)
Пример #50
0
 def plugin_path(cls):
     result = []
     plugins_dir = FSGSDirectories.get_plugins_dir()
     if plugins_dir and os.path.isdir(plugins_dir):
         result.append(plugins_dir)
     expansion_dir = os.path.join(FSGSDirectories.get_base_dir(),
                                  "Workspace", "Expansion")
     if expansion_dir and os.path.isdir(expansion_dir):
         result.append(expansion_dir)
     if System.macos:
         system_plugins_dir = os.path.join(fsboot.executable_dir(), "..",
                                           "..", "..", "..", "..", "..",
                                           "Plugins")
     else:
         system_plugins_dir = os.path.join(fsboot.executable_dir(), "..",
                                           "..", "..", "Plugins")
     if os.path.isdir(system_plugins_dir):
         result.append(system_plugins_dir)
     return result
Пример #51
0
    def multiselect(cls, parent=None):
        default_dir = FSGSDirectories.get_floppies_dir()
        dialog = LauncherFilePicker(
            parent, gettext("Select Multiple Floppies"),
            "floppy", multiple=True)
        if not dialog.show_modal():
            return
        original_paths = dialog.get_paths()
        original_paths.sort()
        paths = []
        for path in original_paths:
            path = Paths.get_real_case(path)
            embedded_files = []
            if path.endswith(".zip"):
                archive = Archive(path)
                files = archive.list_files()
                for file in files:
                    name, ext = os.path.splitext(file)
                    # FIXME: get list of floppy extensions from a central
                    # place
                    if ext in [".adf", ".ipf"]:
                        embedded_files.append(file)
            if len(embedded_files) > 0:
                embedded_files.sort()
                print("found embedded floppy images:")
                print(embedded_files)
                for file in embedded_files:
                    paths.append(file)
            else:
                paths.append(path)

        checksum_tool = ChecksumTool(parent)
        for i, path in enumerate(paths):
            sha1 = checksum_tool.checksum(path)
            path = Paths.contract_path(
                path, default_dir, force_real_case=False)

            if i < 4:
                LauncherConfig.set_multiple([
                    ("floppy_drive_{0}".format(i), path),
                    ("x_floppy_drive_{0}_sha1".format(i), sha1)])
            LauncherConfig.set_multiple([
                ("floppy_image_{0}".format(i), path),
                ("x_floppy_image_{0}_sha1".format(i), sha1)])

        # blank the rest of the drives
        for i in range(len(paths), 4):
            LauncherConfig.set_multiple([
                ("floppy_drive_{0}".format(i), ""),
                ("x_floppy_drive_{0}_sha1".format(i), "")])
        # blank the rest of the image list
        for i in range(len(paths), 20):
            LauncherConfig.set_multiple([
                ("floppy_image_{0}".format(i), ""),
                ("x_floppy_image_{0}_sha1".format(i), "")])
Пример #52
0
    def get_cover_path(self):
        sha1 = LauncherConfig.get("front_sha1")
        if sha1:
            return "sha1:" + sha1

        path = self.get_override_path("cover_image")
        if path and os.path.exists(path):
            return path
        if self.uuid:
            paths = FSGSDirectories.get_images_dirs()
            for dir_ in paths:
                p = os.path.join(dir_, self.platform, "Images",
                                 self.uuid[:2], self.uuid, "front.png")
                if os.path.exists(p):
                    return p
                p = os.path.join(dir_, self.platform, "Thumbnails",
                                 self.uuid[:2], self.uuid, "front.png")
                if os.path.exists(p):
                    return p
        letter = self.get_letter(self.name)
        if not letter:
            return None
        name = self.name
        override_dir = LauncherConfig.get("covers_dir")
        if override_dir:
            paths = [Paths.expand_path(override_dir)]
        else:
            paths = FSGSDirectories.get_covers_dirs()
        for dir_ in paths:
            path = os.path.join(dir_, letter, name + ".jpg")
            if os.path.exists(path):
                return path
            path = os.path.join(dir_, letter, name + ".png")
            if os.path.exists(path):
                return path
            path = os.path.join(dir_, name + ".jpg")
            if os.path.exists(path):
                return path
            path = os.path.join(dir_, name + ".png")
            if os.path.exists(path):
                return path
        return None
Пример #53
0
 def encode_path(self, path):
     # This only works if both path and FSGSDirectories.base_dir (etc) have
     # been normalized with get_real_case.
     path = path.replace("\\", "/")
     base_dir = FSGSDirectories.get_base_dir()
     if path.startswith(base_dir):
         path = path[len(base_dir):]
         if path.startswith("/"):
             path = path[1:]
         path = "$/" + path
     return path
Пример #54
0
 def encode_path(self, path):
     # This only works if both path and FSGSDirectories.base_dir (etc) have
     # been normalized with get_real_case.
     path = path.replace("\\", "/")
     base_dir = FSGSDirectories.get_base_dir()
     if path.startswith(base_dir):
         path = path[len(base_dir) :]
         if path.startswith("/"):
             path = path[1:]
         path = "$/" + path
     return path
Пример #55
0
    def load_plugins(cls):
        if cls._plugins_loaded:
            return
        cls._plugins_loaded = True

        plugins_dir = FSGSDirectories.get_plugins_dir()
        if plugins_dir:
            dont_write_bytecode = sys.dont_write_bytecode
            try:
                cls._load_plugins(plugins_dir)
            finally:
                sys.dont_write_bytecode = dont_write_bytecode
Пример #56
0
    def browse(self, dir_mode):
        default_dir = FSGSDirectories.get_hard_drives_dir()
        dialog = LauncherFilePicker(
            self.get_window(),
            gettext("Choose Hard Drive"),
            "hd",
            LauncherConfig.get(self.config_key),
            dir_mode=dir_mode,
        )
        if not dialog.show_modal():
            dialog.destroy()
            return
        path = dialog.get_path()
        dialog.destroy()

        checksum_tool = ChecksumTool(self.get_window())
        sha1 = ""
        if dir_mode:
            print("not calculating HD checksums for directories")
        else:
            size = os.path.getsize(path)
            if size < 64 * 1024 * 1024:
                sha1 = checksum_tool.checksum(path)
            else:
                print("not calculating HD checksums HD files > 64MB")
        full_path = path

        # FIXME: use contract function
        dir_path, file = os.path.split(path)
        self.text_field.set_text(file)
        if os.path.normcase(os.path.normpath(dir_path)) == os.path.normcase(
            os.path.normpath(default_dir)
        ):
            path = file

        self.text_field.set_text(path)
        values = [(self.config_key, path), (self.config_key_sha1, sha1)]
        if self.index == 0:
            # whdload_args = ""
            # dummy, ext = os.path.splitext(path)
            # if not dir_mode and ext.lower() in Archive.extensions:
            #     try:
            #         whdload_args = self.calculate_whdload_args(full_path)
            #     except Exception:
            #         traceback.print_exc()
            # values.append(("x_whdload_args", whdload_args))
            values.extend(
                whdload.generate_config_for_archive(
                    full_path, model_config=False
                ).items()
            )
        LauncherConfig.set_multiple(values)