private void Verarbeiten() { try { if (this.InvokeRequired) { this.Invoke(new NormalVoid(Verarbeiten)); return; } label2.Text = ""; status.Text = "Starte Converter..."; Binsembler b2db = new Binsembler(); b2db.Status += new Binsembler.StatusHandler(b2db_Status); b2db.Compile(this.file.Text, this.file.Text + ".txt"); TransferStatus(); status.Text = "Konvertierung erfolgreich!"; b2db = null; } catch (Exception e) { TransferStatus(); MessageBox.Show("Fehler bei der Umwandlung:\n" + e.Message); status.Text = "Fehler bei der Umwandlung: " + e.Message; } }
static int Main(string[] args) { foreach (string a in args) { string[] spl = a.Split('='); string name = spl[0].ToLower(); //string value = spl.Length > 1 ? a.Substring(name.Length + 1) : null; switch (name) { case "-V": case "--version": Console.WriteLine("Binsembler"); Console.WriteLine("\t(c) 2011 Carl Kittelberger"); Console.WriteLine("\tVersion " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version); Console.WriteLine("\tBuild for architecture " + System.Reflection.Assembly.GetExecutingAssembly().GetName().ProcessorArchitecture); Console.WriteLine("\tBuild flags: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Flags.ToString()); Console.WriteLine(); return 0; case "-l": case "--license": if (File.Exists("LICENSE")) { Console.WriteLine(File.ReadAllText("LICENSE")); } else { Console.WriteLine("Warning: No license file found - deleted?"); } return 0; case "-h": case "--help": Usage(); return 0; } } if (args.Length == 0) { Console.WriteLine("Activating GUI..."); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Console.WriteLine("GUI now running."); Application.Run(new Main()); } else { string input = ""; string output = ""; int start = 0; int end = -1; Binsembler conv = new Binsembler(); foreach (string a in args) { string[] spl = a.Split('='); string name = spl[0].ToLower(); string value = spl.Length > 1 ? a.Substring(name.Length + 1) : null; switch (name) { case "--output-file": case "--output": case "-o": output = value; break; case "--buffer-length": case "--bufflen": case "-b": int x = 0; int.TryParse(value, out x); if (x <= 0) { Console.WriteLine("Warning: Invalid buffer length given, applying standard value."); } else { conv.BufferLength = x; } break; case "-w": case "--word": case "--use-word": Console.WriteLine("16-bit mode activated."); conv.BitFormat = BitFormat.SixteenBit; break; case "--no-zero": case "-0-": case "--without-zero": Console.WriteLine("No ending zero byte."); conv.OutputZeroEnd = false; break; case "--zero": case "-0+": case "--with-zero": Console.WriteLine("With ending zero byte."); conv.OutputZeroEnd = true; break; case "--use-format": case "--format": case "-f": /** * $0: Standard value * $1: Binary value * $2: Octal value * $3: Base32 value (not implemented) * $4: Base64 value (not implemented) */ switch (value.ToLower()) { case "$hex": case "$hexadecimal": case "$": conv.ValueFormat = ValueFormat.ShortHexadecimal; break; case "hex": case "hexadecimal": case "0x": conv.ValueFormat = ValueFormat.FullHexadecimal; break; case "b": case "bin": case "binary": conv.ValueFormat = ValueFormat.Binary; break; case "o": case "octal": conv.ValueFormat = ValueFormat.Octal; break; case "d": case "decimal": conv.ValueFormat = ValueFormat.Decimal; break; default: Console.WriteLine("WARNING: Unknown value format, applying standard value format."); break; } break; case "--start-byte": case "--start": case "-s": int y = 0; int.TryParse(value, out y); if (y <= 0) { Console.WriteLine("Warning: Invalid start position given, applying standard value."); } else { start = y; } break; case "--end-byte": case "--end": case "-e": int z = 0; int.TryParse(value, out z); if (z <= 0) { Console.WriteLine("Warning: Invalid end position given, applying standard value."); } else { end = z; } break; } } input = args[args.Length - 1]; if (output.Trim() == "") output = input + ".txt"; /* Console.WriteLine("Input file: \t" + input); Console.WriteLine("Output file: \t" + output); Console.WriteLine("Buffer length:\t" + bufflen.ToString() + " Bytes per buffer"); Console.WriteLine(); */ try { conv.Compile(input, output, start, end); } catch(Exception n) { Console.WriteLine("Compiler error: " + n.Message); } } return 0; }
public static void Main(string[] args) { Console.WriteLine ("Binsembler test tool"); Console.WriteLine (); Console.WriteLine("Version info:"); Process pr = new Process(); pr.StartInfo = new ProcessStartInfo(System.IO.Path.Combine(Environment.CurrentDirectory, "binsembler.exe"), "--version"); pr.StartInfo.UseShellExecute = false; pr.StartInfo.RedirectStandardOutput = true; pr.Start(); while(!pr.StandardOutput.EndOfStream) { Console.WriteLine("[binsembler] " + pr.StandardOutput.ReadLine()); } Console.WriteLine(); Console.WriteLine("(A1) Library: Instanced standard compilation (One-Line-Conversion)"); new Binsembler().Compile("melodies1.mp3"); ParseFile("melodies1.mp3.txt"); Console.WriteLine("(A2) Library: Instanced 16-bit standard compilation"); Binsembler conv = new Binsembler(); conv.BitFormat = BitFormat.SixteenBit; conv.Compile("melodies1.mp3"); ParseFile("melodies1.mp3.txt"); Console.WriteLine("(A3) Library: Instanced decimal compilation"); conv.BitFormat = BitFormat.EightBit; conv.Compile("melodies1.mp3"); ParseFile("melodies1.mp3.txt"); Console.WriteLine("(A4) Library: Instanced decimal standard compilation"); conv.BitFormat = BitFormat.SixteenBit; conv.ValueFormat = ValueFormat.Decimal; conv.Compile("melodies1.mp3"); ParseFile("melodies1.mp3.txt"); Console.WriteLine("(B1) Executable: Standard compilation"); pr.StartInfo.Arguments = "melodies1.mp3"; pr.Start(); pr.WaitForExit(); ParseFile("melodies1.mp3.txt"); Console.WriteLine("(B1) Executable: 16-bit standard compilation"); pr.StartInfo.Arguments = "-w melodies1.mp3"; pr.Start(); pr.WaitForExit(); ParseFile("melodies1.mp3.txt"); Console.WriteLine("(B1) Executable: Decimal compilation"); pr.StartInfo.Arguments = "--format=d melodies1.mp3"; pr.Start(); pr.WaitForExit(); ParseFile("melodies1.mp3.txt"); Console.WriteLine("(B1) Executable: 16-bit decimal compilation"); pr.StartInfo.Arguments = "--format=d -w melodies1.mp3"; pr.Start(); pr.WaitForExit(); ParseFile("melodies1.mp3.txt"); Console.WriteLine("========================== FINISHED ============================="); Console.ReadKey(); }