本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipFile.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.Delete方法的具体用法?C# ZipFile.Delete怎么用?C# ZipFile.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.ZipFile
的用法示例。
在下文中一共展示了ZipFile.Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryDeleting
void TryDeleting(byte[] master, int totalEntries, int additions, params int[] toDelete)
{
MemoryStream ms = new MemoryStream();
ms.Write(master, 0, master.Length);
using (ZipFile f = new ZipFile(ms)) {
f.IsStreamOwner = false;
Assert.AreEqual(totalEntries, f.Count);
Assert.IsTrue(f.TestArchive(true));
f.BeginUpdate(new MemoryArchiveStorage());
for (int i = 0; i < additions; ++i) {
f.Add(new StringMemoryDataSource("Another great file"),
string.Format("Add{0}.dat", i + 1));
}
foreach (int i in toDelete) {
f.Delete(f[i]);
}
f.CommitUpdate();
/* write stream to file to assist debugging.
byte[] data = ms.ToArray();
using ( FileStream fs = File.Open(@"c:\aha.zip", FileMode.Create, FileAccess.ReadWrite, FileShare.Read) ) {
fs.Write(data, 0, data.Length);
}
*/
int newTotal = totalEntries + additions - toDelete.Length;
Assert.AreEqual(newTotal, f.Count,
string.Format("Expected {0} entries after update found {1}", newTotal, f.Count));
Assert.IsTrue(f.TestArchive(true), "Archive test should pass");
}
}
示例2: AddAndDeleteEntries
public void AddAndDeleteEntries()
{
string tempFile = GetTempFilePath();
Assert.IsNotNull(tempFile, "No permission to execute this test?");
string addFile = Path.Combine(tempFile, "a.dat");
MakeTempFile(addFile, 1);
string addFile2 = Path.Combine(tempFile, "b.dat");
MakeTempFile(addFile2, 259);
tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
using (ZipFile f = ZipFile.Create(tempFile)) {
f.BeginUpdate();
f.Add(addFile);
f.Add(addFile2);
f.CommitUpdate();
Assert.IsTrue(f.TestArchive(true));
}
using (ZipFile f = new ZipFile(tempFile)) {
Assert.AreEqual(2, f.Count);
Assert.IsTrue(f.TestArchive(true));
f.BeginUpdate();
f.Delete(f[0]);
f.CommitUpdate();
Assert.AreEqual(1, f.Count);
Assert.IsTrue(f.TestArchive(true));
}
File.Delete(addFile);
File.Delete(addFile2);
File.Delete(tempFile);
}
示例3: AddToEmptyArchive
public void AddToEmptyArchive()
{
string tempFile = GetTempFilePath();
Assert.IsNotNull(tempFile, "No permission to execute this test?");
string addFile = Path.Combine(tempFile, "a.dat");
MakeTempFile(addFile, 1);
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
try
{
tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
using (ZipFile f = ZipFile.Create(tempFile))
{
f.BeginUpdate();
f.Add(addFile);
f.CommitUpdate();
Assert.AreEqual(1, f.Count);
Assert.IsTrue(f.TestArchive(true));
}
using (ZipFile f = new ZipFile(tempFile))
{
Assert.AreEqual(1, f.Count);
f.BeginUpdate();
f.Delete(f[0]); // failing here in 4 and 3 - fixed - one-off in zipfile
f.CommitUpdate();
Assert.AreEqual(0, f.Count);
Assert.IsTrue(f.TestArchive(true));
f.Close();
}
store.DeleteFile(tempFile);
}
finally
{
store.DeleteFile(addFile);
}
}
}
示例4: Delete
/// <summary>
/// Delete entries from an archive
/// </summary>
/// <param name="fileSpecs">The file specs to operate on.</param>
void Delete(ArrayList fileSpecs)
{
string zipFileName = fileSpecs[0] as string;
if (Path.GetExtension(zipFileName).Length == 0)
{
zipFileName = Path.ChangeExtension(zipFileName, ".zip");
}
try
{
using (ZipFile zipFile = new ZipFile(zipFileName))
{
zipFile.BeginUpdate();
for ( int i = 1; i < fileSpecs.Count; ++i )
{
zipFile.Delete((string)fileSpecs[i]);
}
zipFile.CommitUpdate();
}
}
catch(Exception ex)
{
Console.WriteLine("Problem deleting files - '{0}'", ex.Message);
}
}
示例5: DeleteContent
void DeleteContent(string loc)
{
ZipFile zipFile = new ZipFile(FileLoc);
// Must call BeginUpdate to start, and CommitUpdate at the end.
zipFile.BeginUpdate();
zipFile.Delete(loc);
// Both CommitUpdate and Close must be called.
zipFile.CommitUpdate();
zipFile.Close();
}
示例6: groupBox1_DragDrop
private void groupBox1_DragDrop(object sender, DragEventArgs e)
{
try
{
modInstallerLabel.Text = Util.langNode("adding");
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
ZipFile zf = new ZipFile(jarList.SelectedNode.Name);
String comment = zf.ZipFileComment + "\r\n--- " + DateTime.Now + " " + Util.langNode("addedthesefiles") + " ---\r\n";
zf.BeginUpdate();
int i = 0;
foreach (string file in files)
{
Console.WriteLine("Adding " + file);
if (((File.GetAttributes(file) & FileAttributes.Directory) == FileAttributes.Directory))
{
System.Console.WriteLine("It is a directory!");
//zf.AddDirectory(dirname);
string[] filesindir = Directory.GetFiles(file, "*", SearchOption.AllDirectories);
// Display all the files.
foreach (string fileindir in filesindir)
{
Console.WriteLine("Adding " + fileindir.Replace(Directory.GetParent(file).FullName, ""));
zf.Add(fileindir, fileindir.Replace(Directory.GetParent(file).FullName, ""));
comment += fileindir.Replace(Directory.GetParent(file).FullName, "") + "\r\n";
i++;
}
}
else
{
zf.Add(file, System.IO.Path.GetFileName(file));
comment += System.IO.Path.GetFileName(file) + "\r\n";
i++;
}
}
ZipEntry mi = zf.GetEntry("META-INF");
if (mi != null)
{
zf.Delete(mi);
comment += String.Format(Util.langNode("removedfile"), "META-INF") + "\r\n";
}
zf.SetComment(comment);
jarCommentBox.Text = comment;
zf.CommitUpdate();
zf.Close();
modInstallerLabel.Text = String.Format(Util.langNode("addedfiles"), i);
}
catch (Exception ex)
{
System.Console.WriteLine("Could not write: " + ex.Message + "\r\n" + ex.StackTrace);
modInstallerLabel.Text = String.Format(Util.langNode("errordetail"), ex.Message);
}
}
示例7: deleteFromDisk
/// <summary>
/// delete image file inside the zip file, or return a name of file to delete on the hard drive.
/// Make sure you dispose of this PhotoDescr before deleting the file.
/// </summary>
public string deleteFromDisk()
{
string ret = null;
if(this.imageSourceIsLocal)
{
// make sure the image is not used/locked and we can actually delete it:
releaseImage();
ImageCache.releaseImage(m_imageFileName);
GC.Collect();
int pos = m_imageFileName.IndexOf("|");
if(pos >= 0)
{
// this is a .zip or .gpz file
string zipFileName = m_imageFileName.Substring(0, pos);
if (!File.Exists(zipFileName))
{
LibSys.StatusBar.Error("Failed to open Zip");
throw new InvalidOperationException("'" + zipFileName + "' not found or not a valid zip file");
}
using (ZipFile zip = new ZipFile(zipFileName))
{
string photoFileName = m_imageFileName.Substring(pos + 1);
ZipEntry zipEntry = zip.GetEntry(photoFileName);
if (zipEntry != null)
{
zip.BeginUpdate();
zip.Delete(zipEntry);
}
else
{
zip.Close();
throw new InvalidOperationException("'" + photoFileName + "' is not found inside " + zipFileName);
}
zip.CommitUpdate();
}
}
else
{
ret = m_imageFileName;
}
}
return ret;
}
示例8: DeleteContent
void DeleteContent(string loc)
{
ZipFile zipFile = new ZipFile(this.zipArchive);
// Must call BeginUpdate to start, and CommitUpdate at the end.
zipFile.BeginUpdate();
zipFile.Delete(loc);
// Both CommitUpdate and Close must be called.
zipFile.CommitUpdate();
zipFile.IsStreamOwner = false; zipFile.Close();
this.zipArchive.Position = 0;
}
示例9: Save
public override void Save(string tvOutputFile)
{
if (tvOutputFile != this.FileName)
{
File.Copy(this.FileName, tvOutputFile);
this.FileName = tvOutputFile;
}
using (var zip = new ZipFile(this.FileName))
{
zip.BeginUpdate();
foreach (var channelList in this.DataRoot.ChannelLists)
{
var dbPath = this.dbPathByChannelList[channelList];
SaveChannelList(channelList, dbPath);
var entryName = Path.GetFileName(dbPath);
zip.Delete(entryName);
zip.Add(dbPath, entryName);
}
zip.CommitUpdate();
}
}
示例10: RemoveSignatures
public static void RemoveSignatures(string jar)
{
// Ensures the specified package has no signatures to speak of.
using (var zip = new ZipFile(jar))
{
zip.BeginUpdate();
var entry = zip.GetEntry("META-INF/MANIFEST.MF");
if (entry != null)
zip.Delete(entry);
zip.GetEntry("META-INF/MOJANG_C.SF");
if (entry != null)
zip.Delete(entry);
zip.GetEntry("META-INF/MOJANG_C.DSA");
if (entry != null)
zip.Delete(entry);
zip.CommitUpdate();
}
}
示例11: SaveChannels
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);
}
示例12: savePhotoParameters
public static void savePhotoParameters(Form ownerForm, string folderOrZipName)
{
if (Project.photoParametersDonotwrite)
{
return;
}
if (AllFormats.isZipFile(folderOrZipName))
{
if (!File.Exists(folderOrZipName))
{
Project.ErrorBox(ownerForm, "Zip file not found: " + folderOrZipName);
return;
}
string ppfName = folderOrZipName + "|" + Project.PHOTO_PARAM_FILE_NAME;
string message = "Confirm: will write new Camera Time Shift to " + ppfName
+ "\n\nDo you want to create/overwrite the file (inside the ZIP archive)?";
if (!Project.photoParametersAsk || Project.YesNoBox(ownerForm, message))
{
if (!File.Exists(folderOrZipName))
{
Project.ErrorBox(ownerForm, "Failed to open Zip file: " + folderOrZipName);
return;
}
XmlDocument xmlDoc = null;
using (ZipFile zip = new ZipFile(folderOrZipName))
{
ZipEntry entry = zip.GetEntry(Project.PHOTO_PARAM_FILE_NAME);
if (entry == null)
{
LibSys.StatusBar.Trace("IP: creating photo parameters entry: " + folderOrZipName + "|" + Project.PHOTO_PARAM_FILE_NAME);
xmlDoc = makePhotoParametersXmlDoc();
zip.BeginUpdate();
}
else
{
string fileName = entry.Name;
LibSys.StatusBar.Trace("IP: existing photo parameters entry: " + folderOrZipName + "|" + fileName);
xmlDoc = new XmlDocument();
Stream stream = zip.GetInputStream(entry);
using (StreamReader rdr = new StreamReader(stream))
{
xmlDoc.LoadXml(rdr.ReadToEnd());
}
editPhotoParametersXmlDoc(xmlDoc);
zip.BeginUpdate();
zip.Delete(entry);
}
StringMemoryDataSource m = new StringMemoryDataSource(xmlDoc.OuterXml);
zip.Add(m, Project.PHOTO_PARAM_FILE_NAME);
lastPhotoParametersFileName = ppfName;
zip.CommitUpdate();
}
}
}
else
{
if (!Directory.Exists(folderOrZipName))
{
Project.ErrorBox(ownerForm, "Folder not found: " + folderOrZipName);
return;
}
string ppfName = Path.Combine(folderOrZipName, Project.PHOTO_PARAM_FILE_NAME);
string message = "Confirm: will write new Camera Time Shift to " + ppfName + "\n\nDo you want to "
+ (File.Exists(ppfName) ? "overwrite" : "create") + " the file?";
if (!Project.photoParametersAsk || Project.YesNoBox(ownerForm, message))
{
try
{
if (File.Exists(ppfName))
{
LibSys.StatusBar.Trace("IP: existing photo parameters file: " + ppfName);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(ppfName);
editPhotoParametersXmlDoc(xmlDoc);
xmlDoc.Save(ppfName);
lastPhotoParametersFileName = ppfName;
}
else
{
LibSys.StatusBar.Trace("IP: creating photo parameters file: " + ppfName);
XmlDocument xmlDoc = makePhotoParametersXmlDoc();
xmlDoc.Save(ppfName);
//.........这里部分代码省略.........
示例13: savePhotoPositions
public static void savePhotoPositions(Form ownerForm, string folderOrZipName)
{
if (Project.photoPositionsDonotwrite)
{
return;
}
XmlDocument xmlDoc = makePhotoPositionsXmlDoc();
if (AllFormats.isZipFile(folderOrZipName))
{
if (!File.Exists(folderOrZipName))
{
Project.ErrorBox(ownerForm, "Zip file not found: " + folderOrZipName);
return;
}
string ppfName = folderOrZipName + "|" + Project.PHOTO_POSITIONS_FILE_NAME;
string message = "Confirm: will write photo positions to " + ppfName
+ "\n\nDo you want to create/overwrite the file (inside the ZIP archive)?";
if (!Project.photoPositionsAsk || Project.YesNoBox(ownerForm, message))
{
if (!File.Exists(folderOrZipName))
{
Project.ErrorBox(ownerForm, "Failed to open Zip file: " + folderOrZipName);
return;
}
using (ZipFile zip = new ZipFile(folderOrZipName))
{
ZipEntry entry = zip.GetEntry(Project.PHOTO_POSITIONS_FILE_NAME);
if (entry == null)
{
LibSys.StatusBar.Trace("IP: creating photo positions entry: " + folderOrZipName + "|" + Project.PHOTO_POSITIONS_FILE_NAME);
zip.BeginUpdate();
}
else
{
string fileName = entry.Name;
LibSys.StatusBar.Trace("IP: existing photo positions entry: " + folderOrZipName + "|" + fileName);
zip.BeginUpdate();
zip.Delete(entry);
}
StringMemoryDataSource m = new StringMemoryDataSource(xmlDoc.OuterXml);
zip.Add(m, Project.PHOTO_POSITIONS_FILE_NAME);
zip.CommitUpdate();
}
}
}
else
{
if (!Directory.Exists(folderOrZipName))
{
Project.ErrorBox(ownerForm, "Folder not found: " + folderOrZipName);
return;
}
string ppfName = Path.Combine(folderOrZipName, Project.PHOTO_POSITIONS_FILE_NAME);
try
{
if (File.Exists(ppfName))
{
LibSys.StatusBar.Trace("IP: existing photo positions file: " + ppfName);
}
else
{
LibSys.StatusBar.Trace("IP: creating photo positions file: " + ppfName);
}
xmlDoc.Save(ppfName);
}
catch (Exception e)
{
LibSys.StatusBar.Error("DlgPhotoManager:savePhotoPositions() " + e.Message);
}
}
}
示例14: ZipFiles
private void ZipFiles()
{
const string entryName = "chmgt_type001/" + FILE_chmgt_db;
using (var zip = new ZipFile(this.FileName))
{
zip.BeginUpdate();
zip.Delete(entryName);
zip.Add(this.tempDir + "chmgt.db", entryName);
zip.CommitUpdate();
}
}
示例15: Delete
/// <summary>
/// Delete entries from an archive
/// </summary>
/// <param name="fileSpecs">The file specs to operate on.</param>
void Delete(ArrayList fileSpecs)
{
var zipFileName = fileSpecs[0] as string;
if (Path.GetExtension(zipFileName).Length == 0) {
zipFileName = Path.ChangeExtension(zipFileName, ".zip");
}
using (ZipFile zipFile = new ZipFile(zipFileName)) {
zipFile.BeginUpdate();
for ( int i = 1; i < fileSpecs.Count; ++i ) {
zipFile.Delete((string)fileSpecs[i]);
}
zipFile.CommitUpdate();
}
}