/// <summary>
 /// Create Zip
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BtnCreateZip_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var factory = new GeneralZipFactory();
         factory.CompressProgress += OnCompressProgress;
         //Compress all files in this path:D:\Updatetest_hub\Run_app , D:\Updatetest_hub
         factory.CreatefOperate(GetOperationType(), TxtZipPath.Text, TxtUnZipPath.Text).
         CreatZip();
     }
     catch (Exception ex)
     {
         MessageBox.Show($"CreatZip error : { ex.Message } ");
     }
 }
 /// <summary>
 /// UnZip
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BtnUnZip_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var factory = new GeneralZipFactory();
         factory.UnZipProgress += OnUnZipProgress;
         factory.Completed     += OnCompleted;
         //D:\Updatetest_hub\Run_app\1.zip , D:\Updatetest_hub
         factory.CreatefOperate(GetOperationType(), TxtZipPath.Text, TxtUnZipPath.Text, true).
         UnZip();
     }
     catch (Exception ex)
     {
         MessageBox.Show($"UnZip error : { ex.Message } ");
     }
 }
        /// <summary>
        /// Generate patch file [Cannot contain files with the same name but different extensions] .
        /// </summary>
        /// <param name="appPath">Previous version folder path .</param>
        /// <param name="targetPath">Recent version folder path.</param>
        /// <param name="patchPath">Store discovered incremental update files in a temporary directory .</param>
        /// <param name="compressProgressCallback">Incremental package generation progress callback function.</param>
        /// <param name="type">7z or zip</param>
        /// <param name="encoding">Incremental packet encoding format .</param>
        /// <returns></returns>
        public async Task Clean(string appPath, string targetPath, string patchPath = null, Action <object, BaseCompressProgressEventArgs> compressProgressCallback = null, OperationType type = OperationType.GZip, Encoding encoding = null)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(patchPath))
                {
                    patchPath = Path.Combine(Environment.CurrentDirectory, PATCHS);
                }
                if (!Directory.Exists(patchPath))
                {
                    Directory.CreateDirectory(patchPath);
                }

                //Take the left tree as the center to match the files that are not in the right tree .
                var tupleResult = FileUtil.Compare(targetPath, appPath);

                //Binary differencing of like terms .
                foreach (var file in tupleResult.Item2)
                {
                    var oldfile       = Path.Combine(appPath, file.Name);
                    var newfile       = file.FullName;
                    var extensionName = Path.GetExtension(file.FullName);
                    if (File.Exists(oldfile) && File.Exists(newfile) && !Filefilter.Diff.Contains(extensionName))
                    {
                        //Generate the difference file to the difference directory .
                        await new BinaryHandle().Clean(Path.Combine(appPath, file.Name), file.FullName,
                                                       Path.Combine(patchPath, $"{ Path.GetFileNameWithoutExtension(file.Name) }{ PATCH_FORMAT }"));
                    }
                    else
                    {
                        File.Copy(newfile, Path.Combine(patchPath, Path.GetFileName(newfile)), true);
                    }
                }
                _compressProgressCallback = compressProgressCallback;
                var factory = new GeneralZipFactory();
                if (_compressProgressCallback != null)
                {
                    factory.CompressProgress += OnCompressProgress;
                }
                //The update package exists in the 'target path' directory.
                factory.CreatefOperate(type, patchPath, targetPath, true, encoding).CreatZip();
            }
            catch (Exception ex)
            {
                throw new Exception($"Generate error : { ex.Message } !", ex.InnerException);
            }
        }
Exemple #4
0
 /// <summary>
 /// UnZip
 /// </summary>
 /// <param name="zipfilepath"></param>
 /// <param name="unzippath"></param>
 /// <param name="action"></param>
 /// <returns></returns>
 protected bool UnZip(BaseContext context)
 {
     try
     {
         bool isComplated       = false;
         var  generalZipfactory = new GeneralZipFactory();
         generalZipfactory.UnZipProgress += (sender, e) => context.OnProgressEventAction(this, ProgressType.Updatefile, "Updatting file...");
         generalZipfactory.Completed     += (sender, e) => isComplated = true;
         generalZipfactory.CreatefOperate(MatchType(context.Format), context.ZipfilePath, context.TargetPath, false, context.Encoding).
         UnZip();
         return(isComplated);
     }
     catch (Exception ex)
     {
         context.OnExceptionEventAction(this, ex);
         return(false);
     }
 }