NormalizePathForUseInZipFile() public static method

Utility routine for transforming path names from filesystem format (on Windows that means backslashes) to a format suitable for use within zipfiles. This means trimming the volume letter and colon (if any) And swapping backslashes for forward slashes.
public static NormalizePathForUseInZipFile ( string pathName ) : string
pathName string source path.
return string
        internal static string NameInArchive(String filename, string directoryPathInArchive)
        {
            string result = null;

            if (directoryPathInArchive == null)
            {
                result = filename;
            }

            else
            {
                if (String.IsNullOrEmpty(directoryPathInArchive))
                {
                    result = Path.GetFileName(filename);
                }
                else
                {
                    // explicitly specify a pathname for this file
                    result = Path.Combine(directoryPathInArchive, Path.GetFileName(filename));
                }
            }

            //result = Path.GetFullPath(result);
            result = SharedUtilities.NormalizePathForUseInZipFile(result);

            return(result);
        }
 public ZipEntry this[String fileName]
 {
     get
     {
         var entries = RetrievalEntries;
         var key     = SharedUtilities.NormalizePathForUseInZipFile(fileName);
         if (entries.ContainsKey(key))
         {
             return(entries[key]);
         }
         // workitem 11056
         key = key.Replace("/", "\\");
         if (entries.ContainsKey(key))
         {
             return(entries[key]);
         }
         return(null);
     }
 }
        public void RemoveEntry(ZipEntry entry)
        {
            //if (!_entries.Values.Contains(entry))
            //    throw new ArgumentException("The entry you specified does not exist in the zip archive.");
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            var path = SharedUtilities.NormalizePathForUseInZipFile(entry.FileName);

            _entries.Remove(path);
            if (!AnyCaseInsensitiveMatches(path))
            {
                _entriesInsensitive.Remove(path);
            }
            _zipEntriesAsList = null;

#if NOTNEEDED
            if (_direntries != null)
            {
                bool FoundAndRemovedDirEntry = false;
                foreach (ZipDirEntry de1 in _direntries)
                {
                    if (entry.FileName == de1.FileName)
                    {
                        _direntries.Remove(de1);
                        FoundAndRemovedDirEntry = true;
                        break;
                    }
                }

                if (!FoundAndRemovedDirEntry)
                {
                    throw new BadStateException("The entry to be removed was not found in the directory.");
                }
            }
#endif
            _contentsChanged = true;
        }
Beispiel #4
0
 // Token: 0x06000658 RID: 1624 RVA: 0x0000BD33 File Offset: 0x00009F33
 public bool ContainsEntry(string name)
 {
     return(this._entriesWritten.ContainsKey(SharedUtilities.NormalizePathForUseInZipFile(name)));
 }
        private static ZipEntry Create(string nameInArchive, ZipEntrySource source, Object arg1, Object arg2)
        {
            if (String.IsNullOrEmpty(nameInArchive))
            {
                throw new 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 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.

                    // 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);
                    }

                    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);
        }