From 3a571c7baf433f0dacf8431f6f91c2b0fbf5a73e Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 26 Aug 2011 23:50:50 +0200 Subject: [PATCH] Create a new config.xml if it exists but is empty. Throw an error if the format is invalid. Fixes #315 --- SparkleLib/SparkleConfig.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/SparkleLib/SparkleConfig.cs b/SparkleLib/SparkleConfig.cs index bf9e4c6d..bbfae552 100644 --- a/SparkleLib/SparkleConfig.cs +++ b/SparkleLib/SparkleConfig.cs @@ -65,10 +65,27 @@ namespace SparkleLib { SparkleHelpers.DebugInfo ("Config", "Created \"" + icons_path + "\""); } - if (!File.Exists (FullPath)) + try { + Load (FullPath); + + } catch (FileNotFoundException) { CreateInitialConfig (); - Load (FullPath); + } catch (XmlException) { + + FileInfo file = new FileInfo (FullPath); + + if (file.Length == 0) { + File.Delete (FullPath); + CreateInitialConfig (); + + } else { + throw new XmlException (FullPath + " does not contain a valid SparkleShare XML tree."); + } + + } finally { + Load (FullPath); + } }