本文整理汇总了C#中Ionic.Zip.ZipFile.UpdateFile方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.UpdateFile方法的具体用法?C# ZipFile.UpdateFile怎么用?C# ZipFile.UpdateFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ionic.Zip.ZipFile
的用法示例。
在下文中一共展示了ZipFile.UpdateFile方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ZipFiles
/// <summary>Copy all the files in the TOC to the all the destination zips</summary>
/// <param name="TableOfContents">Container for all the files to copy</param>
public static void ZipFiles( TOC TableOfContents )
{
// Handle zips
if( Options.ZipName.Length > 0 )
{
long TotalFilesZipped = TableOfContents.Entries.Count;
long TotalBytesZipped = TableOfContents.Entries.Sum( x => x.Info.Length );
ZipFile Zip = new ZipFile( Options.ZipName );
Zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Level9;
Zip.UseZip64WhenSaving = Zip64Option.Always;
Zip.BufferSize = 0x10000;
TableOfContents.Entries.ForEach( x => Zip.UpdateFile( x.Name ) );
Log( " ... saving zip: " + Zip.Name, ConsoleColor.Green );
Zip.Save();
FileInfo ZipInfo = new FileInfo( Zip.Name );
Log( "Completed saving zip with " + TotalFilesZipped + " files to " + ZipInfo.Length + " bytes (from " + TotalBytesZipped + ")", ConsoleColor.Green );
}
}
示例2: 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);
}
}
示例3: Create_DuplicateEntries_wi8047
public void Create_DuplicateEntries_wi8047()
{
string zipFileToCreate = Path.Combine(TopLevelDir, "Create_DuplicateEntries_wi8047.zip");
string filename = "file.test";
string dirToZip = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
var files = TestUtilities.GenerateFilesFlat(dirToZip);
using (var zip = new ZipFile())
{
int n = _rnd.Next(files.Length);
zip.UpdateFile(files[n]).FileName = filename;
int n2 = 0;
while ((n2 = _rnd.Next(files.Length)) == n) ;
zip.UpdateFile(files[n2]).FileName = filename;
zip.Save(zipFileToCreate);
}
}
示例4: Pack
/// <summary>
/// Creates/updates a ZIP archive.
/// </summary>
/// <param name="baseDirectory">
/// The base directory. Can be <see langword="null"/> or empty.
/// </param>
/// <param name="searchPatterns">
/// The search patterns relative to the <paramref name="baseDirectory"/> or the current working
/// directory. May include wildcards ('?', '*').
/// </param>
/// <param name="recursive">
/// If set to <see langword="true"/> all subdirectories will be included in the search.
/// </param>
/// <param name="packageFileName">The file name of the ZIP archive.</param>
/// <param name="cancellationToken">
/// The token to monitor for cancellation requests. The default value is
/// <see cref="CancellationToken.None"/>.
/// </param>
public void Pack(string baseDirectory, IEnumerable<string> searchPatterns, bool recursive, string packageFileName, CancellationToken cancellationToken)
{
if (searchPatterns == null)
throw new ArgumentNullException(nameof(searchPatterns));
baseDirectory = string.IsNullOrEmpty(baseDirectory)
? Directory.GetCurrentDirectory()
: Path.GetFullPath(baseDirectory);
if (File.Exists(packageFileName))
WriteLine("Updating existing package \"{0}\".", packageFileName);
else
WriteLine("Creating new package \"{0}\".", packageFileName);
// Create/open ZIP archive.
using (var zipFile = new ZipFile(packageFileName))
{
bool isDirty = false;
zipFile.CompressionLevel = CompressionLevel.BestCompression;
zipFile.Password = string.IsNullOrEmpty(Password) ? null : Password;
zipFile.Encryption = string.IsNullOrEmpty(Password) ? EncryptionAlgorithm.None : Encryption;
//zipFile.StatusMessageTextWriter = MessageWriter;
zipFile.ZipErrorAction = ZipErrorAction.Throw;
zipFile.SaveProgress += (s, e) =>
{
if (cancellationToken.IsCancellationRequested)
e.Cancel = true;
// Note: We could report the saving progress here.
};
// Search for files.
var fileNames = new List<string>();
foreach (var searchPattern in searchPatterns)
{
cancellationToken.ThrowIfCancellationRequested();
fileNames.AddRange(GetFiles(baseDirectory, searchPattern, recursive));
}
// Exclude output file in case it is included in the search results.
fileNames.Remove(Path.GetFullPath(packageFileName));
// Sort in ascending order.
fileNames.Sort();
// Create a copy of the original ZIP entries.
var originalZipEntries = zipFile.Entries.ToList();
// Add/update files in ZIP archive.
foreach (var fileName in fileNames)
{
cancellationToken.ThrowIfCancellationRequested();
var fileInfo = new FileInfo(fileName);
string directory = fileInfo.DirectoryName;
string directoryInArchive = ChangePath(directory, baseDirectory, string.Empty);
string filenameInArchive = Path.Combine(directoryInArchive, fileInfo.Name);
filenameInArchive = NormalizePath(filenameInArchive);
var zipEntry = zipFile[filenameInArchive];
if (zipEntry == null)
{
// ----- New file.
MessageWriter.WriteLine("Adding \"{0}\".", filenameInArchive);
isDirty = true;
if (!IsTestRun)
zipFile.AddFile(fileName, directoryInArchive);
}
else
{
// ----- Existing file.
originalZipEntries.Remove(zipEntry);
if (fileInfo.LastWriteTimeUtc > zipEntry.ModifiedTime // Input file is newer.
|| fileInfo.Length != zipEntry.UncompressedSize) // Different file size.
{
MessageWriter.WriteLine("Updating \"{0}\".", filenameInArchive);
isDirty = true;
if (!IsTestRun)
zipFile.UpdateFile(fileName, directoryInArchive);
}
//.........这里部分代码省略.........
示例5: CompressFiles_zip
public void CompressFiles_zip(string destinationDirectory, string archiveName, string pwd, params string[] files)
{
try
{
if (archiveName == null || archiveName == string.Empty)
archiveName = DateTime.Now.ToString("dd_MM_yyyy");
else
if (archiveName[0] == '#')
archiveName = System.String.Format("{0}_{1:dd_MM_yyyy}", archiveName.Substring(1), System.DateTime.Now);
if (pwd == null || pwd == string.Empty)
pwd = Convert.ToString(int.Parse(DateTime.Now.ToString("ddMMyyyy")), 16).ToUpper();
//DateTime.Now.ToString("C_dd_MM_yyyy");
string pathZip = destinationDirectory + "\\" + archiveName + ".storage";
using (ZipFile zip = new ZipFile(pathZip))
{
//zip.AddFile("ReadMe.txt"); // unencrypted
//zip.
zip.Password = pwd;
zip.Encryption = EncryptionAlgorithm.WinZipAes256;
string singleName = string.Empty;
//ZipEntry itemZ = new ZipEntry();
foreach (string item in files)
{
singleName = item;
if (zip.ContainsEntry(singleName))
zip.UpdateFile(singleName).Password = pwd;
else
{
//itemZ.Encryption = EncryptionAlgorithm.WinZipAes256;
//itemZ.Password = pwd;
//itemZ.FileName = item;
zip.AddFile(singleName).Password = pwd;
//zip.Entries.Add(itemZ);
//ZipEntry.itemZ = new ZipEntry();
}
}
//zip.AddFile().pa(files, destinationDirectory);
//zip.AddFile("2008_Annual_Report.pdf");
try
{
zip.Comment = string.Format("{0}", int.Parse(zip.Comment) + 1);
}
catch (Exception ex)
{
pdLogger.pdLogger.Logme(ex, System.Reflection.MethodInfo.GetCurrentMethod().Name);
zip.Comment = zip.Count.ToString();
}
zip.Save(pathZip);
}
}
catch (Exception ex)
{
pdLogger.pdLogger.Logme(ex, System.Reflection.MethodInfo.GetCurrentMethod().Name);
}
}
示例6: AddToJar
/// <summary>
/// Recursively adds files from the given directory into the given jar
/// </summary>
/// <param name="dir">directory to copy files from</param>
/// <param name="jarFile">jar file to add them to</param>
private void AddToJar(string dir, ZipFile jarFile, string pathInJar = "")
{
IEnumerable<string> cFiles = Directory.EnumerateFileSystemEntries(dir);
foreach (string f in cFiles)
{
// For files that are not zip files...
if (File.Exists(f) && Path.GetExtension(f) != ".zip")
{
// Automatically put world edit in the bin folder.
if (Path.GetFileName(f) == "WorldEdit.jar")
{
File.Copy(f,
Path.Combine(Target.BinDir, "WorldEdit.jar"), true);
continue;
}
string existing = Path.Combine(pathInJar, Path.GetFileName(f));
int index = 0;
if (jarFile[existing] != null &&
!string.IsNullOrEmpty(jarFile[existing].Comment) &&
!Int32.TryParse(jarFile[existing].Comment, out index))
{
Console.WriteLine("Can't parse index: {0}", jarFile[existing].Comment);
}
if (jarFile[existing] != null &&
index > (int)modFileIndices[f])
{
DebugUtils.Print("File conflict between {0} in jar ({2}) and {1} ({3}) " +
"being added, " + "not overwriting.", existing, f,
jarFile[existing].Comment,
(modFileIndices.ContainsKey(f) ?
modFileIndices[f].ToString() : "none"));
}
else
{
if (jarFile[existing] != null)
{
DebugUtils.Print("File conflict between {0} " +
"in jar ({2}) and {1} ({3}) " +
"being added, " + " overwriting.", existing, f,
jarFile[existing].Comment,
(modFileIndices.ContainsKey(f) ?
modFileIndices[f].ToString() : "none"));
}
ZipEntry fEntry = jarFile.UpdateFile(f, pathInJar);
fEntry.SetEntryTimes(File.GetCreationTime(f),
fEntry.AccessedTime, fEntry.ModifiedTime);
if (modFileIndices.ContainsKey(f))
fEntry.Comment = modFileIndices[f].ToString();
}
}
// For directories
else if (Directory.Exists(f))
{
DebugUtils.Print("Adding subdirectory " + f + " to " +
Path.Combine(pathInJar, Path.GetFileName(f)));
AddToJar(f, jarFile, Path.Combine(pathInJar, Path.GetFileName(f)));
}
// For zip files
else if (File.Exists(f) &&
(Path.GetExtension(f) == ".zip" || Path.GetExtension(f) == ".jar"))
{
string tmpDir = Path.Combine(Target.RootDir, MODTEMP_DIR_NAME,
Path.GetFileNameWithoutExtension(f));
DebugUtils.Print("Adding zip file {0}, extracting to {1}...", f, tmpDir);
//Console.WriteLine("Temp directory for {0}: {1}", f, tmpDir);
if (Directory.Exists(tmpDir))
{
Directory.Delete(tmpDir, true);
Directory.CreateDirectory(tmpDir);
}
else
Directory.CreateDirectory(tmpDir);
//Console.WriteLine("Extracting {0} to temp directory...", f);
using (ZipFile zipFile = new ZipFile(f))
{
foreach (ZipEntry entry in zipFile)
{
entry.Extract(tmpDir);
string extractedFile = Path.Combine(tmpDir,
entry.FileName.Replace('/', Path.DirectorySeparatorChar));
//if (modFileIndices.ContainsKey(f))
// continue;
RecursiveSetIndex(extractedFile, (int) modFileIndices[f]);
// If it's a file
// if (File.Exists(extractedFile))
//.........这里部分代码省略.........
示例7: StorePacks
/// <summary>
/// Store the current pack files in storage.
/// </summary>
/// <param name="zip"><see cref="ZipFile" /> to store the current packs in.</param>
private void StorePacks(ZipFile zip)
{
const string ExdPackPattern = "0a*.*";
foreach (var file in Packs.DataDirectory.EnumerateFiles(ExdPackPattern, SearchOption.AllDirectories)) {
string targetDir = GameVersion + "/" + file.Directory.Name;
zip.UpdateFile(file.FullName, targetDir);
}
}
示例8: AddToJar
/// <summary>
/// Recursively adds files from the given directory into the given jar
/// </summary>
/// <param name="dir">directory to copy files from</param>
/// <param name="jarFile">jar file to add them to</param>
private void AddToJar(string dir, ZipFile jarFile, string pathInJar = "")
{
IEnumerable<string> cFiles = Directory.EnumerateFileSystemEntries(dir);
foreach (string f in cFiles)
{
// For files that are not zip files...
if (File.Exists(f) && Path.GetExtension(f) != ".zip")
{
// Automatically put world edit in the bin folder.
if (Path.GetFileName(f) == "WorldEdit.jar")
{
File.Copy(f,
Path.Combine(Target.RootDir, ".minecraft", "bin", "WorldEdit.jar"), true);
continue;
}
string existing = Path.Combine(pathInJar, Path.GetFileName(f));
if (jarFile[existing] != null &&
jarFile[existing].CreationTime.CompareTo(File.GetCreationTimeUtc(f)) > 0)
{
//Console.WriteLine("File conflict between {0} in jar ({2}) and {1} ({3}) " +
// "being added, " + "not overwriting.", existing, f,
// jarFile[existing].CreationTime.ToString(),
// File.GetCreationTimeUtc(f).ToString());
}
else
{
if (jarFile[existing] != null)
{
//Console.WriteLine("File conflict between {0} in jar ({2}) and {1} ({3}) " +
// "being added, " + " overwriting.", existing, f,
// jarFile[existing].CreationTime.ToString(),
// File.GetCreationTimeUtc(f).ToString());
}
ZipEntry fEntry = jarFile.UpdateFile(f, pathInJar);
fEntry.SetEntryTimes(File.GetCreationTime(f),
fEntry.AccessedTime, fEntry.ModifiedTime);
}
}
// For directories
else if (Directory.Exists(f))
{
Console.WriteLine("Adding subdirectory " + f + " to " +
Path.Combine(pathInJar, Path.GetFileName(f)));
AddToJar(f, jarFile, Path.Combine(pathInJar, Path.GetFileName(f)));
}
// For zip files
else if (File.Exists(f) && Path.GetExtension(f) == ".zip" && OSUtils.Windows)
{
string tmpDir = Path.Combine(Target.RootDir, MODTEMP_DIR_NAME,
Path.GetFileNameWithoutExtension(f));
Console.WriteLine("Adding zip file {0}, extracting to {1}...", f, tmpDir);
//Console.WriteLine("Temp directory for {0}: {1}", f, tmpDir);
if (Directory.Exists(tmpDir))
{
Directory.Delete(tmpDir, true);
Directory.CreateDirectory(tmpDir);
}
else
Directory.CreateDirectory(tmpDir);
//Console.WriteLine("Extracting {0} to temp directory...", f);
ZipFile zipFile = new ZipFile(f);
foreach (ZipEntry entry in zipFile)
{
entry.Extract(tmpDir);
string extractedFile = Path.Combine(tmpDir, entry.FileName);
// If it's a file
if (File.Exists(extractedFile))
File.SetCreationTime(extractedFile, File.GetCreationTime(f));
// If it's a directory
else if (Directory.Exists(extractedFile))
Directory.SetCreationTime(extractedFile, File.GetCreationTime(f));
//Console.WriteLine("{0} create time is {1}", extractedFile,
// File.GetCreationTime(f).ToString());
}
//Console.WriteLine("Adding to jar...");
AddToJar(tmpDir, jarFile, pathInJar);
}
}
}
示例9: Button1_Click
//.........这里部分代码省略.........
routesRecord.Dispose();
stopsRecord.Dispose();
calendarsRecord.Dispose();
calendarDatesRecord.Dispose();
tripsRecord.Dispose();
stopTimesRecord.Dispose();
fareAttributesRecord.Dispose();
fareRulesRecord.Dispose();
testingRecord.Dispose();
GC.Collect();
}
catch (IOException except)
{
status.Text = except.Message;
}
// If there are no errors, zip up the files and validate the feed
if (errors > 0)
{
status.Text = "<b>Feed NOT Published.</b> Last attempted -- " + DateTime.Now.ToString("dddd, MMMM dd, yyyy hh:mm tt");
if (errors == 1)
{
message.Text = message.Text + "<br /><b>There is currently " + errors + " error in your transit grouping.</b><br /><br />The Feed Creation has been halted until this error can be resolved.";
}
else
{
message.Text = message.Text + "<br /><b>There are currently " + errors + " errors in your transit grouping.</b><br /><br />The Feed Creation has been halted until these errors can be resolved.";
}
}
else
{
// Zip up the txt files
if (!File.Exists(transitDirectory + "\\" + arch))
{
ZipFile output = new ZipFile();
output.AddFile(transitDirectory + "\\agency.txt", ".");
output.AddFile(transitDirectory + "\\feed_info.txt", ".");
output.AddFile(transitDirectory + "\\routes.txt", ".");
output.AddFile(transitDirectory + "\\stops.txt", ".");
output.AddFile(transitDirectory + "\\calendar.txt", ".");
output.AddFile(transitDirectory + "\\calendar_dates.txt", ".");
output.AddFile(transitDirectory + "\\trips.txt", ".");
output.AddFile(transitDirectory + "\\stop_times.txt", ".");
output.AddFile(transitDirectory + "\\fare_attributes.txt", ".");
output.AddFile(transitDirectory + "\\fare_rules.txt", ".");
output.Name = transitDirectory + "\\" + arch;
output.Save();
output.Dispose();
GC.Collect();
}
else
{
ZipFile output = new ZipFile(transitDirectory + "\\" + arch);
output.UpdateFile(transitDirectory + "\\agency.txt", ".");
output.UpdateFile(transitDirectory + "\\feed_info.txt", ".");
output.UpdateFile(transitDirectory + "\\routes.txt", ".");
output.UpdateFile(transitDirectory + "\\stops.txt", ".");
output.UpdateFile(transitDirectory + "\\calendar.txt", ".");
output.UpdateFile(transitDirectory + "\\calendar_dates.txt", ".");
output.UpdateFile(transitDirectory + "\\trips.txt", ".");
output.UpdateFile(transitDirectory + "\\stop_times.txt", ".");
output.UpdateFile(transitDirectory + "\\fare_attributes.txt", ".");
output.UpdateFile(transitDirectory + "\\fare_rules.txt", ".");
output.Save();
output.Dispose();
GC.Collect();
}
// Feed validation
try
{
string fileName = transitDirectory + @"\\feedvalidator_googletransit.exe";
Process cmdLineProcess = new Process();
cmdLineProcess.StartInfo.FileName = fileName;
cmdLineProcess.StartInfo.Arguments = "-o " + transitDirectory + "\\error.html -l 9999 " + transitDirectory + "\\" + arch;
cmdLineProcess.StartInfo.UseShellExecute = true;
cmdLineProcess.StartInfo.CreateNoWindow = true;
cmdLineProcess.StartInfo.RedirectStandardOutput = false;
cmdLineProcess.StartInfo.RedirectStandardError = false;
if (cmdLineProcess.Start())
{
//litsample1.Text = cmdLineProcess.StandardOutput.ReadToEnd();
}
else
{
throw new ApplicationException("Can't read the command line process:" + fileName);
}
}
catch (ApplicationException except)
{
message.Text = message.Text + except.Message;
}
status.Text = "<b>Feed Published Successfully</b> -- " + DateTime.Now.ToString("dddd, MMMM dd, yyyy hh:mm tt");
message.Text = message.Text + "<br />View the full Feed Validation Report: <a href='/transit/error.html' target='_blank'>Google Feed Validation Report</a><br />View the testing.txt file: <a href='/transit/testing.txt' target='_blank'>testing.txt</a>";
}
return;
}
示例10: UpdateZip_UpdateFile_2_NoPasswords
public void UpdateZip_UpdateFile_2_NoPasswords()
{
string filename = null;
int entriesAdded = 0;
int j = 0;
string repeatedLine = null;
// select the name of the zip file
string zipFileToCreate = Path.Combine(TopLevelDir, "UpdateZip_UpdateFile_NoPasswords.zip");
// create the subdirectory
string subdir = Path.Combine(TopLevelDir, "A");
Directory.CreateDirectory(subdir);
// create the files
int NumFilesToCreate = _rnd.Next(23) + 14;
for (j = 0; j < NumFilesToCreate; j++)
{
filename = Path.Combine(subdir, String.Format("file{0:D3}.txt", j));
repeatedLine = String.Format("This line is repeated over and over and over in file {0}",
Path.GetFileName(filename));
TestUtilities.CreateAndFillFileText(filename, repeatedLine, _rnd.Next(34000) + 5000);
entriesAdded++;
}
// create the zip archive
Directory.SetCurrentDirectory(TopLevelDir);
using (ZipFile zip1 = new ZipFile())
{
String[] filenames = Directory.GetFiles("A");
foreach (String f in filenames)
zip1.UpdateFile(f, "");
zip1.Comment = "UpdateTests::UpdateZip_UpdateFile_NoPasswords(): This archive will be updated.";
zip1.Save(zipFileToCreate);
}
// Verify the number of files in the zip
Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), entriesAdded,
"Zoiks! The Zip file has the wrong number of entries.");
// create another subdirectory
subdir = Path.Combine(TopLevelDir, "updates");
Directory.CreateDirectory(subdir);
// Create a bunch of new files, in that new subdirectory
var UpdatedFiles = new List<string>();
int NumToUpdate = _rnd.Next(NumFilesToCreate - 4);
for (j = 0; j < NumToUpdate; j++)
{
// select a new, uniquely named file to create
do
{
filename = String.Format("file{0:D3}.txt", _rnd.Next(NumFilesToCreate));
} while (UpdatedFiles.Contains(filename));
// create a new file, and fill that new file with text data
repeatedLine = String.Format("**UPDATED** This file ({0}) has been updated on {1}.",
filename, System.DateTime.Now.ToString("yyyy-MM-dd"));
TestUtilities.CreateAndFillFileText(Path.Combine(subdir, filename), repeatedLine, _rnd.Next(34000) + 5000);
UpdatedFiles.Add(filename);
}
// update those files in the zip archive
using (ZipFile zip2 = FileSystemZip.Read(zipFileToCreate))
{
foreach (string s in UpdatedFiles)
zip2.UpdateFile(Path.Combine(subdir, s), "");
zip2.Comment = "UpdateTests::UpdateZip_UpdateFile_NoPasswords(): This archive has been updated.";
zip2.Save(zipFileToCreate);
}
// Verify the number of files in the zip
Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), entriesAdded,
"Zoiks! The Zip file has the wrong number of entries.");
// update those files AGAIN in the zip archive
using (ZipFile zip3 = FileSystemZip.Read(zipFileToCreate))
{
foreach (string s in UpdatedFiles)
zip3.UpdateFile(Path.Combine(subdir, s), "");
zip3.Comment = "UpdateTests::UpdateZip_UpdateFile_NoPasswords(): This archive has been re-updated.";
zip3.Save(zipFileToCreate);
}
// extract the updated files and verify their contents
using (ZipFile zip4 = FileSystemZip.Read(zipFileToCreate))
{
foreach (string s in UpdatedFiles)
{
repeatedLine = String.Format("**UPDATED** This file ({0}) has been updated on {1}.",
s, System.DateTime.Now.ToString("yyyy-MM-dd"));
zip4[s].Extract("extract");
// verify the content of the updated file.
var sr = new StreamReader(Path.Combine("extract", s));
string sLine = sr.ReadLine();
sr.Close();
Assert.AreEqual<string>(repeatedLine, sLine,
String.Format("The content of the Updated file ({0}) in the zip archive is incorrect.", s));
//.........这里部分代码省略.........
示例11: UpdatePackages
public void UpdatePackages(string packagesDirectory, string zipFileName)
{
using (var zipFile = new ZipFile(zipFileName)) {
_log.InfoFormat("Updating packages in {0}", zipFileName);
var zippedPackages = zipFile.SelectEntries("name = *.gz", PackagesName).ToList();
var notUpdatedPackages = zippedPackages.ConvertAll(p => p.FileName).ToList();
foreach (var entry in zippedPackages) {
var filePath = Utils.GetFilePath(packagesDirectory, entry.FileName);
var fileInfo = new FileInfo(filePath);
_log.InfoFormat("Updating package: {0}", fileInfo.Name);
zipFile.UpdateFile(fileInfo.FullName, PackagesName);
notUpdatedPackages.Remove(fileInfo.Name);
}
if (notUpdatedPackages.Count > 0) {
throw new Exception("Some packages not updated. " + string.Concat(notUpdatedPackages));
}
_log.InfoFormat("Saving zip: {0}", zipFileName);
zipFile.Save();
}
}