示例#1
0
    def get_cached_package_metadata(self, reference):
        zip_path = self.get_package_cache_path(reference)

        try:
            with ZipFile(zip_path) as unzip:
                data = json.loads(
                    unzip.read("manifest.json").decode("utf-8-sig"))
                icon_data = BytesIO(unzip.read("icon.png"))
        except Exception:
            return PackageMetadata(
                namespace=reference.namespace,
                name=reference.name,
                version=reference.version_str,
                description="",
                downloads="Unknown",
                dependencies=[],
                extra_data={},
            )

        return PackageMetadata(
            namespace=reference.namespace,
            name=reference.name,
            version=reference.version_str,
            description=data.get("description", ""),
            downloads="Unknown",
            icon_data=icon_data,
            dependencies=[
                PackageReference.parse(x)
                for x in data.get("dependencies", [])
            ],
            extra_data=data.get("extra_data", {}),
        )
示例#2
0
 def extracted_packages(self):
     result = []
     for entry in self.extracted_log_path.glob("*.json"):
         try:
             result.append(PackageReference.parse(entry.stem))
         except Exception:
             pass
     return result
示例#3
0
 def managed_packages(self):
     result = []
     for entry in self.managed_mods_path.glob("*"):
         if entry.is_dir() and (entry / "manifest.json").exists():
             try:
                 result.append(PackageReference.parse(entry.name))
             except Exception:
                 pass
     return result
示例#4
0
 def get_managed_package_metadata(self, reference):
     managed_path = self.get_managed_package_path(reference)
     manifest_path = managed_path / "manifest.json"
     icon_path = managed_path / "icon.png"
     with open(manifest_path, "rb") as f:
         data = json.loads(f.read().decode("utf-8-sig"))
     with open(icon_path, "rb") as f:
         icon_data = BytesIO(f.read())
     return PackageMetadata(
         namespace=reference.namespace,
         name=reference.name,
         version=reference.version_str,
         description=data.get("description", ""),
         downloads="Unknown",
         icon_data=icon_data,
         dependencies=[
             PackageReference.parse(x)
             for x in data.get("dependencies", [])
         ],
     )
示例#5
0
    async def attempt_import(self, raw_data):
        try:
            references = json.loads(raw_data)
        except Exception:
            wx.MessageBox(
                "Failed to import mod configuration. Is it proper JSON?",
                "Error",
                wx.OK | wx.ICON_ERROR,
            )
            return

        try:
            references = [PackageReference.parse(x) for x in references]
        except Exception:
            wx.MessageBox(
                "Failed to parse some of the mod names and could not import.",
                "Error",
                wx.OK | wx.ICON_ERROR,
            )
            return

        for reference in references:
            await self.add_job(DownloadAndInstallPackage, reference)
示例#6
0
    def resolve_package_metadata(self, reference):
        """
        :param package: The package to resolve metadata for
        :type package: PackageReference or Package or str
        """
        if hasattr(reference, "package_reference"):
            reference = reference.package_reference
        if not isinstance(reference, PackageReference):
            reference = PackageReference.parse(reference)
        if reference in self.api.packages:
            url = self.api.packages[reference.without_version].package_url
            return PackageMetadata.from_package(self.api.packages[reference],
                                                url)

        if not reference.version:
            version = self.get_newest_managed(reference)
            if version:
                return self.get_managed_package_metadata(version)

        if reference in self.managed_packages:
            return self.get_managed_package_metadata(reference)

        if reference in self.extracted_packages:
            if not reference.version:
                version = self.get_newest_extracted(reference)
                if version:
                    return self.get_cached_package_metadata(version)
            return self.get_cached_package_metadata(reference)

        if not reference.version:
            version = self.get_newest_cached(reference)
            if version:
                return self.get_cached_package_metadata(version)

        if reference in self.cached_packages:
            return self.get_cached_package_metadata(reference)
        return PackageMetadata.empty()
示例#7
0
 def cached_packages(self):
     return [
         PackageReference.parse(x.stem)
         for x in self.mod_cache_path.glob("*.zip")
     ]