示例#1
0
        protected override void DisposeUnmanagedResources()
        {
            if (ReferencePackages?.Any() != true)
            {
                return;
            }

            foreach (var sdkModel in ReferencePackages)
            {
                sdkModel.Dispose();
            }
        }
示例#2
0
        public static bool CreateBaseEdition(
            string UUPPath,
            string LanguageCode,
            string EditionID,
            string InputWindowsREPath,
            string OutputInstallImage,
            Common.CompressionType CompressionType,
            ProgressCallback progressCallback = null)
        {
            bool result = true;

            WimCompressionType compression = WimCompressionType.None;

            switch (CompressionType)
            {
            case Common.CompressionType.LZMS:
                compression = WimCompressionType.Lzms;
                break;

            case Common.CompressionType.LZX:
                compression = WimCompressionType.Lzx;
                break;

            case Common.CompressionType.XPRESS:
                compression = WimCompressionType.Xpress;
                break;
            }

            HashSet <string> ReferencePackages, referencePackagesToConvert;
            string           BaseESD = null;

            (result, BaseESD, ReferencePackages, referencePackagesToConvert) = FileLocator.LocateFilesForBaseEditionCreation(UUPPath, LanguageCode, EditionID, progressCallback);
            if (!result)
            {
                goto exit;
            }

            progressCallback?.Invoke(Common.ProcessPhase.PreparingFiles, true, 0, "Converting Reference Cabinets");

            int counter = 0;
            int total   = referencePackagesToConvert.Count;

            foreach (var file in referencePackagesToConvert)
            {
                int progressoffset = (int)Math.Round((double)counter / total * 100);
                int progressScale  = (int)Math.Round((double)1 / total * 100);

                string refesd = ConvertCABToESD(Path.Combine(UUPPath, file), progressCallback, progressoffset, progressScale);
                if (string.IsNullOrEmpty(refesd))
                {
                    progressCallback?.Invoke(Common.ProcessPhase.ReadingMetadata, true, 0, "Reference ESD creation from Cabinet files failed");
                    goto exit;
                }
                ReferencePackages.Add(refesd);
                counter++;
            }

            //
            // Gather information to transplant later into DisplayName and DisplayDescription
            //
            WIMInformationXML.IMAGE image;
            imagingInterface.GetWIMImageInformation(BaseESD, 3, out image);

            //
            // Export the install image
            //
            void callback(string Operation, int ProgressPercentage, bool IsIndeterminate)
            {
                progressCallback?.Invoke(Common.ProcessPhase.ApplyingImage, IsIndeterminate, ProgressPercentage, Operation);
            };

            result = imagingInterface.ExportImage(
                BaseESD,
                OutputInstallImage,
                3,
                referenceWIMs: ReferencePackages,
                compressionType: compression,
                progressCallback: callback);
            if (!result)
            {
                goto exit;
            }

            WIMInformationXML.WIM wim;
            imagingInterface.GetWIMInformation(OutputInstallImage, out wim);

            //
            // Set the correct metadata on the image
            //
            image.DISPLAYNAME        = image.NAME;
            image.DISPLAYDESCRIPTION = image.NAME;
            image.FLAGS = image.WINDOWS.EDITIONID;
            if (image.WINDOWS.LANGUAGES == null)
            {
                image.WINDOWS.LANGUAGES = new WIMInformationXML.LANGUAGES()
                {
                    LANGUAGE = LanguageCode,
                    FALLBACK = new WIMInformationXML.FALLBACK()
                    {
                        LANGUAGE = LanguageCode,
                        Text     = "en-US"
                    },
                    DEFAULT = LanguageCode
                };
            }
            result = imagingInterface.SetWIMImageInformation(OutputInstallImage, wim.IMAGE.Count, image);
            if (!result)
            {
                goto exit;
            }

            void callback2(string Operation, int ProgressPercentage, bool IsIndeterminate)
            {
                progressCallback?.Invoke(Common.ProcessPhase.IntegratingWinRE, IsIndeterminate, ProgressPercentage, Operation);
            };

            //
            // Integrate the WinRE image into the installation image
            //
            progressCallback?.Invoke(Common.ProcessPhase.IntegratingWinRE, true, 0, "");

            result = imagingInterface.AddFileToImage(
                OutputInstallImage,
                wim.IMAGE.Count,
                InputWindowsREPath,
                Path.Combine("Windows", "System32", "Recovery", "Winre.wim"),
                callback2);
            if (!result)
            {
                goto exit;
            }

exit:
            return(result);
        }