本文整理汇总了C#中Ionic.Zip.ZipFile.zCompressionRatio方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.zCompressionRatio方法的具体用法?C# ZipFile.zCompressionRatio怎么用?C# ZipFile.zCompressionRatio使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ionic.Zip.ZipFile
的用法示例。
在下文中一共展示了ZipFile.zCompressionRatio方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Zip
public List<string> Zip()
{
int nbZip = 0;
IEnumerable<XElement> zips = gConfig.GetElements("Backup/Zip");
foreach (XElement xeZip in zips)
{
nbZip += xeZip.zXPathValues("Source/SourceDirectory").Count();
nbZip += xeZip.zXPathValues("Source/SourceFile").Count();
}
List<string> zipFiles = new List<string>();
int iZip = 0;
foreach (XElement xeZip in zips)
{
if (gAbortTask) break;
CompressionLevel compressionLevel = GetCompressionLevel(xeZip.zXPathValue("CompressionLevel"));
string sZipDir = xeZip.zXPathValue("ZipDirectory");
foreach (string sourceDir in xeZip.zXPathValues("Source/SourceDirectory"))
{
if (gAbortTask) break;
gTaskProgress.SetProgressText("Zip " + sourceDir);
gTaskProgress.SetProgress(++iZip, nbZip);
if (!zDirectory.Exists(sourceDir))
{
//cTrace.Trace("Zip : directory does'nt exist {0}", sourceDir);
gTaskTrace.WriteLine("Zip : directory does'nt exist {0}", sourceDir);
continue;
}
DateTime t3 = DateTime.Now;
using (ZipFile zip = new ZipFile())
{
zip.SaveProgress += new EventHandler<SaveProgressEventArgs>(ZipSaveProgress);
//zip.CompressionLevel = CompressionLevel.BestSpeed;
zip.CompressionLevel = compressionLevel;
zip.AddDirectory(sourceDir, "");
string sPath = zpath.PathSetDirectory(zPath.GetFileNameWithoutExtension(sourceDir) + ".zip", sZipDir);
string sDir = zPath.GetDirectoryName(sPath);
if (!zDirectory.Exists(sDir))
zDirectory.CreateDirectory(sDir);
zip.Save(sPath);
if (gAbortTask) break;
zipFiles.Add(sPath);
int nbFiles = zip.zNbFile();
//int nbDir = zip.zNbDirectory();
long compressedSize = zip.zCompressedSize();
long uncompressedSize = zip.zUncompressedSize();
double ratio = zip.zCompressionRatio();
TimeSpan t4 = DateTime.Now.Subtract(t3);
gTaskTrace.WriteLine("Zip : {0,-40} - ratio {1,4:0.0} - nb files {2,5} - size {3,8} / {4,8} - {5:00}:{6:00}:{7:00}", sourceDir, ratio, nbFiles, GetSizeString(compressedSize), GetSizeString(uncompressedSize), t4.Hours, t4.Minutes, t4.Seconds);
}
}
foreach (string sourceFile in xeZip.zXPathValues("Source/SourceFile"))
{
if (gAbortTask) break;
gTaskProgress.SetProgressText("Zip " + sourceFile);
gTaskProgress.SetProgress(++iZip, nbZip);
if (!zFile.Exists(sourceFile))
{
//cTrace.Trace("Zip : file does'nt exist {0}", sourceFile);
gTaskTrace.WriteLine("Zip : file does'nt exist {0}", sourceFile);
continue;
}
DateTime t3 = DateTime.Now;
using (ZipFile zip = new ZipFile())
{
zip.SaveProgress += new EventHandler<SaveProgressEventArgs>(ZipSaveProgress);
//zip.CompressionLevel = CompressionLevel.BestSpeed;
zip.CompressionLevel = compressionLevel;
zip.AddFile(sourceFile, "");
string sPath = zpath.PathSetDirectory(zPath.GetFileNameWithoutExtension(sourceFile) + ".zip", sZipDir);
string sDir = zPath.GetDirectoryName(sPath);
if (!zDirectory.Exists(sDir))
zDirectory.CreateDirectory(sDir);
zip.Save(sPath);
if (gAbortTask) break;
zipFiles.Add(sPath);
int nbFiles = zip.zNbFile();
//int nbDir = zip.zNbDirectory();
long compressedSize = zip.zCompressedSize();
long uncompressedSize = zip.zUncompressedSize();
double ratio = zip.zCompressionRatio();
TimeSpan t4 = DateTime.Now.Subtract(t3);
gTaskTrace.WriteLine("Zip : {0,-40} - ratio {1,4:0.0} - nb files {2,5} - size {3,8} / {4,8} - {5:00}:{6:00}:{7:00}", sourceFile, ratio, nbFiles, GetSizeString(compressedSize), GetSizeString(uncompressedSize), t4.Hours, t4.Minutes, t4.Seconds);
}
}
}
return zipFiles;
}