Exemple #1
0
        /// <summary>
        /// Retrieves an item from the input directory.
        /// </summary>
        /// <param name="dir">Directory containing the item.</param>
        /// <param name="path">Path to the item (can include subdirectories).</param>
        public static IArchiveData GetItem(this IArchiveDirectory dir, string path)
        {
            var names = path.Split(DirectorySeperators, StringSplitOptions.RemoveEmptyEntries);

            // Return null if path split didn't get any results.
            if (names.Length == 0)
            {
                return(null);
            }

            IArchiveDirectory current = dir;

            for (int i = 0; i < names.Length; i++)
            {
                var name = names[i];

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

                switch (name)
                {
                case ".":
                    continue;

                case "..":
                    current = current.Parent as IArchiveDirectory;
                    continue;

                default:
                {
                    var item = current.FirstOrDefault(x => x.Name == name);

                    if (i == names.Length - 1)
                    {
                        return(item);
                    }

                    current = item as IArchiveDirectory;

                    break;
                }
                }
            }

            return(current);
        }