private RAFArchive GetArchive(string v) { RAFArchive archive; if (archives.TryGetValue(v, out archive)) { return(archive); } var folder = Path.Combine(this.root, "filearchives", v); Directory.CreateDirectory(folder); var rafs = Directory.EnumerateFiles(folder, "*.raf").ToList(); if (rafs.Any()) { archive = new RAFArchive(rafs.First()); } else { archive = new RAFArchive(Path.Combine(folder, "Archive_1.raf")); } archives.Add(v, archive); return(archive); }
void bw_MinifyArchiveWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker bw = (BackgroundWorker)sender; RAFArchive archive = (RAFArchive)e.Argument; Console.WriteLine("Minifying Archive: " + archive.GetID()); //Create temporary dat file Console.WriteLine("-> Creating temporary file"); string tempDatFilePath = archive.RAFFilePath + ".dat.temp"; FileStream datFs = File.Create(tempDatFilePath); Console.WriteLine("-> Begin Writing New Entries"); List <RAFFileListEntry> entries = archive.GetDirectoryFile().GetFileList().GetFileEntries(); for (int i = 0; i < entries.Count; i++) { //Report progress to main thread if ((i % 100) == 0) { bw.ReportProgress((int)(i * 100 / entries.Count), entries[i].FileName); } byte[] rawContent = entries[i].GetRawContent(); datFs.Write(rawContent, 0, rawContent.Length); } Console.WriteLine(" ->Done"); Console.WriteLine("-> Delete old Archive File... (Closing File Stream)"); archive.GetDataFileContentStream().Close(); //First we close the old .dat file stream, so we can replace the unowned file Console.WriteLine(" Stream Closed... Now deleting old DAT file"); File.Delete(archive.RAFFilePath + ".dat"); Console.WriteLine(" Move Replacement DAT File..."); File.Move(tempDatFilePath, archive.RAFFilePath + ".dat"); Console.WriteLine("-> Generate new Archive Directory File (*.raf)."); archive.SaveDirectoryFile(); Console.WriteLine("-> Done"); }
void bw_AnalyzeArchiveWorker_DoWork(object sender, DoWorkEventArgs e) { Console.WriteLine("Analyzing - doing work"); BackgroundWorker bw = (BackgroundWorker)sender; RAFArchive[] archives = (RAFArchive[])e.Argument; TimeSpan updateInterval = new TimeSpan(0, 0, 0, 0, 100); DateTime lastUpdate = DateTime.Now - updateInterval; long bytesWasted = 0; Console.WriteLine("Enter for. Archives count: " + archives.Length); for (int i = 0; i < archives.Length; i++) { RAFArchive archive = archives[i]; long archiveBytesUsed = 0; //We add to this each time, then find out how many bytes could have been saved. List <RAFFileListEntry> entries = archive.GetDirectoryFile().GetFileList().GetFileEntries(); Console.WriteLine("Analyzing Archive: " + archive.GetID() + "; " + entries.Count + " entries"); for (int j = 0; j < entries.Count; j++) { //Console.WriteLine(" " + j); //Report progress to main thread if (j % 100 == 0) { bw.ReportProgress(0, new long[] { j, i, bytesWasted }); lastUpdate = DateTime.Now; } //Console.WriteLine(" !"); archiveBytesUsed += entries[j].FileSize; } bytesWasted += new FileInfo(archive.RAFFilePath + ".dat").Length - archiveBytesUsed; Console.WriteLine("Current Bytes Wasted: " + bytesWasted); } }
/// <summary> /// Event handler for when a DragDrop operation completed on top of the changesview /// </summary> void changesView_DragDrop(object sender, DragEventArgs e) { //Check if we have a file/list of filfes if (e.Data is DataObject && ((DataObject)e.Data).ContainsFileDropList()) { DataObject dataObject = (DataObject)e.Data; StringCollection dropList = dataObject.GetFileDropList(); List <string> filePaths = new List <string>(); foreach (string path in dropList) { if (File.GetAttributes(path).HasFlag(FileAttributes.Directory)) { filePaths.AddRange(Util.GetAllChildFiles(path));//Directory.GetFiles(rootPath, "**", SearchOption.AllDirectories); } else { filePaths.Add(path); } } if (filePaths.Count == 1) //test if its a project { if (filePaths[0].ToLower().EndsWith(".rmproj")) { if (HasProjectChanged) { PromptSaveToClose(); } //Load the project LoadProject(filePaths[0]); return; } } //Iterate through all files StringQueryDialog nameQueryDialog = new StringQueryDialog("Type File Group Name:"); nameQueryDialog.ShowDialog(); if (nameQueryDialog.Value.Trim() == "") { Log("Invalid name '{0}' given. ".F(nameQueryDialog.Value.Trim())); return; } TristateTreeNode topNode = new TristateTreeNode(nameQueryDialog.Value); topNode.HasCheckBox = true; for (int z = 0; z < filePaths.Count; z++) { SetTaskbarProgress(z * 100 / filePaths.Count); string filePath = filePaths[z].Replace("\\", "/"); //Console.WriteLine(filePath); //ADD TO VIEW HERE TristateTreeNode node; topNode.Nodes.Add( node = new TristateTreeNode(filePath) ); node.HasCheckBox = true; //changesView.Rows[rowIndex].Cells[CN_LOCALPATH].Style.Alignment = DataGridViewContentAlignment.MiddleRight; //Split the path into pieces split by FSOs... Search the RAF archives and see if we can link it to the raf path string[] pathParts = filePath.Split("/"); RAFFileListEntry matchedEntry = null; List <RAFFileListEntry> lastMatches = null; bool done = false; //Smart search insertion for (int i = 1; i < pathParts.Length + 1 && !done; i++) { string[] searchPathParts = pathParts.SubArray(pathParts.Length - i, i); string searchPath = String.Join("/", searchPathParts); //Console.WriteLine(searchPath); List <RAFFileListEntry> matches = new List <RAFFileListEntry>(); RAFArchive[] archives = rafArchives.Values.ToArray(); for (int j = 0; j < archives.Length; j++) { List <RAFFileListEntry> newmatches = archives[j].GetDirectoryFile().GetFileList().SearchFileEntries(searchPath); matches.AddRange(newmatches); } if (matches.Count == 1) { matchedEntry = matches[0]; done = true; } else if (matches.Count == 0) { done = true; } else { lastMatches = matches; } } if (matchedEntry == null) { if (lastMatches != null && lastMatches.Count > 0) { //Resolve ambiguity FileEntryAmbiguityResolver ambiguityResolver = new FileEntryAmbiguityResolver(lastMatches.ToArray(), "!"); ambiguityResolver.ShowDialog(); RAFFileListEntry resolvedItem = (RAFFileListEntry)ambiguityResolver.SelectedItem; if (resolvedItem != null) { matchedEntry = resolvedItem; } } else if (advancedUser) { //We'll use the file browser to select where we want to save... string rafPath = PickRafPath(false) + "/"; RAFArchive archive = rafArchives[rafPath.Replace("\\", "/").Split("/").First()]; rafPath = rafPath.Substring(rafPath.IndexOf("/") + 1); //remove the archive name now... if (rafPath.Length != 0) { Console.WriteLine("FRP: " + "len!= 0"); if (rafPath[rafPath.Length - 1] == '/') { Console.WriteLine("FRP: " + rafPath); rafPath = rafPath.Substring(0, rafPath.Length - 1);//remove the trailing /, since we add it later } } Console.WriteLine("FRP: " + rafPath); if (rafPath == "") { matchedEntry = new RAFFileListEntry(archive, pathParts.Last(), UInt32.MaxValue, (UInt32) new FileInfo(filePath).Length, UInt32.MaxValue); } else { matchedEntry = new RAFFileListEntry(archive, rafPath + "/" + pathParts.Last(), UInt32.MaxValue, (UInt32) new FileInfo(filePath).Length, UInt32.MaxValue); } //Add the tree node to the raf viewer } } if (matchedEntry != null) //If it's still not resolved { node.Tag = new ChangesViewEntry(filePath, matchedEntry, node); node.Nodes.Add(new TristateTreeNode("Local Path: " + filePath)); node.Nodes.Add(new TristateTreeNode("RAF Path: " + matchedEntry.RAFArchive.GetID() + "/" + matchedEntry.FileName)); node.Nodes[0].HasCheckBox = false; node.Nodes[1].HasCheckBox = false; //changesView.Rows[rowIndex].Cells[CN_RAFPATH].Value = matchedEntry.RAFArchive.GetID() + "/" + matchedEntry.FileName; //changesView.Rows[rowIndex].Cells[CN_RAFPATH].Tag = matchedEntry; } else { node.Tag = new ChangesViewEntry(filePath, null, node); node.Nodes.Add(new TristateTreeNode("Local Path: " + filePath)); node.Nodes.Add(new TristateTreeNode("RAF Path: " + "undefined")); node.Nodes[0].HasCheckBox = false; node.Nodes[1].HasCheckBox = false; Log("Unable to link file '" + filePath + "' to RAF Archive. Please manually select RAF path"); } } changesView.Nodes.Add(topNode); changesView.Invalidate(); SetTaskbarProgress(0); } }
///<summary> ///Returns a guess of the RAF Path, including the archive id or "undefined" ///</summary> public string GuessRafPathFromPath(string basePath) { string[] pathParts = basePath.Replace("\\", "/").Split("/"); RAFFileListEntry matchedEntry = null; List <RAFFileListEntry> lastMatches = null; bool done = false; //Smart search insertion for (int i = 1; i < pathParts.Length + 1 && !done; i++) { string[] searchPathParts = pathParts.SubArray(pathParts.Length - i, i); string searchPath = String.Join("/", searchPathParts); //Console.WriteLine(searchPath); List <RAFFileListEntry> matches = new List <RAFFileListEntry>(); RAFArchive[] archives = rafManager.Archives.ToArray(); for (int j = 0; j < archives.Length; j++) { List <RAFFileListEntry> newmatches = archives[j].GetDirectoryFile().GetFileList().SearchFileEntries(searchPath); matches.AddRange(newmatches); } if (matches.Count == 1) { matchedEntry = matches[0]; done = true; } else if (matches.Count == 0) { done = true; } else { lastMatches = matches; } } if (matchedEntry == null) { if (lastMatches != null && lastMatches.Count > 0) { //Resolve ambiguity FileEntryAmbiguityResolver ambiguityResolver = new FileEntryAmbiguityResolver(lastMatches.ToArray(), "Notes: " + basePath); ambiguityResolver.ShowDialog(); RAFFileListEntry resolvedItem = (RAFFileListEntry)ambiguityResolver.SelectedItem; if (resolvedItem != null) { matchedEntry = resolvedItem; } } else if (permitExperimentalFileAddingCB.Checked)//advanced user { //We'll use the file browser to select where we want to save... string rafPath = PickRafPath(false) + "/"; RAFArchive archive = rafManager.Archives.Where( (Func <RAFArchive, bool>) delegate(RAFArchive arc) { return(arc.GetID().ToLower() == rafPath.Replace("\\", "/").Split("/").First().ToLower()); } ).First(); rafPath = rafPath.Substring(rafPath.IndexOf("/") + 1); //remove the archive name now... if (rafPath.Length != 0) { Console.WriteLine("FRP: " + "len!= 0"); if (rafPath[rafPath.Length - 1] == '/') { Console.WriteLine("FRP: " + rafPath); rafPath = rafPath.Substring(0, rafPath.Length - 1);//remove the trailing /, since we add it later } } Console.WriteLine("FRP: " + rafPath); if (rafPath == "") { matchedEntry = new RAFFileListEntry(archive, pathParts.Last(), UInt32.MaxValue, (UInt32) new FileInfo(basePath).Length, UInt32.MaxValue); } else { matchedEntry = new RAFFileListEntry(archive, rafPath + "/" + pathParts.Last(), UInt32.MaxValue, (UInt32) new FileInfo(basePath).Length, UInt32.MaxValue); } //Add the tree node to the raf viewer } } if (matchedEntry != null) //If it is resolved { /* * node.Tag = new ChangesViewEntry(filePath, matchedEntry, node); * node.Nodes.Add(new TristateTreeNode("Local Path: " + filePath)); * node.Nodes.Add(new TristateTreeNode("RAF Path: " + matchedEntry.RAFArchive.GetID() + "/" + matchedEntry.FileName)); * node.Nodes[0].HasCheckBox = false; * node.Nodes[1].HasCheckBox = false; */ //Don't add it return(matchedEntry.RAFArchive.GetID() + "/" + matchedEntry.FileName); //changesView.Rows[rowIndex].Cells[CN_RAFPATH].Value = matchedEntry.RAFArchive.GetID() + "/" + matchedEntry.FileName; //changesView.Rows[rowIndex].Cells[CN_RAFPATH].Tag = matchedEntry; } else { /* * node.Tag = new ChangesViewEntry(filePath, null, node); * node.Nodes.Add(new TristateTreeNode("Local Path: " + filePath)); * node.Nodes.Add(new TristateTreeNode("RAF Path: " + "undefined")); * node.Nodes[0].HasCheckBox = false; * node.Nodes[1].HasCheckBox = false; * Log("Unable to link file '" + filePath + "' to RAF Archive. Please manually select RAF path"); */ //Log("Unable to resolve local path to RAF path: " + basePath); return("undefined"); } }
static void Main(string[] args) { if (args.Length < 3) { PrintHelp(); return; } string leaguePath = args[0]; Regex regex = new Regex(args[1]); bool disableOutput = (args[2] == "1"); // Go through all folders and make a list of all RAF files. List <RAFArchive> RAFFileNames = new List <RAFArchive>(); string[] archiveDirs = Directory.GetDirectories(leaguePath); foreach (string subDir in archiveDirs) { string path = subDir + "\\"; // We are in some 0.0.0.XX or whatever folder...there should be a RAF file in here string[] fileNames = Directory.GetFiles(path); foreach (string fileName in fileNames) { if (fileName.EndsWith("raf")) { RAFArchive archv = new RAFArchive(fileName); Console.WriteLine(fileName); RAFFileNames.Add(archv); Dictionary <string, RAFFileListEntry> entries = archv.FileDictFull; foreach (KeyValuePair <string, RAFFileListEntry> entry in entries) { Match match = regex.Match(entry.Key); if (match.Success) { Console.WriteLine(entry.Key); if (disableOutput) { continue; } // Export the contents that we found out to an appropriately named file. byte[] byteData = entry.Value.GetContent(); // Dump out. string outputFile = entry.Value.FileName; // If directory doesn't exist make it. string dirName = Path.GetDirectoryName(outputFile); if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } int suffix = 0; while (File.Exists(outputFile)) { outputFile += suffix; ++suffix; } FileStream fs = new System.IO.FileStream(outputFile, System.IO.FileMode.Create, System.IO.FileAccess.Write); fs.Write(byteData, 0, byteData.Length); fs.Close(); } } } } } int exit = Console.Read(); return; }
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"); } } }
private void BeginMinifyArchive(RAFArchive archive) { bw.RunWorkerAsync(archive); }
/// <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."); } } }