Ejemplo n.º 1
0
        bool Search(List <PackObject> list, DirectoryInfo current)
        {
            PackObject last = null;

            DirectoryInfo[] dirs = current.GetDirectories();
            for (int i = 0; i < dirs.Length; i++)
            {
                if (string.Compare(dirs[i].Name, "user", true) == 0) // ignore "user" folders
                {
                    continue;
                }

                // search all directories
                var dir = new PackDir(dirs[i]);
                list.Add(dir);

                if (!Search(list, dirs[i]))
                {
                    list.RemoveAt(list.Count - 1); // don't add empty folders
                }
                last = dir;
            }

            FileInfo[] files = current.GetFiles();
            for (int i = 0; i < files.Length; i++)
            {
                // add files
                var file = new PackFile(files[i]);
                list.Add(file);
                last = file;
            }

            if (last == null)
            {
                return(false);
            }
            else
            {
                last.IsLast = true; // last item in this folder is marked
                return(true);
            }
        }
Ejemplo n.º 2
0
        public static PackObject ReadNew(PacketStream stream, string path)
        {
            int    type   = stream.ReadByte();
            string name   = Path.Combine(path, stream.ReadStringShort());
            bool   isLast = (type & 2) > 0;

            if ((type & ~2) == (int)PackObjectType.File)
            {
                PackFile file = new PackFile(new FileInfo(name));
                file.ReadHeader(stream);
                file.IsLast = isLast;
                return(file);
            }
            else
            {
                PackDir dir = new PackDir(new DirectoryInfo(name));
                dir.IsLast = isLast;
                return(dir);
            }
        }