示例#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
文件: Utilities.cs 项目: Qdabra/QFS
        private static string GetTemplate(string folderPath)
        {
            string  templateName = Path.Combine(folderPath, DateTime.Now.ToString("yyyymmDDHHmmss") + ".xsn");
            CabInfo cab          = new CabInfo(templateName);

            cab.Pack(folderPath);
            return(templateName);
        }
示例#3
0
        /// <summary>Creates a new cabinet file from the specified folder. WILL OVERWRITE ANY EXISTING CABINET FILE</summary>
        /// <param name="Folder"></param>
        /// <param name="Cab"></param>
        public static void FolderToCab(string Folder, string Cab)
        {
            if (File.Exists(Cab))
            {
                File.Delete(Cab);
            }
            CabInfo C = new CabInfo(Cab);

            C.Pack(Folder, true, CompressionLevel.None, ProgHandler);
        }
示例#4
0
 public static string Compress(string folderPath, string fileNamePath)
 {
     try
     {
         var cab = new CabInfo(fileNamePath);
         cab.Pack(folderPath, true, Microsoft.Deployment.Compression.CompressionLevel.Max, null);
         return(cab.FullName);
     }
     catch
     {
         return(String.Empty);
     }
 }
示例#5
0
 static void Main(string[] args)
 {
     try
     {
         const string CabFile   = @"E:\Gits\sample code\TestQML.cab";
         const string CabFolder = @"E:\Gits\sample code\TestQML";
         var          cabInfo   = new CabInfo(CabFile);
         cabInfo.Pack(CabFolder, true, Microsoft.Deployment.Compression.CompressionLevel.Max, Hanler);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
示例#6
0
        /// <summary>
        /// create a cab file from content of folder
        /// Save cab file into the same
        /// </summary>
        /// <param name="sourcefolder"></param>
        /// <param name="newFileName"></param>
        /// <returns></returns>
        private static string createCabFile(string sourcefolder, string newFileName)
        {
            //FileInfo fInfo = new FileInfo(oldFileName);

            //string directory = fInfo.DirectoryName;

            // path + fileName
            string newFileFullName = Path.Combine(sourcefolder, newFileName);

            CabInfo cab;

            bool isAscii = IsAscii(newFileName);

            // if only ascii characters in string then just pack file
            if (isAscii)
            {
                cab = new CabInfo(newFileFullName);
                cab.Pack(sourcefolder);
            }
            // if others than ascii characters are in filename, we need to pack to other file and then rename. CabInfo can't handle all unicode characters
            else
            {
                // use this is a temp file
                string tempCabFile = Path.Combine(sourcefolder, "TEMPCABFILE.xsn");

                cab = new CabInfo(tempCabFile);
                cab.Pack(sourcefolder);

                // delete already existing file
                if (File.Exists(newFileFullName))
                {
                    File.Delete(newFileName);
                }

                // move files to this location and rename (both happens in .Move)
                File.Move(tempCabFile, newFileFullName);
            }

            // return filepath of newly generated file
            return(newFileFullName);
        }
示例#7
0
        private async void Start_Click(object sender, RoutedEventArgs e)
        {
            IsBusy = true;
            var archive = Path.Combine(TargetPath, ArchiveName);

            try
            {
                // Create the file, or overwrite if the file exists.
                File.Create(archive).Dispose();
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
            }

            await Task.Factory.StartNew(() =>
            {
                try
                {
                    var cabInfo = new CabInfo(archive);
                    cabInfo.Pack(SourcePath, _includeSubFolders, Microsoft.Deployment.Compression.CompressionLevel.Max, null);
                    _isSuccess = true;
                }
                catch
                {
                    _isSuccess = false;
                }
            });

            IsBusy = false;

            if (_isSuccess)
            {
                System.Windows.MessageBox.Show("Successfully created cabinet!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                System.Windows.MessageBox.Show("Oops something went wrong!", "Failure", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
示例#8
0
        /// <summary>
        /// Copy each resource from its destination to a temp Cab folder. Each resource then is packed into a separate Cab-file.
        /// </summary>
        /// <param name="resources"></param>
        /// <returns></returns>
        internal string Write(Resource[] resources)
        {
            var index = 0;

            var tempCabFolderPath = string.Concat(Path.GetTempPath(), Guid.NewGuid());

            if (!Directory.Exists(tempCabFolderPath))
            {
                Directory.CreateDirectory(tempCabFolderPath);
            }

            foreach (var resource in resources)
            {
                var resourceTempFolderPath = Path.GetTempPath() + Guid.NewGuid();
                var resourceFolder         = resource.GetResourceFolder(resourceTempFolderPath);

                if (!Directory.Exists(resourceFolder))
                {
                    Directory.CreateDirectory(resourceFolder);
                }

                // We have checked resource.FilePath for possible null values as we received the input parameters
                File.Copy(resource.FilePath, Path.Combine(resourceFolder, Path.GetFileName(resource.FilePath)));

                var cabFileName = string.Format("ITEM~{0}.cab", index);

                resource.ShortCabinetName = cabFileName;

                index = index + 1;

                var cabInfo = new CabInfo(Path.Combine(tempCabFolderPath, cabFileName));
                cabInfo.Pack(resourceTempFolderPath, true, Microsoft.Deployment.Compression.CompressionLevel.Normal, null);
            }

            return(tempCabFolderPath);
        }
示例#9
0
        private void InsertUpdateFileToCab(string filePath)
        {
            EFile file;


            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                FileInfo fileInfo = new FileInfo(filePath);
                file            = new EFile();
                file.FileName   = Path.GetFileName(filePath);
                file.Lenght     = fileInfo.Length;
                file.LastUpDate = DateTime.Now;
                file.Source     = "New File";
                file.FileIcon   = FileIconLoader.GetFileIcon(file.FileName, false);
            }
            string temp = Path.GetTempPath() + "TempCab";

            cab.Unpack(temp);

            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(Path.GetTempPath() + "TempCab/_setup.xml");
            XmlNode root = xmldoc.SelectSingleNode("/wap-provisioningdoc/characteristic[@type='FileOperation']/characteristic[@translation='install']");
            //XmlNode root = xmldoc.SelectSingleNode("/wap-provisioningdoc/characteristic[@type='FileOperation']");


            //root.Attributes[""] = "";

            bool isExist = false;

            foreach (EFile f in Files)
            {
                if ((f.FileName.ToLower() == file.FileName.ToLower()) || (f.FileName.ToUpper() == file.FileName.ToUpper()))
                {
                    isExist     = true;
                    file.Source = f.Source;

                    f.Lenght     = file.Lenght;
                    f.LastUpDate = file.LastUpDate;

                    File.Copy(filePath, temp + "\\" + file.Source, true);
                }
            }

            if (!isExist)
            {
                File.Copy(filePath, temp + "\\" + file.FileName, true);

                //XmlNode node = xmldoc.CreateNode(XmlNodeType.Element, "characteristic",null);

                //XmlAttribute attr_type = xmldoc.CreateAttribute("type");
                //attr_type.Value = file.FileName;

                //XmlAttribute attr_translation = xmldoc.CreateAttribute("install");
                //attr_translation.Value = "install";

                //node.Attributes.Append(attr_type);
                //node.Attributes.Append(attr_translation);

                //root.AppendChild(node);

                //xmldoc.Save(Path.GetTempPath() + "TempCab/_setup.xml");

                Files.Add(file);
            }



            cab.Pack(temp, true, Microsoft.Deployment.Compression.CompressionLevel.None, null);

            Directory.Delete(temp, true);

            BindDataGrid();
        }
示例#10
0
        public static void Main(string[] args)
        {
            Options ops = new Options();

            CommandLine.Parser.Default.ParseArguments(args, ops);
            ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
            //ops.dbxToken = "";  //Hardcode your dropbox token here if you do not wish to pass as an argument


            if (ops.path == null)
            {
                return;
            }

            if (ops.decrypt == true)
            {
                DecryptFile(ops);
                return;
            }

            if (ops.compression == Options.Methods.Cab)
            {
                ops.OutFile = "data.cab";
                CabInfo cab = new CabInfo(Path.Combine(ops.path, ops.OutFile));
                try
                {
                    Thread cabThread = new Thread(() =>
                    {
                        cab.Pack(ops.path, true, Microsoft.Deployment.Compression.CompressionLevel.Max, null);
                    });
                    cabThread.Start();
                    cabThread.Join();

                    Console.WriteLine("[*] Attempting to encrypt cab file.");
                    EncryptFile(ops);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
            else
            {
                if (ops.compression == Options.Methods.Zip)
                {
                    ZipFile zip = new ZipFile();
                    try
                    {
                        ops.OutFile = "data.zip";
                        Thread zipThread = new Thread(() =>
                        {
                            string[] files = Directory.GetFiles(ops.path);
                            foreach (string fileName in files)
                            {
                                zip.AddFile(fileName, "archive");
                                zip.Save(Path.Combine(ops.path, ops.OutFile));
                            }
                        });
                        zipThread.Start();
                        zipThread.Join();

                        Console.WriteLine("[*] Attempting to encrypt zip file.");
                        EncryptFile(ops);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                }
                else
                {
                    return;
                }
            }
        }