config: don't write any debug output, as DebugInfo method requires a working config

This commit is contained in:
Hylke Bons 2012-01-18 13:03:23 +00:00
parent 994ccbb07b
commit c0d5e4f6ea
2 changed files with 19 additions and 27 deletions

View file

@ -25,17 +25,17 @@ namespace SparkleLib {
public class SparkleConfig : XmlDocument {
public static string ConfigPath = Path.Combine (
private static string default_config_path = Path.Combine (
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
"sparkleshare");
public bool DebugMode = true;
public static SparkleConfig DefaultConfig = new SparkleConfig (default_config_path, "config.xml");
public static bool DebugMode = true;
public static SparkleConfig DefaultConfig = new SparkleConfig (ConfigPath, "config.xml");
public string FullPath;
public string LogFilePath;
public string TmpPath;
public string LogFilePath;
public string HomePath {
get {
@ -69,16 +69,12 @@ namespace SparkleLib {
}
}
if (!Directory.Exists (config_path)) {
if (!Directory.Exists (config_path))
Directory.CreateDirectory (config_path);
SparkleHelpers.DebugInfo ("Config", "Created \"" + config_path + "\"");
}
string icons_path = System.IO.Path.Combine (config_path, "icons");
if (!Directory.Exists (icons_path)) {
string icons_path = Path.Combine (config_path, "icons");
if (!Directory.Exists (icons_path))
Directory.CreateDirectory (icons_path);
SparkleHelpers.DebugInfo ("Config", "Created \"" + icons_path + "\"");
}
try {
Load (FullPath);

View file

@ -22,29 +22,25 @@ namespace SparkleLib {
public static class SparkleHelpers {
public static bool ShowDebugInfo = true;
private static object debug_lock = new object ();
// Show debug info if needed
public static void DebugInfo (string type, string message)
{
if (ShowDebugInfo) {
string timestamp = DateTime.Now.ToString ("HH:mm:ss");
if (!message.StartsWith ("["))
message = " " + message;
if (!message.StartsWith ("["))
message = " " + message;
string timestamp = DateTime.Now.ToString ("HH:mm:ss");
string line = timestamp + " " + "[" + type + "]" + message;
string line = timestamp + " " + "[" + type + "]" + message;
if (SparkleConfig.DebugMode)
Console.WriteLine (line);
if (SparkleConfig.DefaultConfig.DebugMode)
Console.WriteLine (line);
lock (debug_lock) {
File.AppendAllText (
SparkleConfig.DefaultConfig.LogFilePath,
line + Environment.NewLine
);
}
lock (debug_lock) {
File.AppendAllText (
SparkleConfig.DefaultConfig.LogFilePath,
line + Environment.NewLine
);
}
}