using System;
using System.IO;
using System.Text;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Holo
{
///
/// Provides file, environment and minor string manipulation actions.
///
public static class IO
{
///
/// Returns the directory of the executeable (without backslash at end) as a string.
///
public static string workingDirectory
{
get
{
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Substring(6);
}
}
///
/// Returns the value of a private profile string in a textfile as a string.
///
/// The section where the value is located in.
/// The key of the value.
/// The location of the textfile.
public static string Read(string key)
{
string[] lines = File.ReadAllLines(workingDirectory + "\\bin\\mysql.ini");
foreach (string line in lines)
{
if (line.Split('=')[0] == key)
return line.Split('=')[1];
}
return "";
}
///
/// Updates a value of a key in a textfile using WritePrivateProfileString.
///
/// The section where the key to update is located in.
/// The key to update.
/// The new value for the key.
/// The location of the textfile.
public static void Write(string key, string value)
{
StreamWriter tr = File.AppendText(workingDirectory + "\\bin\\mysql.ini");
tr.Write(key + "=" + value + Environment.NewLine);
tr.Close();
}
///
/// Returns a bool, which indicates if the specified path leads to a file.
///
/// The full location of the file.
public static bool fileExists(string fileLocation)
{
return File.Exists(fileLocation);
}
public static void createINI()
{
Directory.CreateDirectory(workingDirectory + "\\bin");
FileStream file = File.Create(workingDirectory + "\\bin\\mysql.ini");
file.Close();
}
}
}