private void btnReIssueProfile_Click(object sender, EventArgs e) { if (MessageBox.Show("Reissuing a profile certificate will allow you register again with the same email address and change your information in the profile certificate while keeping all your profile settings intact.\r\n\r\nAre you sure you want to reissue the selected profile?\r\n\r\nWARNING! This will revoke the previously issued profile certificate however, your settings will remain intact.", "Reissue Profile Certificate?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes) { this.Hide(); _profileFilePath = Path.Combine(_localAppData, (lstProfiles.SelectedItem as string) + ".profile"); using (frmPassword frm = new frmPassword(_profileFilePath)) { if (frm.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { _profile = frm.Profile; using (frmRegister frmReg = new frmRegister(_localAppData, _profile, _profileFilePath, true)) { if (frmReg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { _profile = frmReg.Profile; _profileFilePath = frmReg.ProfileFilePath; string profileName = Path.GetFileNameWithoutExtension(_profileFilePath); lstProfiles.SelectedItem = profileName; } } } } this.Show(); } }
private void frmRegisterNow_Click(object sender, EventArgs e) { this.Hide(); using (frmRegister frm = new frmRegister(_localAppData)) { DialogResult result = frm.ShowDialog(this); switch (result) { case System.Windows.Forms.DialogResult.OK: _profile = frm.Profile; _profileFilePath = frm.ProfileFilePath; this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); break; case System.Windows.Forms.DialogResult.Ignore: this.Show(); break; default: this.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.Close(); break; } } }
private void btnNewProfile_Click(object sender, EventArgs e) { this.Hide(); using (frmRegister frm = new frmRegister(_localAppData)) { if (frm.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { _profile = frm.Profile; _profileFilePath = frm.ProfileFilePath; string profileName = Path.GetFileNameWithoutExtension(_profileFilePath); lstProfiles.Items.Add(profileName); lstProfiles.SelectedItem = profileName; } } this.Show(); }
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); } }
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); } }