aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Engine/Misc
diff options
context:
space:
mode:
authorAlex-TIMEHACK <[email protected]>2017-11-18 16:29:54 +0000
committerAlex-TIMEHACK <[email protected]>2017-11-18 16:29:54 +0000
commit4037be53b29a122732cfc10693e9c0027f606bb0 (patch)
tree8533ea9ee0ac8f5f7f696b85cb039f783657ada0 /ShiftOS.Engine/Misc
parent65b7ac2b8cbc4478f6d31a21f106048aeb075078 (diff)
parent97722fbe9d474adffbba0b92e9727c48a8205234 (diff)
downloadshiftos-rewind-4037be53b29a122732cfc10693e9c0027f606bb0.tar.gz
shiftos-rewind-4037be53b29a122732cfc10693e9c0027f606bb0.tar.bz2
shiftos-rewind-4037be53b29a122732cfc10693e9c0027f606bb0.zip
Updated my fork!
Conflicts: ShiftOS.Engine/ShiftOS.Engine.csproj ShiftOS.Engine/Terminal/Commands/Hello.cs ShiftOS.Engine/Terminal/TerminalBackend.cs ShiftOS.Engine/Terminal/TerminalCommand.cs ShiftOS.Main/ShiftOS.Main.csproj ShiftOS.Main/ShiftOS/Apps/Terminal.cs ShiftOS.Main/ShiftOS/Desktop.cs
Diffstat (limited to 'ShiftOS.Engine/Misc')
-rw-r--r--ShiftOS.Engine/Misc/EventList.cs71
-rw-r--r--ShiftOS.Engine/Misc/IniFile.cs50
-rw-r--r--ShiftOS.Engine/Misc/Tools.cs96
3 files changed, 217 insertions, 0 deletions
diff --git a/ShiftOS.Engine/Misc/EventList.cs b/ShiftOS.Engine/Misc/EventList.cs
new file mode 100644
index 0000000..e5202e7
--- /dev/null
+++ b/ShiftOS.Engine/Misc/EventList.cs
@@ -0,0 +1,71 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace ShiftOS.Engine.Misc
+{
+ [Serializable]
+ public class EventList<T> : List<T>
+ {
+ public event EventHandler<EventListArgs<T>> ItemAdded;
+ public event EventHandler<EventListArgs<T>> ItemRemoved;
+
+ public new void Add(T obj)
+ {
+ base.Add(obj);
+ ItemAdded?.Invoke(this, new EventListArgs<T>(obj));
+ }
+
+ public new void AddRange(IEnumerable<T> objs)
+ {
+ foreach (var obj in objs)
+ {
+ base.Add(obj);
+ ItemAdded?.Invoke(this, new EventListArgs<T>(obj));
+ }
+ }
+
+ public new bool Remove(T obj)
+ {
+ var b = base.Remove(obj);
+
+ ItemRemoved?.Invoke(this, new EventListArgs<T>(obj));
+ return b;
+ }
+
+ public new void RemoveAt(int index)
+ {
+ base.RemoveAt(index);
+ ItemRemoved?.Invoke(this, new EventListArgs<T>(default));
+ }
+
+ public new void RemoveAll(Predicate<T> match)
+ {
+ //will this work
+ foreach (var item in this.Where(match as Func<T, bool> ?? throw new InvalidOperationException()))
+ {
+ Remove(item);
+ }
+ }
+
+ public new void RemoveRange(int start, int end)
+ {
+ for (var i = start; i <= end; i++)
+ {
+ Remove(this[i]);
+ }
+ }
+
+ public new void Clear()
+ {
+ RemoveAll(x => true);
+ }
+ }
+
+ public class EventListArgs<T> : EventArgs
+ {
+ public EventListArgs(T item) => Item = item;
+
+ public T Item { get; }
+ }
+}
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..11f4761
--- /dev/null
+++ b/ShiftOS.Engine/Misc/Tools.cs
@@ -0,0 +1,96 @@
+using System;
+using System.Diagnostics;
+using System.Drawing;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Windows.Forms;
+using ShiftOS.Engine.Properties;
+using ShiftOS.Engine.ShiftFS;
+using ShiftOS.Engine.WindowManager;
+
+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();
+
+ //I wanna DESTROY this method
+ [DllImport("user32.dll")]
+ 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);
+ tempicon.Dispose();
+
+ return newIcon;
+ }
+
+ public static void DisplayShiftFolder(this ListView list, ShiftDirectory dir)
+ {
+ var dirs = dir.OfType<ShiftDirectory>().ToArray();
+ for (var i = 0; i < dirs.Length; i++)
+ {
+ list.Items.Add(
+ new ListViewItem
+ {
+ Text = dirs[i].Name,
+ ImageIndex = i,
+ StateImageIndex = i,
+ ImageKey = dirs[i].Guid.ToString(),
+ Tag = dirs[i]
+ });
+
+ list.StateImageList.Images.Add(dirs[i].Guid.ToString(), Resources.iconFileOpener_fw);
+ }
+
+ var items = dir.OfType<ShiftFile>().ToArray();
+ for (var i = 0; i < items.Length; i++)
+ {
+ list.Items.Add(
+ new ListViewItem
+ {
+ Text = items[i].Name,
+ ImageIndex = i,
+ StateImageIndex = i,
+ ImageKey = items[i].Guid.ToString(),
+ Tag = items[i],
+ });
+
+ list.StateImageList.Images.Add(items[i].Guid.ToString(), items[i].Icon ?? Resources.iconFileOpener_fw);
+ }
+ }
+
+ public static void ShowDrivesList(this ListView list, ShiftWindow window = null)
+ {
+ var imageList = new ImageList();
+ list.SmallImageList = imageList;
+ list.LargeImageList = imageList;
+ list.StateImageList = imageList;
+
+ for (var i = 0; i < ShiftFS.ShiftFS.Drives.Count; i++)
+ {
+ list.Items.Add(
+ new ListViewItem
+ {
+ Text = $"{ShiftFS.ShiftFS.Drives[i].Name} ({ShiftFS.ShiftFS.Drives[i].Letter})",
+ ImageIndex = i,
+ StateImageIndex = i,
+ ImageKey= ShiftFS.ShiftFS.Drives[i].Guid.ToString(),
+ Tag = ShiftFS.ShiftFS.Drives[i]
+ });
+
+ list.StateImageList.Images.Add(ShiftFS.ShiftFS.Drives[i].Guid.ToString(), window?.Icon.ToBitmap() ?? Resources.ArtPadsave);
+ }
+ }
+
+ }
+} \ No newline at end of file