WinCE6.0: "Last Modified time" not written correctly

Aug 3, 2009 at 12:03 PM

Hi,

I am using the library 1.8.4.5 on my Windows CE 6.0 device. At the moment I am struggling with the following problem: All files which have been successfully extracted have the actual time (time of extraction) set as the Last Modified time.

In my source code I have checked the properties LastModified and Mtime of an affected ZIP entry during the Extracting_BeforeExtractEntry event. At this time Mtime is "12:00:00 AM" and LastModified is "4/9/2009 12:31:32 PM".  The property LastModified contains the correct DOS Last Modified time. The content of Mtime is not clear to me. I thought Mtime should be empty (if no NTFS time was available) or the same as LastModified? So the property LastModified contains the correct time, however DoNetZip does not use it.

During my tests I have found this topic:  SetLastWriteTime fails on Compact Framework. It seems to me that my problem is maybe related to this issue.

I apologize if this question has been answered but I have not been able to find any information on this error.

Regards Peter

Coordinator
Aug 3, 2009 at 12:25 PM

It's possible on WinCE for the SetLastWriteTime to fail.  I have not understood the reasons for failure enough to prevent it.  However, when it fails the change made for the workitem you cited was to NOT throw an exception if SetLastWriteTime fails.  Instead, in this case DotNetZip will log a message to the StatusMessageTextWriter, describing the failure and the exact error code.  This change was made for v1.8.3.9 of the library.  If you are using v1.8.4.5, then you have the change.

Therefore, at the moment the best I can suggest is to set the SMTW to a StringWriter to see if those messages are being logged. If they are being logged, we will have more information in the message to help troubleshoot the problem.

StringWriter sw = new StringWriter();
using (ZipFile zip = ZipFile.Read(whatever))
{
  zip.StatusMessageTextWriter = sw;
  // call Extract methods here ...
}

Aug 3, 2009 at 12:37 PM

Hi!

this is my output:

Warning: SetLastWriteTime failed. entry(Liesmich.txt)  file(\Temp\New folder\Liesmich.txt) rc(87)

Regards Peter

Aug 3, 2009 at 2:50 PM
Edited Aug 3, 2009 at 2:52 PM

Hi Cheeso,

I have just compiled the soure code from this ZIP file DotNetZip-src-v1.8.4.14.zip and found the cause of the problem.  In the file ZipEntry.cs (it's a part of the project "Zip Partial DLL") there is the function
SetLastWriteTime. This function calls the native API function CreateFileCE of CoreDll.dll:

IntPtr hFile  = (IntPtr) CreateFileCE(filename, 
          (uint)FileAccess.Write, 
          (uint)FileShare.Write, 
          0, 
          (uint) 3,  // == open existing
          (uint)0, // flagsAndAttributes 
           0);




If I replace the FileAccess enumeration FileAccess.Write and the FileShare enumeration FileShare.Write with the WinAPI constant values of GENERIC_WRITE (0x40000000L)
and FILE_SHARE_WRITE (0x00000002) the problem is fixed
IntPtr hFile  = (IntPtr) CreateFileCE(filename, 
      (uint)0x40000000L,  
      (uint)0x00000002L, 
      0, 
      (uint) 3,  // == open existing
      (uint)0, // flagsAndAttributes 
      0);
The values of the .NET enumerations do not match the values of the WinAPI constants.
Regards Peter





Coordinator
Aug 3, 2009 at 4:18 PM

Thank you Peter, very good fix. 

Coordinator
Aug 3, 2009 at 4:21 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.