From dc61820bafa770d9d3c8ed502cd99513f83b119f Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 11 May 2011 20:29:29 +0100 Subject: [PATCH] helpers: fix whitespace and coding style --- SparkleLib/SparkleHelpers.cs | 99 ++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 56 deletions(-) diff --git a/SparkleLib/SparkleHelpers.cs b/SparkleLib/SparkleHelpers.cs index 24e29154..8d25bbff 100644 --- a/SparkleLib/SparkleHelpers.cs +++ b/SparkleLib/SparkleHelpers.cs @@ -14,80 +14,67 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . + using System; using System.IO; namespace SparkleLib { - - public static class SparkleHelpers - { + + public static class SparkleHelpers { - public static bool ShowDebugInfo = true; + public static bool ShowDebugInfo = true; - // Show debug info if needed - public static void DebugInfo (string type, string message) - { + // Show debug info if needed + public static void DebugInfo (string type, string message) + { + if (ShowDebugInfo) { + string timestamp = DateTime.Now.ToString ("HH:mm:ss"); - if (ShowDebugInfo) { + if (!message.StartsWith ("[")) + message = " " + message; - string timestamp = DateTime.Now.ToString ("HH:mm:ss"); - - if (message.StartsWith ("[")) - Console.WriteLine ("[" + timestamp + "]" + "[" + type + "]" + message); - else - Console.WriteLine ("[" + timestamp + "]" + "[" + type + "] " + message); - - } - - } + // TODO: Write to a log + Console.WriteLine ("[" + timestamp + "]" + "[" + type + "]" + message); + } + } - // Makes it possible to combine more than - // two paths at once - public static string CombineMore (params string [] parts) - { + // Makes it possible to combine more than + // two paths at once + public static string CombineMore (params string [] parts) + { + string new_path = ""; - string new_path = ""; + foreach (string part in parts) + new_path = Path.Combine (new_path, part); - foreach (string part in parts) - new_path = Path.Combine (new_path, part); - - return new_path; - - } + return new_path; + } - // Recursively sets access rights of a folder to 'Normal' - public static void ClearAttributes (string path) - { + // Recursively sets access rights of a folder to 'Normal' + public static void ClearAttributes (string path) + { + if (Directory.Exists (path)) { + string [] folders = Directory .GetDirectories (path); - if (Directory.Exists (path)) { + foreach (string folder in folders) + ClearAttributes (folder); - string [] folders = Directory .GetDirectories (path); + string [] files = Directory .GetFiles(path); - foreach (string folder in folders) - ClearAttributes (folder); - - string [] files = Directory .GetFiles(path); - - foreach (string file in files) - File.SetAttributes (file, FileAttributes.Normal); - - } - - } + foreach (string file in files) + File.SetAttributes (file, FileAttributes.Normal); + } + } - // Converts a UNIX timestamp to a more usable time object - public static DateTime UnixTimestampToDateTime (int timestamp) - { - - DateTime unix_epoch = new DateTime (1970, 1, 1, 0, 0, 0, 0); - return unix_epoch.AddSeconds (timestamp); - - } - - } - + // Converts a UNIX timestamp to a more usable time object + public static DateTime UnixTimestampToDateTime (int timestamp) + { + DateTime unix_epoch = new DateTime (1970, 1, 1, 0, 0, 0, 0); + return unix_epoch.AddSeconds (timestamp); + } + } }