本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.FastZip类的典型用法代码示例。如果您正苦于以下问题:C# FastZip类的具体用法?C# FastZip怎么用?C# FastZip使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FastZip类属于ICSharpCode.SharpZipLib.Zip命名空间,在下文中一共展示了FastZip类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractArchive
internal static bool ExtractArchive(string archive, string destination)
{
//REFACTOR: Only create RAR and ZIP classes after discovering that the file actually has a .zip or .rar extension
FileInfo archiveFI = new FileInfo(archive);
Rar rar = new Rar();
FastZip fz = new FastZip();
double archivesize = archiveFI.Length * 2;
char driveLetter = archiveFI.FullName[0];
if (!CheckDiskSpaceQuota(archivesize, driveLetter)) return false;
if (archiveFI.Extension == ".rar" || archiveFI.Extension == ".RAR")
return ExtractRarArchive(archive, destination, archiveFI, rar);
// ReSharper disable ConvertIfStatementToReturnStatement
if (archiveFI.Extension == ".zip" || archiveFI.Extension == ".ZIP")
// ReSharper restore ConvertIfStatementToReturnStatement
return ExtractZipArchive(archive, destination, fz);
//TODO: Should this return false?
return true;
}
示例2: ExtractZipArchive
private static bool ExtractZipArchive(string archive, string destination, FastZip fz)
{
DirectoryInfo newdirFI;
if (!Directory.Exists(destination))
{
newdirFI = Directory.CreateDirectory(destination);
if (!Directory.Exists(newdirFI.FullName))
{
//MessageBox.Show("Directory " + destination + " could not be created.");
return false;
}
}
else newdirFI = new DirectoryInfo(destination);
try
{
Thread.Sleep(500);
fz.ExtractZip(archive, newdirFI.FullName, "");
}
catch (Exception e)
{
Debugger.LogMessageToFile("The archive " + archive + " could not be extracted to destination " + destination +
". The following error ocurred: " + e);
}
return true;
}
示例3: UnzipNewAgentVersion
private void UnzipNewAgentVersion()
{
_logger.Log("Unzipping files");
var fz = new FastZip();
fz.ExtractZip(Constants.AgentServiceReleasePackage, Constants.AgentServiceUnzipPath, "");
_logger.Log("Unzipping files complete");
}
开发者ID:rackerlabs,项目名称:openstack-guest-agents-windows-xenserver-old,代码行数:7,代码来源:InstallAgentService.cs
示例4: Program
public Program()
{
string[] dirs=Directory.GetDirectories(".");
foreach (string dir in dirs)
{
DataBase.AnimatedBitmap an = new DataBase.AnimatedBitmap();
an._Name =Path.GetFileName(dir);
foreach (string file in Directory.GetFiles(dir))
if (Regex.IsMatch(Path.GetExtension(file), "jpg|png", RegexOptions.IgnoreCase))
an._Bitmaps.Add(file.Replace(@"\", "/","./",""));
if (an._Bitmaps.Count > 0)
{
Image img = Bitmap.FromFile(an._Bitmaps.First());
an._Width = img.Width;
an._Height = img.Height;
_DataBase._AnimatedBitmaps.Add(an);
}
}
Common._XmlSerializer.Serialize("./db.xml", _DataBase);
FastZip _FastZip = new FastZip();
_FastZip.CreateZip("content.zip","./",true,@"\.jpg|\.png|.\xml");
}
示例5: DownloadAndUpdateSnakeBite
private static void DownloadAndUpdateSnakeBite(string URL)
{
// Download update archive
using (WebClient w = new WebClient()) w.DownloadFile(URL, "update.dat");
// Extract archive
FastZip z = new FastZip();
z.ExtractZip("update.dat", "_update", "(.*?)");
// Move update file
File.Delete("SnakeBite.exe");
File.Delete("MakeBite.exe");
File.Delete("GzsTool.Core.dll");
File.Delete("fpk_dictionary.txt");
File.Delete("qar_dictionary.txt");
File.Move("_update/SnakeBite.exe", "SnakeBite.exe");
File.Move("_update/MakeBite.exe", "MakeBite.exe");
File.Move("_update/GzsTool.Core.dll", "GzsTool.Core.dll");
File.Move("_update/fpk_dictionary.txt", "fpk_dictionary.txt");
File.Move("_update/qar_dictionary.txt", "qar_dictionary.txt");
// Restart updater
Process updater = new Process();
updater.StartInfo.Arguments = "-u";
updater.StartInfo.UseShellExecute = false;
updater.StartInfo.FileName = "sbupdater.exe";
updater.Start();
Environment.Exit(0);
}
示例6: MergeFile
private static async Task MergeFile( MergeParams p ) {
var zf = new FastZip();
using ( var s = File.OpenWrite( p.DestImg ) ) {
s.Seek( 0, SeekOrigin.End );
zf.CreateZip( s, Path.GetDirectoryName( p.DataSource ), false, Path.GetFileName( p.DataSource ), "" );
}
}
示例7: UnzipProject
/// <summary>
///
/// </summary>
/// <param name="filename"></param>
/// <returns>temporary project file name.</returns>
public string UnzipProject(string filename)
{
output = null;
// Check File
if (!File.Exists(filename))
throw new EcellException(string.Format(MessageResources.ErrLoadPrj, filename));
// Extract zip
string dir = Path.Combine(Util.GetTmpDir(), Path.GetRandomFileName());
FastZip fz = new FastZip();
fz.ExtractZip(filename, dir, null);
// Check Project File.
string project = Path.Combine(dir,Constants.fileProjectXML);
string info = Path.Combine(dir,Constants.fileProjectInfo);
if(File.Exists(project))
output = project;
else if(File.Exists(info))
output = info;
if (output == null)
{
Directory.Delete(dir);
throw new EcellException(string.Format(MessageResources.ErrLoadPrj, filename));
}
// Return project path.
return output;
}
示例8: BackupNow
public static void BackupNow(MCServer s)
{
Database.AddLog("Backing up " + s.ServerTitle, "backup");
//Check for a backup dir and create if not
if (!Directory.Exists(s.ServerDirectory + @"\backups\")) Directory.CreateDirectory(s.ServerDirectory + @"\backups\");
//Force a save
s.Save();
s.DisableSaving();
//Copy world to a temp Dir
if (Directory.Exists(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\")) Directory.Delete(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\", true);
if (!Directory.Exists(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\")) Directory.CreateDirectory(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\");
Util.Copy(s.ServerDirectory + @"\world\", s.ServerDirectory + @"\backups\temp\");
//Re-enable saving then force another save
s.EnableSaving();
s.Save();
//Now zip up temp dir and move to backups
FastZip z = new FastZip();
z.CreateEmptyDirectories = true;
z.CreateZip(s.ServerDirectory + @"\backups\" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + ".zip", s.ServerDirectory + @"\backups\temp\", true, "");
//If the server is empty, reset the HasChanged
if (s.Players.Count == 0) s.HasChanged = false;
}
示例9: gerarZipDiretorio
public void gerarZipDiretorio(string sDiretorioOrigem, string sDiretorioDestino)
{
FastZip sz = new FastZip();
try
{
string sArquivoZip = string.Empty;
//Aqui vou criar um nome do arquivo.
DateTime newDate = DateTime.Now;
sArquivoZip = "MeuZip_" + Convert.ToString(newDate).Replace("/", "_").Replace(":", "") + ".zip";
//Só um tratamento para garantir mais estabilidade
if (sDiretorioOrigem.Substring(sDiretorioOrigem.Length - 2) != "\\" || sDiretorioDestino.Substring(sDiretorioDestino.Length - 2) != "\\")
{
sDiretorioOrigem = sDiretorioOrigem + "\\";
}
sz.Password = txtDiretorioZipSenha.Text;
//Gera o ZIP
sz.CreateZip(sDiretorioDestino + sArquivoZip, sDiretorioOrigem + "" + "\\", true, "", "");
}
catch (Exception ex)
{
MessageBox.Show("Ocorreu um erro durante o processo de compactação : " + ex);
}
finally
{
//Limpa o Objeto
sz = null;
}
}
示例10: UnZipFile
/// <summary>
/// 解压zip文件
/// </summary>
/// <param name="_zipFile">需要解压的zip路径+名字</param>
/// <param name="_outForlder">解压路径</param>
public void UnZipFile(string _zipFile, string _outForlder)
{
if (Directory.Exists(_outForlder))
Directory.Delete(_outForlder, true);
Directory.CreateDirectory(_outForlder);
progress = progressOverall = 0;
Thread thread = new Thread(delegate ()
{
int fileCount = (int)new ZipFile(_zipFile).Count;
int fileCompleted = 0;
FastZipEvents events = new FastZipEvents();
events.Progress = new ProgressHandler((object sender, ProgressEventArgs e) =>
{
progress = e.PercentComplete;
if (progress == 100) { fileCompleted++; progressOverall = 100 * fileCompleted / fileCount; }
});
events.ProgressInterval = TimeSpan.FromSeconds(progressUpdateTime);
events.ProcessFile = new ProcessFileHandler(
(object sender, ScanEventArgs e) => { });
FastZip fastZip = new FastZip(events);
fastZip.ExtractZip(_zipFile, _outForlder, "");
});
thread.IsBackground = true;
thread.Start();
}
示例11: buttonCreateBackup_Click
private void buttonCreateBackup_Click(object sender, EventArgs e)
{
if (Directory.Exists("_backup")) Directory.Delete("_backup", true);
Directory.CreateDirectory("_backup");
// prompt user for backup filename
SaveFileDialog saveBackup = new SaveFileDialog();
saveBackup.Filter = "SnakeBite Backup|*.sbb";
DialogResult saveResult = saveBackup.ShowDialog();
if (saveResult != DialogResult.OK) return;
// copy current settings
objSettings.SaveSettings();
File.Copy(ModManager.GameDir + "\\sbmods.xml", "_backup\\sbmods.xml");
// copy current 01.dat
File.Copy(ModManager.GameArchivePath, "_backup\\01.dat");
// compress to backup
FastZip zipper = new FastZip();
zipper.CreateZip(saveBackup.FileName, "_backup", true, "(.*?)");
Directory.Delete("_backup", true);
MessageBox.Show("Backup complete.", "SnakeBite", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
示例12: PackFiles
/// <summary>压缩文件</summary>
/// <param name="filename">filename生成的文件的名称,如:C:\RAR\075_20110820153200001-1.rar</param>
/// <param name="directory">directory要压缩的文件夹路径,如:C:\OA</param>
/// <returns></returns>
public static bool PackFiles(string filename, string directory)
{
try
{
directory = directory.Replace("/", "\\");
if (!directory.EndsWith("\\"))
directory += "\\";
if (!System.IO.Directory.Exists(directory))
{
System.IO.Directory.CreateDirectory(directory);
}
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
FastZip fz = new FastZip();
fz.CreateEmptyDirectories = true;
fz.CreateZip(filename, directory, true, "");
return true;
}
catch (Exception)
{
return false;
}
}
示例13: Basics
public void Basics()
{
const string tempName1 = "a(1).dat";
MemoryStream target = new MemoryStream();
string tempFilePath = GetTempFilePath();
Assert.IsNotNull(tempFilePath, "No permission to execute this test?");
string addFile = Path.Combine(tempFilePath, tempName1);
MakeTempFile(addFile, 1);
try {
FastZip fastZip = new FastZip();
fastZip.CreateZip(target, tempFilePath, false, @"a\(1\)\.dat", null);
MemoryStream archive = new MemoryStream(target.ToArray());
using (ZipFile zf = new ZipFile(archive)) {
Assert.AreEqual(1, zf.Count);
ZipEntry entry = zf[0];
Assert.AreEqual(tempName1, entry.Name);
Assert.AreEqual(1, entry.Size);
Assert.IsTrue(zf.TestArchive(true));
zf.Close();
}
}
finally {
File.Delete(tempName1);
}
}
示例14: Main
private static void Main(string[] args)
{
if (args.Length != 3)
{
Console.Error.WriteLine("Error: not enough arguments");
Console.Error.WriteLine("Usage: MetroIdeUpdateManager <update zip> <metroide exe> <parent pid>");
return;
}
string zipPath = args[0];
string exePath = args[1];
int pid = Convert.ToInt32(args[2]);
try
{
// Wait for Assembly to close
try
{
Process process = Process.GetProcessById(pid);
process.WaitForExit();
process.Close();
}
catch
{
}
// Extract the update zip
var fz = new FastZip {CreateEmptyDirectories = true};
for (int i = 0; i < 5; i++)
{
try
{
fz.ExtractZip(zipPath, Directory.GetCurrentDirectory(), null);
break;
}
catch (IOException)
{
Thread.Sleep(1000);
if (i == 4)
{
throw;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Assembly Update Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
try
{
File.Delete(zipPath);
}
catch
{
}
// Launch "The New iPa... Assembly"
Process.Start("Assembly://post-update");
}
示例15: ChoosePackageDialog
private void ChoosePackageDialog()
{
// Configure open file dialog box
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.FileName = "Document"; // Default file name
dlg.DefaultExt = ".AGT"; // Default file extension
dlg.Filter = "Agent Package (.agt)|*.agt"; // Filter files by extension
// Show open file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process open file dialog box results
if (result == true)
{
// Open document
PackageSource = dlg.FileName;
ICSharpCode.SharpZipLib.Zip.FastZip fz = new FastZip();
var root = System.IO.Path.Combine(System.IO.Path.GetTempPath(), (Guid.NewGuid().ToString()));
fz.ExtractZip(PackageSource, root, FastZip.Overwrite.Always, null, null, null, true);
PackageFile = System.IO.Path.Combine(root, "package.json");
if (System.IO.File.Exists(PackageFile))
{
var cnt = System.IO.File.ReadAllText(PackageFile);
Contents = cnt;
}
}
}