SaveSettings() public method

public SaveSettings ( ) : void
return void
Esempio n. 1
0
        private bool network_ReceivedKey(Network network, ReceivedKeyEventArgs args)
        {
            try {
                var             publicKey = new PublicKey(args.Key.Info, args.Key.Key);
                TrustedNodeInfo nodeInfo  = new TrustedNodeInfo(publicKey);

                if (args.Node != null)
                {
                    nodeInfo.Identifier = args.Node.NickName;
                }
                else
                {
                    nodeInfo.Identifier = nodeInfo.NodeID;
                }

                // First person to connect? Put them in charge!
                if (network.TrustedNodes.Count == 0)
                {
                    LogItem(String.Format("[!] WARNING! {0} is now the admin!", publicKey.Nickname));
                    if (!settings.AdminIDs.Contains(nodeInfo.NodeID))
                    {
                        settings.AdminIDs.Add(nodeInfo.NodeID);
                        settings.SaveSettings();
                    }
                    return(true);
                }

                // Don't accept the key now, but keep it around
                string keyDir  = GetKeyDir(network);
                string keyFile = GetKeyFileName(network, nodeInfo.NodeID);
                if (IO.File.Exists(keyFile) == false)
                {
                    if (IO.Directory.Exists(keyDir) == false)
                    {
                        IO.Directory.CreateDirectory(keyDir);
                    }
                    IO.File.WriteAllText(keyFile, publicKey.ToArmoredString());
                }
            } catch (Exception ex) {
                Core.LoggingService.LogError("Error in network_ReceivedKey: " + ex);
            }
            return(false);
        }
Esempio n. 2
0
        public SettingsCreator(string fileName)
        {
            // Create settings file
            Settings settings = new Settings();

            settings.FileName = fileName;

            Console.Write("NickName = ");
            settings.NickName = Console.ReadLine();

            Console.Write("\nReal Name = ");
            settings.RealName = Console.ReadLine();

            Console.Write("\nGenerating keypair....");

            System.Security.Cryptography.RSACryptoServiceProvider newKey;
            newKey = new System.Security.Cryptography.RSACryptoServiceProvider(2048);
            settings.SetKey(newKey.ToXmlString(true));

            Console.Write("Done!\n\nNow you need to define a network.\n\n");

            NetworkInfo networkInfo = new NetworkInfo();

            Console.Write("Network Name = ");
            networkInfo.NetworkName = Console.ReadLine();

            settings.Networks.Add(networkInfo);

            Console.WriteLine("All done, saving settings now!");

            if (fileName.IndexOf(Path.DirectorySeparatorChar) > -1)
            {
                settings.DataPath = fileName.Substring(0, fileName.LastIndexOf(Path.DirectorySeparatorChar));
            }
            else
            {
                settings.DataPath = Environment.CurrentDirectory;
            }

            settings.SaveSettings();

            Console.WriteLine("WARNING: The first person who connects to me will become the admin!");
        }
Esempio n. 3
0
        public SettingsCreator(string fileName)
        {
            // Create settings file
            Settings settings = new Settings ();
            settings.FileName = fileName;

            Console.Write("NickName = ");
            settings.NickName = Console.ReadLine();

            Console.Write("\nReal Name = ");
            settings.RealName = Console.ReadLine();

            Console.Write("\nGenerating keypair....");

            System.Security.Cryptography.RSACryptoServiceProvider newKey;
            newKey = new System.Security.Cryptography.RSACryptoServiceProvider (2048);
            settings.SetKey(newKey.ToXmlString(true));

            Console.Write("Done!\n\nNow you need to define a network.\n\n");

            NetworkInfo networkInfo = new NetworkInfo();

            Console.Write("Network Name = ");
            networkInfo.NetworkName = Console.ReadLine();

            settings.Networks.Add(networkInfo);

            Console.WriteLine("All done, saving settings now!");

            if (fileName.IndexOf(Path.DirectorySeparatorChar) > -1) {
                settings.DataPath = fileName.Substring(0, fileName.LastIndexOf(Path.DirectorySeparatorChar));
            } else {
                settings.DataPath = Environment.CurrentDirectory;
            }

            settings.SaveSettings();

            Console.WriteLine("WARNING: The first person who connects to me will become the admin!");
        }