Exemplo n.º 1
0
        private void CreateAndStartProfile()
        {
            if (_createProfileWindowShown)
            {
                return;
            }

            _createProfileWindowShown = true;

            using (frmCreateProfile frm = new frmCreateProfile())
            {
                frm.Activate();

                if (frm.ShowDialog(this) == DialogResult.OK)
                {
                    int localServicePort;

                    if (frm.NodeType == MeshNodeType.P2P)
                    {
                        localServicePort = (new Random()).Next(10000, 65000); //fixed random port for p2p
                    }
                    else
                    {
                        localServicePort = 0; //new random port at startup for Tor node
                    }
                    MeshNode node = new MeshNode(frm.NodeType, frm.PrivateKey, SecureChannelCipherSuite.DHE2048_RSA2048_WITH_AES256_CBC_HMAC_SHA256, Convert.ToUInt16(localServicePort), frm.ProfileDisplayName, _profileFolder, GetDownloadFolder(), _torController);

                    if (frm.NodeType == MeshNodeType.P2P)
                    {
                        //create default local network group for LAN user discovery
                        node.CreateGroupChat("Local Network", "", true);
                    }

                    string profileFilePath = Path.Combine(_profileFolder, frm.ProfileDisplayName + ".profile");

                    using (FileStream fS = new FileStream(profileFilePath, FileMode.Create, FileAccess.ReadWrite))
                    {
                        node.ChangePassword(frm.ProfilePassword);
                        node.SaveTo(fS);
                    }

                    LoadProfileMainForm(frm.ProfileDisplayName, node, profileFilePath);
                }
                else
                {
                    if (cmbProfiles.Items.Count > 0)
                    {
                        this.Show();
                        this.Activate();
                    }
                }
            }

            _createProfileWindowShown = false;
        }
Exemplo n.º 2
0
        private void SaveProfile()
        {
            //write profile in tmp file
            using (FileStream fS = new FileStream(_profileFilePath + ".tmp", FileMode.Create, FileAccess.ReadWrite, FileShare.None))
            {
                _node.AppData = SaveProfileSettings();
                _node.SaveTo(fS);
            }

            File.Delete(_profileFilePath + ".bak");                 //remove old backup file
            File.Move(_profileFilePath, _profileFilePath + ".bak"); //make current profile file as backup file
            File.Move(_profileFilePath + ".tmp", _profileFilePath); //make tmp file as profile file
        }