示例#1
0
        /// <summary>
        /// Create an AAPKG file from a source directory
        /// </summary>
        /// <param name="SourceDirectory"></param>
        /// <param name="AAPKGFilename"></param>
        public void CreateAAPKG(string SourceDirectory, string AAPKGFilename, Microsoft.Deployment.Compression.CompressionLevel CompressionLevel = Microsoft.Deployment.Compression.CompressionLevel.Normal)
        {
            string file1Path;

            try
            {
                log.Debug("");

                file1Path = Path.GetTempPath() + "file1.cab";

                // Create the File1.cab file from the directory containing all of the source files
                CabInfo ci = new CabInfo(file1Path);
                ci.Pack(SourceDirectory, true, CompressionLevel, null);

                //Now create a string list of just the File1.cab file and compress this to the final aapkg file
                List <String> SourceFiles = new List <String>();
                SourceFiles.Add(file1Path);
                CabInfo ciAAPKG = new CabInfo(AAPKGFilename);
                ciAAPKG.PackFiles(null, SourceFiles, null, CompressionLevel, null);
            }
            catch
            {
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// Remove all AAPDF files from an AAPKG file
        /// </summary>
        /// <param name="AAPKGFilePath"></param>
        /// <param name="NewAAPKGFileName"></param>
        /// <param name="CompressionLevel"></param>
        public void RemoveAAPDFFromAAPKGFile(string AAPKGFilePath, string NewAAPKGFileName = "", Microsoft.Deployment.Compression.CompressionLevel CompressionLevel = Microsoft.Deployment.Compression.CompressionLevel.Normal)
        {
            try
            {
                log.Debug("");

                this.MinifyAAPKG(AAPKGFilePath, null, true, NewAAPKGFileName, CompressionLevel);
            }
            catch
            {
                throw;
            }
        }
示例#3
0
        /// <summary>
        /// Remove all templates from an AAPKG file
        /// </summary>
        /// <param name="AAPKGFilePath"></param>
        /// <param name="NewAAPKGFileName"></param>
        /// <param name="CompressionLevel"></param>
        public void RemoveTemplatesFromAAPKG(string AAPKGFilePath, string NewAAPKGFileName = "", Microsoft.Deployment.Compression.CompressionLevel CompressionLevel = Microsoft.Deployment.Compression.CompressionLevel.Normal)
        {
            string workingPath;
            string manifestFileName;

            try
            {
                log.Debug("");

                // Extract to a temporary location
                workingPath = this.UnpackAAPKG(AAPKGFilePath);

                //Calculate the path to the manifest
                manifestFileName = workingPath + @"\Manifest.xml";

                // Load the Manifest File
                XDocument xmanifestDoc = XDocument.Load(manifestFileName);

                //Remove items from aaPKG file based on the objects to keep list that has been passed
                this.RemoveTemplatesFromUnpackedFiles(workingPath, ref xmanifestDoc, new List <String>());

                // Save the doc back
                xmanifestDoc.Save(manifestFileName);

                //If we don't have a new aapkg name then just reuse the old name
                if (NewAAPKGFileName == "")
                {
                    NewAAPKGFileName = AAPKGFilePath;
                }

                // Repackage the AAPKG
                this.CreateAAPKG(workingPath, NewAAPKGFileName, CompressionLevel);

                //Delete the working path
                if (System.IO.Directory.Exists(workingPath))
                {
                    System.IO.Directory.Delete(workingPath, true);
                }
            }
            catch
            {
                throw;
            }
        }
示例#4
0
        /// <summary>
        /// Minify an AAPKG by removing objects from an AAPKG
        /// </summary>
        /// <param name="AAPKGFilePath"></param>
        /// <param name="ObjectsToKeep"></param>
        /// <param name="ExcludeAAPDFFiles"></param>
        /// <param name="NewAAPKGFileName"></param>
        /// <param name="CompressionLevel"></param>
        public void MinifyAAPKG(string AAPKGFilePath, List <String> ObjectsToKeep = null, bool ExcludeAAPDFFiles = true, string NewAAPKGFileName = "", Microsoft.Deployment.Compression.CompressionLevel CompressionLevel = Microsoft.Deployment.Compression.CompressionLevel.Normal)
        {
            string workingPath;
            string manifestFileName;

            try
            {
                log.Debug("");

                // Extract to a temporary location
                workingPath = this.UnpackAAPKG(AAPKGFilePath);
                log.Debug("workingPath: " + workingPath);

                //Calculate the path to the manifest
                manifestFileName = workingPath + @"\Manifest.xml";
                log.Debug("manifestFileName: " + manifestFileName);

                // Load the Manifest File
                XDocument xmanifestDoc = XDocument.Load(manifestFileName);
                log.Debug("xmanifestDoc: ");
                log.Debug(xmanifestDoc.ToString());


                // If objects is null then create a blank
                if (ObjectsToKeep == null)
                {
                    ObjectsToKeep = new List <String>();
                    log.Debug("ObjectsToKeep Null.  Set to new List<String>()");
                }


                log.Debug("ObjectsToKeep: " + ObjectsToKeep.ToString());

                // If the Objects to Keep list is not null then remove items based on the list
                if (ObjectsToKeep.Count() > 0)
                {
                    //Remove items from aaPKG file based on the objects to keep list that has been passed
                    this.RemoveItemsFromUnpackedFiles(workingPath, ref xmanifestDoc, ObjectsToKeep);
                }

                log.Debug("ExcludeAAPDFFiles: " + ExcludeAAPDFFiles);
                // Remove the aaPDF files if required
                if (ExcludeAAPDFFiles)
                {
                    this.RemoveAAPDFFilesFromUnpackedFiles(workingPath, ref xmanifestDoc);
                }

                // Save the doc back
                xmanifestDoc.Save(manifestFileName);
                log.Debug("Saved xmanifestDoc");
                log.Debug("xmanifestDoc: ");
                log.Debug(xmanifestDoc.ToString());


                //If we don't have a new aapkg name then just reuse the old name
                if (NewAAPKGFileName == "")
                {
                    log.Debug("NewAAPKGFileName blank. Setting to " + AAPKGFilePath);
                    NewAAPKGFileName = AAPKGFilePath;
                }

                // Repackage the AAPKG
                this.CreateAAPKG(workingPath, NewAAPKGFileName, CompressionLevel);

                //Delete the working path
                if (System.IO.Directory.Exists(workingPath))
                {
                    System.IO.Directory.Delete(workingPath, true);
                }
                log.Debug("workingPath " + workingPath + " deleted");
            }
            catch
            {
                throw;
            }
        }