SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Problems with ziping Files that are used from a other Programm

Last post 05-19-2008 2:54 PM by freestyler38. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-15-2008 10:33 AM

    Problems with ziping Files that are used from a other Programm

    I used for Create a Zipfile the Zipfile Class, wenn i try to add a File that is used from a other Programm i get no Exception, but the File is not added and the Zipfile is closed from something in the SharpZipLib, so i get a Exception from the next add "Can not access closed file". The new ZipFile(string filename) can only used for reading, but for updating a Zipfile i find nothing.
  • 05-19-2008 11:15 AM In reply to

    Re: Problems with ziping Files that are used from a other Programm

    Hei! I have changed the source of the SharpZipLib. Now i am testing the changes i have add a catch block for IOException, where i set a bool var, so the Zipfile Object in SharpZipLib is not closed when allok is false, so i can conitue adding.
  • 05-19-2008 2:54 PM In reply to

    Re: Problems with ziping Files that are used from a other Programm

    So it works ihave changed the RunUpdates method in Zipfile.cs: void RunUpdates() { long sizeEntries = 0; long endOfStream = 0; bool allOk = true; bool directUpdate = false; bool zipContinue = false; string msg=""; long destinationPosition = 0; // NOT SFX friendly ZipFile workFile; if ( IsNewArchive ) { workFile = this; workFile.baseStream_.Position = 0; directUpdate = true; } else if ( archiveStorage_.UpdateMode == FileUpdateMode.Direct ) { workFile = this; workFile.baseStream_.Position = 0; directUpdate = true; // Sort the updates by offset within copies/modifies, then adds. // This ensures that data required by copies will not be overwritten. updates_.Sort(new UpdateComparer()); } else { workFile = ZipFile.Create(archiveStorage_.GetTemporaryOutput()); workFile.UseZip64 = UseZip64; if (key != null) { workFile.key = (byte[)key.Clone(); } } try { foreach (ZipUpdate update in updates_) { if (update != null) { switch (update.Command) { case UpdateCommand.Copy: if (directUpdate) { CopyEntryDirect(workFile, update, ref destinationPosition); } else { CopyEntry(workFile, update); } break; case UpdateCommand.Modify: // TODO: Direct modifying of an entry will take some legwork. ModifyEntry(workFile, update); break; case UpdateCommand.Add: if (!IsNewArchive && directUpdate) { workFile.baseStream_.Position = destinationPosition; } AddEntry(workFile, update); if (directUpdate) { destinationPosition = workFile.baseStream_.Position; } break; } } } if (!IsNewArchive && directUpdate) { workFile.baseStream_.Position = destinationPosition; } long centralDirOffset = workFile.baseStream_.Position; foreach (ZipUpdate update in updates_) { if (update != null) { sizeEntries += workFile.WriteCentralDirectoryHeader(update.OutEntry); } } byte[ theComment = (newComment_ != null) ? newComment_.RawComment : ZipConstants.ConvertToArray(comment_); using (ZipHelperStream zhs = new ZipHelperStream(workFile.baseStream_)) { zhs.WriteEndOfCentralDirectory(updateCount_, sizeEntries, centralDirOffset, theComment); } endOfStream = workFile.baseStream_.Position; // And now patch entries... foreach (ZipUpdate update in updates_) { if (update != null) { // If the size of the entry is zero leave the crc as 0 as well. // The calculated crc will be all bits on... if ((update.CrcPatchOffset > 0) && (update.OutEntry.CompressedSize > 0)) { workFile.baseStream_.Position = update.CrcPatchOffset; workFile.WriteLEInt((int)update.OutEntry.Crc); } if (update.SizePatchOffset > 0) { workFile.baseStream_.Position = update.SizePatchOffset; if (update.OutEntry.LocalHeaderRequiresZip64) { workFile.WriteLeLong(update.OutEntry.Size); workFile.WriteLeLong(update.OutEntry.CompressedSize); } else { workFile.WriteLEInt((int)update.OutEntry.CompressedSize); workFile.WriteLEInt((int)update.OutEntry.Size); } } } } } catch (IOException ex) { if (ex.Message.EndsWith(" because it is being used by another process.")) { msg = ex.Message; allOk = false; zipContinue = true; } else { allOk = false; zipContinue = false; } } catch (Exception) { allOk = false; zipContinue = false; } finally { if ( directUpdate ) { if ( allOk ) { workFile.baseStream_.Flush(); workFile.baseStream_.SetLength(endOfStream); } } else { workFile.Close(); } } if ( allOk ) { if ( directUpdate ) { isNewArchive_ = false; workFile.baseStream_.Flush(); ReadEntries(); } else { baseStream_.Close(); Reopen(archiveStorage_.ConvertTemporaryToFinal()); } } else { if (!zipContinue) { workFile.Close(); if (!directUpdate && (workFile.Name != null)) { File.Delete(workFile.Name); } } else { throw(new Exception(msg)); } } }
Page 1 of 1 (3 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.