From 5cb49f332856ac312e8840ec04c7869b892d4dd4 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 16 Apr 2017 14:18:02 -0400 Subject: Store widget locations in file --- ShiftOS.WinForms/WidgetManager.cs | 45 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'ShiftOS.WinForms/WidgetManager.cs') 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 GetAllWidgetTypes() { Dictionary types = new Dictionary(); - 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(); + var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is DesktopWidgetAttribute) as DesktopWidgetAttribute; + try + { + dict = JsonConvert.DeserializeObject>(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(); + var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is DesktopWidgetAttribute) as DesktopWidgetAttribute; + try + { + dict = JsonConvert.DeserializeObject>(Utils.ReadAllText(Paths.GetPath("widgets.dat"))); + + return dict[attrib.ToString()]; + + } + catch + { + return new Point(-1, -1); + } + finally + { + } + + } } } -- cgit v1.2.3