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
{
#region DLL Imports
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
#endregion
///
/// 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 readINI(string iniSection, string iniKey, string iniLocation)
{
StringBuilder _TMP = new StringBuilder(255);
try
{
int i = GetPrivateProfileString(iniSection, iniKey, "", _TMP, 255, iniLocation);
return _TMP.ToString();
}
catch
{
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 writeINI(string iniSection, string iniKey, string iniValue, string iniLocation)
{
WritePrivateProfileString(iniSection, iniKey, iniValue, iniLocation);
}
///
/// 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);
}
}
}