public static void NewConnections(string filename)
{
try
{
var connectionsLoader = new ConnectionsLoader();
if (filename == GetDefaultStartupConnectionFileName())
{
Settings.Default.LoadConsFromCustomLocation = false;
}
else
{
Settings.Default.LoadConsFromCustomLocation = true;
Settings.Default.CustomConsPath = filename;
}
var dirname = GetDirectoryName(filename);
if(dirname != null)
Directory.CreateDirectory(dirname);
// Use File.Open with FileMode.CreateNew so that we don't overwrite an existing file
var fileStream = File.Open(filename, FileMode.CreateNew, FileAccess.Write, FileShare.None);
using (var xmlTextWriter = new XmlTextWriter(fileStream, System.Text.Encoding.UTF8))
{
xmlTextWriter.Formatting = Formatting.Indented;
xmlTextWriter.Indentation = 4;
xmlTextWriter.WriteStartDocument();
xmlTextWriter.WriteStartElement("Connections"); // Do not localize
xmlTextWriter.WriteAttributeString("Name", Language.strConnections);
xmlTextWriter.WriteAttributeString("Export", "", "False");
xmlTextWriter.WriteAttributeString("Protected", "", "GiUis20DIbnYzWPcdaQKfjE2H5jh//L5v4RGrJMGNXuIq2CttB/d/BxaBP2LwRhY");
xmlTextWriter.WriteAttributeString("ConfVersion", "", "2.5");
xmlTextWriter.WriteEndElement();
xmlTextWriter.WriteEndDocument();
}
// Load config
connectionsLoader.ConnectionFileName = filename;
ConnectionTreeModel = connectionsLoader.LoadConnections(false);
Windows.TreeForm.ConnectionTreeModel = ConnectionTreeModel;
}
catch (Exception ex)
{
MessageCollector.AddExceptionMessage(Language.strCouldNotCreateNewConnectionsFile, ex);
}
}