Example #1
0
        public D2pDirectory TryGetDirectory(string directory)
        {
            string[] directoriesName = directory.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);

            if (directoriesName.Length == 0)
            {
                return(null);
            }

            D2pDirectory current = m_rootDirectories.SingleOrDefault(entry => entry.Name == directoriesName[0]);

            if (current == null)
            {
                return(null);
            }

            foreach (string dir in directoriesName.Skip(1))
            {
                if (!current.HasDirectory(dir))
                {
                    return(null);
                }

                current = current.TryGetDirectory(dir);
            }

            return(current);
        }
Example #2
0
        public D2pDirectory[] GetDirectoriesTree(string directory)
        {
            var result = new List <D2pDirectory>();

            string[] directoriesName = directory.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);

            if (directoriesName.Length == 0)
            {
                return(new D2pDirectory[0]);
            }

            D2pDirectory current = m_rootDirectories.SingleOrDefault(entry => entry.Name == directoriesName[0]);

            if (current == null)
            {
                return(new D2pDirectory[0]);
            }

            result.Add(current);

            foreach (string dir in directoriesName.Skip(1))
            {
                if (!current.HasDirectory(dir))
                {
                    return(result.ToArray());
                }

                current = current.TryGetDirectory(dir);
                result.Add(current);
            }

            return(result.ToArray());
        }
Example #3
0
        public bool HasDirectory(string directory)
        {
            string[] directoriesName = directory.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);

            if (directoriesName.Length == 0)
            {
                return(false);
            }

            D2pDirectory current = null;

            m_rootDirectories.TryGetValue(directoriesName[0], out current);

            if (current == null)
            {
                return(false);
            }

            foreach (string dir in directoriesName.Skip(1))
            {
                if (!current.HasDirectory(dir))
                {
                    return(false);
                }

                current = current.TryGetDirectory(dir);
            }

            return(true);
        }
Example #4
0
        private void InternalAddDirectories(D2pEntry entry)
        {
            string[] directories = entry.GetDirectoriesName();

            if (directories.Length == 0)
            {
                return;
            }

            D2pDirectory current = null;

            if (!HasDirectory(directories[0]))
            {
                current = new D2pDirectory(directories[0]);

                m_rootDirectories.Add(current);
            }
            else
            {
                current = TryGetDirectory(directories[0]);
            }

            current.Entries.Add(entry);

            foreach (string directory in directories.Skip(1))
            {
                if (!current.HasDirectory(directory))
                {
                    var dir = new D2pDirectory(directory)
                    {
                        Parent = current
                    };
                    current.Directories.Add(dir);

                    current = dir;
                }
                else
                {
                    current = current.TryGetDirectory(directory);
                }

                current.Entries.Add(entry);
            }

            entry.Directory = current;
        }
Example #5
0
        private void InternalAddDirectories(D2pEntry entry)
        {
            string[] directories = entry.GetDirectoriesName();

            if (directories.Length == 0)
            {
                return;
            }

            D2pDirectory current = null;

            if (!m_rootDirectories.ContainsKey(directories[0]))
            {
                m_rootDirectories.Add(directories[0], current = new D2pDirectory(directories[0]));
            }
            else
            {
                current = m_rootDirectories[directories[0]];
            }

            current.Entries.Add(entry);

            foreach (string directory in directories.Skip(1))
            {
                var next = current.TryGetDirectory(directory);
                if (next == null)
                {
                    var dir = new D2pDirectory(directory)
                    {
                        Parent = current
                    };
                    current.Directories.Add(directory, dir);

                    current = dir;
                }
                else
                {
                    current = current.TryGetDirectory(directory);
                }

                current.Entries.Add(entry);
            }

            entry.Directory = current;
        }
Example #6
0
        private void InternalRemoveDirectories(D2pEntry entry)
        {
            D2pDirectory current = entry.Directory;

            while (current != null)
            {
                current.Entries.Remove(entry);

                if (current.Parent != null && current.Entries.Count == 0)
                {
                    current.Parent.Directories.Remove(current);
                }
                else if (current.IsRoot && current.Entries.Count == 0)
                {
                    m_rootDirectories.Remove(current);
                }

                current = current.Parent;
            }
        }
Example #7
0
        public void ExtractDirectory(string directoryName, string destination)
        {
            if (!HasDirectory(directoryName))
            {
                throw new InvalidOperationException(string.Format("Directory {0} does not exist", directoryName));
            }

            D2pDirectory directory = TryGetDirectory(directoryName);

            if (!Directory.Exists(Path.GetDirectoryName(Path.Combine(destination, directory.FullName))))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(destination, directory.FullName)));
            }

            foreach (D2pEntry entry in directory.Entries)
            {
                ExtractFile(entry.FullFileName, Path.Combine(destination, entry.FullFileName));
            }

            foreach (D2pDirectory pDirectory in directory.Directories)
            {
                ExtractDirectory(pDirectory.FullName, destination);
            }
        }
Example #8
0
        private void InternalAddDirectories(D2pEntry entry)
        {
            string[] directories = entry.GetDirectoriesName();

            if (directories.Length == 0)
                return;

            D2pDirectory current = null;
            if (!m_rootDirectories.ContainsKey(directories[0]))
            {
                m_rootDirectories.Add(directories[0], current = new D2pDirectory(directories[0]));
            }
            else
            {
                current = m_rootDirectories[directories[0]];
            }

            current.Entries.Add(entry);

            foreach (string directory in directories.Skip(1))
            {
                var next = current.TryGetDirectory(directory);
                if (next == null)
                {
                    var dir = new D2pDirectory(directory)
                                  {
                                      Parent = current
                                  };
                    current.Directories.Add(directory, dir);

                    current = dir;
                }
                else
                {
                    current = current.TryGetDirectory(directory);
                }

                current.Entries.Add(entry);
            }

            entry.Directory = current;
        }
Example #9
0
        private void InternalAddDirectories(D2pEntry entry)
        {
            var directories = entry.GetDirectoriesName();

            if (directories.Length == 0)
                return;

            D2pDirectory current = null;
            if (!HasDirectory(directories[0]))
            {
                current = new D2pDirectory(directories[0]);

                m_rootDirectories.Add(current);
            }
            else
            {
                current = TryGetDirectory(directories[0]);
            }

            current.Entries.Add(entry);

            foreach (var directory in directories.Skip(1))
            {
                if (!current.HasDirectory(directory))
                {
                    var dir = new D2pDirectory(directory)
                    {
                        Parent = current
                    };
                    current.Directories.Add(dir);

                    current = dir;
                }
                else
                {
                    current = current.TryGetDirectory(directory);
                }

                current.Entries.Add(entry);
            }

            entry.Directory = current;
        }