Exemple #1
0
        private void ProcessEvent(FileSystemEventArgs e)
        {
            string relativePath;

            if (e.FullPath.StartsWith(m_basePath))
            {
                relativePath = e.FullPath.SubstringAfterFirst(m_basePath);
            }
            else
            {
                return;
            }
            try
            {
                switch (e.ChangeType)
                {
                case WatcherChangeTypes.Created:
                    if (Directory.Exists(e.FullPath))
                    {
                        FSNodeDir tmp = m_rootNode.GetSubDirByPath(relativePath);
                        if (tmp == null)
                        {
                            m_rootNode.TryAddDirFromRelativePath(relativePath);
                        }
                    }
                    else
                    {
                        FSNodeFile file = m_rootNode.TryAddFileFromRelativePath(relativePath);
                        if (file != null && file is FSNodeVirtualFile)
                        {
                            if (file.Parent != null)
                            {
                                file.Parent.LocalCountAdd(1);
                            }
                            InvokeNodeFileIsVirtualChanged((FSNodeVirtualFile)file);
                        }
                    }
                    break;

                case WatcherChangeTypes.Deleted:
                    FSNode tmp2 = m_rootNode.GetSubNodeByPath(relativePath);
                    if (tmp2 == null)
                    {
                        return;
                    }
                    if (tmp2 is FSNodeDir)
                    {
                        if (!((FSNodeDir)tmp2).HasVirtual)
                        {
                            tmp2.RemoveSelf(true);
                        }
                        else
                        {
                            ((FSNodeDir)tmp2).RemoveAllLocalChilds();
                        }
                        return;
                    }
                    if (tmp2 is FSNodeVirtualFile)
                    {
                        if (tmp2.Parent != null)
                        {
                            tmp2.Parent.LocalCountAdd(-1);
                        }
                        InvokeNodeFileIsVirtualChanged((FSNodeVirtualFile)tmp2);
                        return;
                    }
                    tmp2.RemoveSelf(true);
                    break;

                case WatcherChangeTypes.Renamed:
                    relativePath = ((RenamedEventArgs)e).OldFullPath.SubstringAfterFirst(m_basePath);
                    FSNode file2 = m_rootNode.GetSubNodeByPath(relativePath);
                    file2.Name = e.Name.SubstringAfterLast('\\');
                    break;
                }
            }
            catch (ObjectDisposedException)
            {
            }
        }