EldoS | Feel safer!

Software components for data protection, secure storage and transfer

DateTime info on directories

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#36402
Posted: 04/05/2016 15:21:35
by Steve Jensen (Priority Premium support level)
Joined: 02/16/2016
Posts: 16

I apologize if this is simple and I just overlooked it, but what property do I set so that directories in an archive get the same date time as the system folder? Files get the system date/time stamp, but it looks like folders get DateTime.Min or some other invalid value. The details of a folder in Winzip show this message:

For file "MYFOLDER\", the time stamp in the central directory is invalid, using the current system time instead.

Thanks.
#36403
Posted: 04/05/2016 16:53:51
by Ken Ivanov (EldoS Corp.)

Hi Steve,

Could you please specify how exactly are you packing files in your code? We've just tried to reproduce the behaviour you reported with a couple of code constructs, but all worked well.

Ken
#36404
Posted: 04/05/2016 17:38:55
by Steve Jensen (Priority Premium support level)
Joined: 02/16/2016
Posts: 16

Quote
Ken Ivanov wrote:
Could you please specify how exactly are you packing files in your code?


Are you asking specifically how I am "adding" files/folders to the archive? If yes, then I am just calling TElZipWriter.Add(parent, file) and then setting the ExtractionPath property on the returned TElArchiveDirectoryEntry object returned from .Add(). m_lstFileEntries is a List of ZipItem entries, class that I created.

Code
class ZipItem<T1, T2>
{
    public T1 Path { get; private set; }
    public T2 Folder { get; private set; }
    internal ZipItem(T1 path, T2 folder)
    {
        Path = path;
        Folder = folder;
    }
}

foreach (ZipItem<string, string> file in m_lstFileEntries)
{
  if (File.Exists(file.Path))
  {
    SBArcZip.TElZipArchiveDirectoryEntry parent = GetParentArchiveDirectoryEntry(file.Folder);
    SBArcZip.TElZipArchiveDirectoryEntry entry = zipWriter.Add(parent, file.Path);
    entry.ExtractionPath = file.Folder;
  }
}
#36405
Posted: 04/05/2016 18:31:06
by Ken Ivanov (EldoS Corp.)

Thank you, that's nearly what I was asking about.

While it is still unclear what your GetParentArchiveDirectoryEntry() method does, I generally understood the way you manage your archives. As you are apparently adding directories 'manually' via TElZipArchiveDirectoryEntry.AddNewEntry() method, you also need to set up their attributes. You can do that in the following way:

Code
SBArcZip.TElZipArchiveDirectoryEntry direntry = parent.AddNewEntry("mydir");
direntry.IsDirectory = true;
direntry.FileAttributesCompatibility = SBZipUtils.Unit.ZIP_FILEATTR_MSDOS;
direntry.Attributes.Directory = true;
[B]direntry.Attributes.ModTime = DateTime.Now[/B];


The line that is supposed to be in bold is the one that sets the directory modification time.

Ken
#36406
Posted: 04/05/2016 18:41:04
by Steve Jensen (Priority Premium support level)
Joined: 02/16/2016
Posts: 16

Sorry I didn't include that, the function is below. It just looks to see if the directory already exists and returns the existing entry or creates a new one. Is there a better way to do this or is this fine?

I see now what I am missing with the directoryEntry attributes. Thanks.

Code
// Returns parent TElZipArchiveDirectoryEntry object for given path.
SBArcZip.TElZipArchiveDirectoryEntry GetParentArchiveDirectoryEntry(string directory)
{
    SBArcZip.TElZipArchiveDirectoryEntry parent = zipWriter.Directory;

    // Account for subfolders.
    string[] folders = directory.Split(new char[] { '\\' });

    foreach (string folder in folders)
    {
        if (folder.Length > 0)
        {
            SBArcZip.TElZipArchiveDirectoryEntry existingEntry = parent.EntryWithName(folder);

            if (existingEntry == null)
            {
                parent = zipWriter.MakeDir(parent, folder);
            }
            else
            {
                parent = existingEntry;
            }
        }
    }

    return parent;
}
#36407
Posted: 04/05/2016 19:06:16
by Ken Ivanov (EldoS Corp.)

Thank you. Even though you use MakeDir() and not AddNewEntry() method (as I was assuming) to add new directory entries, the work performed by both methods is fairly similar. In contrast to higher-level filesystem-based methods (such as TElZipWriter.Add()), both MakeDir() and AddNewEntry() work with 'virtualized' entries, not straightforwardly associated with any physical disk files or folders. When adding folders in the virtualized manner, their attributes must also be set manually, as the component has no knowledge about where to get them. Please use the code snippet in my previous message as a guide on setting directory attributes manually.

By the way, the following line is not needed when creating archives, as the extraction path is generated automatically basing on the place of the entry in the archive hierarchy:

entry.ExtractionPath = file.Folder;

Ken
#36408
Posted: 04/05/2016 19:49:46
by Steve Jensen (Priority Premium support level)
Joined: 02/16/2016
Posts: 16

Ken,

Thank you for the help. You guys have excellent support.
Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.

Reply

Statistics

Topic viewed 2006 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!