コード例 #1
0
ファイル: Program.cs プロジェクト: JamesMcWhinney/inSSIDer-2
        static void Main(string[] args)
        {
            Debug.WriteLine("inSSIDer 2 version " + Application.ProductVersion + " Starting");
            //TODO: Make conmmand line option to enable logging on debug builds. Like /log
            #if DEBUG && LOG
            Log.Start();
            #endif
            Debug.WriteLine("Hook exception handlers");
            // Create new instance of UnhandledExceptionDlg:
            // NOTE: this hooks up the exception handler functions
            UnhandledExceptionDlg exDlg = new UnhandledExceptionDlg();
            InitializeExceptionHandler(exDlg);

            Debug.WriteLine("Check .NET configuration system");
            //Check for config system condition here
            if(!Settings.Default.CheckSettingsSystem())
            {
                //The settings system is broken, notify and exit
                MessageBox.Show(
                    Localizer.GetString("ConfigSystemError"),
                    "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            #if DEBUG && LOG
            frmTest ft = new frmTest();
            Thread debugThread = new Thread(() => Application.Run(ft));
            debugThread.Start();
            #endif

            //Initialize the scanner object before passing it to any interface
            ScanController scanner = new ScanController();
            Exception error;

            Debug.WriteLine("Initialize ScanController");
            scanner.Initialize(out error);
            if (error != null)
            {
                //An error!
                scanner.Dispose();
                scanner = null;
                //So the error handler will catch it
                //throw ex;

                //Log it
                Log.WriteLine(string.Format("Exception message:\r\n\r\n{0}\r\n\r\nStack trace:\r\n{1}", error.Message, error.StackTrace));

                if (error is System.ComponentModel.Win32Exception)
                {
                    //The wireless system failed
                    if (Utilities.IsXp())
                    {
                        MessageBox.Show(Localizer.GetString("WlanServiceNotFoundXP"), "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Hand);
                    }
                    else
                    {
                        MessageBox.Show(Localizer.GetString("WlanServiceNotFound7"), "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Hand);
                    }
                }
                else
                {
                    //Any other exceptions
                    MessageBox.Show(error.Message, "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Hand);
                }
            }

            if (scanner == null) return;

            //Start the scanning if it was last time and we have the last interface
            //Otherwise, if we only have the interface, but not scanning, just set the interface selector to the last interface.
            //TODO: Actually have the auto-start as an option. :)

            NetworkInterface netInterface = InterfaceManager.Instance.LastInterface;
            if (netInterface != null)
            {
                Debug.WriteLine("We have a last interface, start scanning with it.");
                //Set the interface
                scanner.Interface = netInterface;
                if (Settings.Default.scanLastEnabled)
                    scanner.StartScanning();
            }

            //The main form will run unless mini is specified
            IScannerUi form = null;

            Switching = Settings.Default.lastMini ? Utilities.SwitchMode.ToMini : Utilities.SwitchMode.ToMain;

            //if(Settings.Default.lastMini)
            //{
            //    Switching = Utilities.SwitchMode.ToMini;
            //    form = new FormMini();
            //    SettingsMgr.ApplyMiniFormSettings((Form)form);
            //}
            //else
            //{
            //    Switching = Utilities.SwitchMode.ToMain;
            //    form = new FormMain();
            //    SettingsMgr.ApplyMainFormSettings((Form)form);
            //}

            //Apply settings now
            SettingsMgr.ApplyGpsSettings(scanner.GpsControl);

            do
            {
                //Check for switching
                switch (Switching)
                {
                    case Utilities.SwitchMode.None:
                        //We're not switching, close program
                        break;
                    case Utilities.SwitchMode.ToMain:
                        //We're switching to the main form
                        Debug.WriteLine("Switch to main form");
                        form = new FormMain(scanner);
                        SettingsMgr.ApplyMainFormSettings((Form)form);
                        break;
                    case Utilities.SwitchMode.ToMini:
                        //We're switching to the mini form
                        Debug.WriteLine("Switch to mini form");
                        form = new FormMini();
                        SettingsMgr.ApplyMiniFormSettings((Form)form);
                        break;
                }
                LastSwitch = Switching;
                //If we've switched, we don't need to get stuck in a loop
                Switching = Utilities.SwitchMode.None;

                form.Initalize(ref scanner);
                try
                {
                    Application.Run(form as Form);
                }
                catch (ObjectDisposedException)
                {

                }
                catch (AccessViolationException)
                {
                    Debug.WriteLine("AccessViolationException, attempt to recover");
                    if (Application.VisualStyleState == System.Windows.Forms.VisualStyles.VisualStyleState.NonClientAreaEnabled)
                        throw;
                    // This could be caused by visual styles
                    Application.VisualStyleState = System.Windows.Forms.VisualStyles.VisualStyleState.NonClientAreaEnabled;
                    // Trigger restart
                    Switching = LastSwitch;//Utilities.SwitchMode.ToMain;
                }

            } while (Switching != Utilities.SwitchMode.None);

            Settings.Default.lastMini = form.GetType() == typeof(FormMini);

            if(scanner.GpsControl != null)
            //GPS enabled setting
            Settings.Default.gpsEnabled = scanner.GpsControl.Enabled;

            // Save Filters

            //Save settings before exit
            Settings.Default.Save();

            //Dispose the scanner, we're done with it
            scanner.Dispose();

            Debug.WriteLine("Execution Finished, you may now close this window", "Program.Main()");
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ashokgelal/inSSIDer-2
        static void Main(string[] args)
        {
            //TODO: Make conmmand line option to enable logging on debug builds. Like /log
            #if DEBUG && LOG
            Log.Start();
            #endif
            // Create new instance of UnhandledExceptionDlg:
            // NOTE: this hooks up the exception handler functions
            UnhandledExceptionDlg exDlg = new UnhandledExceptionDlg();
            InitializeExceptionHandler(exDlg);

            //Check for config system condition here
            if(!Settings.Default.CheckSettingsSystem())
            {
                //The settings system is broken, notify and exit
                MessageBox.Show(
                    Localizer.GetString("ConfigSystemError"),
                    "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //Initalize the scanner object before passing it to any interface
            ScanController scanner = new ScanController();
            Exception error;

            scanner.Initalize(out error);
            if (error != null)
            {
                //An error!
                scanner.Dispose();
                scanner = null;
                //So the error handler will catch it
                //throw ex;

                //Log it
                Log.WriteLine(string.Format("Exception message:\r\n\r\n{0}\r\n\r\nStack trace:\r\n{1}", error.Message, error.StackTrace));

                if (error is System.ComponentModel.Win32Exception)
                {
                    //The wireless system failed
                    if (Utilities.IsXp())
                    {
                        MessageBox.Show(Localizer.GetString("WlanServiceNotFoundXP"), "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Hand);
                    }
                    else
                    {
                        MessageBox.Show(Localizer.GetString("WlanServiceNotFound7"), "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Hand);
                    }
                }
                else
                {
                    //Any other exceptions
                    MessageBox.Show(error.Message, "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Hand);
                }
            }

            if (scanner == null) return;

            //Start the scanning if it was last time and we have the last interface
            //Otherwise, if we only have the interface, but not scanning, just set the interface selector to the last interface.
            //TODO: Actually have the auto-start as an option. :)

            NetworkInterface netInterface = InterfaceManager.Instance.LastInterface;
            if (netInterface != null)
            {
                //Set the interface
                scanner.Interface = netInterface;
                if (Settings.Default.scanLastEnabled)
                    scanner.StartScanning();
            }

            //The main form will run unless mini is specified
            IScannerUi form;

            if(Settings.Default.lastMini)
            {
                form = new FormMini();
                SettingsMgr.ApplyMiniFormSettings((Form)form);
            }
            else
            {
                form = new FormMain();
                SettingsMgr.ApplyMainFormSettings((Form)form);
            }

            //Apply settings now
            SettingsMgr.ApplyGpsSettings(scanner.GpsControl);

            //Start GPS if it was started last time

            do
            {
                //Check for switching
                switch (Switching)
                {
                    case Utilities.SwitchMode.None:
                        //We're not switching, close program
                        break;
                    case Utilities.SwitchMode.ToMain:
                        //We're switching to the main form
                        form = new FormMain();
                        SettingsMgr.ApplyMainFormSettings((Form)form);
                        break;
                    case Utilities.SwitchMode.ToMini:
                        //We're switching to the mini form
                        form = new FormMini();
                        SettingsMgr.ApplyMiniFormSettings((Form)form);
                        break;
                }
                //If we've switched, we don't need to get stuck in a loop
                Switching = Utilities.SwitchMode.None;

                form.Initalize(ref scanner);
                try
                {
                    Application.Run(form as Form);
                }
                catch (ObjectDisposedException)
                {

                }

            } while (Switching != Utilities.SwitchMode.None);

            Settings.Default.lastMini = form.GetType() == typeof(FormMini);

            //GPS enabled setting
            Settings.Default.gpsEnabled = scanner.GpsControl.Enabled;

            //Save settings before exit
            Settings.Default.Save();

            //Dispose the scanner, we're done with it
            scanner.Dispose();
        }