示例#1
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            //load chats and ui views
            lblUserName.Text = _profile.LocalCertificateStore.Certificate.IssuedTo.Name;

            foreach (BitChat chat in _service.GetBitChatList())
            {
                AddChatView(chat);
            }

            lstChats.SelectItem(lstChats.GetFirstItem());
            ShowSelectedChatView();

            //load settings
            bool loadDefaultSettings = true;

            if (_profile.ClientData != null)
            {
                try
                {
                    LoadProfileSettings(_profile.ClientData);
                    loadDefaultSettings = false;
                }
                catch
                { }
            }

            if (loadDefaultSettings)
            {
                this.Width  = 960;
                this.Height = 540;

                Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;

                this.Left = workingArea.Width - workingArea.Left - this.Width - 20;
                this.Top  = 100;
            }

            //create AppLink
            _link = new AppLink(Program.APP_LINK_PORT);
            _link.CommandReceived += _link_CommandReceived;

            //if (_cmdLine != null)
            //    _link_CommandReceived(_cmdLine);


            //start automatic update client
            _updateClient = new AutomaticUpdateClient(Program.MUTEX_NAME, Application.ProductVersion, Program.UPDATE_URI, Program.UPDATE_CHECK_INTERVAL_DAYS, Program.TRUSTED_CERTIFICATES, _lastUpdateCheckedOn, _lastModifiedGMT);
            _updateClient.ExitApplication   += _updateClient_ExitApplication;
            _updateClient.UpdateAvailable   += _updateClient_UpdateAvailable;
            _updateClient.NoUpdateAvailable += _updateClient_NoUpdateAvailable;
            _updateClient.UpdateError       += _updateClient_UpdateError;


            //show tray icon
            notifyIcon1.Visible = true;
        }
示例#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);
            }
        }
示例#3
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            //load chats and ui views
            lblUserName.Text = _profile.LocalCertificateStore.Certificate.IssuedTo.Name;

            foreach (BitChat chat in _service.GetBitChatList())
                AddChatView(chat);

            lstChats.SelectItem(lstChats.GetFirstItem());
            ShowSelectedChatView();

            //load settings
            bool loadDefaultSettings = true;

            if (_profile.ClientData != null)
            {
                try
                {
                    LoadProfileSettings(_profile.ClientData);
                    loadDefaultSettings = false;
                }
                catch
                { }
            }

            if (loadDefaultSettings)
            {
                this.Width = 960;
                this.Height = 540;

                Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;

                this.Left = workingArea.Width - workingArea.Left - this.Width - 20;
                this.Top = 100;
            }

            //create AppLink
            _link = new AppLink(Program.APP_LINK_PORT);
            _link.CommandReceived += _link_CommandReceived;

            //if (_cmdLine != null)
            //    _link_CommandReceived(_cmdLine);

            //start automatic update client
            _updateClient = new AutomaticUpdateClient(Program.MUTEX_NAME, Application.ProductVersion, Program.UPDATE_URI, Program.UPDATE_CHECK_INTERVAL_DAYS, Program.TRUSTED_CERTIFICATES, _lastUpdateCheckedOn, _lastModifiedGMT);
            _updateClient.ExitApplication += _updateClient_ExitApplication;
            _updateClient.UpdateAvailable += _updateClient_UpdateAvailable;
            _updateClient.NoUpdateAvailable += _updateClient_NoUpdateAvailable;
            _updateClient.UpdateError += _updateClient_UpdateError;

            //show tray icon
            notifyIcon1.Visible = true;
        }