public Config(string fullPath)
{
FullPath = fullPath;
ConfigPath = Path.GetDirectoryName(FullPath);
Console.WriteLine("FullPath:" + FullPath);
// Create configuration folder if it does not exist yet.
if (!Directory.Exists(ConfigPath))
Directory.CreateDirectory(ConfigPath);
// Create an empty XML configuration file if none is present yet.
if (!File.Exists(FullPath))
CreateInitialConfigFile();
// Load the XML configuration.
try
{
Load();
}
catch (TypeInitializationException)
{
CreateInitialConfigFile();
}
catch (FileNotFoundException)
{
CreateInitialConfigFile();
}
catch (XmlException)
{
FileInfo file = new FileInfo(FullPath);
// If the XML configuration file exists but with file size zero, then recreate it.
if (file.Length == 0)
{
File.Delete(FullPath);
CreateInitialConfigFile();
}
else
{
throw new XmlException(FullPath + " does not contain a valid config XML structure.");
}
}
finally
{
Load();
}
}