Exemple #1
0
        /// <summary>
        /// Constructs a new FileTree from the given path and SGAs.
        /// Set an EntryPoint name to only add files from SGAs which belong to an EntryPoint with the specified name.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="sgas"></param>
        /// <param name="epName"></param>
        public FileTree(string path, IEnumerable <SGAFile> sgas, string epName = null)
        {
            if (!path.EndsWith('\\'))
            {
                path += '\\';
            }
            m_basePath = path;
            m_rootNode = new FSNodeDir(path, this);

            foreach (SGAFile sga in sgas)
            {
                foreach (SGAEntryPoint ep in sga)
                {
                    if (epName != null && string.Compare(ep.Name, epName, true) != 0)
                    {
                        continue;
                    }

                    foreach (SGAStoredDirectory sgasd in ep.StoredDirectories.Values)
                    {
                        string    dirpath = sgasd.GetPath();
                        FSNodeDir dirnode = m_rootNode.TryAddDirFromRelativePath(dirpath);
                        if (sgasd.StoredFiles.Values.Count > 0)
                        {
                            dirnode.HasVirtual = true;
                        }
                        foreach (SGAStoredFile sgasf in sgasd.StoredFiles.Values)
                        {
                            FSNodeFile file = dirnode.GetFile(sgasf.Name);
                            if (file == null)
                            {
                                new FSNodeVirtualFile(sgasf.Name, sgasf, this)
                                {
                                    Parent = dirnode
                                };
                            }
                            else if (!(file is FSNodeVirtualFile))
                            {
                                dirnode.RemoveChild(file);
                                new FSNodeVirtualFile(sgasf.Name, sgasf, this)
                                {
                                    Parent = dirnode
                                };
                            }
                        }
                    }
                }
            }

            SetupWatcher(path);
            SetupConsumerThread();
        }
Exemple #2
0
        /// <summary>
        /// Constructs a new FileTree from the given path and SGAs.
        /// Set an EntryPoint name to only add files from SGAs which belong to an EntryPoint with the specified name.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="sgas"></param>
        /// <param name="epName"></param>
        public FileTree(string path, IEnumerable<SGAFile> sgas, string epName = null)
        {
            if (!path.EndsWith('\\'))
                path += '\\';
            m_basePath = path;
            m_rootNode = new FSNodeDir(path, this);

            foreach (SGAFile sga in sgas)
            {
                foreach (SGAEntryPoint ep in sga)
                {
                    if (epName != null && string.Compare(ep.Name, epName, true) != 0)
                        continue;

                    foreach (SGAStoredDirectory sgasd in ep.StoredDirectories.Values)
                    {
                        string dirpath = sgasd.GetPath();
                        FSNodeDir dirnode = m_rootNode.TryAddDirFromRelativePath(dirpath);
                        if (sgasd.StoredFiles.Values.Count > 0)
                            dirnode.HasVirtual = true;
                        foreach (SGAStoredFile sgasf in sgasd.StoredFiles.Values)
                        {
                            FSNodeFile file = dirnode.GetFile(sgasf.Name);
                            if (file == null)
                            {
                                new FSNodeVirtualFile(sgasf.Name, sgasf, this) {Parent = dirnode};
                            }
                            else if (!(file is FSNodeVirtualFile))
                            {
                                dirnode.RemoveChild(file);
                                new FSNodeVirtualFile(sgasf.Name, sgasf, this) {Parent = dirnode};
                            }
                        }
                    }
                }
            }

            SetupWatcher(path);
            SetupConsumerThread();
        }
Exemple #3
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)
            {
            }
        }