public static void SaveConfig(ConfigClass _config) { Configuration cfg = Configuration.LoadFromFile(configFile); cfg["MAIN"].GetValuesFrom(_config); cfg.SaveToFile("CaptureFS.cfg"); }
/// <summary> /// Creates new config and sets it to default values. /// </summary> private void SetupConfig(SharpConfig.Configuration config) { SetupEntries(config, boolStateConfiguration); SetupEntries(config, boolConfiguration); SetupEntries(config, floatConfiguration); SetupEntries(config, intConfiguration); config.SaveToFile(filename); }
/// <summary> /// Tool Data Save /// </summary> public void ToolDataSave(string _strFileName) { var config = new SharpConfig.Configuration(); config[SAVEDATA_SECTION][SAVEDATA_KEY_INDEX].IntValue = m_Data._iIndex; config[SAVEDATA_SECTION][SAVEDATA_KEY_HORIZONTAL].IntValue = m_Data._iHorizontal; config[SAVEDATA_SECTION][SAVEDATA_KEY_VERTICAL].IntValue = m_Data._iVertical; config[SAVEDATA_SECTION][SAVEDATA_KEY_TOUCHCOUNT].IntValue = m_Data._iTouchCount; config[SAVEDATA_SECTION][SAVEDATA_KEY_PIECE_IMG].IntValueArray = m_Data._iArrayPieceImg; config[SAVEDATA_SECTION][SAVEDATA_KEY_PIECE_ROTATE].IntValueArray = m_Data._iArrayPieceRotate; config.SaveToFile(_strFileName); }
public static void SaveConfigFile() { section["Template"].SetValue(Template); section["OutPutDir"].SetValue(OutPutDir); section["NameSpace"].SetValue(NameSpace); section["ClassSuffix"].SetValue(ClassSuffix); section["FileType"].SetValue(FileType); section["FileEncoding"].SetValue(FileEncoding); section["UnKnowDbType"].SetValue(UnKnowDbType); section["TableComment"].SetValue(TableComment); section["ColumnComment"].SetValue(ColumnComment); section["SqlserverConnectionString"].SetValue(SqlserverConnectionString); section["MysqlConnectionString"].SetValue(MysqlConnectionString); section["SqliteConnectionString"].SetValue(SqliteConnectionString); section["PostgresqlConnectionString"].SetValue(PostgresqlConnectionString); section["OracleConnectionString"].SetValue(OracleConnectionString); config.SaveToFile(configFile); }
private static void CreateLoadConfig() { string username; string password; string databasename; string dbServerip; if (File.Exists(Directory.GetCurrentDirectory() + "\\KoiAnime_Server.cfg")) { var config = SharpConfig.Configuration.LoadFromFile("KoiAnime_Server.cfg"); var databaseSection = config["DATABASE"]; string dbServerIP = databaseSection["DBServerIP"].StringValue; string dbUserName = databaseSection["Username"].StringValue; string dbUserPassword = databaseSection["Password"].StringValue; string dbName = databaseSection["DatabaseName"].StringValue; Properties.Settings.Default.koianimeConnectionString = "server=" + dbServerIP + ";" + "user id=" + dbUserName + ";" + "persistsecurityinfo=False;" + "database=" + dbName + ";" + "password="******"KoiAnime Database Server Configurator v0.1\n--------------------------------\n"); Console.Write("Write your IP address of server: "); dbServerip = Console.ReadLine(); Console.Write("Write your UserName of the Database: "); username = Console.ReadLine(); Console.Write("Write the password of the Username Database: "); password = Console.ReadLine(); Console.Write("Write the name of the Database: "); databasename = Console.ReadLine(); config["DATABASE"]["DBServerIP"].StringValue = dbServerip; config["DATABASE"]["Username"].StringValue = username; config["DATABASE"]["Password"].StringValue = password; config["DATABASE"]["DatabaseName"].StringValue = databasename; config.SaveToFile(Directory.GetCurrentDirectory() + "\\KoiAnime_Server.cfg"); Properties.Settings.Default.koianimeConnectionString = "server=" + dbServerip + ";" + "user id=" + username + ";" + "persistsecurityinfo=False;" + "database=" + databasename + ";" + "password=" + password; Console.Clear(); } }
/// <summary> /// Populate the config with the initial ship data. /// </summary> private void LoadInitialShipList() { try { SharpConfig.Configuration config = GetConfigurationObject(); ShipSection shipSection = ((ShipSection)ConfigurationManager.GetSection("ships")); int id = 0; if (settingsRef.AvailableShips == null) { settingsRef.AvailableShips = string.Empty; } bool noneOwned = string.IsNullOrEmpty(settingsRef.AvailableShips); foreach (ShipConfig ship in shipSection.ShipSettings.Cast <ShipConfig>()) { string sectionName = "Default {0}".With(++id); if (!settingsRef.AvailableShips.Contains(sectionName)) { settingsRef.AvailableShips += ",{0}".With(sectionName); } config[sectionName]["Capacity"].DecimalValue = decimal.TryParse(ship.InitialCapacity, out decimal capacity) ? capacity : 1; config[sectionName]["LadenLY"].DecimalValue = decimal.TryParse(ship.InitialLadenLY, out decimal ladenLy) ? ladenLy : 1; config[sectionName]["unladenLY"].DecimalValue = decimal.TryParse(ship.InitialUnladenLY, out decimal unladenLy) ? unladenLy : 1; config[sectionName]["shipName"].StringValue = ship.Name; config[sectionName]["Padsizes"].StringValue = ship.PadSizes; config[sectionName]["shipType"].StringValue = ship.ShipType; if (noneOwned && ship.Name.Equals("Sidewinder")) { settingsRef.LastUsedConfig = sectionName; } } config.SaveToFile(configFile); settingsRef.AvailableShips = settingsRef.AvailableShips.Trim(new char[] { ',' }); } catch (Exception ex) { Debug.WriteLine(ex.GetFullMessage()); } }
/// <summary> /// Save the settings to the ini file. /// </summary> public static void SaveSettingsToIniFile() { SharpConfig.Configuration config = GetConfigurationObject(); TDSettings settings = settingsRef; SharpConfig.Section configSection = config["App"]; // Settgins used for trade route calculation. configSection["Age"].DecimalValue = settings.Age; configSection["Avoid"].StringValue = settings.Avoid ?? string.Empty; configSection["BlackMarket"].BoolValue = settings.BlackMarket; configSection["Direct"].BoolValue = settings.Direct; configSection["Demand"].DecimalValue = settings.Demand; configSection["EndJumps"].DecimalValue = settings.EndJumps; configSection["ExtraRunParams"].StringValue = settings.ExtraRunParams ?? string.Empty; configSection["GPT"].DecimalValue = settings.GPT; configSection["Hops"].DecimalValue = settings.Hops; configSection["IncludeInsurance"].BoolValue = settings.IncludeInsurance; configSection["Jumps"].DecimalValue = settings.Jumps; configSection["Limit"].DecimalValue = settings.Limit; configSection["Loop"].BoolValue = settings.Loop; configSection["LoopInt"].DecimalValue = settings.LoopInt; configSection["LSPenalty"].DecimalValue = settings.LSPenalty; configSection["Margin"].DecimalValue = settings.Margin; configSection["MarkedStations"].StringValue = settings.MarkedStations ?? string.Empty; configSection["MaxGPT"].DecimalValue = settings.MaxGPT; configSection["MaxLSDistance"].DecimalValue = settings.MaxLSDistance; configSection["NumberOfRoutes"].DecimalValue = settings.NumberOfRoutes; configSection["Planetary"].StringValue = settings.Planetary ?? string.Empty; configSection["PruneHops"].DecimalValue = settings.PruneHops; configSection["PruneScore"].DecimalValue = settings.PruneScore; configSection["Shorten"].BoolValue = settings.Shorten; configSection["ShowJumps"].BoolValue = settings.ShowJumps; configSection["ShowProgress"].BoolValue = settings.ShowProgress; configSection["StartJumps"].DecimalValue = settings.StartJumps; configSection["Stock"].DecimalValue = settings.Stock; configSection["Summary"].BoolValue = settings.Summary; configSection["Towards"].BoolValue = settings.Towards; configSection["Unique"].BoolValue = settings.Unique; configSection["Verbosity"].DecimalValue = settings.Verbosity; configSection["Via"].StringValue = settings.Via ?? string.Empty; // Commander settings configSection = config["Commander"]; configSection["CmdrName"].StringValue = settings.CmdrName ?? string.Empty; configSection["Credits"].DecimalValue = settings.Credits; configSection["RebuyPercentage"].DecimalValue = settings.RebuyPercentage; // TD Helper system settings. configSection = config["System"]; configSection["AvailableShips"].StringValue = settings.AvailableShips ?? string.Empty; configSection["CopySystemToClipboard"].BoolValue = settings.CopySystemToClipboard; configSection["DisableNetLogs"].BoolValue = settings.DisableNetLogs; configSection["DoNotUpdate"].BoolValue = settings.DoNotUpdate; configSection["HasUpdated"].BoolValue = settings.HasUpdated; configSection["ImportPath"].StringValue = settings.ImportPath ?? string.Empty; configSection["LastUsedConfig"].StringValue = settings.LastUsedConfig ?? string.Empty; configSection["Locale"].StringValue = settings.Locale ?? string.Empty; configSection["LocationChild"].StringValue = settings.LocationChild ?? string.Empty; configSection["LocationParent"].StringValue = settings.LocationParent ?? string.Empty; configSection["MiniModeOnTop"].BoolValue = settings.MiniModeOnTop; configSection["NetLogPath"].StringValue = settings.NetLogPath ?? string.Empty; configSection["PythonPath"].StringValue = settings.PythonPath ?? string.Empty; configSection["Quiet"].BoolValue = settings.Quiet; configSection["SizeChild"].StringValue = settings.SizeChild ?? string.Empty; configSection["SizeParent"].StringValue = settings.SizeParent ?? string.Empty; configSection["TDVersion"].StringValue = settings.TDVersion ?? string.Empty; configSection["TestSystems"].BoolValue = settings.TestSystems; configSection["TimeOut"].IntValue = settings.TimeOut; configSection["TreeViewFont"].StringValue = settings.TreeViewFont ?? string.Empty; configSection["UploadPath"].StringValue = settings.UploadPath ?? string.Empty; configSection = config["EDDBlink"]; configSection["SkipVend"].BoolValue = settings.SkipVend; configSection["Solo"].BoolValue = settings.Solo; // Update the current ship if required. if (!string.IsNullOrEmpty(settings.LastUsedConfig)) { string sectionName = settings.LastUsedConfig; bool hasSection = config.FirstOrDefault(x => x.Name == sectionName) != null; if (hasSection) { if (config[sectionName]["Capacity"].DecimalValue != settings.Capacity) { config[sectionName]["Capacity"].DecimalValue = settings.Capacity; } if (config[sectionName]["LadenLY"].DecimalValue != settings.LadenLY) { config[sectionName]["LadenLY"].DecimalValue = settings.LadenLY; } if (config[sectionName]["Padsizes"].StringValue != settings.Padsizes) { config[sectionName]["Padsizes"].StringValue = settings.Padsizes; } if (config[sectionName]["UnladenLY"].DecimalValue != settings.UnladenLY) { config[sectionName]["UnladenLY"].DecimalValue = settings.UnladenLY; } } else { config[sectionName]["Capacity"].DecimalValue = settings.Capacity; config[sectionName]["LadenLY"].DecimalValue = settings.LadenLY; config[sectionName]["Padsizes"].StringValue = settings.Padsizes; config[sectionName]["UnladenLY"].DecimalValue = settings.UnladenLY; } } config.SaveToFile(configFile); }
private void start_button_Click(object sender, RoutedEventArgs e) { if (isRunning == false) { int tmpInt; var section = config["General"]; section["LocalHost"].StringValue = localHostTextBox.Text.Trim(); section["LocalPort"].IntValue = (int.TryParse(localPortTextBox.Text, out tmpInt)) ? tmpInt : 7070; section["HttpHost"].StringValue = httpHostTextBox.Text.Trim(); section["HttpPort"].IntValue = (int.TryParse(httpPortTextBox.Text, out tmpInt)) ? tmpInt : 7080; section["RemoteHost"].StringValue = remoteHostTextBox.Text.Trim(); section["RemotePort"].IntValue = (int.TryParse(remotePortTextBox.Text, out tmpInt)) ? tmpInt : 22; section["PrivateFilePath"].StringValue = privateFilePathTextBox.Text.Trim(); config.SaveToFile(App.TempDir + "\\" + ConfigFileName); string plinkPath = App.TempDir + "\\" + "plink.exe"; if (!File.Exists(plinkPath)) { var stream = File.Create(plinkPath); var data = TinyTunnel.Properties.Resources.plink; stream.Write(data, 0, data.Length); stream.Close(); } string privateFilePath = App.TempDir + "\\" + section["PrivateFilePath"].StringValue; if (!File.Exists(privateFilePath)) { notifyIcon.ShowBalloonTip(5000, section["PrivateFilePath"].StringValue + " not found", "Please click \"Gen\" to generate a private key file and save it to (" + privateFilePath + ")", ToolTipIcon.Info); return; } string cowPath = App.TempDir + "\\" + "cow.exe"; if (!File.Exists(cowPath)) { var stream = File.Create(cowPath); var data = TinyTunnel.Properties.Resources.cow; stream.Write(data, 0, data.Length); stream.Close(); } string cowRcPath = App.TempDir + "\\" + "rc.txt"; { var writer = new StreamWriter(cowRcPath, false); writer.WriteLine(String.Format("listen = http://{0}:{1}", section["HttpHost"].StringValue, section["HttpPort"].StringValue)); writer.WriteLine(String.Format("proxy = socks5://{0}:{1}", section["LocalHost"].StringValue, section["LocalPort"].StringValue)); writer.Flush(); writer.Close(); } if (test_tunnel()) { start_tunnel(); } else { notifyIcon.ShowBalloonTip(5000, "Tunnel connect test failed!", "Can not connect to tunnel, please check your remote host and local configuration.", ToolTipIcon.Error); } } else { close_tunnel(); } }