示例#1
0
 public static void ZipAndroidProject(string dir)
 {
     using (var zip = new Ionic.Zip.ZipFile(Encoding.GetEncoding("gbk"))) {
         zip.AddFiles(Directory.GetFiles(dir).Where(i => !i.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase)).ToArray(), "");
         zip.AddFiles(Directory.GetFiles(Path.Combine(dir, "app")), "app");
         zip.AddDirectory(Path.Combine(Path.Combine(dir, "app"), "src"), "app/src");
         zip.AddDirectory(Path.Combine(dir, "gradle"), "gradle");
         var targetFileName = Path.Combine(dir, Path.GetFileName(dir) + ".zip");
         var count          = 0;
         while (File.Exists(targetFileName))
         {
             targetFileName = Path.Combine(dir, string.Format("{0} {1:000}.zip", Path.GetFileName(dir), ++count));
         }
         zip.Save(targetFileName);
     }
 }
示例#2
0
        void bwBackup_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (File.Exists(tempPath + "\\" + "DB_Full.bak"))
                {
                    File.Delete(tempPath + "\\" + "DB_Full.bak");
                }


                int x = BaseDataBase._NonQuery(string.Format("BACKUP DATABASE [Ma3an] TO DISK = '{0}\\DB_Full.bak' WITH NOFORMAT, NOINIT, SKIP, NOREWIND, NOUNLOAD,  STATS = 10", tempPath, BaseDataBase.ConnectionStringMaster));
                if (x == -1)
                {
                    using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile())
                    {
                        zip.Password = "******";
                        string[] files = Directory.GetFiles(Environment.CurrentDirectory + "\\Data");
                        zip.AddFiles(files, "Data");
                        zip.AddFile(tempPath + "\\" + "DB_Full.bak", "");
                        zip.Save(e.Argument + "\\" + BaseDataBase.DateNow.ToString("DB_Backup_ddMMyyyy") + ".bak");
                    }

                    //ZipFile.CreateFromDirectory("Data", e.Argument + "\\" + BaseDataBase.DateNow.ToString("DB_Backup_ddMMyyyy") + ".bak", CompressionLevel.NoCompression, true);
                    //using (ZipArchive zip = ZipFile.Open(e.Argument + "\\" + BaseDataBase.DateNow.ToString("DB_Backup_ddMMyyyy") + ".bak", ZipArchiveMode.Update))
                    //{
                    //    zip.CreateEntryFromFile(tempPath + "\\" + "DB_Full.bak", "DB_Full.bak");
                    //}
                }
                else
                {
                    e.Cancel = true;
                }
            }
            catch (Exception ex) { e.Cancel = true; }
        }
示例#3
0
        private ActionResult zipFiles(string sid)
        {
            JsonResult   result;
            MessageModel msg;
            string       dirPath = Server.MapPath("~/Temps/" + sid);

            if (!Directory.Exists(dirPath))
            {
                result      = new JsonResult();
                msg         = new MessageModel();
                msg.Code    = 500;
                msg.Message = "文件夹不存在";
                result.Data = msg;
                result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                return(result);
            }


            String ext = "*-min.jpg,*-min.jpeg,*-min.png";

            IEnumerable <string> list = Directory.GetFiles(dirPath).ToList()
                                        .Where(item => { return(ext.Contains(Path.GetExtension(item).ToLower())); })
                                        .Where(item => { return(Path.GetFileNameWithoutExtension(item).EndsWith("-min")); });

            using (Ionic.Zip.ZipFile entry = new Ionic.Zip.ZipFile())
            {
                //for(int i = 0;i<list.Length;i++){
                //    String path = list[i];
                //    String filename = Path.GetFileName(path);

                //}

                String zipPath = dirPath + "\\piccompress.zip";

                entry.AddFiles(list, "");



                entry.Save(zipPath);
            }


            result   = new JsonResult();
            msg      = new MessageModel();
            msg.Code = 200;
            string rootpath = Request.ApplicationPath;

            rootpath    = rootpath.EndsWith("/") ? rootpath : rootpath + "/";
            msg.Message = rootpath + "temps/" + sid + "/piccompress.zip";
            result.Data = msg;
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            return(result);
        }
示例#4
0
        public override bool Run()
        {
            var zipFileName = Path.ChangeExtension(mControl.DestinationFilePathResolvedValue, Common.FileExtensions.ZipFileExtension);

            using (var zip = new Ionic.Zip.ZipFile(zipFileName))
            {
                var files = Directory.EnumerateFiles(mControl.SourceFilePathResolvedValue, "*", SearchOption.AllDirectories);
                zip.AddFiles(files);
                zip.Save();
            }

            return(true);
        }
示例#5
0
        public static ZipFile Zip(ZipConfiguration config)
        {
            config.Validate();

            var zipFile = new ZipFile();

            zipFile.File = config.Destination;

            using (var zip = new Ionic.Zip.ZipFile(zipFile.File.FullName))
            {
                PrepareZipFile(zipFile, config);

                var fileNames = from f in zipFile.ZipItems select f.Name;

                zip.AddFiles(fileNames.ToList(), directoryPathInArchive: "");
                zip.ParallelDeflateThreshold = -1;
                zip.Save();
            }

            return(zipFile);
        }
示例#6
0
        private static void CriarArquivoZip()
        {
            if (File.Exists(_arquivoModelosProjetoPath))
            {
                File.Delete(_arquivoModelosProjetoPath);
            }

            if (File.Exists(_checksumPath))
            {
                File.Delete(_checksumPath);
            }

            using (var zipFile = new Ionic.Zip.ZipFile(System.Text.Encoding.UTF8))
            {
                zipFile.AddFiles(ObterImagensAtivas());
                zipFile.Save(_arquivoModelosProjetoPath);
            }

            var checksum = CreateMd5();

            File.WriteAllText(_checksumPath, checksum);
        }
示例#7
0
        /// <summary>
        /// 将传入的文件列表压缩到指定的目录下
        /// </summary>
        /// <param name="sourceFilesPaths">要压缩的文件路径列表</param>
        /// <param name="compressFileSavePath">压缩文件存放路径</param>
        /// <param name="compressFileName">压缩文件名(全名)</param>
        public static void Compress(IEnumerable <string> sourceFilesPaths, string compressFileSavePath)
        {
            if (File.Exists(compressFileSavePath))
            {
                try
                {
                    File.Delete(compressFileSavePath);
                }
                catch
                {
                }
            }

            try
            {
                using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(compressFileSavePath, Encoding.Default))
                {
                    //加密压缩
                    //将要压缩的文件夹添加到zip对象中去(要压缩的文件夹路径和名称)
                    zip.AddFiles(sourceFilesPaths.Distinct(), "");
                    //将要压缩的文件添加到zip对象中去,如果文件不存在抛错FileNotFoundExcept
                    //zip.AddFile(@"E:\\yangfeizai\\12051214544443\\"+"Jayzai.xml");
                    zip.Save();
                }
            }
            catch
            {
                using (ZipFile zip = ZipFile.Create(compressFileSavePath))
                {
                    zip.BeginUpdate();
                    sourceFilesPaths.ToList().ForEach(p =>
                    {
                        zip.Add(p, Path.GetFileName(p));
                    });
                    zip.CommitUpdate();
                }
            }
        }