diff options
Diffstat (limited to 'ShiftOS.Engine/Misc')
| -rw-r--r-- | ShiftOS.Engine/Misc/IniFile.cs | 50 | ||||
| -rw-r--r-- | ShiftOS.Engine/Misc/Tools.cs | 29 |
2 files changed, 79 insertions, 0 deletions
diff --git a/ShiftOS.Engine/Misc/IniFile.cs b/ShiftOS.Engine/Misc/IniFile.cs new file mode 100644 index 0000000..e31583f --- /dev/null +++ b/ShiftOS.Engine/Misc/IniFile.cs @@ -0,0 +1,50 @@ +using System.Runtime.InteropServices; +using System.Text; + +namespace ShiftOS.Engine.Misc +{ + /// <summary> + /// Create a New INI file to store or load data + /// </summary> + public class IniFile + { + readonly string _path; + + public IniFile(string iniPath) => _path = iniPath; + + [DllImport("kernel32")] + static extern long WritePrivateProfileString( + string section, + string key, + string val, + string filePath); + + [DllImport("kernel32")] + static extern int GetPrivateProfileString( + string section, + string key, + string def, + StringBuilder retVal, + int size, + string filePath); + + public void WriteValue(string section, string key, string value) + { + WritePrivateProfileString(section, key, value, _path); + } + + public string ReadValue(string section, string key) + { + var temp = new StringBuilder(255); + GetPrivateProfileString( + section, + key, + "", + temp, + 255, + _path); + + return temp.ToString(); + } + } +}
\ No newline at end of file diff --git a/ShiftOS.Engine/Misc/Tools.cs b/ShiftOS.Engine/Misc/Tools.cs new file mode 100644 index 0000000..6430084 --- /dev/null +++ b/ShiftOS.Engine/Misc/Tools.cs @@ -0,0 +1,29 @@ +using System; +using System.Drawing; +using System.Runtime.InteropServices; + +namespace ShiftOS.Engine.Misc +{ + /// <summary> + /// Random class full of unassorted [but also uncategorizable] tools. + /// </summary> + public static class Tools + { + public static Random Rnd = new Random(); + + [DllImport("user32.dll", CharSet = CharSet.Auto)] + public static extern bool DestroyIcon(IntPtr handle); + + public static Icon ToIcon(this Bitmap bm) + { + var tempicon = Icon.FromHandle(bm.GetHicon()); + + var newIcon = tempicon.Clone() as Icon; + + //for some reason this exists + DestroyIcon(tempicon.Handle); + + return newIcon; + } + } +}
\ No newline at end of file |
