本文整理汇总了C#中Ionic.Zip.ZipFile.RemoveEntry方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.RemoveEntry方法的具体用法?C# ZipFile.RemoveEntry怎么用?C# ZipFile.RemoveEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ionic.Zip.ZipFile
的用法示例。
在下文中一共展示了ZipFile.RemoveEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handle
protected override OperationResult Handle(ZipEntry entry, ZipFile zip)
{
string orig = entry.FileName;
string stripped = GetStripped(entry.FileName);
if (stripped == null)
{
if (entry.IsDirectory)
{
zip.RemoveEntry(entry);
return OperationResult.Removed;
}
stripped = orig;
}
try
{
entry.FileName = stripped;
return OperationResult.Changed;
}
catch (Exception ex)
{
string type = entry.IsDirectory ? "directory" : "file";
throw new Exception(string.Format("Could not rename {0} '{1}' to '{2}'", type, orig, stripped), ex);
}
}
示例2: AddToZip
public static void AddToZip(BackgroundWorker worker, string zipfile, string FileToAdd, string AsFilename = "", bool showProgress = true, Ionic.Zlib.CompressionLevel complevel = Ionic.Zlib.CompressionLevel.Default)
{
if (!File.Exists(zipfile))
throw new FileNotFoundException("Zipfile " + zipfile + " does not exist");
bool exists = ExistsInZip(zipfile, AsFilename == "" ? FileToAdd : AsFilename);
using (ZipFile zip = new ZipFile(zipfile))
{
Utility.SetZipTempFolder(zip);
zip.CompressionLevel = complevel;
if (exists)
zip.RemoveEntry(AsFilename == "" ? FileToAdd : AsFilename);
ZipEntry ze = zip.AddFile(FileToAdd, "");
if (!string.IsNullOrEmpty(AsFilename))
ze.FileName = AsFilename;
if (showProgress)
zip.SaveProgress += (o, e) =>
{
if (e.EventType == ZipProgressEventType.Saving_EntryBytesRead && e.CurrentEntry.FileName == (AsFilename == "" ? FileToAdd : AsFilename))
worker.ReportProgress((int)((float)e.BytesTransferred / e.TotalBytesToTransfer * 100));
};
zip.Save();
}
}
示例3: Delete
public override void Delete(Guid id)
{
using(var zip = new ZipFile(Path))
{
zip.RemoveEntry(id + ".xml");
zip.Save();
}
}
示例4: Handle
protected override OperationResult Handle(ZipEntry entry, ZipFile zip)
{
if (_regex.IsMatch(entry.FileName))
{
zip.RemoveEntry(entry);
return OperationResult.Removed;
}
return OperationResult.NoChange;
}
示例5: AddConfigurationToZip
static void AddConfigurationToZip(ZipFile zipFile, VersionedConfiguration versionedConfiguration, string fileName)
{
var configuarationMemoryStream = ZipSerializeHelper.Serialize(versionedConfiguration);
if (zipFile.Entries.Any(x => x.FileName == fileName))
{
zipFile.RemoveEntry(fileName);
}
configuarationMemoryStream.Position = 0;
zipFile.AddEntry(fileName, configuarationMemoryStream);
}
示例6: IntoZip
public static void IntoZip(string fileName, MemoryStream stream)
{
var path = ".\\Configuration\\";
var zipName = "config.fscp";
var filePath = path + fileName;
var zipPath = path + zipName;
var zip = new ZipFile(zipPath);
if (zip.Entries.FirstOrDefault(x => x.FileName == fileName) != null)
zip.RemoveEntry(fileName);
stream.Position = 0;
zip.AddEntry(fileName, stream);
zip.Save(zipPath);
}
示例7: ExecuteTransformationOnArchive
private static void ExecuteTransformationOnArchive(
ZipFile zippedXapFile,
string targetEnvironment,
string silverlightEnvironmentTransformFile)
{
zippedXapFile[SILVERLIGHT_CONFIG_FILE].Extract(_platformTempFilePath);
zippedXapFile[silverlightEnvironmentTransformFile].Extract(_platformTempFilePath);
new MsBuildConfigTransform().ExecuteTransformation(targetEnvironment, _platformTempFilePath);
zippedXapFile.RemoveEntry(SILVERLIGHT_CONFIG_FILE);
zippedXapFile.AddFile(Path.Combine(_platformTempFilePath, SILVERLIGHT_CONFIG_FILE), "");
zippedXapFile.Save();
}
示例8: MakeModpack
public void MakeModpack()
{
String[] fileList = Directory.GetFiles(tmp, "*", SearchOption.AllDirectories);
using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(mcFile)) {
foreach (String file in fileList) {
String newFile = file.Substring(tmp.Length);
Console.WriteLine(newFile);
if (zip.ContainsEntry(newFile))
zip.RemoveEntry(newFile);
zip.AddFile(file, Path.GetDirectoryName(newFile));
}
zip.Save();
MessageBox.Show("Done...");
}
/* using (ZipArchive zip = System.IO.Compression.ZipFile.Open(mcFile, ZipArchiveMode.Update)) {
foreach (String file in fileList) {
var fileInZip = (from f in zip.Entries
where f.Name == Path.GetFileName(file)
select f).FirstOrDefault();
if (fileInZip != null)
fileInZip.Delete();
zip.CreateEntryFromFile(file, file.Remove(0, tmp.Length), CompressionLevel.Optimal);
}
}*/
//ZipFile zip = new ZipFile(Path.Combine(path, ".minecraft" + Path.DirectorySeparatorChar, "bin" + Path.DirectorySeparatorChar, "minecraft.jar"));
//zip.AddDirectory(tmp);
//zip.Save(Path.Combine(path, ".minecraft" + Path.DirectorySeparatorChar, "bin" + Path.DirectorySeparatorChar, "minecraft.jar"));
}
示例9: SaveContentXml
private void SaveContentXml(ZipFile templateFile, XmlDocument contentXml)
{
templateFile.RemoveEntry("content.xml");
MemoryStream memStream = new MemoryStream();
contentXml.Save(memStream);
memStream.Seek(0, SeekOrigin.Begin);
templateFile.AddEntry("content.xml", memStream);
}
示例10: downloadForgeButton_Click
private void downloadForgeButton_Click(object sender, EventArgs e)
{
string forge_ver = (int)Forge1NumericUpDown.Value + "." + (int)Forge2NumericUpDown.Value + "." + (int)Forge3NumericUpDown.Value + "." + (int)Forge4NumericUpDown.Value;
string forge_url = "http://files.minecraftforge.net/minecraftforge-universal-" + forge_ver + ".zip";
WebClient client = new WebClient();
try
{
client.DownloadFile(forge_url, AppData + @"minecraftforge-universal-" + forge_ver + ".zip");
}
catch (WebException exc)
{
MessageBox.Show("Ошибка при загрузке minecraftforge-universal-" + forge_ver + ".zip: " + exc.Message, "Лаунчер", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
ZipFile forge_zip = new ZipFile("minecraftforge-universal-" + forge_ver + ".zip");
ZipFile mc_jar = new ZipFile(AppData + @"/.minecraft/bin/minecraft.jar");
forge_zip.RemoveEntry("META-INF");
mc_jar.RemoveEntry("META-INF");
Directory.CreateDirectory("Forge-TEMP");
forge_zip.ExtractAll("Forge-TEMP");
string[] files = Directory.GetFiles("Forge-TEMP");
foreach (string file in files)
{
mc_jar.AddFile("Forge-TEMP/" + file);
}
Directory.Delete("Forge-TEMP", true);
forge_zip.Save();
mc_jar.Save();
}
示例11: Init
//.........这里部分代码省略.........
if ((int)worldJson["hardmodeOres"][2] == -1)
worldJson["hardmodeOres"][2] = 111;
buttons.Add(oreButtons[0] = new MenuButton(0, "Cobalt", "", "", () =>
{
if ((int)worldJson["hardmodeOres"][0] == 107)
{
worldJson["hardmodeOres"][0] = 221;
oreButtons[0].displayText = "Palladium";
}
else
{
worldJson["hardmodeOres"][0] = 107;
oreButtons[0].displayText = "Cobalt";
}
Main.PlaySound(12);
}).Where(mb =>
{
if ((int)worldJson["hardmodeOres"][0] == 221)
mb.displayText = "Palladium";
mb.SetAutomaticPosition(aLeft, lid++);
}));
buttons.Add(oreButtons[1] = new MenuButton(0, "Mithril", "", "", () =>
{
if ((int)worldJson["hardmodeOres"][1] == 108)
{
worldJson["hardmodeOres"][1] = 222;
oreButtons[1].displayText = "Orchialcum";
}
else
{
worldJson["hardmodeOres"][1] = 108;
oreButtons[1].displayText = "Mithril";
}
Main.PlaySound(12);
}).Where(mb =>
{
if ((int)worldJson["hardmodeOres"][1] == 222)
mb.displayText = "Orchialcum";
mb.SetAutomaticPosition(aCentre, cid++);
}));
buttons.Add(oreButtons[2] = new MenuButton(0, "Adamantite", "", "", () =>
{
if ((int)worldJson["hardmodeOres"][2] == 111)
{
worldJson["hardmodeOres"][2] = 223;
oreButtons[2].displayText = "Titanium";
}
else
{
worldJson["hardmodeOres"][2] = 111;
oreButtons[2].displayText = "Adamantite";
}
Main.PlaySound(12);
}).Where(mb =>
{
if ((int)worldJson["hardmodeOres"][2] == 223)
mb.displayText = "Titanium";
mb.SetAutomaticPosition(aRight, rid++);
}));
lid++;
cid++;
rid++;
buttons.Add(new MenuButton(0, "Save & go back", "World Select").Where(mb =>
{
mb.Click += () =>
{
using (ZipFile zf = new ZipFile(selectedWorldPath))
{
zf.RemoveEntry("Info.json");
zf.AddEntry("Info.json", JsonMapper.ToJson(worldJson));
zf.Save();
Main.LoadWorlds();
}
};
mb.SetAutomaticPosition(new MenuAnchor()
{
anchor = new Vector2(0.5f, 0f),
offset = new Vector2(-105f, 200f),
offset_button = new Vector2(0f, 50f)
}, lid++);
}));
buttons.Add(new MenuButton(0, "Go back without saving", "World Select").Where(mb => mb.SetAutomaticPosition(new MenuAnchor()
{
anchor = new Vector2(0.5f, 0f),
offset = new Vector2(105f, 200f),
offset_button = new Vector2(0f, 50f)
}, rid++)));
}
示例12: Create_RenameRemoveAndRenameAgain_wi8047
public void Create_RenameRemoveAndRenameAgain_wi8047()
{
string filename = "file.test";
string dirToZip = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
var files = TestUtilities.GenerateFilesFlat(dirToZip);
for (int m = 0; m < 2; m++)
{
string zipFileToCreate = Path.Combine(TopLevelDir, String.Format("Create_RenameRemoveAndRenameAgain_wi8047-{0}.zip", m));
using (var zip = new ZipFile())
{
// select a single file from the list
int n = _rnd.Next(files.Length);
// insert the selected file into the zip, and also rename it
zip.UpdateFile(files[n]).FileName = filename;
// conditionally save
if (m > 0) zip.Save(zipFileToCreate);
// remove the original file
zip.RemoveEntry(zip[filename]);
// select another file from the list, making sure it is not the same file
int n2 = 0;
while ((n2 = _rnd.Next(files.Length)) == n) ;
// insert that other file and rename it
zip.UpdateFile(files[n2]).FileName = filename;
zip.Save(zipFileToCreate);
}
Assert.AreEqual<int>(1, TestUtilities.CountEntries(zipFileToCreate), "Trial {0}: The Zip file has the wrong number of entries.", m);
}
}
示例13: RebaseFiles
/// <summary>
/// this is used to rebase the paths in the .zip file if the skin folders are not directly in the root of the zip
/// for example the extra-skins.zip we ship is structured like this: extra-skins/artisteer-30alphamotors/
/// so skin folders are inside the extra-skins folder and we want to extract them directly without including the extra-skins folder
/// so we have to remove that base folder by renaming the files and removing that part.
/// </summary>
/// <param name="zip"></param>
/// <param name="baseToRemove"></param>
private void RebaseFiles(ZipFile zip, string baseToRemove)
{
if (string.IsNullOrEmpty(baseToRemove)) { return; }
// we cannot edit the file names while enumerating them so we first get a list of filenames
List<string> fileNames = new List<string>();
foreach (ZipEntry e in zip)
{
fileNames.Add(e.FileName);
}
foreach (string s in fileNames)
{
ZipEntry e = zip[s];
if (e != null)
{
if ((e.FileName.StartsWith(baseToRemove)) && (e.FileName.Length > baseToRemove.Length))
{
e.FileName = e.FileName.Replace(baseToRemove, string.Empty);
}
}
}
// get rid of the outer folder
zip.RemoveEntry(baseToRemove);
zip.Save();
}
示例14: btnOk_Click
private void btnOk_Click(object sender, EventArgs e)
{
//Validate plugin folder
if (!Directory.Exists(PluginFolder))
{
MessageBox.Show(@"Please select a valid folder to create the plugin from.");
return;
}
//Prompt for save path
if(sfdPlugin.ShowDialog() != DialogResult.OK)
{
return;
}
if (File.Exists(sfdPlugin.FileName))
{
FileHelper.DeleteFile(sfdPlugin.FileName);
}
//Create plugin file
using(var zip = new ZipFile())
{
var directory = new DirectoryInfo(PluginFolder);
//Add files in directory
foreach (var fileToAdd in Directory.GetFiles(PluginFolder, "*.*", SearchOption.AllDirectories))
{
if (this.AllFilesRadioButton.Checked || mWhatIsConsideredCode.Contains(FileManager.GetExtension(fileToAdd).ToLower()))
{
string relativeDirectory = null;
relativeDirectory = FileManager.MakeRelative(FileManager.GetDirectory(fileToAdd), directory.Parent.FullName);
if (relativeDirectory.EndsWith("/"))
{
relativeDirectory = relativeDirectory.Substring(0, relativeDirectory.Length - 1);
}
zip.AddFile(fileToAdd, relativeDirectory);
}
}
//Add compatibility file
var time = new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime;
if (zip.Entries.Any(item => item.FileName == directory.Name + "/" + "Compatibility.txt"))
{
zip.RemoveEntry(directory.Name + "/" + "Compatibility.txt");
}
try
{
zip.AddFileFromString("Compatibility.txt", directory.Name, time.ToString());
}
catch (Exception)
{
MessageBox.Show("The directory already contains a Compatibility.txt file name. The plugin will still be created but it may not properly include compatibility information. Consider removing this file and re-creating the plugin.");
}
zip.Save(sfdPlugin.FileName);
}
MessageBox.Show(@"Successfully created.");
System.Diagnostics.Process.Start(FileManager.GetDirectory(sfdPlugin.FileName));
Close();
}
示例15: SaveContentPackage
private void SaveContentPackage(bool forceLocationSelection)
{
if (!ValidateResourceEntries()) return;
if (forceLocationSelection || String.IsNullOrWhiteSpace(Model.FilePath))
{
SaveFilePrompt.Filter = ExtensionFactory.BuildContentPackageFileFilter();
if ((bool)SaveFilePrompt.ShowDialog())
{
Model.FilePath = SaveFilePrompt.FileName;
}
}
if (!String.IsNullOrWhiteSpace(Model.FilePath))
{
try
{
Model.Description = txtDescription.Text;
Model.Name = txtName.Text;
XmlSerializer serializer = new XmlSerializer(typeof(ContentPackageXML));
StringWriter stringWriter = new StringWriter();
XmlWriterSettings settings = new XmlWriterSettings { Indent = true, Encoding = Encoding.ASCII};
XmlWriter writer = XmlWriter.Create(stringWriter, settings);
serializer.Serialize(writer, Model);
string manifestXML = stringWriter.ToString();
File.WriteAllText("./Manifest.xml", manifestXML);
using (ZipFile zipFile = new ZipFile(Model.FilePath))
{
zipFile.CompressionLevel = CompressionLevel.None;
// Update the Manifest.xml file.
if (zipFile["Manifest.xml"] != null)
{
zipFile.RemoveEntry("Manifest.xml");
}
zipFile.AddFile("./Manifest.xml", "");
List<ContentPackageResourceXML> resourceList = lstAddedResources.Items.Cast<ContentPackageResourceXML>().ToList();
// Remove files which are no longer used.
for(int index = zipFile.Entries.Count; index > 0; index--)
{
ZipEntry entry = zipFile[index-1];
if (entry.FileName != "Manifest.xml")
{
if (!resourceList.Exists(x => x.FileName == entry.FileName))
{
zipFile.RemoveEntry(entry);
}
}
}
// Upsert new/modified files
foreach (ContentPackageResourceXML resource in resourceList)
{
ZipEntry entry = zipFile[resource.FileName];
if(entry == null)
{
zipFile.AddFile(resource.FilePath, "");
}
else
{
// Modified file isn't in the package. Remove existing and replace with new version.
if (!resource.IsInPackage && File.Exists(resource.FilePath))
{
zipFile.RemoveEntry(entry);
zipFile.AddFile(resource.FilePath, "");
}
}
}
zipFile.Save();
// Mark all as "unmodified"
resourceList.ForEach(a => a.IsInPackage = true);
// Clean up
File.Delete("./Manifest.xml");
Model.IsModified = false;
}
}
catch
{
throw;
}
}
}