helpers: fix whitespace and coding style
This commit is contained in:
parent
5f1fa163df
commit
dc61820baf
|
@ -14,80 +14,67 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace SparkleLib {
|
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
|
// Show debug info if needed
|
||||||
public static void DebugInfo (string type, string message)
|
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");
|
// TODO: Write to a log
|
||||||
|
Console.WriteLine ("[" + timestamp + "]" + "[" + type + "]" + message);
|
||||||
if (message.StartsWith ("["))
|
}
|
||||||
Console.WriteLine ("[" + timestamp + "]" + "[" + type + "]" + message);
|
}
|
||||||
else
|
|
||||||
Console.WriteLine ("[" + timestamp + "]" + "[" + type + "] " + message);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Makes it possible to combine more than
|
// Makes it possible to combine more than
|
||||||
// two paths at once
|
// two paths at once
|
||||||
public static string CombineMore (params string [] parts)
|
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)
|
return new_path;
|
||||||
new_path = Path.Combine (new_path, part);
|
}
|
||||||
|
|
||||||
return new_path;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Recursively sets access rights of a folder to 'Normal'
|
// Recursively sets access rights of a folder to 'Normal'
|
||||||
public static void ClearAttributes (string path)
|
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)
|
foreach (string file in files)
|
||||||
ClearAttributes (folder);
|
File.SetAttributes (file, FileAttributes.Normal);
|
||||||
|
}
|
||||||
string [] files = Directory .GetFiles(path);
|
}
|
||||||
|
|
||||||
foreach (string file in files)
|
|
||||||
File.SetAttributes (file, FileAttributes.Normal);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Converts a UNIX timestamp to a more usable time object
|
// Converts a UNIX timestamp to a more usable time object
|
||||||
public static DateTime UnixTimestampToDateTime (int timestamp)
|
public static DateTime UnixTimestampToDateTime (int timestamp)
|
||||||
{
|
{
|
||||||
|
DateTime unix_epoch = new DateTime (1970, 1, 1, 0, 0, 0, 0);
|
||||||
DateTime unix_epoch = new DateTime (1970, 1, 1, 0, 0, 0, 0);
|
return unix_epoch.AddSeconds (timestamp);
|
||||||
return unix_epoch.AddSeconds (timestamp);
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue