예제 #1
0
 public override void AddChild(WPath childPath)
 {
     //do nothing
 }
 public override void AddChild(WPath childPath)
 {
     childPath.ParentDirectory = this;
     Children.Add(childPath);
 }
        //should be moved to pathwrapper
        private WPath ParentDirInfo(WPath wPath)
        {
            var parentDirInfo = wPath.FileSystemItem;
            var dirName = parentDirInfo.FullName;
            var projectName = WFiles[0].Name;

            //add a 1 char offset unless we're looking in the project root
            var parentProjectDirectory = (WDirectory) WFiles[0];

            //if parent project dir is not the project root
            if (dirName.Split('\\').Last() != projectName)
            {
                var splitPath =
                    dirName.Substring(dirName.LastIndexOf(projectName)
                                      + projectName.Count())
                        .Split(new[] {"\\"}, StringSplitOptions
                            .RemoveEmptyEntries).ToList();
                if (parentDirInfo.Extension != "") //is file
                {
                    splitPath.RemoveAt(splitPath.Count - 1);
                }
                if (splitPath.Count == 1 && splitPath[0] == projectName)
                    return parentProjectDirectory;
                foreach (var dir in splitPath)
                {
                    parentProjectDirectory = parentProjectDirectory[dir];
                }
            }
            return parentProjectDirectory;
        }
예제 #4
0
 public abstract void AddChild(WPath childPath);
        public void RemovePath(WPath wPath, bool delete = true)
        {
            if (wPath.Children != null && wPath.Children.Count > 0)
            {
                // ReSharper disable once ForCanBeConvertedToForeach
                for (var index = 0; index < wPath.Children.Count; index++)
                {
                    RemovePath(wPath.Children[index], delete);
                }
            }

            var name = wPath.FileSystemItem.FullName;
            var splitPath = name.Substring(name.IndexOf(Name)).Split('\\').ToList();
            splitPath.RemoveAt(splitPath.Count - 1);
            var element = Configuration.Root.Element(PathsTag);
            var itemPath = wPath.FileSystemItem.FullName;
                //save file WPath before the item is removed from configuration
            //get parents
            foreach (var directory in splitPath)
            {
                element = (from dirElement in element.Elements(DirectoryTag)
                    where
                        string.Equals(dirElement.Attribute(NameAttribute).Value, directory,
                            StringComparison.CurrentCultureIgnoreCase)
                    select dirElement).First();
            }

            var tag = FileTag;
            if (wPath is WDirectory)
                tag = DirectoryTag;

            //remove from configuration and config.xml
            try
            {
                (from childElement in element.Elements(tag)
                    where
                        string.Equals(childElement.Attribute(NameAttribute).Value, wPath.FileSystemItem.Name,
                            StringComparison.CurrentCultureIgnoreCase)
                    select childElement).First().Remove();
                SaveConfiguration();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            //remove from WFiles
            var parentProjectDirectory = ParentDirInfo(wPath);
            parentProjectDirectory.Children.Remove(wPath);

            try
            {
                //delete WPath if delete is true and WPath exists
                if (!delete) return;
                if (wPath is WDirectory && Directory.Exists(wPath.FileSystemItem.FullName))
                    Directory.Delete(itemPath, true);
                else if (File.Exists(wPath.FileSystemItem.FullName))
                {
                    File.Delete(itemPath);
                }
            }
            catch (IOException)
            {
                throw new IOException("Item(s) could not be deleted from your filesystem. Try removing them manually.");
            }
        }