private void Visit(FSNodeDir startDir) { if (m_stopSearch.WaitOne(0)) { return; } foreach (FSNodeFile file in startDir.Files) { if (m_stopSearch.WaitOne(0)) { return; } if (file.Name.EndsWith(".rbf")) { UniFile uni = file.GetUniFile(); RelicBinaryFile rbf; try { rbf = new RelicBinaryFile(uni) { KeyProvider = ModManager.RBFKeyProvider, UseKeyProvider = RBFSettings.UseKeyProviderForLoading }; rbf.ReadData(); } catch (Exception ex) { if (OnFileOpenFailed != null) { OnFileOpenFailed(ex); } if (m_advanceProgressCallback != null) { m_advanceProgressCallback.Invoke(); } continue; } m_foreachRBF.Invoke(rbf.AttributeStructure, file.PathInTree); } if (m_advanceProgressCallback != null) { m_advanceProgressCallback.Invoke(); } } foreach (FSNodeDir dir in startDir.Directories) { if (m_stopSearch.WaitOne(0)) { return; } Visit(dir); } }
private static string[] GetDataEntries(string relativePath) { if (FileManager.DataTree != null) { FSNodeDir dir = FileManager.DataTree.RootNode.GetSubDirByPath(relativePath); if (dir != null) { string[] files = dir.GetRelativePaths(removeFromFileEnding: "."); return(files); } } return(null); }
private static string[] GetAttribEntries(string relativePath) { if (FileManager.AttribTree != null) { FSNodeDir dir = FileManager.AttribTree.RootNode.GetSubDirByPath("simulation\\attrib\\" + relativePath); if (dir != null) { string[] files = dir.GetRelativePaths("simulation\\attrib\\", "."); return(files); } } return(null); }
/// <summary> /// Creates a new RBFCrawler that call the specified delegate for every RBF and starts at a given directory. /// </summary> /// <param name="foreachRBF">This delegate is called for every RBF.</param> /// <param name="startNode">The crawler will begin searching for RBF files from this node.</param> /// <param name="advanceProgressCallback">Called everytime a file has been processed.</param> /// <exception cref="ArgumentNullException"><paramref name="foreachRBF" /> is <c>null</c>.</exception> public RBFCrawler(CrawlerCallback foreachRBF, FSNodeDir startNode, Action advanceProgressCallback) { if (foreachRBF == null) { throw new ArgumentNullException("foreachRBF"); } if (startNode == null) { throw new ArgumentNullException("startNode"); } m_foreachRBF = foreachRBF; m_startNode = startNode; m_advanceProgressCallback = advanceProgressCallback; UseDedicatedThread = true; }
private static string[] GetAttribFilesAbs(string absolutePath, string removeFromFront = "simulation\\attrib\\", string[] extensions = null, string[] excludeEndings = null, bool recursive = true) { if (FileManager.AttribTree != null) { FSNodeDir dir = FileManager.AttribTree.RootNode.GetSubDirByPath(absolutePath); if (dir != null) { string[] files = recursive ? dir.GetRelativeFilePathsWithSubs(removeFromFront, ".", extensions, excludeEndings). ToArray() : dir.GetRelativeFilePaths(removeFromFront, ".", extensions, excludeEndings); return(files); } } return(null); }
private void BtnSearchClick(object sender, EventArgs e) { if (!m_chkbxSearchForKey.Checked && !m_chkbxSearchForValue.Checked) { UIHelper.ShowError("No search criteria specified!"); return; } if (FileManager.AttribTree == null) { UIHelper.ShowError("The attrib-tree could not be found! Ensure that there is a mod loaded"); return; } FSNodeDir startingNode = m_tbxInitialNode.Text == string.Empty ? FileManager.AttribTree.RootNode : FileManager.AttribTree.RootNode.GetSubNodeByPath(m_tbxInitialNode.Text) as FSNodeDir; if (startingNode == null) { UIHelper.ShowError( "The specified starting node could not be found or is not a directory! " + "Ensure that it exists in the attrib-tree!"); return; } m_lbxSearchResults.Items.Clear(); m_progBarSearch.Value = 1; m_progBarSearch.Step = 1; m_progBarSearch.Minimum = 1; m_progBarSearch.Maximum = startingNode.GetTotalFileCount(); m_sSearchKey = m_tbxSearchKey.Text; m_sSearchValue = m_tbxSearchValue.Text; m_bSearchForKey = m_chkbxSearchForKey.Checked; m_bSearchForValue = m_chkbxSearchForValue.Checked; m_bFullText = m_chkbxFullText.Checked; m_btnSearch.Enabled = false; m_results = new Dictionary <string, SearchResult>(); m_crawler = new RBFCrawler(Search, startingNode, AdvanceProgress); m_crawler.OnFinished += CrawlerOnFinished; m_crawler.Start(); }
private static string[] GetDataFilesAbs(string absolutePath, string removeFromFront = "", string[] extensions = null, string[] excludeEndings = null, bool recursive = true) { if (FileManager.DataTree != null) { FSNodeDir dir = FileManager.DataTree.RootNode.GetSubDirByPath(absolutePath); if (dir != null) { string[] files; if (recursive) { files = dir.GetRelativeFilePathsWithSubs(removeFromFront, ".", extensions, excludeEndings).ToArray(); } else { files = dir.GetRelativeFilePaths(removeFromFront, ".", extensions, excludeEndings); } return(files); } } return(null); }
private static void PasteNode(FSNode node, FSNodeDir into, string newName) { if (node == null || into == null) { return; } try { string dirPath = into.Path + '\\'; if (File.Exists(dirPath + newName)) { string name = newName.SubstringBeforeLast('.'); string ext = newName.SubstringAfterLast('.', true); int numOfThatKind = into.Directories.Count(d => d.Name.StartsWith(name + "_copy")); numOfThatKind += into.Files.Count(d => d.Name.StartsWith(name + "_copy")); if (numOfThatKind > 0) { PasteNode(node, into, name + "_copy_" + (numOfThatKind + 1) + ext); } else { PasteNode(node, into, name + "_copy" + ext); } return; } if (node is FSNodeVirtualFile) { var virtualFile = node as FSNodeVirtualFile; if (virtualFile.HasLocal) { if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } File.Copy(virtualFile.Path, dirPath + newName); } else { virtualFile.Extract(dirPath + newName); } } else if (node is FSNodeFile) { var file = node as FSNodeFile; if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } File.Copy(file.Path, dirPath + newName); } else if (node is FSNodeDir) { var dir = node as FSNodeDir; if (!Directory.Exists(dirPath + newName)) { Directory.CreateDirectory(dirPath + newName); } into = into.GetDirectory(newName); foreach (var d in dir.Directories) { PasteNode(d, into, d.Name); } foreach (var f in dir.Files) { PasteNode(f, into, f.Name); } } } catch (Exception ex) { UIHelper.ShowError("Failed to paste: " + ex.Message); } }
/// <summary> /// Creates a new RBFCrawler that call the specified delegate for every RBF and starts at a given directory. /// </summary> /// <param name="foreachRBF">This delegate is called for every RBF.</param> /// <param name="startNode">The crawler will begin searching for RBF files from this node.</param> public RBFCrawler(CrawlerCallback foreachRBF, FSNodeDir startNode) : this(foreachRBF, startNode, null) { }