Ejemplo n.º 1
0
        public static bool UpdateEntry(string zipFileName, string entryname, byte[] buffer, string password = null)
        {
            try
            {
                string dir     = Path.GetDirectoryName(zipFileName);
                string tmpfile = Path.Combine(dir, entryname + ".tmp");
                if (File.Exists(tmpfile))
                {
                    File.Delete(tmpfile);
                }
                FileStream streamWriter = File.Create(tmpfile);
                streamWriter.Write(buffer, 0, buffer.Length);
                SharpZipLib.Zip.ZipFile s = new SharpZipLib.Zip.ZipFile(zipFileName);
                s.Password = password;

                SharpZipLib.Zip.StaticDiskDataSource data = new SharpZipLib.Zip.StaticDiskDataSource(tmpfile);
                s.BeginUpdate();
                s.Add(data, entryname);
                s.CommitUpdate();
                s.Close();
                streamWriter.Close();
                if (File.Exists(tmpfile))
                {
                    File.Delete(tmpfile);
                }
                return(true);
            }
            catch (Exception e)
            {
                LogUtil.LogError(e.Message);
                return(false);
            }
        }
Ejemplo n.º 2
0
 public static bool UpdateEntry(string zipFileName, string entryname, string filename, string password = null)
 {
     try
     {
         SharpZipLib.Zip.ZipFile s = new SharpZipLib.Zip.ZipFile(zipFileName);
         s.Password = password;
         SharpZipLib.Zip.StaticDiskDataSource data = new SharpZipLib.Zip.StaticDiskDataSource(filename);
         s.BeginUpdate();
         s.Add(data, entryname);
         s.CommitUpdate();
         s.Close();
         return(true);
     }
     catch (Exception e)
     {
         LogUtil.LogError(e.Message);
         return(false);
     }
 }