def get_all_mods(self, progress_func=None):
        """Returns data and errors for all mods."""

        enabled_mod_folders = files.listdir_dirs(self.get_sim_mod_folder(),
                                                 full_paths=True)
        disabled_mod_folders = files.listdir_dirs(
            files.get_mod_install_folder(), full_paths=True)

        for folder in enabled_mod_folders:
            # remove duplicate folders from disabled list if there is a symlink for them
            if files.is_symlink(folder):
                install_folder = os.path.join(files.get_mod_install_folder(),
                                              os.path.basename(folder))
                if install_folder in disabled_mod_folders:
                    disabled_mod_folders.remove(install_folder)

        enabled_mod_data, enabled_mod_errors = self.get_mods(
            enabled_mod_folders, enabled=True, progress_func=progress_func)
        disabled_mod_data, disabled_mod_errors = self.get_mods(
            disabled_mod_folders,
            enabled=False,
            progress_func=progress_func,
            start=len(enabled_mod_data) - 1,
        )

        return (
            enabled_mod_data + disabled_mod_data,
            enabled_mod_errors + disabled_mod_errors,
        )
Exemple #2
0
def is_sim_packages_folder(folder):
    """Returns whether the given folder is the FS2020 packages folder.
    Not a perfect test, but a decent guess."""
    # test if the folder above it contains both 'Community' and 'Official'
    logger.debug("Testing if {} is MSFS sim packages folder".format(folder))
    try:
        packages_folders = files.listdir_dirs(folder)
        status = "Official" in packages_folders and "Community" in packages_folders
        logger.debug("Folder {} is MSFS sim packages folder: {}".format(folder, status))
        return status
    except Exception:
        logger.exception("Checking sim packages folder status failed")
        return False
    def get_sim_official_folder(self):
        """Returns the path to the official packages folder inside Flight Simulator.
        Tries to resolve symlinks in every step of the path."""
        # logger.debug("Determining path for sim official packages folder")

        # path to official packages folder
        official_packages = files.resolve_symlink(
            os.path.join(self.sim_packages_folder, "Official"))
        # choose folder inside
        store = files.listdir_dirs(official_packages)[0]

        return files.fix_path(
            files.resolve_symlink(os.path.join(official_packages, store)))
Exemple #4
0
def get_enabled_mods(sim_folder):
    """Returns data for the enabled mods."""
    logger.debug("Retrieving list of enabled mods")
    enabled_mods = []
    errors = []

    for folder in files.listdir_dirs(sim_mod_folder(sim_folder)):
        # parse each mod
        try:
            enabled_mods.append(parse_mod_manifest(sim_folder, folder, True))
        except (NoManifestError, ManifestError):
            errors.append(folder)

    return enabled_mods, errors
Exemple #5
0
    def move_mod_install_folder(
        self, src: str, dest: str, update_func: Callable = None
    ) -> None:
        """Moves the mod install folder."""
        logger.debug("Moving mod install folder from {} to {}".format(src, dest))
        # first, build a list of the currently enabled mods
        enabled_mod_folders = files.listdir_dirs(self.get_sim_mod_folder())

        # move the install folder
        files.move_folder(src, dest, update_func=update_func)

        # set new config value
        config.set_key_value(config.MOD_INSTALL_FOLDER_KEY, dest, path=True)
        # clear the cache
        self.clear_mod_cache()
        config.get_key_value.cache_clear()

        # now, go through mods in the install folder and re-enable them
        # if they were enabled before.
        moved_mod_folders = files.listdir_dirs(dest)

        for mod_folder in moved_mod_folders:
            if mod_folder in enabled_mod_folders:
                self.enable_mod(mod_folder, update_func=update_func)
Exemple #6
0
def get_disabled_mods(sim_folder):
    """Returns data for the disabled mods."""
    logger.debug("Retrieving list of disabled mods")
    # ensure cache folder already exists
    files.create_mod_cache_folder()

    disabled_mods = []
    errors = []

    for folder in files.listdir_dirs(files.MOD_CACHE_FOLDER):
        # parse each mod
        try:
            disabled_mods.append(parse_mod_manifest(sim_folder, folder, False))
        except (NoManifestError, ManifestError):
            errors.append(folder)

    return disabled_mods, errors