Ejemplo n.º 1
0
        internal void RemoveAllLocalChilds()
        {
            for (int i = 0; i < m_files.Count;)
            {
                FSNodeFile fsnf = m_files.Values[i];
                if (!(fsnf is FSNodeVirtualFile))
                {
                    fsnf.RemoveSelf();
                }
                else
                {
                    i++;
                    if (m_tree != null)
                    {
                        m_tree.InvokeNodeFileIsVirtualChanged((FSNodeVirtualFile)fsnf);
                    }
                }
            }

            for (int i = 0; i < m_subdirs.Count;)
            {
                FSNodeDir fsnd = m_subdirs.Values[i];
                if (!fsnd.m_hasVirtual)
                {
                    fsnd.RemoveSelf();
                }
                else
                {
                    fsnd.RemoveAllLocalChilds();
                    i++;
                }
            }
            LocalCountZero();
        }
Ejemplo n.º 2
0
        static private void TryToGetKeyProvider()
        {
            const string flbPath = "simulation\\attrib\\fieldnames.flb";

            if (!ToolSettings.IsInRetributionMode)
            {
                LoggingManager.SendMessage("ModManager - not in Retribuion-mode, no need to load KeyProvider");
                return;
            }
            LoggingManager.SendMessage("ModManager - Trying to load the KeyProvider (FLB-file)");
            try
            {
                FSNodeFile file = FileManager.AttribTree.RootNode.GetFileByPath(flbPath);
                if (file == null)
                {
                    UIHelper.ShowWarning("Unable to find the FLB file! You probably won't be able to open RBFs.");
                    LoggingManager.SendWarning("ModManager - Failed to load FLB-file from path " + flbPath);
                    return;
                }
                UniFile uni     = file.GetUniFile();
                var     flbFile = new FieldNameFile(uni);
                flbFile.ReadData();
                RBFKeyProvider = flbFile;
            }
            catch (Exception ex)
            {
                UIHelper.ShowError("Unable to open or read the FLB file! You probably won't be able to open RBFs.");
                LoggingManager.SendError("ModManager - Error while loading FLB-file");
                LoggingManager.HandleException(ex);
                return;
            }
            LoggingManager.SendMessage("ModManager - Successfully loaded KeyProvider from " + flbPath);
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        public void MergeWith(FSNodeDir node)
        {
            for (int i = 0; i < node.FilesList.Count; i++)
            {
                FSNodeFile fsnf = node.FilesList.Values[i];
                if (!ContainsFile(fsnf.Name))
                {
                    if (!HasLocalFile(fsnf.Name))
                    {
                        continue;
                    }
                    if (fsnf is FSNodeVirtualFile)
                    {
                        new FSNodeFile(fsnf.Name, m_tree, this);
                        if (m_tree != null)
                        {
                            m_tree.InvokeNodeFileIsVirtualChanged((FSNodeVirtualFile)node.m_files[fsnf.Name]);
                        }
                        node.LocalCountAdd(-1);
                    }
                    else
                    {
                        fsnf.Parent = this;
                        node.LocalCountAdd(-1);
                        i--;
                    }
                }
                else if (m_files[fsnf.Name] is FSNodeVirtualFile && m_files[fsnf.Name].HasLocal)
                {
                    if (m_tree != null)
                    {
                        m_tree.InvokeNodeFileIsVirtualChanged((FSNodeVirtualFile)m_files[fsnf.Name]);
                    }
                    LocalCountAdd(1);
                }
            }

            for (int i = 0; i < node.SubDirsList.Count; i++)
            {
                FSNodeDir fsnd = node.SubDirsList.Values[i];
                if (!ContainsDirectory(fsnd.Name))
                {
                    fsnd.Parent = this;
                    i--;
                }
                else
                {
                    m_subdirs[fsnd.m_name].MergeWith(fsnd);
                }
            }
        }
Ejemplo n.º 5
0
        public FSNodeFile TryAddFileFromRelativePath(string path)
        {
            if (!File.Exists(m_tree.BasePath + path))
            {
                //throw new CopeException("The file you're trying to add does not exist! Base path: {0} ; relative path: {1}", _tree.BasePath, path);
                return(null);
            }
            string dirPath = path.SubstringBeforeLast('\\', true);

            FSNodeFile newFile;

            if (dirPath.Contains('\\'))
            {
                FSNodeDir direc    = TryAddDirFromRelativePath(dirPath);
                string    filename = path.SubstringAfterLast('\\');
                newFile = !direc.ContainsFile(filename) ? new FSNodeFile(path.SubstringAfterLast('\\'), m_tree, direc) : direc.m_files[filename];
                return(newFile);
            }
            newFile = new FSNodeFile(path.SubstringAfterLast('\\'), m_tree, this);
            return(newFile);
        }
Ejemplo n.º 6
0
 public bool ContainsFile(FSNodeFile file)
 {
     return(m_files.ContainsValue(file));
 }
Ejemplo n.º 7
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)
            {
            }
        }
Ejemplo n.º 8
0
 public bool ContainsFile(FSNodeFile file)
 {
     return m_files.ContainsValue(file);
 }
Ejemplo n.º 9
0
        public FSNodeFile TryAddFileFromRelativePath(string path)
        {
            if (!File.Exists(m_tree.BasePath + path))
            {
                //throw new CopeException("The file you're trying to add does not exist! Base path: {0} ; relative path: {1}", _tree.BasePath, path);
                return null;
            }
            string dirPath = path.SubstringBeforeLast('\\', true);

            FSNodeFile newFile;
            if (dirPath.Contains('\\'))
            {
                FSNodeDir direc = TryAddDirFromRelativePath(dirPath);
                string filename = path.SubstringAfterLast('\\');
                newFile = !direc.ContainsFile(filename) ? new FSNodeFile(path.SubstringAfterLast('\\'), m_tree, direc) : direc.m_files[filename];
                return newFile;
            }
            newFile = new FSNodeFile(path.SubstringAfterLast('\\'), m_tree, this);
            return newFile;
        }
Ejemplo n.º 10
0
        public override FSNode GClone()
        {
            var copy = new FSNodeFile(m_name, m_tree);

            return(copy);
        }
Ejemplo n.º 11
0
 public override FSNode GClone()
 {
     var copy = new FSNodeFile(m_name, m_tree);
     return copy;
 }