12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- namespace ISCSIConsole
- {
- public partial class Program
- {
-
-
-
- [STAThread]
- static void Main(string[] args)
- {
- Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
- AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
- if (args.Length > 0)
- {
- if (args[0] == "/help")
- {
-
- }
- if (args[0] == "/log")
- {
- string path = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
- if (!path.EndsWith(@"\"))
- {
- path += @"\";
- }
- path += String.Format("Log {0}.txt", DateTime.Now.ToString("yyyy-MM-dd HH-mm"));
- bool success = OpenLogFile(path);
- if (!success)
- {
- MessageBox.Show("Cannot open log file", "Error");
- }
- }
- else
- {
- StringBuilder builder = new StringBuilder();
- builder.AppendLine("Command line arguments:");
- builder.AppendLine("/log - will write log file to executable directory");
- MessageBox.Show(builder.ToString(), "Error");
- return;
- }
- }
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new MainForm());
- }
- public static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
- {
- HandleUnhandledException(e.Exception);
- }
- private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- if (e.ExceptionObject != null)
- {
- Exception ex = (Exception)e.ExceptionObject;
- HandleUnhandledException(ex);
- }
- }
- private static void HandleUnhandledException(Exception ex)
- {
- string message = String.Format("Exception: {0}: {1} Source: {2} {3}", ex.GetType(), ex.Message, ex.Source, ex.StackTrace);
- MessageBox.Show(message, "Error");
- Application.Exit();
- }
- }
- }
|