Converting Static Data Dump Into LavishSettings

GliderPro

Active Member
Here is an example of converting the MS SQL data from CCP into a LavishSettings file using C#.

Code:
string connectionString = GetConnectionString();
using (SqlConnection connection = new SqlConnection(connectionString))
{
	connection.Open();
	connection.ChangeDatabase("trinity_1.0");
	SqlCommand command = connection.CreateCommand();
	command.CommandText = "SELECT stationID, solarSystemID, stationName FROM staStations";
	SqlDataReader reader = command.ExecuteReader();

	Console.WriteLine("<?xml version='1.0' encoding='UTF-8'?>");
	Console.WriteLine("<!-- Generated by LavishSettings v2 -->");
	Console.WriteLine("<InnerSpaceSettings>");
	Console.WriteLine("\t<Set Name=\"Stations\">");

	while (reader.Read())
	{
		Int32 stationID, solarSystemID;
		String stationName;

		try
		{
			stationID = (Int32)reader[0];
		}
		catch (InvalidCastException ex)
		{
			stationID = -1;
		}

		try
		{
			solarSystemID = (Int32)reader[1];
		}
		catch (InvalidCastException ex)
		{
			solarSystemID = -1;
		}

		try
		{
			stationName = (String)reader[2];
		}
		catch (InvalidCastException ex)
		{
			stationName = "";
		}

		Console.WriteLine(String.Format("\t\t<Set Name=\"{0}\">", stationID));
		Console.WriteLine(String.Format("\t\t\t<Setting Name=\"solarSystemID\">{0}</Setting>",
			solarSystemID));
		Console.WriteLine(String.Format("\t\t\t<Setting Name=\"stationName\">{0}</Setting>",
			stationName.TrimEnd()));
		Console.WriteLine("\t\t</Set>");
	}

	// Call Close when done reading.
	reader.Close();

	Console.WriteLine("\t</Set>");
	Console.WriteLine("</InnerSpaceSettings>");
}
 
Top Bottom