Ejemplo n.º 1
0
        public InstallManifestFile(FileInfo file)
        {
            try
            {
                using var filestream = file.OpenRead();
                var content = XElement.Load(filestream);
                if (content.Name != "DAZInstallManifest")
                {
                    throw new CorruptFileException($"Not install manifest file: {file.FullName}");
                }

                GlobalID = content.Element("GlobalID")?.Attribute("VALUE")?.Value;

                var metadataGUIDElement = content.Element("MetadataGlobalID");

                ProductName     = content.Element("ProductName")?.Attribute("VALUE")?.Value;
                ProductStoreID  = content.Element("ProductStoreIDX")?.Attribute("VALUE")?.Value;
                UserInstallPath = content.Element("UserInstallPath")?.Attribute("VALUE")?.Value;

                // Only handle content packages not plugins.
                var installedTypes = content.Element("InstallTypes")?.Attribute("VALUE")?.Value;
                if (installedTypes == "Content")
                {
                    Files         = PackageManifestFile.GetFiles(content);
                    MetadataFiles = PackageManifestFile.FindMetadataFile(Files);
                }
            }
            catch (XmlException)
            {
                throw new CorruptFileException($"File maybe corrupt: {file.FullName}");
            }
            catch (IOException e)
            {
                throw new CorruptFileException($"{e.Message}\nFile:{file.FullName}");
            }
        }
        public DazProductZip(FileInfo file)
        {
            this.file = file;
            try
            {
                using var archive = System.IO.Compression.ZipFile.OpenRead(file.ToString());

                // Check Manifest.dsx file
                var manifestFile = archive.GetEntry("Manifest.dsx");

                if (manifestFile == null)
                {
                    HasSupplementFile = false;
                    return;
                }

                var packageXML = PackageManifestFile.GetXML(manifestFile);

                /// Check for metadata file
                var files = PackageManifestFile.GetFiles(packageXML);
                metadataFiles = PackageManifestFile.FindMetadataFile(files);

                var numberOfMetadataFiles = metadataFiles.Count;
                MissingMetadata       = numberOfMetadataFiles == 0;
                MultipleMetadataFiles = numberOfMetadataFiles != 1;

                if (!MissingMetadata && !MultipleMetadataFiles)
                {
                    var metadataFileEntry = "Content/" + metadataFiles.First();

                    var metadataFile = archive.GetEntry(metadataFileEntry);

                    if (metadataFile == null)
                    {
                        MissingMetadata = true;
                        return;
                    }

                    packageMetadata = new PackageMetadata(metadataFile);
                    ProductName     = packageMetadata.ProductName;
                }

                // Check for Supplemen.dsx file.
                try
                {
                    var supplementFileEntry = archive.GetEntry("Supplement.dsx");
                    if (supplementFileEntry == null)
                    {
                        HasSupplementFile = false;
                        return;
                    }
                    var supplement = new SupplementFile(supplementFileEntry);
                    ProductName       = supplement.ProductName;
                    HasSupplementFile = true;
                }
                catch (InvalidOperationException)
                {
                }
            }
            catch (InvalidDataException e)
            {
                // Missing metadata file or metadata file is corrupt i think.
                //throw new CorruptFileException($"{e.Message} {file.FullName}"); // TODO check what is causing this.
                InfoBox.Write($"{e.Message} {file.FullName}", InfoBox.Level.Warning);
            }
        }