/// <summary> /// Gets the full path of this FSO in the Riot Archive File. /// Includes archive optionally /// </summary> public string GetRAFPath(bool includeArchive) { Stack <string> resultStack = new Stack <string>(); RAFInMemoryFileSystemObject currentNode = this; while (currentNode != null && ((currentNode.GetFSOType() != RAFFSOType.ARCHIVE) || includeArchive)) { resultStack.Push(currentNode.Name); currentNode = (RAFInMemoryFileSystemObject)currentNode.Parent; } if (resultStack.Count == 0) { return(""); } //flatten the stack StringBuilder resultSb = new StringBuilder(); resultSb.Append(resultStack.Pop()); while (resultStack.Count != 0) { resultSb.Append("/" + resultStack.Pop()); } return(resultSb.ToString()); }
private void findNextButton_Click(object sender, EventArgs e) { List<RAFInMemoryFileSystemObject> result = null; List<RAFInMemoryFileSystemObject> pastNodes = new List<RAFInMemoryFileSystemObject>(); while (result == null || result.Count == 0) { pastNodes.Add(currentNode); result = Search(stringSearch.Text, currentNode, ignore); if (result.Count == 0) { if (currentNode.Parent == null) //End of raf archive { currentNode = allNodes[(1 + Array.IndexOf(allNodes, currentNode)) % allNodes.Length]; //Select next node if (pastNodes.Contains(currentNode)) //Done { SearchOutOfOptions(); ignore.Clear(); return; } } else { currentNode = (RAFInMemoryFileSystemObject)currentNode.Parent; } } } //Find the first result and select it on the tree view (its the result), then ignore it in the future currentNode.TreeView.SelectedNode = result[0]; currentNode.TreeView.Focus(); ignore.Add(result[0]); }
void DumpRafArchiveByFSO(RAFInMemoryFileSystemObject fso, string dumpDirectory) { Title("Dump: " + fso.GetRAFPath()); if (fso.GetFSOType() == RAFFSOType.ARCHIVE || fso.GetFSOType() == RAFFSOType.DIRECTORY) { Util.PrepareDirectory(dumpDirectory + "/" + fso.GetRAFPath()); } else { //Gets the path of our containing folder in the raf archive. //This is akin to new FileInfo(path).DirectoryName if we had a localPath string containingFolderPath = fso.GetRAFPath().Replace("\\", "/").Reverse(); containingFolderPath = containingFolderPath.Substring(Math.Max(containingFolderPath.IndexOf("/"), 0)); containingFolderPath = containingFolderPath.Reverse(); Util.PrepareDirectory(dumpDirectory + "/" + fso.GetRAFPath()); Console.WriteLine("Dump to: " + dumpDirectory + "/" + fso.GetRAFPath()); File.WriteAllBytes(dumpDirectory + "/" + fso.GetRAFPath(), rafManager.ResolveRAFPathToEntry(fso.GetTopmostParent().Text + "/" + fso.GetRAFPath()).GetContent() ); } for (int i = 0; i < fso.Nodes.Count; i++) { DumpRafArchiveByFSO((RAFInMemoryFileSystemObject)fso.Nodes[i], dumpDirectory); } }
private void findNextButton_Click(object sender, EventArgs e) { List <RAFInMemoryFileSystemObject> result = null; List <RAFInMemoryFileSystemObject> pastNodes = new List <RAFInMemoryFileSystemObject>(); while (result == null || result.Count == 0) { pastNodes.Add(currentNode); result = Search(stringSearch.Text, currentNode, ignore); if (result.Count == 0) { if (currentNode.Parent == null) //End of raf archive { currentNode = allNodes[(1 + Array.IndexOf(allNodes, currentNode)) % allNodes.Length]; //Select next node if (pastNodes.Contains(currentNode)) //Done { SearchOutOfOptions(); ignore.Clear(); return; } } else { currentNode = (RAFInMemoryFileSystemObject)currentNode.Parent; } } } //Find the first result and select it on the tree view (its the result), then ignore it in the future currentNode.TreeView.SelectedNode = result[0]; currentNode.TreeView.Focus(); ignore.Add(result[0]); }
/// <summary> /// Allows the user to pick a RAF file from the rafContentView control... /// /// TODO: 5 second timer for stopping /// TODO: This needs to be made better. it's pretty annoying to work with on the user-viewpoint /// </summary> /// <returns></returns> private string PickRafPath(bool includeFiles) { RAFInMemoryFileSystemObject[] nodes = new RAFInMemoryFileSystemObject[this.rafContentView.Nodes.Count]; for (int i = 0; i < nodes.Length; i++) nodes[i] = (RAFInMemoryFileSystemObject)this.rafContentView.Nodes[i].Clone(); RAFPathSelector selectorDialog = new RAFPathSelector(nodes, includeFiles); selectorDialog.ShowDialog(); return selectorDialog.SelectedNodePath; }
public RAFSearchBox(RAFInMemoryFileSystemObject[] nodes) { InitializeComponent(); allNodes = nodes; currentNode = nodes[0]; this.KeyUp += new KeyEventHandler(RAFSearchBox_KeyUp); this.stringSearch.KeyUp += new KeyEventHandler(RAFSearchBox_KeyUp); }
/// <summary> /// Gets the topmost parent of this RAF In Memory FSO /// Also known as, the archive itself /// </summary> /// <returns></returns> public RAFInMemoryFileSystemObject GetTopmostParent() { RAFInMemoryFileSystemObject currentNode = this; while (currentNode.Parent != null) { currentNode = (RAFInMemoryFileSystemObject)currentNode.Parent; } return(currentNode); }
/// <summary> /// Adds a child FSO to this node /// </summary> public RAFInMemoryFileSystemObject AddChildFSO(RAFFSOType type, string name) { RAFInMemoryFileSystemObject result = null; this.Nodes.Add( result = new RAFInMemoryFileSystemObject( this, type, name ) ); return result; }
/// <summary> /// Adds a child FSO to this node /// </summary> public RAFInMemoryFileSystemObject AddChildFSO(RAFFSOType type, string name) { RAFInMemoryFileSystemObject result = null; this.Nodes.Add( result = new RAFInMemoryFileSystemObject( this, type, name ) ); return(result); }
public RAFSearchBox(RAFInMemoryFileSystemObject node) { InitializeComponent(); Text = Text + " (searching within '" + node.Text + "')"; allNodes = new RAFInMemoryFileSystemObject[] { node }; currentNode = node; this.KeyUp += new KeyEventHandler(RAFSearchBox_KeyUp); this.stringSearch.KeyUp += new KeyEventHandler(RAFSearchBox_KeyUp); }
/// <summary> /// Allows the user to pick a RAF file from the rafContentView control... /// /// TODO: 5 second timer for stopping /// TODO: This needs to be made better. it's pretty annoying to work with on the user-viewpoint /// </summary> /// <returns></returns> private string PickRafPath(bool includeFiles) { RAFInMemoryFileSystemObject[] nodes = new RAFInMemoryFileSystemObject[this.rafContentView.Nodes.Count]; for (int i = 0; i < nodes.Length; i++) { nodes[i] = (RAFInMemoryFileSystemObject)this.rafContentView.Nodes[i].Clone(); } RAFPathSelector selectorDialog = new RAFPathSelector(nodes, includeFiles); selectorDialog.ShowDialog(); return(selectorDialog.SelectedNodePath); }
private List<RAFInMemoryFileSystemObject> Search(string phrase, RAFInMemoryFileSystemObject node, List<RAFInMemoryFileSystemObject> ignore) { phrase = phrase.ToLower(); List<RAFInMemoryFileSystemObject> results = new List<RAFInMemoryFileSystemObject>(); if (node.Text.ToLower().Contains(phrase)) if (!ignore.Contains(node)) results.Add(node); for(int i = 0; i < node.Nodes.Count; i++) results.AddRange(Search(phrase, (RAFInMemoryFileSystemObject)node.Nodes[i], ignore)); return results; }
/// <summary> /// Creates a new deep copy of this RAF In Memory FSO /// /// ...Only Nodes are deep copied /// </summary> /// <returns></returns> public override object Clone() { RAFInMemoryFileSystemObject result = new RAFInMemoryFileSystemObject(null, this.fsoType, this.Name); for (int i = 0; i < this.Nodes.Count; i++) { result.Nodes.Add((RAFInMemoryFileSystemObject)this.Nodes[i].Clone()); } if (this.IsExpanded) { result.Expand(); } return(result); }
private void findPreviousButton_Click(object sender, EventArgs e) { if (ignore.Count > 1) { ignore.RemoveAt(ignore.Count - 1); ignore.RemoveAt(ignore.Count - 1); findNextButton_Click(sender, e); } else { ignore.Clear(); currentNode = allNodes[(-1 + allNodes.Length + Array.IndexOf(allNodes, currentNode)) % allNodes.Length]; //Select previous node findNextButton_Click(sender, e); } }
/// <summary> /// When a RafContentView node is double clicked, extract and view its content /// </summary> void rafContentView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { RAFInMemoryFileSystemObject node = (RAFInMemoryFileSystemObject)e.Node; string nodeInternalPath = node.GetRAFPath(); if (node.GetFSOType() == RAFFSOType.FILE) { //We have double clicked a file... find out what file it was List <RAFFileListEntry> entries = rafManager.Archives.Where( (Func <RAFArchive, bool>) delegate(RAFArchive arc) { return(arc.GetID().ToLower() == node.GetTopmostParent().Name); } ).First().GetDirectoryFile().GetFileList().GetFileEntries(); //Find the RAF File entry that corresponds to the clicked file... RAFFileListEntry entry = entries.Where( (Func <RAFFileListEntry, bool>) delegate(RAFFileListEntry theEntry) { return(theEntry.FileName == nodeInternalPath); } ).First(); //Now select a viewer to use for the file. //Unnecessary for the most part, can be enabled in the future: if (entry.FileSize < 10000 || //If > 200, ask, then continue MessageBox.Show("This file is quite large ({0} bytes). Sure you want to read it?".F(entry.FileSize), "", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) if (entry.FileName.ToLower().EndsWith("dds")) { ShowDirectDrawSurface(entry.GetContent()); } else if (entry.FileName.ToLower().EndsWith("inibin") || entry.FileName.ToLower().EndsWith("troybin")) { ShowInibinFile(this.baseTitle + " - inibin/troybin view - " + nodeInternalPath, entry.GetContent()); } else if (entry.FileName.EndsWithAny(new string[] { ".cfg", ".ini", ".txt", ".log", ".list", ".xml" })) { ShowEditableTextFile(rafManager.ResolveRAFPathToEntry(node.GetTopmostParent().Text + "/" + node.GetRAFPath())); } else if (entry.FileName.EndsWithAny(new string[] { ".bmp", ".jpg" })) { new BitmapViewer("Bitmap Viewer", entry.GetContent()).Show(); } else //If all else fails, just use the binary viewer { ShowBinaryFile(this.baseTitle + " - " + nodeInternalPath, entry.GetContent()); } } }
/// <summary> /// TreeNode that can be displayed in a treeview. Represents a RAF Internal File System Object. /// </summary> /// <param name="parent"></param> /// <param name="fsoType"></param> /// <param name="name"></param> public RAFInMemoryFileSystemObject(RAFInMemoryFileSystemObject parent, RAFFSOType fsoType, string name) :base( //lol. Is this a sign that I haven't played with C# enough? /*(fsoType==RAFFSOType.DIRECTORY? "[DIR] ": (fsoType==RAFFSOType.ARCHIVE? "[ARC] ": "[FIL] " ) ) + */name ) { //if(this.parent != null) // this.parent.Nodes.Add(this); this.fsoType = fsoType; this.Name = name; this.Text = name; }
/// <summary> /// TreeNode that can be displayed in a treeview. Represents a RAF Internal File System Object. /// </summary> /// <param name="parent"></param> /// <param name="fsoType"></param> /// <param name="name"></param> public RAFInMemoryFileSystemObject(RAFInMemoryFileSystemObject parent, RAFFSOType fsoType, string name) : base( //lol. Is this a sign that I haven't played with C# enough? /*(fsoType==RAFFSOType.DIRECTORY? * "[DIR] ": * (fsoType==RAFFSOType.ARCHIVE? * "[ARC] ": * "[FIL] " * ) * ) + */name ) { //if(this.parent != null) // this.parent.Nodes.Add(this); this.fsoType = fsoType; this.Name = name; this.Text = name; }
/// <summary> /// Instantiated a new RAFPathSelector, which takes /// in a group of RAF In memory FSOs and allows the user to select /// a single node. /// </summary> /// <param name="nodes"></param> public RAFPathSelector(RAFInMemoryFileSystemObject[] nodes, bool includeFiles) { InitializeComponent(); //Resizes layout and add handler for resizing ManageLayout(); this.Resize += delegate(object s, EventArgs e){ ManageLayout(); }; //Add event handler for form closing, to store last location this.FormClosing += new FormClosingEventHandler(TreeNodeSelector_FormClosing); //When a node is clicked, GUI is updated to show the path of the node this.treeView.NodeMouseClick += new TreeNodeMouseClickEventHandler(treeView_NodeMouseClick); //When we are loaded, we set our position this.Load += new EventHandler(TreeNodeSelector_Load); //Add the nodes we're supposed to view. treeView.Nodes.AddRange(nodes); }
private List <RAFInMemoryFileSystemObject> Search(string phrase, RAFInMemoryFileSystemObject node, List <RAFInMemoryFileSystemObject> ignore) { phrase = phrase.ToLower(); List <RAFInMemoryFileSystemObject> results = new List <RAFInMemoryFileSystemObject>(); if (node.Text.ToLower().Contains(phrase)) { if (!ignore.Contains(node)) { results.Add(node); } } for (int i = 0; i < node.Nodes.Count; i++) { results.AddRange(Search(phrase, (RAFInMemoryFileSystemObject)node.Nodes[i], ignore)); } return(results); }
/// <summary> /// Adds a child FSO to this treenode. /// This function supports pathing, so you can add a file with directory names! /// /// Directories are created if not existing already /// /// Such as: root/subDir/SubSubDir/file.name /// </summary> public RAFInMemoryFileSystemObject AddToTree(RAFFSOType type, string name) { string[] dirNames = name.Replace("\\", "/").Split("/"); RAFInMemoryFileSystemObject currentNode = this; //Traverse FS Tree to the directory containing our file for (int i = 0; i < dirNames.Length - 1; i++) { RAFInMemoryFileSystemObject childNode = currentNode.GetChildFSO(dirNames[i]); if (childNode == null) { childNode = currentNode.AddChildFSO(RAFFSOType.DIRECTORY, dirNames[i]); } currentNode = childNode; } //Add the childnode to our tree.. return(currentNode.AddChildFSO(RAFFSOType.FILE, dirNames.Last())); }
void DumpRafArchiveByFSO(RAFInMemoryFileSystemObject fso, string dumpDirectory) { Title("Dump: " + fso.GetRAFPath()); if (fso.GetFSOType() == RAFFSOType.ARCHIVE || fso.GetFSOType() == RAFFSOType.DIRECTORY) { PrepareDirectory(dumpDirectory + "/" + fso.GetRAFPath()); } else { string containingFolderPath = fso.GetRAFPath().Replace("\\", "/").Reverse(); containingFolderPath = containingFolderPath.Substring(Math.Max(containingFolderPath.IndexOf("/"), 0)); containingFolderPath = containingFolderPath.Reverse(); PrepareDirectory(dumpDirectory + "/" + fso.GetRAFPath()); Console.WriteLine("Dump to: " + dumpDirectory + "/" + fso.GetRAFPath()); File.WriteAllBytes(dumpDirectory + "/" + fso.GetRAFPath(), ResolveRAFPathToEntry(fso.GetTopmostParent().Text + "/" + fso.GetRAFPath()).GetContent() ); } for (int i = 0; i < fso.Nodes.Count; i++) { DumpRafArchiveByFSO((RAFInMemoryFileSystemObject)fso.Nodes[i], dumpDirectory); } }
void rafContentView_MouseClick(object sender, MouseEventArgs e) { rafContentView.SelectedNode = rafContentView.GetNodeAt(e.Location); if (e.Button == System.Windows.Forms.MouseButtons.Right) { RAFInMemoryFileSystemObject fso = (RAFInMemoryFileSystemObject)rafContentView.SelectedNode; ContextMenu cm = new ContextMenu(); if (fso != null) { MenuItem dump = new MenuItem("Dump"); #region Dump Menu Entry dump.Click += delegate(Object sender2, EventArgs e2) { if (fso.GetFSOType() == RAFFSOType.ARCHIVE || fso.GetFSOType() == RAFFSOType.DIRECTORY) { FolderBrowserDialog folderDialog = new FolderBrowserDialog(); folderDialog.Description = "Select the folder where you wish to dump the files"; folderDialog.ShowDialog(); if (folderDialog.SelectedPath != "") { Title("Begin Dumping: " + fso.GetRAFPath()); DumpRafArchiveByFSO(fso, folderDialog.SelectedPath); Log("Done dumping: " + fso.GetRAFPath()); Title(""); } } else { SaveFileDialog sfd = new SaveFileDialog(); string fileName = fso.GetRAFPath().Replace("\\", "/").Split("/").Last(); string fileExt = fileName.Substring(fileName.LastIndexOf(".") + 1); sfd.Filter = "File|." + fileExt; sfd.FileName = fileName; sfd.ShowDialog(); if (sfd.FileName != "") { Log("Begin dumping: " + fileName); File.WriteAllBytes( sfd.FileName, rafManager.ResolveRAFPathToEntry( fso.GetTopmostParent().Text + "/" + fso.GetRAFPath() ).GetContent() ); Log("Done dumping: " + fileName); } } }; #endregion cm.MenuItems.Add(dump); #region file viewing entries if (fso.GetFSOType() == RAFFSOType.FILE) { MenuItem viewAsTextFile = new MenuItem("View As Text File"); viewAsTextFile.Click += delegate(Object sender2, EventArgs e2) { new TextViewer( rafManager.ResolveRAFPathToEntry( fso.GetTopmostParent().Text + "/" + fso.GetRAFPath() ) ).Show(); }; cm.MenuItems.Add(viewAsTextFile); MenuItem viewAsBinary = new MenuItem("View As Binary File"); viewAsBinary.Click += delegate(Object sender2, EventArgs e2) { new BinaryViewer(this.baseTitle + " - " + fso.GetTopmostParent() + "/" + fso.GetRAFPath(), rafManager.ResolveRAFPathToEntry( fso.GetTopmostParent().Text + "/" + fso.GetRAFPath() ).GetContent() ).Show(); }; cm.MenuItems.Add(viewAsBinary); if (fso.GetRAFPath().ToLower().EndsWith("inibin") || fso.GetRAFPath().ToLower().EndsWith("troybin")) { MenuItem viewAsINIBIN = new MenuItem("View As INIBIN File"); viewAsINIBIN.Click += delegate(Object sender2, EventArgs e2) { try { new TextViewer(this.baseTitle + " - inibin/troybin view - " + fso.GetTopmostParent() + "/" + fso.GetRAFPath(), new InibinFile().main( rafManager.ResolveRAFPathToEntry( fso.GetTopmostParent().Text + "/" + fso.GetRAFPath() ).GetContent() ) ).Show(); return; } catch { Log("Error parsing INIBIN/TROYBIN file"); } }; cm.MenuItems.Add(viewAsINIBIN); } } #endregion #if true || DEBUG if (fso.GetFSOType() == RAFFSOType.FILE) { MenuItem delete = new MenuItem("Delete - Note, RAF Manager MUST RESTART after you use this for things to display properly."); delete.Click += delegate(Object s2, EventArgs e2) { RAFFileListEntry entry = rafManager.ResolveRAFPathToEntry(fso.GetRAFPath(true)); entry.RAFArchive.GetDirectoryFile().DeleteFileEntry(entry); entry.RAFArchive.SaveDirectoryFile(); }; cm.MenuItems.Add(delete); //TOdo: delete treenodes. For now, just restart client } #endif } MenuItem searchThis = new MenuItem("Search This Archive"); searchThis.Click += delegate(object s2, EventArgs e2) { new RAFSearchBox(fso).Show(); }; cm.MenuItems.Add(searchThis); MenuItem searchAll = new MenuItem("Search All Archives"); searchAll.Click += delegate(object s2, EventArgs e2) { RAFInMemoryFileSystemObject[] nodes = new RAFInMemoryFileSystemObject[rafContentView.Nodes.Count]; for (int i = 0; i < rafContentView.Nodes.Count; i++) { nodes[i] = (RAFInMemoryFileSystemObject)rafContentView.Nodes[i]; } new RAFSearchBox(nodes).Show(); }; cm.MenuItems.Add(searchAll); cm.Show(rafContentView, new Point(e.X, e.Y)); } }
/// <summary> /// Loads the RAF Archives /// </summary> public void LoadRAFArchives() { ArchiveFSOs = new List <RAFInMemoryFileSystemObject>(); Archives = new List <RAFArchive>(); TreeView temp = new TreeView(); //temp.TreeViewNodeSorter = new RAFFSOTreeNodeSorter(); string[] archivePaths = Directory.GetDirectories(fileArchivesPath); for (int i = 0; i < archivePaths.Length; i++) { string archiveName = archivePaths[i].Replace(fileArchivesPath, "").Replace("/", ""); gui.LogToLoader("Load Archive - " + archiveName + " [0%]"); //Title("Loading RAF File - " + archiveName); //Log("Loading RAF Archive Folder: " + archiveName); RAFArchive raf = null; RAFInMemoryFileSystemObject archiveRoot = new RAFInMemoryFileSystemObject(null, RAFFSOType.ARCHIVE, archiveName); temp.Nodes.Add(archiveRoot); ArchiveFSOs.Add(archiveRoot); #if !DEBUG try { #endif //Load raf file table and add to our list of archives Archives.Add( raf = new RAFArchive( Directory.GetFiles(archivePaths[i], "*.raf")[0] ) ); //Enumerate entries and add to our tree... in the future this should become sorted List <RAFFileListEntry> entries = raf.GetDirectoryFile().GetFileList().GetFileEntries(); for (int j = 0; j < entries.Count; j++) { // Console.WriteLine(entries[j].StringNameHash.ToString("x").PadLeft(8, '0').ToUpper()); if (j % 1000 == 1000) { gui.SetLastLoaderLine("Load Archive - " + archiveName + " [" + (j * 100 / entries.Count) + "%]"); } //Title("Loading RAF Files - " + archiveName +" - " + j+"/"+entries.Count); RAFInMemoryFileSystemObject node = archiveRoot.AddToTree(RAFFSOType.FILE, entries[j].FileName); } //Log(entries.Count.ToString() + " Files"); #if !DEBUG } catch (Exception exception) { Log("FAILED:\r\n" + exception.Message + "\r\n"); } #endif //Add to our tree displayer //Title("Sorting nodes... this might take a while"); if (archiveRoot.Nodes.Count == 0) { MessageBox.Show("Another instance of RAF Manager is likely already open.\r\n" + "If not, then another application has not released control over the \r\n" + "RAF Archives. RAF Manager will continue to run, but some features \r\n" + "may not work properly. Usually a restart of the application will \r\n" + "fix this. If you have issues, post a reply on the forum thread, \r\n" + "whose link can be found under the 'About' menu header."); } } }
/// <summary> /// Creates a new deep copy of this RAF In Memory FSO /// /// ...Only Nodes are deep copied /// </summary> /// <returns></returns> public override object Clone() { RAFInMemoryFileSystemObject result = new RAFInMemoryFileSystemObject(null, this.fsoType, this.Name); for (int i = 0; i < this.Nodes.Count; i++) result.Nodes.Add((RAFInMemoryFileSystemObject)this.Nodes[i].Clone()); if (this.IsExpanded) result.Expand(); return result; }
void rafContentView_MouseClick(object sender, MouseEventArgs e) { rafContentView.SelectedNode = rafContentView.GetNodeAt(e.Location); if (e.Button == System.Windows.Forms.MouseButtons.Right) { RAFInMemoryFileSystemObject fso = (RAFInMemoryFileSystemObject)rafContentView.SelectedNode; ContextMenu cm = new ContextMenu(); if (fso != null) { MenuItem dump = new MenuItem("Dump"); #region Dump Menu Entry dump.Click += delegate(Object sender2, EventArgs e2) { if (fso.GetFSOType() == RAFFSOType.ARCHIVE || fso.GetFSOType() == RAFFSOType.DIRECTORY) { FolderBrowserDialog folderDialog = new FolderBrowserDialog(); folderDialog.Description = "Select the folder where you wish to dump the files"; folderDialog.ShowDialog(); if (folderDialog.SelectedPath != "") { Title("Begin Dumping: " + fso.GetRAFPath()); DumpRafArchiveByFSO(fso, folderDialog.SelectedPath); Log("Done dumping: " + fso.GetRAFPath()); Title(""); } } else { SaveFileDialog sfd = new SaveFileDialog(); string fileName = fso.GetRAFPath().Replace("\\", "/").Split("/").Last(); string fileExt = fileName.Substring(fileName.LastIndexOf(".") + 1); sfd.Filter = "File|." + fileExt; sfd.FileName = fileName; sfd.ShowDialog(); if (sfd.FileName != "") { Log("Begin dumping: " + fileName); File.WriteAllBytes( sfd.FileName, ResolveRAFPathToEntry( fso.GetTopmostParent().Text + "/" + fso.GetRAFPath() ).GetContent() ); Log("Done dumping: " + fileName); } } }; #endregion cm.MenuItems.Add(dump); #region file viewing entries if (fso.GetFSOType() == RAFFSOType.FILE) { MenuItem viewAsTextFile = new MenuItem("View As Text File"); viewAsTextFile.Click += delegate(Object sender2, EventArgs e2) { new TextViewer( ResolveRAFPathToEntry( fso.GetTopmostParent().Text + "/" + fso.GetRAFPath() ) ).Show(); }; cm.MenuItems.Add(viewAsTextFile); MenuItem viewAsBinary = new MenuItem("View As Binary File"); viewAsBinary.Click += delegate(Object sender2, EventArgs e2) { new BinaryViewer(this.baseTitle + " - " + fso.GetTopmostParent() + "/" + fso.GetRAFPath(), ResolveRAFPathToEntry( fso.GetTopmostParent().Text + "/" + fso.GetRAFPath() ).GetContent() ).Show(); }; cm.MenuItems.Add(viewAsBinary); if (fso.GetRAFPath().ToLower().EndsWith("inibin") || fso.GetRAFPath().ToLower().EndsWith("troybin")) { MenuItem viewAsINIBIN = new MenuItem("View As INIBIN File"); viewAsINIBIN.Click += delegate(Object sender2, EventArgs e2) { try { new TextViewer(this.baseTitle + " - inibin/troybin view - " + fso.GetTopmostParent() + "/" + fso.GetRAFPath(), new InibinFile().main( ResolveRAFPathToEntry( fso.GetTopmostParent().Text + "/" + fso.GetRAFPath() ).GetContent() ) ).Show(); return; } catch { Log("Error parsing INIBIN/TROYBIN file"); } }; cm.MenuItems.Add(viewAsINIBIN); } } #endregion #if true || DEBUG if (fso.GetFSOType() == RAFFSOType.FILE) { MenuItem delete = new MenuItem("Delete - Note, RAF Manager MUST RESTART after you use this for things to display properly."); delete.Click += delegate(Object s2, EventArgs e2) { RAFFileListEntry entry = ResolveRAFPathToEntry(fso.GetRAFPath(true)); entry.RAFArchive.GetDirectoryFile().DeleteFileEntry(entry); entry.RAFArchive.SaveDirectoryFile(); }; cm.MenuItems.Add(delete); //TOdo: delete treenodes. For now, just restart client } #endif } MenuItem searchThis = new MenuItem("Search This Archive"); searchThis.Click += delegate(object s2, EventArgs e2) { new RAFSearchBox(fso).Show(); }; cm.MenuItems.Add(searchThis); MenuItem searchAll = new MenuItem("Search All Archives"); searchAll.Click += delegate(object s2, EventArgs e2) { RAFInMemoryFileSystemObject[] nodes = new RAFInMemoryFileSystemObject[rafContentView.Nodes.Count]; for (int i = 0; i < rafContentView.Nodes.Count; i++) nodes[i] = (RAFInMemoryFileSystemObject)rafContentView.Nodes[i]; new RAFSearchBox(nodes).Show(); }; cm.MenuItems.Add(searchAll); cm.Show(rafContentView, new Point(e.X, e.Y)); } }
void DumpRafArchiveByFSO(RAFInMemoryFileSystemObject fso, string dumpDirectory) { Title("Dump: " + fso.GetRAFPath()); if (fso.GetFSOType() == RAFFSOType.ARCHIVE || fso.GetFSOType() == RAFFSOType.DIRECTORY) { PrepareDirectory(dumpDirectory + "/" + fso.GetRAFPath()); } else { //Gets the path of our containing folder in the raf archive. //This is akin to new FileInfo(path).DirectoryName if we had a localPath string containingFolderPath = fso.GetRAFPath().Replace("\\", "/").Reverse(); containingFolderPath = containingFolderPath.Substring(Math.Max(containingFolderPath.IndexOf("/"), 0)); containingFolderPath = containingFolderPath.Reverse(); PrepareDirectory(dumpDirectory + "/" + fso.GetRAFPath()); Console.WriteLine("Dump to: " + dumpDirectory + "/" + fso.GetRAFPath()); File.WriteAllBytes(dumpDirectory + "/" + fso.GetRAFPath(), ResolveRAFPathToEntry(fso.GetTopmostParent().Text + "/" + fso.GetRAFPath()).GetContent() ); } for (int i = 0; i < fso.Nodes.Count; i++) DumpRafArchiveByFSO((RAFInMemoryFileSystemObject)fso.Nodes[i], dumpDirectory); }
/// <summary> /// Loads the RAF Archives /// </summary> public void LoadRAFArchives() { ArchiveFSOs = new List<RAFInMemoryFileSystemObject>(); Archives = new List<RAFArchive>(); TreeView temp = new TreeView(); //temp.TreeViewNodeSorter = new RAFFSOTreeNodeSorter(); string[] archivePaths = Directory.GetDirectories(fileArchivesPath); for (int i = 0; i < archivePaths.Length; i++) { string archiveName = archivePaths[i].Replace(fileArchivesPath, "").Replace("/", ""); gui.LogToLoader("Load Archive - " + archiveName + " [0%]"); //Title("Loading RAF File - " + archiveName); //Log("Loading RAF Archive Folder: " + archiveName); RAFArchive raf = null; RAFInMemoryFileSystemObject archiveRoot = new RAFInMemoryFileSystemObject(null, RAFFSOType.ARCHIVE, archiveName); temp.Nodes.Add(archiveRoot); ArchiveFSOs.Add(archiveRoot); #if !DEBUG try { #endif //Load raf file table and add to our list of archives Archives.Add( raf = new RAFArchive( Directory.GetFiles(archivePaths[i], "*.raf")[0] ) ); //Enumerate entries and add to our tree... in the future this should become sorted List<RAFFileListEntry> entries = raf.GetDirectoryFile().GetFileList().GetFileEntries(); for (int j = 0; j < entries.Count; j++) { // Console.WriteLine(entries[j].StringNameHash.ToString("x").PadLeft(8, '0').ToUpper()); if (j % 1000 == 1000) gui.SetLastLoaderLine("Load Archive - " + archiveName + " [" + (j * 100 / entries.Count) + "%]"); //Title("Loading RAF Files - " + archiveName +" - " + j+"/"+entries.Count); RAFInMemoryFileSystemObject node = archiveRoot.AddToTree(RAFFSOType.FILE, entries[j].FileName); } //Log(entries.Count.ToString() + " Files"); #if !DEBUG } catch (Exception exception) { Log("FAILED:\r\n" + exception.Message + "\r\n"); } #endif //Add to our tree displayer //Title("Sorting nodes... this might take a while"); if (archiveRoot.Nodes.Count == 0) { MessageBox.Show("Another instance of RAF Manager is likely already open.\r\n" + "If not, then another application has not released control over the \r\n" + "RAF Archives. RAF Manager will continue to run, but some features \r\n" + "may not work properly. Usually a restart of the application will \r\n" + "fix this. If you have issues, post a reply on the forum thread, \r\n" + "whose link can be found under the 'About' menu header."); } } }
void MainForm_Load(object sender, EventArgs e) { MainWindowLoading loader = new MainWindowLoading(); loader.Show(); loader.Log("Begin Check For Updates"); CheckForUpdates(); loader.Log("Find Archives Folder"); SetArchivesRoot(); loader.Log("Begin Loading RAF Archives"); consoleLogTB.Text = "www.ItzWarty.com Riot Archive File Packer/Unpacker " + ApplicationInformation.BuildTime; rafContentView.TreeViewNodeSorter = new RAFFSOTreeNodeSorter(); //Enumerate RAF files string[] archivePaths = Directory.GetDirectories(archivesRoot); #region load_raf_archives for (int i = 0; i < archivePaths.Length; i++) { string archiveName = archivePaths[i].Replace(archivesRoot, "").Replace("/", ""); loader.Log("Load Archive - " + archiveName +" [0%]"); //Title("Loading RAF File - " + archiveName); //Log("Loading RAF Archive Folder: " + archiveName); RAFArchive raf = null; RAFInMemoryFileSystemObject archiveRoot = new RAFInMemoryFileSystemObject(null, RAFFSOType.ARCHIVE, archiveName); rafContentView.Nodes.Add(archiveRoot); #if !DEBUG try { #endif //Load raf file table and add to our list of archives rafArchives.Add(archiveName, raf = new RAFArchive( Directory.GetFiles(archivePaths[i], "*.raf")[0] ) ); //Enumerate entries and add to our tree... in the future this should become sorted List<RAFFileListEntry> entries = raf.GetDirectoryFile().GetFileList().GetFileEntries(); for (int j = 0; j < entries.Count; j++) { // Console.WriteLine(entries[j].StringNameHash.ToString("x").PadLeft(8, '0').ToUpper()); if (j % 1000 == 0) loader.Log("Load Archive - " + archiveName + " [" + (j * 100 / entries.Count) + "%]"); //Title("Loading RAF Files - " + archiveName +" - " + j+"/"+entries.Count); RAFInMemoryFileSystemObject node = archiveRoot.AddToTree(RAFFSOType.FILE, entries[j].FileName); } //Log(entries.Count.ToString() + " Files"); #if !DEBUG } catch (Exception exception) { Log("FAILED:\r\n" + exception.Message + "\r\n"); } #endif //Add to our tree displayer //Title("Sorting nodes... this might take a while"); if (archiveRoot.Nodes.Count == 0) { MessageBox.Show("Another instance of RAF Manager is likely already open.\r\n" + "If not, then another application has not released control over the \r\n" + "RAF Archives. RAF Manager will continue to run, but some features \r\n" + "may not work properly. Usually a restart of the application will \r\n" + "fix this. If you have issues, post a reply on the forum thread, \r\n" + "whose link can be found under the 'About' menu header."); } } #endregion try { while (loader.Visible) //Hack - i have no idea why this is necessary sometimes... probs race condition somewhere { loader.Hide(); Application.DoEvents(); } }catch{} lock (consoleLogTB) { Log(""); Log("A simple guide for using RAF Manager can be located at About->Simple Guide."); Log(""); if (File.Exists(".laststate.rmproj")) { Log("Open last state"); OpenProject(".laststate.rmproj"); } } }
void MainForm_Load(object sender, EventArgs e) { MainWindowLoading loader = new MainWindowLoading(); loader.Show(); loader.Log("Begin Check For Updates"); CheckForUpdates(); loader.Log("Find Archives Folder"); SetArchivesRoot(); loader.Log("Begin Loading RAF Archives"); consoleLogTB.Text = "www.ItzWarty.com Riot Archive File Packer/Unpacker " + ApplicationInformation.BuildTime; rafContentView.TreeViewNodeSorter = new RAFFSOTreeNodeSorter(); //Enumerate RAF files string[] archivePaths = Directory.GetDirectories(archivesRoot); #region load_raf_archives for (int i = 0; i < archivePaths.Length; i++) { string archiveName = archivePaths[i].Replace(archivesRoot, "").Replace("/", ""); loader.Log("Load Archive - " + archiveName + " [0%]"); //Title("Loading RAF File - " + archiveName); //Log("Loading RAF Archive Folder: " + archiveName); RAFArchive raf = null; RAFInMemoryFileSystemObject archiveRoot = new RAFInMemoryFileSystemObject(null, RAFFSOType.ARCHIVE, archiveName); rafContentView.Nodes.Add(archiveRoot); #if !DEBUG try { #endif //Load raf file table and add to our list of archives rafArchives.Add(archiveName, raf = new RAFArchive( Directory.GetFiles(archivePaths[i], "*.raf")[0] ) ); //Enumerate entries and add to our tree... in the future this should become sorted List <RAFFileListEntry> entries = raf.GetDirectoryFile().GetFileList().GetFileEntries(); for (int j = 0; j < entries.Count; j++) { // Console.WriteLine(entries[j].StringNameHash.ToString("x").PadLeft(8, '0').ToUpper()); if (j % 1000 == 0) { loader.Log("Load Archive - " + archiveName + " [" + (j * 100 / entries.Count) + "%]"); } //Title("Loading RAF Files - " + archiveName +" - " + j+"/"+entries.Count); RAFInMemoryFileSystemObject node = archiveRoot.AddToTree(RAFFSOType.FILE, entries[j].FileName); } //Log(entries.Count.ToString() + " Files"); #if !DEBUG } catch (Exception exception) { Log("FAILED:\r\n" + exception.Message + "\r\n"); } #endif //Add to our tree displayer //Title("Sorting nodes... this might take a while"); if (archiveRoot.Nodes.Count == 0) { MessageBox.Show("Another instance of RAF Manager is likely already open.\r\n" + "If not, then another application has not released control over the \r\n" + "RAF Archives. RAF Manager will continue to run, but some features \r\n" + "may not work properly. Usually a restart of the application will \r\n" + "fix this. If you have issues, post a reply on the forum thread, \r\n" + "whose link can be found under the 'About' menu header."); } } #endregion try { while (loader.Visible) //Hack - i have no idea why this is necessary sometimes... probs race condition somewhere { loader.Hide(); Application.DoEvents(); } }catch {} lock (consoleLogTB) { Log(""); Log("A simple guide for using RAF Manager can be located at About->Simple Guide."); Log(""); if (File.Exists(".laststate.rmproj")) { Log("Open last state"); OpenProject(".laststate.rmproj"); } } }