Exemple #1
0
        static void Main()
        {
            Application.EnableVisualStyles();

            try
            {
                _pp = new ArgumentParser(Environment.GetCommandLineArgs());
                _pp.AddExpanded("/s", "/silent");
                _pp.AddExpanded("/?", "--help");
                _pp.AddExpanded("/tls", "--tls");

                _pp.Parse();
                _silentMode = _pp.SwitchExists("/silent");

                if (_pp.VersionRequested())
                {
                    ShowVersion();
                    Exit(ExitCode.NoError);
                }

                if (_pp.HelpRequested())
                    ShowHelp();

                if (!IsRunningAsAdministrator())
                {
                    var selfName = Process.GetCurrentProcess().MainModule.FileName;
                    ProcessStartInfo self = new ProcessStartInfo(selfName);
                    self.Verb = "runas";
                    self.WindowStyle = ProcessWindowStyle.Hidden;
                    if (_silentMode) self.Arguments = "/silent";

                    try
                    {
                        Process.Start(self);
                    }
                    catch (Win32Exception)
                    {
                        if (!_silentMode)
                            MessageBox.Show(AppResources.NeedAdmin, AppResources.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);

                        Exit(ExitCode.NoAdmin);
                    }

                    Exit(ExitCode.NoError);
                }

                if ((!_silentMode) && (!IsSystemSupported()))
                {
                    if (MessageBox.Show(AppResources.SystemNotSupported, AppResources.AppName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        Exit(ExitCode.SystemNotSupported);
                }

                if ((_silentMode) || (MessageBox.Show(AppResources.Info, AppResources.AppName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes))
                {
                    var exc = ExitCode.NoError;
                    try
                    {
                        InstallCaCertificate();
                    }
                    catch (CommandException e)
                    {
                        ErrorMessage(AppResources.CertFail, e);
                        exc = ExitCode.CertInstallError;
                    }

                    try
                    {
                        if (_pp.SwitchExists("--tls"))
                            InstallNetworkProfile(ProfileType.Tls);
                        else
                            InstallNetworkProfile(ProfileType.Peap);
                    }
                    catch (CommandException e)
                    {
                        ErrorMessage(AppResources.ProfFail, e);
                        exc = exc | ExitCode.ProfileInstallError;
                    }

                    if (exc == ExitCode.NoError)
                        if (!_silentMode)
                            MessageBox.Show(AppResources.Success, AppResources.AppName, MessageBoxButtons.OK, MessageBoxIcon.Information);

                    Exit(exc);
                }

                Exit(ExitCode.NoError);
            }
            catch (Exception ex)
            {
                ErrorMessage(AppResources.UnhandledException, ex);
                Exit(ExitCode.UnhandledException);
            }
        }