private static ZipEntry Create(string nameInArchive, ZipEntrySource source, Object arg1, Object arg2)
{
if (String.IsNullOrEmpty(nameInArchive))
throw new Crisis.Ionic.Zip.ZipException("The entry name must be non-null and non-empty.");
ZipEntry entry = new ZipEntry();
// workitem 7071
// workitem 7926 - "version made by" OS should be zero for compat with WinZip
entry._VersionMadeBy = (0 << 8) + 45; // indicates the attributes are FAT Attributes, and v4.5 of the spec
entry._Source = source;
entry._Mtime = entry._Atime = entry._Ctime = DateTime.UtcNow;
if (source == ZipEntrySource.Stream)
{
entry._sourceStream = (arg1 as Stream); // may or may not be null
}
else if (source == ZipEntrySource.WriteDelegate)
{
entry._WriteDelegate = (arg1 as WriteDelegate); // may or may not be null
}
else if (source == ZipEntrySource.JitStream)
{
entry._OpenDelegate = (arg1 as OpenDelegate); // may or may not be null
entry._CloseDelegate = (arg2 as CloseDelegate); // may or may not be null
}
else if (source == ZipEntrySource.ZipOutputStream)
{
}
// workitem 9073
else if (source == ZipEntrySource.None)
{
// make this a valid value, for later.
entry._Source = ZipEntrySource.FileSystem;
}
else
{
String filename = (arg1 as String); // must not be null
if (String.IsNullOrEmpty(filename))
throw new Crisis.Ionic.Zip.ZipException("The filename must be non-null and non-empty.");
try
{
// The named file may or may not exist at this time. For
// example, when adding a directory by name. We test existence
// when necessary: when saving the ZipFile, or when getting the
// attributes, and so on.
#if NETCF
// workitem 6878
// Ionic.Zip.SharedUtilities.AdjustTime_Win32ToDotNet
entry._Mtime = File.GetLastWriteTime(filename).ToUniversalTime();
entry._Ctime = File.GetCreationTime(filename).ToUniversalTime();
entry._Atime = File.GetLastAccessTime(filename).ToUniversalTime();
// workitem 7071
// can only get attributes of files that exist.
if (File.Exists(filename) || Directory.Exists(filename))
entry._ExternalFileAttrs = (int)NetCfFile.GetAttributes(filename);
#elif SILVERLIGHT
entry._Mtime =
entry._Ctime =
entry._Atime = System.DateTime.UtcNow;
entry._ExternalFileAttrs = (int)0;
#else
// workitem 6878??
entry._Mtime = File.GetLastWriteTime(filename).ToUniversalTime();
entry._Ctime = File.GetCreationTime(filename).ToUniversalTime();
entry._Atime = File.GetLastAccessTime(filename).ToUniversalTime();
// workitem 7071
// can only get attributes on files that exist.
if (File.Exists(filename) || Directory.Exists(filename))
entry._ExternalFileAttrs = (int)File.GetAttributes(filename);
#endif
entry._ntfsTimesAreSet = true;
entry._LocalFileName = Path.GetFullPath(filename); // workitem 8813
}
catch (System.IO.PathTooLongException ptle)
{
// workitem 14035
var msg = String.Format("The path is too long, filename={0}",
filename);
throw new ZipException(msg, ptle);
}
}
entry._LastModified = entry._Mtime;
entry._FileNameInArchive = SharedUtilities.NormalizePathForUseInZipFile(nameInArchive);
// We don't actually slurp in the file data until the caller invokes Write on this entry.
return entry;
}