Esempio n. 1
0
        public static void Main(string[] args)
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                #region check for multiple instances

                bool createdNewMutex;

                _app = new Mutex(true, MUTEX_NAME, out createdNewMutex);

                if (!createdNewMutex)
                {
                    AppLink.SendCommand(string.Join(" ", args), APP_LINK_PORT);
                    return;
                }

                #endregion

                string appPath = Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "").Replace("/", "\\");

                #region check for admin priviledge

                if (!(new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator))
                {
                    ProcessStartInfo processInfo = new ProcessStartInfo(appPath, string.Join(" ", args));

                    processInfo.UseShellExecute = true;
                    processInfo.Verb = "runas";

                    try
                    {
                        Process.Start(processInfo);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Technitium Bit Chat requires administrative privileges to run. You will need to contact your system administrator to run this application.", "Cannot Start Bit Chat", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    return;
                }

                #endregion

                #region load trusted certificates

                TRUSTED_CERTIFICATES = new Certificate[1];

                using (MemoryStream mS = new MemoryStream(Convert.FromBase64String(_rootCert)))
                {
                    TRUSTED_CERTIFICATES[0] = new Certificate(mS);
                }

                #endregion

                #region profile manager

                bool loaded = false;

                //read local app data folder
                string localAppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Technitium", "BitChat");

                if (!Directory.Exists(localAppData))
                    Directory.CreateDirectory(localAppData);

                while (true)
                {
                    frmProfileManager mgr = new frmProfileManager(localAppData, loaded);

                    if (mgr.ShowDialog() == DialogResult.OK)
                    {
                        loaded = true;

                        try
                        {
                            if (mgr.Profile != null)
                            {
                                bool loadMainForm = false;

                                if ((mgr.Profile.LocalCertificateStore.Certificate.Type == CertificateType.Normal) && (mgr.Profile.LocalCertificateStore.Certificate.Capability == CertificateCapability.KeyExchange))
                                {
                                    loadMainForm = true;
                                }
                                else
                                {
                                    using (frmRegister frm = new frmRegister(localAppData, mgr.Profile, mgr.ProfileFilePath, false))
                                    {
                                        loadMainForm = (frm.ShowDialog() == DialogResult.OK);
                                    }
                                }

                                if (loadMainForm)
                                {
                                    using (frmMain frm = new frmMain(mgr.Profile, mgr.ProfileFilePath, string.Join(" ", args)))
                                    {
                                        Application.Run(frm);

                                        if (frm.DialogResult != DialogResult.Ignore)
                                            break;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error! " + ex.Message, "Error - Bit Chat Profile Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error! " + ex.Message + "\r\n\r\nClick OK to quit the application.", "Error - Bit Chat", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                #region check for multiple instances

                bool createdNewMutex;

                _app = new Mutex(true, MUTEX_NAME, out createdNewMutex);

                if (!createdNewMutex)
                {
                    AppLink.SendCommand(string.Join(" ", args), APP_LINK_PORT);
                    return;
                }

                #endregion

                string appPath = Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "").Replace("/", "\\");

                #region check for admin priviledge

                if (!(new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator))
                {
                    ProcessStartInfo processInfo = new ProcessStartInfo(appPath, string.Join(" ", args));

                    processInfo.UseShellExecute = true;
                    processInfo.Verb            = "runas";

                    try
                    {
                        Process.Start(processInfo);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Technitium Bit Chat requires administrative privileges to run. You will need to contact your system administrator to run this application.", "Cannot Start Bit Chat", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    return;
                }

                #endregion

                #region load trusted certificates

                TRUSTED_CERTIFICATES = new Certificate[1];

                using (MemoryStream mS = new MemoryStream(Convert.FromBase64String(_rootCert)))
                {
                    TRUSTED_CERTIFICATES[0] = new Certificate(mS);
                }

                #endregion

                #region profile manager

                bool loaded = false;

                //read local app data folder
                string localAppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Technitium", "BitChat");

                if (!Directory.Exists(localAppData))
                {
                    Directory.CreateDirectory(localAppData);
                }

                while (true)
                {
                    frmProfileManager mgr = new frmProfileManager(localAppData, loaded);

                    if (mgr.ShowDialog() == DialogResult.OK)
                    {
                        loaded = true;

                        try
                        {
                            if (mgr.Profile != null)
                            {
                                bool loadMainForm = false;

                                if ((mgr.Profile.LocalCertificateStore.Certificate.Type == CertificateType.Normal) && (mgr.Profile.LocalCertificateStore.Certificate.Capability == CertificateCapability.KeyExchange))
                                {
                                    loadMainForm = true;
                                }
                                else
                                {
                                    using (frmRegister frm = new frmRegister(localAppData, mgr.Profile, mgr.ProfileFilePath, false))
                                    {
                                        loadMainForm = (frm.ShowDialog() == DialogResult.OK);
                                    }
                                }

                                if (loadMainForm)
                                {
                                    using (frmMain frm = new frmMain(mgr.Profile, mgr.ProfileFilePath, string.Join(" ", args)))
                                    {
                                        Application.Run(frm);

                                        if (frm.DialogResult != DialogResult.Ignore)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error! " + ex.Message, "Error - Bit Chat Profile Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error! " + ex.Message + "\r\n\r\nClick OK to quit the application.", "Error - Bit Chat", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }