コード例 #1
0
        public FolderItem(FolderItem p, string name) : base(p)
        {
            //Dir = dir;
            this.name = name;
            if (!Dir.Exists)
            {
                Dir.Create();
            }

            /*watcher = new FileSystemWatcher(dir.FullName, ".galaxy++");
             * watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
             * watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
             * watcher.EnableRaisingEvents = true;*/
        }
コード例 #2
0
        public void Test_Create_If_Dir_Existed_Success()
        {
            //arrange
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test2");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            //act
            Dir.Create(path);

            //assert
            Assert.IsTrue(Directory.Exists(path));

            Directory.Delete(path);
        }
コード例 #3
0
        public override bool FixConflicts(params string[] reqPrefixes)
        {
            /*Dir = new DirectoryInfo(Dir.FullName);
             * foreach (DirItem child in Children)
             * {
             *  if (child is FolderItem)
             *  {
             *      FolderItem folder = (FolderItem) child;
             *      folder.Dir = new DirectoryInfo(folder.Dir.FullName);
             *  }
             *  if (child is FileItem)
             *  {
             *      FileItem folder = (FileItem)child;
             *      folder.File = new FileInfo(folder.File.FullName);
             *  }
             * }
             */
            //If this item does not exist on the hdd, remove it.
            if (!Dir.Exists)
            {
                if (Parent == null)
                {
                    Dir.Create();
                }
                else
                {
                    Parent.Children.Remove(this);
                    return(true);
                }
            }

            /*if (watcher == null)
             * {
             *  watcher = new FileSystemWatcher(Dir.FullName, "*.galaxy++");
             *  watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
             *  watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
             *  watcher.EnableRaisingEvents = true;
             * }*/

            //If this dir contains any dirs or files that is not on the list, add them
            foreach (FileSystemInfo info in Dir.GetFileSystemInfos())
            {
                if (info is FileInfo)
                {
                    FileInfo fileInfo = (FileInfo)info;

                    if (!reqPrefixes.Any(prefix => fileInfo.Name.EndsWith(prefix)))
                    {
                        continue;
                    }



                    if (!Children.Any(child => child.FullName == fileInfo.FullName))
                    {
                        if (fileInfo.Name.EndsWith(".Dialog"))
                        {
                            DialogItem item = new DialogItem(this);
                            item.Name = fileInfo.Name;
                            Children.Add(item);
                        }
                        else
                        {
                            Children.Add(new FileItem(this, fileInfo.Name));
                        }
                    }
                }
                if (info is DirectoryInfo)
                {
                    DirectoryInfo dirInfo = (DirectoryInfo)info;

                    if (!Children.Any(child => (child is FolderItem) && ((FolderItem)child).Dir.FullName.TrimEnd('\\', '/') == dirInfo.FullName.TrimEnd('\\', '/')))
                    {
                        Children.Add(new FolderItem(this, dirInfo.Name));
                    }
                }
            }



            bool changes = false;

            //Visit children
            for (int i = Children.Count - 1; i >= 0; i--)
            {
                changes |= Children[i].FixConflicts(reqPrefixes);
            }

            return(changes);
        }