public virtual Task <FileContent> RemoveAsync(string id) { FileContent file = null; // try to find the real id string real = KeyUtil.FindKey(id, () => _files.Keys); if (real != null) { _logger.LogDebug($"{id} -> {real} will be used when removing the file."); // try to remove the file by using the real id bool succeed = _files.TryRemove(real, out file); if (succeed) { _logger.LogDebug($"Successfully removed a file by using the id {id} -> {real}."); } else { _logger.LogError($"Failed to remove a file by using the id {id} -> {real}."); } } else { _logger.LogDebug($"Unable to find a file to remove by using the id {id}."); } // return the removed file or null if we didn't remove anything return(Task.FromResult(file)); }
public virtual Task <FileContent> GetAsync(string id) { FileContent file = null; // try to find the real id string real = KeyUtil.FindKey(id, () => _files.Keys); if (real != null) { // try to get the file by using the real id bool succeed = _files.TryGetValue(real, out file); if (succeed) { _logger.LogDebug($"Found a file by using the id {id} -> {real}."); } else { _logger.LogError($"Did not found a file by using the id {id} -> {real}."); } } else { _logger.LogDebug($"Unable to find a file by using the id {id}."); } // return the file or null if no data found return(Task.FromResult(file)); }
private void LoadGameDirectory(KeyUtil keyUtil, string gameName) { using (new WaitCursor(this)) { FileSystem fs = new RealFileSystem(); string gamePath = keyUtil.FindGameDirectory(); while (gamePath == null) { var fbd = new VistaFolderBrowserDialog { Description = "Could not find the " + gameName + " game directory. Please select the directory containing " + keyUtil.ExecutableName, ShowNewFolderButton = false }; if (fbd.ShowDialog() == DialogResult.Cancel) { MessageBox.Show( keyUtil.ExecutableName + " is required to extract cryptographic keys for this program to function. " + "SparkIV can not run without this file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (System.IO.File.Exists(Path.Combine(fbd.SelectedPath, keyUtil.ExecutableName))) { gamePath = fbd.SelectedPath; } } byte[] key = keyUtil.FindKey(gamePath); if (key == null) { string message = "Your " + keyUtil.ExecutableName + " seems to be modified or is a newer version than this tool supports. " + "SparkIV can not run without a supported " + keyUtil.ExecutableName + " file." + "\n" + "Would you like to check for updates?"; string caption = "Newer or Modified " + keyUtil.ExecutableName; if (MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes) { Updater.CheckForUpdate(); } return; } KeyStore.SetKeyLoader(() => key); fs.Open(gamePath); if (_fs != null) { _fs.Close(); } _fs = fs; Text = Application.ProductName + " - Browse Game Directory"; PopulateUI(); } }
static int Main(string[] args) { string gtaPath = KeyUtil.FindGTADirectory(); while (gtaPath == null) { Console.Error.WriteLine("ERROR"); Console.Error.WriteLine("Could not find GTAIV directory. Please install GTAIV or copy EFLC.exe\n" + "to the same path as Scruff."); return(1); } byte[] key = KeyUtil.FindKey(gtaPath); if (key == null) { Console.Error.WriteLine("ERROR"); Console.Error.WriteLine("Your EFLC.exe seems to be modified or is a newer version than this tool\n" + "supports. If it is a newer version, please check for an update of Scruff.\n" + "Scruff can not run without a supported EFLC.exe file."); return(1); } KeyStore.SetKeyLoader(() => key); CodeFormatOptions[] formats = { new CodeFormatOptions("d", CodeFormat.ScruffDecompile, "Default Scruff disassembly format"), new CodeFormatOptions("h", CodeFormat.ScruffHeader, "Default Scruff header/local varibles/etc format"), new CodeFormatOptions("hl", CodeFormat.FullDecompile, "High level C-like format"), new CodeFormatOptions("hla", CodeFormat.FullDecompileAnnotate, "High level C-like format (annotated)"), new CodeFormatOptions("ll", CodeFormat.Disassemble, "Low level raw assembly format"), new CodeFormatOptions("cp", CodeFormat.CodePath, "Code path for the control-flow-analyzer (for debugging)"), }; CodeFormat customFormat = CodeFormat.ScruffDecompile; bool defaultMode = true; string filename = null; string outputFilename = null; if (args.Length > 0) { var argsQueue = new Queue <string>(args); while (argsQueue.Count > 0) { var arg = argsQueue.Dequeue(); if (arg.StartsWith("-")) { if (arg == "-o") { defaultMode = false; outputFilename = argsQueue.Dequeue(); } else { foreach (var format in formats) { if (arg == "-" + format.Param) { defaultMode = false; customFormat = format.Format; break; } } } } else { if (argsQueue.Count > 0) { break; } filename = arg; } } } if (filename == null) { var formatParams = new StringBuilder(); foreach (var format in formats) { if (formatParams.Length > 0) { formatParams.Append("|"); } formatParams.Append("-"); formatParams.Append(format.Param); } Console.Error.WriteLine("Scruff - A RAGE Script File Decompiler/Disassembler"); Console.Error.WriteLine("v" + Version + " -- (c) 2008-2009, Aru <oneforaru at gmail dot com>"); Console.Error.WriteLine(); Console.Error.WriteLine(string.Format("Usage: scruff [{0}] [-o filename.sca] filename.sco", formatParams)); Console.Error.WriteLine(); Console.Error.WriteLine("By default, will generate filename.sca (-d) and filename.sch (-h)"); Console.Error.WriteLine("If output file is specified, only filename.sca will be generated."); Console.Error.WriteLine("If format specified without output filename, will dump to console (stdout)."); Console.Error.WriteLine(); Console.Error.WriteLine("For custom options, use:"); Console.Error.WriteLine(" -{0,-5} {1}", "o", "Saves the result to a specified file."); foreach (var format in formats) { Console.Error.WriteLine(" -{0,-5} {1}", format.Param, format.Description); } Console.Error.WriteLine(); /* * Console.Error.WriteLine("Press any key to exit"); * Console.ReadKey(); */ return(1); } var file = new ScriptFile(); try { file.Open(filename); } catch { Console.Error.WriteLine("Invalid input file -- not a valid script."); /* * Console.ReadKey(); */ return(1); } if (defaultMode) { using (var fs = File.OpenWrite(Path.ChangeExtension(filename, "sca"))) { var sw = new StreamWriter(fs); OutputCode(file, CodeFormat.ScruffDecompile, sw); sw.Flush(); } using (var fs = File.OpenWrite(Path.ChangeExtension(filename, "sch"))) { var sw = new StreamWriter(fs); OutputCode(file, CodeFormat.ScruffHeader, sw); sw.Flush(); } } else { if (outputFilename != null) { using (var fs = File.OpenWrite(outputFilename)) { var sw = new StreamWriter(fs); OutputCode(file, customFormat, sw); sw.Flush(); } } else { OutputCode(file, customFormat, Console.Out); } } #if DEBUG Console.ReadLine(); #endif return(0); }