static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("No script file not found"); } else { string scriptFile = args[0]; if (File.Exists(scriptFile)) { if (Path.GetExtension(scriptFile).Equals(".bud")) { Stopwatch watch = new Stopwatch(); watch.Start(); string compiledCode = BuddyCompilerLibrary.Compile(scriptFile); using (FileStream fs = new FileStream(Path.Combine(Path.GetDirectoryName(scriptFile), Path.GetFileNameWithoutExtension(scriptFile) + ".buddy"), FileMode.Create)) using (BinaryWriter bw = new BinaryWriter(fs)) { bw.Write(compiledCode); } watch.Stop(); Console.WriteLine($"'{Path.GetFileName(scriptFile)}' compiled in {watch.ElapsedMilliseconds} ms"); } else if (Path.GetExtension(scriptFile).Equals(".buddy")) { Console.WriteLine($"{Path.GetFileName(scriptFile)} is already compiled"); } else { Console.WriteLine("Only files with the *.bud extension are compilable"); } } else { Console.WriteLine("File path specified is invalid"); } } }
public FormMain() { _notifyIcon = new NotifyIcon(); _notifyIcon.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); _notifyIcon.Text = "Buddy"; _notifyIcon.BalloonTipTitle = "Buddy"; _notifyIcon.BalloonTipText = "Buddy is running in the background"; _notifyIcon.ContextMenuStrip = new ContextMenuStrip(); _notifyIcon.ContextMenuStrip.Items.Add("Exit", null, NotifyIconExit_Click); InitializeComponent(); string[] args = Environment.GetCommandLineArgs(); if (args.Length == 1) { MessageBox.Show("Script file not found", "No Script File", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string exePath = args[0]; string scriptFile = args[1]; foreach (string arg in args) { if (arg.Equals("-s")) { _shouldSilentStart = true; } else if (arg.Equals("-o")) { _shouldOutputCompiled = true; } } if (File.Exists(scriptFile)) { if (Path.GetExtension(scriptFile).Equals(".bud")) { string compiledCode = BuddyCompilerLibrary.Compile(scriptFile); if (_shouldOutputCompiled) { using (FileStream fs = new FileStream(Path.Combine(Path.GetDirectoryName(scriptFile), Path.GetFileNameWithoutExtension(scriptFile) + ".buddy"), FileMode.Create)) using (BinaryWriter bw = new BinaryWriter(fs)) { bw.Write(compiledCode); } } BuddyRuntimeLibrary.Run(compiledCode); } else if (Path.GetExtension(scriptFile).Equals(".buddy")) { BuddyRuntimeLibrary.Run(File.ReadAllText(scriptFile)); } else { MessageBox.Show("Only files with the *.bud or *.buddy extensions are executable by this app", "Invalid Executable", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Script file path specified is invalid", "Invalid File Path", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }