private static void ZippingBinary() // используется ДОзапись, обычным методом .Add(filePath, entryName), для перезаписи с нуля нужно использовать ZipOutputStream zipToWrite = new ZipOutputStream(zipStream) и FileStream targetFile
        {
            if (!File.Exists(pathToBinary))
            {
                throw new Exception("File release.aar not found. Please reimport asset. See README.md for details...");
            }

            if (!Directory.Exists(pathToTempFolder))
            {
                throw new Exception("Temp folder not found. See README.pdf for details...");
            }

            using (FileStream zipStream = new FileStream(pathToBinary, FileMode.Open))
            {
                using (ZipFile zipFile = new ZipFile(zipStream))
                {
                    zipFile.BeginUpdate();
                    zipFile.Add(Path.Combine(pathToTempFolder, MANIFEST_NAME), MANIFEST_NAME);
                    zipFile.Add(Path.Combine(pathToTempFolder, PROVIDER_PATHS_NAME), PROVIDER_PATHS_NAME);
                    zipFile.CommitUpdate();
                }
            }
        }
예제 #2
0
 void runZip(ZipFile nZipFile)
 {
     foreach (SZipDirectory i in mZipDirectorys)
     {
         i.runZip(nZipFile);
     }
     foreach (string i in mZipFiles)
     {
         if (File.Exists(i))
         {
             nZipFile.Add(i);
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Данный метод  ArhYesPath преднозначен для добавление в архив файла
 /// </summary>
 /// <param name="arhName"></param>  Параметр Имени Архива
 /// <param name="file"></param>     Параметр добавляемого файла
 internal static void ArhYesPath(string arhName, DataRow file)
 {
     using (var zipAdd = File.Open(arhName, FileMode.Open, FileAccess.ReadWrite))
     {
         using (var zip1 = new ZipFile(zipAdd))
         {
             zip1.BeginUpdate();
             zip1.Add(Path.GetFullPath(file.ItemArray[0].ToString()), Path.GetFileName(file.ItemArray[0].ToString()));
             zip1.CommitUpdate();
             zip1.Close();
         }
         zipAdd.Close();
     }
 }
예제 #4
0
    /// <summary>
    /// 压缩多个文件
    /// </summary>
    /// <param name="inFiles">压缩文件列表</param>
    /// <param name="outFile">压缩后文件名</param>
    public static void Zip(List <string> inFiles, string zipFile)
    {
        using (ZipFile zip = ZipFile.Create(zipFile))
        {
            zip.BeginUpdate();

            foreach (string inFile in inFiles)
            {
                zip.Add(inFile);
            }

            zip.CommitUpdate();
        }
    }
예제 #5
0
    /// <summary>
    /// 压缩多个文件
    /// </summary>
    /// <param name="inFiles">压缩文件字典(文件名-标识名)</param>
    /// <param name="outFile">压缩后的文件名</param>
    public static void Zip(Dictionary <string, string> inFiles, string zipFile)
    {
        using (ZipFile zip = ZipFile.Create(zipFile))
        {
            zip.BeginUpdate();

            foreach (var kv in inFiles)
            {
                //Debug.Log("fileName: " + kv.Key + " entryName: " + kv.Value);
                zip.Add(kv.Key, kv.Value);
            }
            zip.CommitUpdate();
        }
    }
예제 #6
0
        public void Crypto_AddEncryptedEntryToExistingArchiveSafe()
        {
            var ms = new MemoryStream();

            byte[] rawData;

            using (ZipFile testFile = new ZipFile(ms))
            {
                testFile.IsStreamOwner = false;
                testFile.BeginUpdate();
                testFile.Add(new StringMemoryDataSource("Aha"), "No1", CompressionMethod.Stored);
                testFile.Add(new StringMemoryDataSource("And so it goes"), "No2", CompressionMethod.Stored);
                testFile.Add(new StringMemoryDataSource("No3"), "No3", CompressionMethod.Stored);
                testFile.CommitUpdate();

                Assert.IsTrue(testFile.TestArchive(true));
                rawData = ms.ToArray();
            }

            ms = new MemoryStream(rawData);

            using (ZipFile testFile = new ZipFile(ms))
            {
                Assert.IsTrue(testFile.TestArchive(true));

                testFile.BeginUpdate(new MemoryArchiveStorage(FileUpdateMode.Safe));
                testFile.Password = "******";
                testFile.Add(new StringMemoryDataSource("Zapata!"), "encrypttest.xml");
                testFile.CommitUpdate();

                Assert.IsTrue(testFile.TestArchive(true));

                int entryIndex = testFile.FindEntry("encrypttest.xml", true);
                Assert.IsNotNull(entryIndex >= 0);
                Assert.IsTrue(testFile[entryIndex].IsCrypted);
            }
        }
예제 #7
0
        public void ProcessPath(PscxPathInfo pscxPath)
        {
            _command.WriteVerbose("Add/update " + pscxPath);
            try
            {
                if (_command.InvokeProvider.Item.IsContainer(pscxPath.ToString()))
                {
                    _zip.AddDirectory(pscxPath.ProviderPath);
                }
                else
                {
                    string fileName = pscxPath.ProviderPath;

                    if (_command.FlattenPaths.IsPresent)
                    {
                        fileName = Path.GetFileName(pscxPath.ProviderPath);
                        _command.WriteVerbose(String.Format("Flattened '{0}' to '{1}'", pscxPath.ProviderPath, fileName));
                        _zip.Add(pscxPath.ProviderPath, fileName); // new overload to SZL 0.86 (fixes -append -flattenpath bug)
                    }
                    else
                    {
                        _zip.Add(fileName);
                    }
                }
            }
            catch (PipelineStoppedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                var error = new ErrorRecord(ex, "ZipAddOrUpdateFail", ErrorCategory.WriteError, pscxPath);

                // perhaps allow erroraction to control whether terminating or not
                _command.ThrowTerminatingError(error);
            }
        }
        public override IEnumerable <string> PackByDictReporting(Dictionary <string, string> path, bool removeIfExists)
        {
            HashSet <string> zipNames = new HashSet <string>();

            try
            {
                if (File.Exists(targetArchivePath))
                {
                    if (removeIfExists)
                    {
                        File.Delete(targetArchivePath);
                        targetArchive = ZipFile.Create(targetArchivePath);
                    }
                    else
                    {
                        targetArchive = new ZipFile(targetArchivePath);
                    }
                }
                else
                {
                    targetArchive = ZipFile.Create(targetArchivePath);
                }
            }
            catch
            {
                System.Windows.MessageBox.Show("Packaging failed.");
                yield break;
            }
            foreach (ZipEntry ze in targetArchive)
            {
                zipNames.Add(ze.Name);
                //System.Windows.MessageBox.Show(ze.Name);
            }
            foreach (KeyValuePair <string, string> kvp in path)
            {
                targetArchive.BeginUpdate();
                yield return($"Adding file \"{kvp.Value}\" in to zip.");

                if (targetArchive.FindEntry(kvp.Key, true) > 0)
                {
                    targetArchive.Delete(kvp.Key);
                }
                targetArchive.Add(kvp.Value, kvp.Key);
                yield return($"Added file \"{kvp.Value}\" in to zip.");

                targetArchive.CommitUpdate();
            }
            ((IDisposable)targetArchive).Dispose();
        }
예제 #9
0
        private void ZipDir(ZipFile file, string sitemappath, string entryname)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(sitemappath);

            DirectoryInfo[] directories = directoryInfo.GetDirectories();
            foreach (DirectoryInfo directoryInfo2 in directories)
            {
                ZipDir(file, sitemappath + "\\" + directoryInfo2.Name, entryname + "\\" + directoryInfo2.Name);
            }
            FileInfo[] files = directoryInfo.GetFiles();
            foreach (FileInfo fileInfo in files)
            {
                file.Add(fileInfo.FullName, entryname + "\\" + fileInfo.Name);
            }
        }
예제 #10
0
 /// <summary>
 /// 压缩多个文件
 /// </summary>
 /// <param name="filespath"></param>
 /// <param name="sourcedpath"></param>
 public static void ZipFile(List <string> filespath, string sourcedpath, string entrnameprefix = "")
 {
     using (ZipFile zip = ICSharpCode.SharpZipLib.Zip.ZipFile.Create(sourcedpath))
     {
         zip.BeginUpdate();
         foreach (var v in filespath)
         {
             string   p  = v.Replace("\\", "/");
             string   p1 = ABHelper.GetFileName(p);
             ZipEntry e  = new ZipEntry(p1);
             zip.Add(p, entrnameprefix + p1);
         }
         zip.CommitUpdate();
     }
 }
예제 #11
0
        public override void Zip(ZipFile zip, DeploymentContainer container)
        {
            string zipPath;

            if (SubFolder == null)
            {
                zipPath = container.Key + "/" + System.IO.Path.GetFileName(Path);
            }
            else
            {
                zipPath = container.Key + "/" + SubFolder + "/" + System.IO.Path.GetFileName(Path);
            }

            zip.Add(new FileDataSource(Path), zipPath);
        }
예제 #12
0
        /// <summary>
        /// 添加内容到zip文件,在 ZipFile.CommitUpdate() 之后自动释放流;
        /// </summary>
        public static void Add(this ZipFile zipFile, string entryName, Stream stream)
        {
            if (zipFile == null)
            {
                throw new ArgumentNullException(nameof(zipFile));
            }
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            ZipData data = new ZipData(stream);

            zipFile.Add(data, entryName);
        }
예제 #13
0
        public void CreatePackage()
        {
            if (FileInitialized())
            {
                throw new InvalidOperationException();
            }
            _zipFile = ZipFile.Create(_file);
            _zipFile.BeginUpdate();
            ZipEntry entry = new ZipEntry("~package");

            entry.Size           = 0;
            entry.CompressedSize = 0;
            _zipFile.Add(entry);
            _zipFile.CommitUpdate();
        }
예제 #14
0
    private static void CompressZlib(string inFile, string outFile)
    {
        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
        stopwatch.Start();

        using (ZipFile zip = ZipFile.Create(outFile))
        {
            zip.BeginUpdate();
            zip.Add(inFile, "topbottom.zip.d");
            zip.CommitUpdate();
        }

        stopwatch.Stop();
        Debug.LogFormat("zip encode time: {0}", stopwatch.Elapsed.TotalSeconds);
    }
    /// <summary>
    /// 压缩打包文件
    /// </summary>
    public void ZipFileByCode()
    {
        MemoryStream ms = new MemoryStream();

        byte[] buffer = null;

        using (ZipFile file = ZipFile.Create(ms))
        {
            file.BeginUpdate();
            file.NameTransform = new MyNameTransfom();        //通过这个名称格式化器,可以将里面的文件名进行一些处理。默认情况下,会自动根据文件的路径在zip中创建有关的文件夹。

            file.Add(Server.MapPath("/Content/images/img01.jpg"));
            file.Add(Server.MapPath("/Content/images/img02.jpg"));
            file.CommitUpdate();

            buffer      = new byte[ms.Length];
            ms.Position = 0;
            ms.Read(buffer, 0, buffer.Length);
        }
        Response.AddHeader("content-disposition", "attachment;filename=test.zip");
        Response.BinaryWrite(buffer);
        Response.Flush();
        Response.End();
    }
예제 #16
0
        /// <summary>
        /// 压缩多个文件
        /// </summary>
        /// <param name="destZipName"></param>
        /// <param name="srcFiles"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool MultiZip(string destZipName, string[] srcFiles, string password = "")
        {
            using (ZipFile zip = ICSharpCode.SharpZipLib.Zip.ZipFile.Create(destZipName))
            {
                zip.BeginUpdate();
                foreach (var file in srcFiles)
                {
                    //ZipEntry e = new ZipEntry(Path.GetFileName(file));

                    zip.Add(file, Path.GetFileName(file));
                }
                zip.CommitUpdate();
            }
            return(true);
        }
예제 #17
0
        /// <summary>
        /// 压缩多个文件到zip
        /// </summary>
        /// <param name="files"></param>
        /// <returns></returns>
        public static byte[] DownloadZip(Dictionary <string, string> files)
        {
            byte[] buffer = null;
            using (MemoryStream ms = new MemoryStream())
            {
                using (ZipFile file = ZipFile.Create(ms))
                {
                    file.BeginUpdate();
                    file.NameTransform = new MyNameTransfom();
                    //通过这个名称格式化器,可以将里面的文件名进行一些处理。默认情况下,会自动根据文件的路径在zip中创建有关的文件夹。
                    foreach (var f in files)
                    {
                        var path = FileHelper.MapFilePath(f.Key);
                        if (File.Exists(path))
                        {
                            if (f.Value == f.Key)
                            {
                                file.Add(path);
                            }
                            else
                            {
                                file.Add(path, f.Value + FileHelper.GetExtension(path));
                            }
                            //file.Add(path);
                        }
                    }

                    file.CommitUpdate();

                    buffer      = new byte[ms.Length];
                    ms.Position = 0;
                    ms.Read(buffer, 0, buffer.Length);
                    return(buffer);
                }
            }
        }
        /// <summary>
        /// Commits the updates.
        /// </summary>
        /// <remarks>Documented by Dev03, 2009-07-20</remarks>
        public void CommitUpdates()
        {
            ZipFile zipFile = null;

            try
            {
                zipFile          = new ZipFile(file.FullName);
                zipFile.UseZip64 = UseZip64.Off;  // AAB-20090720: Zip64 caused some problem when modifing the archive (ErrorReportHandler.cs) - Zip64 is required to bypass the 4.2G limitation of the original Zip format (http://en.wikipedia.org/wiki/ZIP_(file_format))

                ZipEntry errorReport = zipFile.GetEntry(Resources.ERRORFILE_NAME);

                MemoryStream stream = new MemoryStream();
                using (Stream s = GetZipStream(errorReport, zipFile))
                {
                    XmlDocument doc = new XmlDocument();
                    using (StreamReader reader = new StreamReader(s, Encoding.Unicode))
                    {
                        doc.LoadXml(reader.ReadToEnd());
                    }
                    foreach (Dictionary <string, string> value in values)
                    {
                        XmlElement xE = doc.CreateElement(value["nodeName"]);
                        xE.InnerText = value["value"].Trim();
                        XmlNode parentNode = doc.SelectSingleNode(value["parentPath"]);
                        if (parentNode == null)
                        {
                            return;
                        }
                        parentNode.AppendChild(xE);
                    }
                    doc.Save(stream);
                }
                ZipData data = new ZipData(stream);
                zipFile.BeginUpdate();
                zipFile.Delete(errorReport);    //delete first!
                zipFile.CommitUpdate();
                zipFile.BeginUpdate();
                zipFile.Add(data, errorReport.Name);
                zipFile.CommitUpdate();
            }
            finally
            {
                if (zipFile != null)
                {
                    zipFile.Close();
                }
            }
        }
예제 #19
0
 /// <summary>
 /// Asks to export the snippet files
 /// </summary>
 private void ExportButtonClick(Object sender, EventArgs e)
 {
     if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
     {
         ZipFile  zipFile      = ZipFile.Create(this.saveFileDialog.FileName);
         String[] snippetFiles = Directory.GetFiles(this.SnippetDir, "*.lds", SearchOption.AllDirectories);
         zipFile.BeginUpdate();
         foreach (String snippetFile in snippetFiles)
         {
             Int32 index = snippetFile.IndexOf("\\Snippets\\");
             zipFile.Add(snippetFile, "$(BaseDir)" + snippetFile.Substring(index));
         }
         zipFile.CommitUpdate();
         zipFile.Close();
     }
 }
예제 #20
0
 private static void GetFilesToZip(IEnumerable <FileSystemInfo> fileSystemInfosToZip, string rootPath, ZipFile z)
 {
     foreach (var fi in fileSystemInfosToZip)
     {
         if (fi is DirectoryInfo)
         {
             var di = (DirectoryInfo)fi;
             GetFilesToZip(di.GetFileSystemInfos(), rootPath, z);
         }
         else
         {
             var fileName = fi.FullName.Replace(rootPath, string.Empty);
             z.Add(fi.FullName, fileName);
         }
     }
 }
예제 #21
0
            /// <summary>
            /// 向zip添加文件
            /// </summary>
            /// <param name="zipFilePath"></param>
            /// <param name="parentFolder"></param>
            /// <param name="filePaths"></param>
            public static void UpdateZipAdd(string zipFilePath, string parentFolder, IEnumerable <string> filePaths)
            {
                ZipFile zip          = new ZipFile(zipFilePath);
                int     folderOffset = parentFolder.Length;

                zip.BeginUpdate();
                foreach (var filePath in filePaths)
                {
                    zip.Add(filePath, filePath.Substring(folderOffset));
                }

                zip.CommitUpdate();
                //关闭zip时同时关闭文件Stream
                zip.IsStreamOwner = true;
                zip.Close();
            }
예제 #22
0
        private void UpdatePackagedWorkbook(ZipFile zipFile, string workbookName)
        {
            // Locate the TWB.  There should only ever be one in a valid packaged workbook
            var workbookArchiveEntry = FindPackagedWorkbooks(zipFile).FirstOrDefault();

            if (workbookArchiveEntry == default(ZipEntry))
            {
                throw new ArgumentException(String.Format("Packaged workbook '{0}' contains no inner workbook!", workbookName));
            }

            using (var workbookStream = zipFile.GetInputStream(workbookArchiveEntry))
            {
                XmlDocument workbookXml = UpdateWorkbookXml(workbookStream);
                zipFile.Add(new XmlDataSource(workbookXml), workbookArchiveEntry.Name);
            }
        }
예제 #23
0
        public ActionResult Getff()
        {
            var filePaths = new List <string>()
            {
                _host.WebRootPath + "/cc.jpg", _host.WebRootPath + "/sy.jpg"
            };

            byte[]       buffer;
            MemoryStream ms = new MemoryStream();

            using (
                ZipFile file = ZipFile.Create(ms))
            {
                file.BeginUpdate();
                file.NameTransform = new MyNameTransfom();
                filePaths.ForEach(t =>
                {
                    var item = new GetDataSource(t);
                    file.Add(item, Path.GetFileName(t));
                });

                file.CommitUpdate();
                buffer      = new byte[ms.Length];
                ms.Position = 0;
                ms.Read(buffer, 0, buffer.Length);
            }

            return(File(buffer, "application/zip", "这是一个打包的文件.zip"));

            //var client = new sRestClient("http://localhost:5001/api");

            //var dic = new Dictionary<string, string>();

            //dic.Add("CompanyId", "中国");

            //int status;

            //var cc = client.Get("account/companyrole", dic, out status);

            //var stude = new student { ID = 34, Name = "张三" };

            //var corse = GetTest.ConvertToCoruse(stude);

            ////get.Get(_host);

            //return corse;
        }
예제 #24
0
        public void AddEncryptedEntriesToExistingArchive()
        {
            const string TestValue = "0001000";
            var          memStream = new MemoryStream();

            using (ZipFile f = new ZipFile(memStream))
            {
                f.IsStreamOwner = false;
                f.UseZip64      = UseZip64.Off;

                var m = new StringMemoryDataSource(TestValue);
                f.BeginUpdate(new MemoryArchiveStorage());
                f.Add(m, "a.dat");
                f.CommitUpdate();
                Assert.IsTrue(f.TestArchive(true), "Archive test should pass");
            }

            using (ZipFile g = new ZipFile(memStream))
            {
                ZipEntry ze = g[0];

                Assert.IsFalse(ze.IsCrypted, "Entry should NOT be encrypted");
                using (StreamReader r = new StreamReader(g.GetInputStream(0)))
                {
                    string data = r.ReadToEnd();
                    Assert.AreEqual(TestValue, data);
                }

                var n = new StringMemoryDataSource(TestValue);

                g.Password      = "******";
                g.UseZip64      = UseZip64.Off;
                g.IsStreamOwner = false;
                g.BeginUpdate();
                g.Add(n, "a1.dat");
                g.CommitUpdate();
                Assert.IsTrue(g.TestArchive(true), "Archive test should pass");
                ze = g[1];
                Assert.IsTrue(ze.IsCrypted, "New entry should be encrypted");

                using (StreamReader r = new StreamReader(g.GetInputStream(0)))
                {
                    string data = r.ReadToEnd();
                    Assert.AreEqual(TestValue, data);
                }
            }
        }
        private void doAfterStuff(string destFolder)
        {
            try
            {
                File.WriteAllText(appDir + @"\tmp\Mod Comments.tweak", "(put your mod comments in here)");

                File.Copy(frm + "\\Objects_server.zip", appDir + @"\tmp\Objects_server.zip", true);
                File.Copy(frm + "\\Objects_server.zip", appDir + @"\_restore_\Objects_server(_Original_).zip", true);

                //ok right here, after they click load archive, were gonna put the M0d Comments.tweak inside of / :)

                ZipFile zipFile = new ZipFile(appDir + @"\tmp\Objects_server.zip");

                zipFile.UseZip64 = UseZip64.Off;

                zipFile.BeginUpdate();

                zipFile.Add(appDir + @"\tmp\Mod Comments.tweak", "Mod Comments.tweak");

                zipFile.CommitUpdate();

                zipFile.Close();



                File.Delete(appDir + @"\tmp\Mod Comments.tweak");

                File.WriteAllText(appDir + @"\modCreated.cfg", "true");

                File.Copy(appDir + @"\welcome.bik", destFolder + "\\Movies\\welcome.bik", true);
                File.Copy(appDir + @"\bf2cursor.ani", destFolder + "\\menu\\external\\FlashMenu\\Cursor\\cursor_arrow.ani", true);
                // now that the vid is copied for startup, edit the Init.con file to show welcome.bik :)

                string[] flTxt = { "rem -- Generated using BF2 Modder --", "bf2Engine.playMovie Movies\\welcome.bik 1" };
                File.WriteAllLines(destFolder + "\\Init.con", flTxt);

                File.Delete(appDir + @"\createMod.bat");

                MessageBox.Show("Import Process Complete!\n\nYou may now begin making mods.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.Close();
            }
            catch (Exception x)
            {
                MessageBox.Show("There was an error ! An explanation follows, please report this error.\n\n\t" + x.Message);
            }
        }
예제 #26
0
        private void SaveChannels(ZipFile zip, string fileName, ChannelList channels, byte[] fileContent)
        {
            if (fileContent == null)
            {
                return;
            }
            zip.Delete(fileName);

            string tempFilePath = Path.GetTempFileName();

            using (var stream = new FileStream(tempFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                this.WriteChannels(channels, fileContent, stream);
            }

            zip.Add(tempFilePath, fileName);
        }
예제 #27
0
        private bool AddAllFilesToZipFile(IProgress progressDlg, ZipFile zFile, IEnumerable <string> files)
        {
            string prevCurrDir = Environment.CurrentDirectory;

            try
            {
                zFile.BeginUpdate();
                progressDlg.Message = Strings.ksBackupStatusMessage;
                foreach (string fileName in files)
                {
                    string shortName = Path.GetFileName(fileName);
                    string entryName = fileName;
                    if (!string.IsNullOrEmpty(entryName))
                    {
                        // The approach of trying to shorten the path messes up the restore process
                        // because the DateTime stored in the zip file is no longer that of the file on disk.
                        // Thererfore when trying to compare file timestamps on restore the version in the
                        // zip file looks newer than it really should be. To fix this we need to set
                        // the current working directory so that the zip library will be able to find
                        // the file and get the datetime stamp correct. (FWR-2267)
                        entryName = FileUtils.GetRelativePath(entryName, dir => Environment.CurrentDirectory = dir,
                                                              m_settings.ProjectPath, m_settings.DatabaseFolder);
                        try
                        {
                            // This first line should generate an exception if we can't read it,
                            // which otherwise happens during CommitUpdate and wrecks everything.
                            using (File.OpenRead(fileName))
                            {
                                zFile.Add(fileName, entryName);
                            }
                        }
                        catch (UnauthorizedAccessException)
                        {
                            m_failedFiles.Add(fileName);
                        }
                    }
                }
                progressDlg.Message = Strings.ksBackupClosing;
                zFile.CommitUpdate();
                return(true);
            }
            finally
            {
                Environment.CurrentDirectory = prevCurrDir;
            }
        }
예제 #28
0
        private ZipFile ReplacePackagedExtracts(ZipFile zipFile, string workbookName)
        {
            var packagedExtracts  = FindPackagedExtracts(zipFile);
            var generatedExtracts = FindAvailableExtracts(outputDirectory).ToDictionary(Path.GetFileName, path => path);

            foreach (ZipEntry packagedExtract in packagedExtracts)
            {
                string extractName = Path.GetFileName(packagedExtract.Name);
                if (!String.IsNullOrEmpty(extractName) && generatedExtracts.ContainsKey(extractName))
                {
                    zipFile.Add(generatedExtracts[extractName], packagedExtract.Name);
                    Log.DebugFormat("Replaced extract '{0}' in workbook '{1}'", extractName, workbookName);
                }
            }

            return(zipFile);
        }
예제 #29
0
파일: Zip.cs 프로젝트: intech-solucoes/lib
        /// <summary>
        /// Adiciona um novo arquivo dentro de um ZIP já existente.
        /// </summary>
        /// <param name="diretorioRaiz">Diretorio raiz do Zip. Só copiar um arquivo de dentro do CTI, e o raiz for INTECH. Logo o arquivo será copiado para dentro do diretório CTI dentro do ZIP </param>
        /// <param name="novoArquivoParaAdicionar">Endereço completo do novo arquivo a ser adicionado.</param>
        /// <param name="caminhoArquivoZip">Caminho do arquivo ZIP</param>
        public static void AdicionaArquivoAoZipExistente(string diretorioRaiz, string novoArquivoParaAdicionar, string caminhoArquivoZip)
        {
            if (File.Exists(novoArquivoParaAdicionar))
            {
                ZipFile arquivoZip = new ZipFile(caminhoArquivoZip);
                arquivoZip.BeginUpdate();

                Int32  indiceDiretorioRaiz     = novoArquivoParaAdicionar.IndexOf(diretorioRaiz);
                String caminhoVirtualDentroZip = novoArquivoParaAdicionar.Substring(0, (indiceDiretorioRaiz + diretorioRaiz.Length));

                arquivoZip.NameTransform = new ZipNameTransform(caminhoVirtualDentroZip);
                arquivoZip.Add(novoArquivoParaAdicionar);

                arquivoZip.CommitUpdate();
                arquivoZip.Close();
            }
        }
예제 #30
0
파일: CompressFile.cs 프로젝트: radtek/vnr
        public static void CreateZipFile(string zipFileStoragePath
                                         , string zipFileName
                                         , FileInfo fileToCompress)
        {
            //create our zip file
            ZipFile z = ZipFile.Create(zipFileStoragePath + zipFileName);

            //initialize the file so that it can accept updates
            z.BeginUpdate();

            //add the file to the zip file
            z.Add(fileToCompress);

            //commit the update once we are done
            z.CommitUpdate();
            //close the file
            z.Close();
        }