diff options
| author | Michael <[email protected]> | 2017-04-16 14:18:02 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-04-16 14:18:02 -0400 |
| commit | 5cb49f332856ac312e8840ec04c7869b892d4dd4 (patch) | |
| tree | 30ffc6a06cefd0f964e86461407e79a933003204 /ShiftOS.WinForms/WidgetManager.cs | |
| parent | 538f99faf7b381717079ea700d4f2e6e908537ea (diff) | |
| download | shiftos_thereturn-5cb49f332856ac312e8840ec04c7869b892d4dd4.tar.gz shiftos_thereturn-5cb49f332856ac312e8840ec04c7869b892d4dd4.tar.bz2 shiftos_thereturn-5cb49f332856ac312e8840ec04c7869b892d4dd4.zip | |
Store widget locations in file
Diffstat (limited to 'ShiftOS.WinForms/WidgetManager.cs')
| -rw-r--r-- | ShiftOS.WinForms/WidgetManager.cs | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/ShiftOS.WinForms/WidgetManager.cs b/ShiftOS.WinForms/WidgetManager.cs index 125c804..15e2076 100644 --- a/ShiftOS.WinForms/WidgetManager.cs +++ b/ShiftOS.WinForms/WidgetManager.cs @@ -1,11 +1,14 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; +using Newtonsoft.Json; using ShiftOS.Engine; +using ShiftOS.Objects.ShiftFS; namespace ShiftOS.WinForms { @@ -14,7 +17,7 @@ namespace ShiftOS.WinForms public static Dictionary<DesktopWidgetAttribute, Type> GetAllWidgetTypes() { Dictionary<DesktopWidgetAttribute, Type> types = new Dictionary<WinForms.DesktopWidgetAttribute, Type>(); - foreach(var exe in Directory.GetFiles(Environment.CurrentDirectory)) + foreach(var exe in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) { if(exe.EndsWith(".exe") || exe.EndsWith(".dll")) { @@ -45,6 +48,46 @@ namespace ShiftOS.WinForms return types; } + internal static void SaveLocation(Type type, Point location) + { + var dict = new Dictionary<string, Point>(); + var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is DesktopWidgetAttribute) as DesktopWidgetAttribute; + try + { + dict = JsonConvert.DeserializeObject<Dictionary<string, Point>>(Utils.ReadAllText(Paths.GetPath("widgets.dat"))); + dict[attrib.ToString()] = location; + } + catch + { + dict.Add(attrib.ToString(), location); + } + finally + { + Utils.WriteAllText(Paths.GetPath("widgets.dat"), JsonConvert.SerializeObject(dict)); + } + + } + + internal static Point LoadLocation(Type type) + { + var dict = new Dictionary<string, Point>(); + var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is DesktopWidgetAttribute) as DesktopWidgetAttribute; + try + { + dict = JsonConvert.DeserializeObject<Dictionary<string, Point>>(Utils.ReadAllText(Paths.GetPath("widgets.dat"))); + + return dict[attrib.ToString()]; + + } + catch + { + return new Point(-1, -1); + } + finally + { + } + + } } } |
