Beispiel #1
0
    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)))
Beispiel #2
0
    def get_sim_mod_folder(self):
        """Returns the path to the community packages folder inside Flight Simulator.
        Tries to resolve symlinks in every step of the path."""
        # logger.debug("Determining path for sim community packages folder")

        return files.fix_path(
            files.resolve_symlink(
                os.path.join(self.sim_packages_folder, "Community")))
Beispiel #3
0
    def get_game_version(self):
        """Attempts to guess the game's version.
        This is based on the fs-base package and the minimum game version listed."""
        logger.debug("Attempting to determine game version")
        version = "???"
        # build path to fs-base manifest
        fs_base = files.resolve_symlink(
            os.path.join(self.get_sim_official_folder(), "fs-base"))
        # parse it if we guessed correct
        if os.path.isdir(fs_base):
            data = self.parse_mod_manifest(fs_base)
            version = data["minimum_game_version"]

        logger.debug("Game version: {}".format(version))
        return version
Beispiel #4
0
    def parse_mod_layout(self, mod_folder: str) -> dict:
        """Builds the mod files info as a dictionary. Parsed from the layout.json."""
        logger.debug("Parsing layout for {}".format(mod_folder))

        layout_path = files.resolve_symlink(os.path.join(mod_folder, "layout.json"))

        if not os.path.isfile(layout_path):
            logger.error("No layout.json found")
            raise NoLayoutError(mod_folder)

        try:
            with open(layout_path, "r", encoding="utf8") as f:
                data = json.load(f)
        except Exception as e:
            if hasattr(e, "winerror"):
                logger.exception("WinError: {}".format(e.winerror))  # type: ignore
            logger.exception("layout.json could not be parsed")
            raise LayoutError(e)

        return data["content"]
Beispiel #5
0
    def parse_mod_manifest(self, mod_folder, enabled=True):
        """Builds the mod metadata as a dictionary. Parsed from the manifest.json."""
        logger.debug("Parsing manifest for {}".format(mod_folder))

        mod_data = {"folder_name": os.path.basename(mod_folder)}
        manifest_path = files.resolve_symlink(
            os.path.join(mod_folder, "manifest.json"))

        if not os.path.isfile(manifest_path):
            logger.error("No manifest.json found")
            raise NoManifestError(mod_folder)

        try:
            with open(manifest_path, "r", encoding="utf8") as f:
                data = json.load(f)
        except Exception as e:
            if hasattr(e, "winerror"):
                logger.exception("WinError: {}".format(e.winerror))
            logger.exception("manifest.json could not be opened/parsed")
            raise ManifestError(e)

        # manifest data
        mod_data["content_type"] = data.get("content_type", "")
        mod_data["title"] = data.get("title", "")
        mod_data["manufacturer"] = data.get("manufacturer", "")
        mod_data["creator"] = data.get("creator", "")
        mod_data["version"] = data.get("package_version", "")
        mod_data["minimum_game_version"] = data.get("minimum_game_version", "")

        # manifest metadata
        # Windows considering moving/copying a file 'creating' it again,
        # and not modifying contents
        mod_data["time_mod"] = datetime.datetime.fromtimestamp(
            os.path.getctime(manifest_path)).strftime("%Y-%m-%d %H:%M:%S")

        # convience, often helps to just have this included in the returned result
        # and its easier to to do here
        mod_data["enabled"] = enabled
        mod_data["full_path"] = os.path.abspath(mod_folder)

        return mod_data