private TextDecoder initDecoder() { TextDecoder decoder = new TextDecoder(); decoder.OpenTable("test.tbl"); return(decoder); }
static void Main(string[] args) { string romName = string.Empty; string tableName = string.Empty; int validStringLength = 5; string encodingName = "utf-8"; string outputName = "output.txt"; bool showHelp = false; Encoding encoding; var options = new OptionSet() { { "l|length=", "the minimum length for a valid string. Default is 5", l => validStringLength = Convert.ToInt32(l) }, { "e|encoding=", "the encoding of the table file (e.g. shift-jis). Default is utf-8", e => encodingName = e }, { "o|output=", "the name of the file to write the text to. Default is output.txt", o => outputName = o }, { "h|help", "show this message", h => showHelp = h != null } }; List <string> unparsedOptions; try { unparsedOptions = options.Parse(args); } catch (OptionException ex) { Console.Write("Text Scanner"); Console.WriteLine(ex.Message); Console.WriteLine("Try 'TextScanner --help' for more information"); return; } if (showHelp) { showUsage(options); return; } if (unparsedOptions.Count < 2) { showUsage(options); return; } if (!checkFile(unparsedOptions[0], "rom")) { return; } romName = unparsedOptions[0]; if (!checkFile(unparsedOptions[1], "table")) { return; } tableName = unparsedOptions[1]; if (validStringLength <= 0) { Console.WriteLine("Error: Invalid string length"); return; } try { encoding = Encoding.GetEncoding(encodingName); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } var decoder = new TextDecoder(); decoder.OpenTable(tableName, encodingName); decoder.SetHexBlock(File.ReadAllBytes(romName)); decoder.StopOnUndefinedCharacter = true; scanFile(decoder, validStringLength, outputName, encoding); }