Exemple #1
0
    private static void MapResBundleFiles(DirectoryInfo a_dir, PathMap a_bundlePathMap, PathMap a_globalPathMap, string a_extension)
    {
        referenceList.AddLast(a_dir.Name);
        FileInfo[] info = a_dir.GetFiles("*" + a_extension);

        LinkedListNode <string> node = null;

        for (int i = 0; i < info.Length; ++i)
        {
            node = referenceList.First;

            string fullName = info[i].Name;

            int    extensionIndex = fullName.IndexOf(".", System.StringComparison.Ordinal);
            string name           = fullName.Substring(0, extensionIndex);
            string extension      = fullName.Substring(extensionIndex, fullName.Length - extensionIndex);

            string fullPath = "";
            while (node != referenceList.Last)
            {
                fullPath += node.Value;
                fullPath += "/";
                node      = node.Next;
            }
            fullPath += node.Value;
            fullPath += "/";

            fullPath += name;
            int pathHash = fullPath.GetHashCode();
            fullPath += extension;
            a_bundlePathMap.Add(pathHash, fullPath);
            a_globalPathMap.Add(pathHash, fullPath);
        }
    }
        public Entry CreateEntry(string dir, string name)
        {
            ExceptionContext.Check(!Disposed);

            Flush();

            string pathEnt;
            string pathTemp;

            GetPath(out pathEnt, out pathTemp, dir, name, true);
            if (PathMap.ContainsKey(pathEnt))
            {
                throw ExceptionContext.ExceptParam(nameof(name), "Duplicate entry: '{0}'", pathEnt);
            }
            else
            {
                PathMap.Add(pathEnt, pathTemp);
            }

            Stream stream;

            if (pathTemp != null)
            {
                stream = new FileStream(pathTemp, FileMode.CreateNew);
            }
            else
            {
                stream = new MemoryStream();
            }

            return(AddEntry(pathEnt, stream));
        }
        public Entry OpenEntryOrNull(string dir, string name)
        {
            ExceptionContext.Check(!Disposed);

            string pathEnt;
            string pathTemp;

            GetPath(out pathEnt, out pathTemp, dir, name, false);

            ZipArchiveEntry entry;
            Stream          stream;
            string          pathAbs;
            string          pathLower = pathEnt.ToLowerInvariant();

            if (PathMap.TryGetValue(pathLower, out pathAbs))
            {
                stream = new FileStream(pathAbs, FileMode.Open, FileAccess.Read);
            }
            else
            {
                if (!_entries.TryGetValue(pathEnt, out entry))
                {
                    //Read old zip file that use backslash in filename
                    var pathEntTmp = pathEnt.Replace("/", "\\");
                    if (!_entries.TryGetValue(pathEntTmp, out entry))
                    {
                        return(null);
                    }
                }

                if (pathTemp != null)
                {
                    // Extract to a temporary file.
                    Directory.CreateDirectory(Path.GetDirectoryName(pathTemp));
                    entry.ExtractToFile(pathTemp);
                    PathMap.Add(pathLower, pathTemp);
                    stream = new FileStream(pathTemp, FileMode.Open, FileAccess.Read);
                }
                else
                {
                    // Extract to a memory stream.
                    ExceptionContext.CheckDecode(entry.Length < int.MaxValue, "Repository stream too large to read into memory");
                    stream = new MemoryStream((int)entry.Length);
                    using (var src = entry.Open())
                        src.CopyTo(stream);
                    stream.Position = 0;
                }
            }

            return(AddEntry(pathEnt, stream));
        }
Exemple #4
0
        public void Add(IColumn column)
        {
            int order;

            if (_order.TryGetValue(column.Path, out order))
            {
                _columns[order] = column;
            }
            else
            {
                _columns.Add(_order.Count, column);
                _order.Add(column.Path, _order.Count);
            }
        }