本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipFile.SetComment方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.SetComment方法的具体用法?C# ZipFile.SetComment怎么用?C# ZipFile.SetComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.ZipFile
的用法示例。
在下文中一共展示了ZipFile.SetComment方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateCommentOnlyOnDisk
public void UpdateCommentOnlyOnDisk()
{
string tempFile = GetTempFilePath();
Assert.IsNotNull(tempFile, "No permission to execute this test?");
tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
if (File.Exists(tempFile))
{
File.Delete(tempFile);
}
using (ZipFile testFile = ZipFile.Create(tempFile))
{
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));
}
using (ZipFile testFile = new ZipFile(tempFile))
{
Assert.IsTrue(testFile.TestArchive(true));
Assert.AreEqual("", testFile.ZipFileComment);
testFile.BeginUpdate(new DiskArchiveStorage(testFile, FileUpdateMode.Direct));
testFile.SetComment("Here is my comment");
testFile.CommitUpdate();
Assert.IsTrue(testFile.TestArchive(true));
}
using (ZipFile testFile = new ZipFile(tempFile))
{
Assert.IsTrue(testFile.TestArchive(true));
Assert.AreEqual("Here is my comment", testFile.ZipFileComment);
}
File.Delete(tempFile);
// Variant using indirect updating.
using (ZipFile testFile = ZipFile.Create(tempFile))
{
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));
}
using (ZipFile testFile = new ZipFile(tempFile))
{
Assert.IsTrue(testFile.TestArchive(true));
Assert.AreEqual("", testFile.ZipFileComment);
testFile.BeginUpdate();
testFile.SetComment("Here is my comment");
testFile.CommitUpdate();
Assert.IsTrue(testFile.TestArchive(true));
}
using (ZipFile testFile = new ZipFile(tempFile))
{
Assert.IsTrue(testFile.TestArchive(true));
Assert.AreEqual("Here is my comment", testFile.ZipFileComment);
}
File.Delete(tempFile);
}
示例2: UpdateCommentOnlyInMemory
public void UpdateCommentOnlyInMemory()
{
MemoryStream ms = new MemoryStream();
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));
}
using (ZipFile testFile = new ZipFile(ms))
{
Assert.IsTrue(testFile.TestArchive(true));
Assert.AreEqual("", testFile.ZipFileComment);
testFile.IsStreamOwner = false;
testFile.BeginUpdate();
testFile.SetComment("Here is my comment");
testFile.CommitUpdate();
Assert.IsTrue(testFile.TestArchive(true));
}
using (ZipFile testFile = new ZipFile(ms))
{
Assert.IsTrue(testFile.TestArchive(true));
Assert.AreEqual("Here is my comment", testFile.ZipFileComment);
}
}
示例3: 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);
}
}
示例4: saveNotes_Click
private void saveNotes_Click(object sender, EventArgs e)
{
try
{
ZipFile zf = new ZipFile(jarList.SelectedNode.Name);
zf.BeginUpdate();
zf.SetComment(jarCommentBox.Text);
zf.CommitUpdate();
zf.Close();
}
catch (Exception ex)
{
MessageBox.Show(this, Util.langNode("couldnotsavenotes") + " " + ex.Message + "\n" + ex.StackTrace, Util.langNode("errorwhilesavingnotes"), MessageBoxButtons.OK);
}
}
示例5: GenerateImage
//.........这里部分代码省略.........
throw new DirectoryNotFoundException("The input directory was not found!");
if (!Directory.Exists(Path.GetDirectoryName(textBoxOutputFile.Text)))
throw new DirectoryNotFoundException("The output path is invalid!");
if (textBoxStickName.Text.Length > 11 || textBoxStickName.Text == string.Empty)
throw new ArgumentException("Invalid Stick name!");
if (textBoxStickID.Text.Length != 9 || textBoxStickID.Text[4] != '-')
throw new ArgumentException("Invalid Stick ID!");
#endregion
string outputFilePath = Path.ChangeExtension(textBoxOutputFile.Text, ".MLifterStick");
#region Create Zip:
Stream output = File.Create(outputFilePath);
ZipOutputStream zipStream = new ZipOutputStream(output);
ZipFile zip = new ZipFile(output);
#endregion
#region Fill Zip:
zip.BeginUpdate();
int pos = 1;
string[] files = Directory.GetFiles(textBoxInputFilePath.Text, "*.*", SearchOption.AllDirectories);
List<string> folders = new List<string>();
foreach (string file in files)
{
toolStripStatusLabelMessage.Text = string.Format("Adding file {0} of {1}...", pos, files.Length);
toolStripProgressBarStatus.Value = Convert.ToInt32(pos++ * 1.0 / files.Length * 100);
Application.DoEvents();
string dir = Path.GetDirectoryName(file).Remove(0, textBoxInputFilePath.Text.Length);
string zipFile = Path.Combine(dir, Path.GetFileName(file));
if (dir.Length > 0)
{
if (!folders.Contains(dir))
{
zip.AddDirectory(dir);
folders.Add(dir);
}
}
zip.Add(new FileDataSource(file), zipFile);
}
toolStripStatusLabelMessage.Text = "Saving image. THIS COULD RUN VERY LONG - PLEASE WAIT!";
Application.DoEvents();
zip.CommitUpdate();
#endregion
VolumeDataStorage vds = new VolumeDataStorage();
#region setting file attributes:
foreach (string file in files)
{
string dir = Path.GetDirectoryName(file).Remove(0, textBoxInputFilePath.Text.Length);
if (dir.StartsWith("\\"))
dir = dir.Remove(0, 1);
string zipFile = Path.Combine(dir, Path.GetFileName(file)).Replace(@"\", "/");
ZipEntry entry = zip.GetEntry(zipFile);
if (entry == null)
continue;
FileAttributes attr = (new FileInfo(file)).Attributes;
if (!(attr == FileAttributes.Archive || attr == FileAttributes.Normal))
vds.FileAttributeList.Add(entry.Name, attr);
toolStripStatusLabelMessage.Text = "Setting file FileAttributes to: " + zipFile;
}
foreach (string folder in folders)
{
FileAttributes attr = (new DirectoryInfo(Path.Combine(textBoxInputFilePath.Text, folder))).Attributes;
if (!(attr == FileAttributes.Archive || attr == FileAttributes.Normal || attr == FileAttributes.Directory))
vds.FolderAttributeList.Add(folder, attr);
toolStripStatusLabelMessage.Text = "Setting folder FileAttributes to: " + folder;
}
#endregion
#region Set Comment:
vds.VolumeLabel = textBoxStickName.Text;
vds.VolumeSerial = textBoxStickID.Text;
string comment = VolumeDataStorage.SerializeData(vds);
File.WriteAllText(Path.Combine(Application.StartupPath, "Comment.txt"), comment);
zip.BeginUpdate();
zip.SetComment(comment);
zip.CommitUpdate();
#endregion
zip.Close();
CreatedImage = outputFilePath;
}