2017-04-16 17:31:23 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-04-16 18:18:02 +00:00
|
|
|
|
using System.Drawing;
|
2017-04-16 17:31:23 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-04-16 18:18:02 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2017-04-16 17:31:23 +00:00
|
|
|
|
using ShiftOS.Engine;
|
2017-04-16 18:18:02 +00:00
|
|
|
|
using ShiftOS.Objects.ShiftFS;
|
2017-04-16 17:31:23 +00:00
|
|
|
|
|
|
|
|
|
namespace ShiftOS.WinForms
|
|
|
|
|
{
|
|
|
|
|
public static class WidgetManager
|
|
|
|
|
{
|
|
|
|
|
public static Dictionary<DesktopWidgetAttribute, Type> GetAllWidgetTypes()
|
|
|
|
|
{
|
2017-06-11 07:34:38 +00:00
|
|
|
|
var ret = new Dictionary<DesktopWidgetAttribute, Type>();
|
|
|
|
|
var types = Array.FindAll(ReflectMan.Types, t => t.GetInterfaces().Contains(typeof(IDesktopWidget)) && Shiftorium.UpgradeAttributesUnlocked(t));
|
|
|
|
|
foreach (var type in types)
|
|
|
|
|
foreach (var attrib in Array.FindAll(type.GetCustomAttributes(false), a => a is DesktopWidgetAttribute))
|
|
|
|
|
ret.Add(attrib as DesktopWidgetAttribute, type);
|
|
|
|
|
return ret;
|
2017-04-16 17:31:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-22 21:10:15 +00:00
|
|
|
|
internal static void SaveDetails(Type type, WidgetDetails location)
|
2017-04-16 18:18:02 +00:00
|
|
|
|
{
|
2017-04-22 21:10:15 +00:00
|
|
|
|
var dict = new Dictionary<string, WidgetDetails>();
|
2017-04-16 18:18:02 +00:00
|
|
|
|
var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is DesktopWidgetAttribute) as DesktopWidgetAttribute;
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-04-22 21:10:15 +00:00
|
|
|
|
dict = JsonConvert.DeserializeObject<Dictionary<string, WidgetDetails>>(Utils.ReadAllText(Paths.GetPath("widgets.dat")));
|
2017-04-16 17:31:23 +00:00
|
|
|
|
|
2017-04-16 18:18:02 +00:00
|
|
|
|
dict[attrib.ToString()] = location;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
dict.Add(attrib.ToString(), location);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
Utils.WriteAllText(Paths.GetPath("widgets.dat"), JsonConvert.SerializeObject(dict));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-22 21:10:15 +00:00
|
|
|
|
internal static WidgetDetails LoadDetails(Type type)
|
2017-04-16 18:18:02 +00:00
|
|
|
|
{
|
2017-04-22 21:10:15 +00:00
|
|
|
|
var dict = new Dictionary<string, WidgetDetails>();
|
2017-04-16 18:18:02 +00:00
|
|
|
|
var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is DesktopWidgetAttribute) as DesktopWidgetAttribute;
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-04-22 21:10:15 +00:00
|
|
|
|
dict = JsonConvert.DeserializeObject<Dictionary<string, WidgetDetails>>(Utils.ReadAllText(Paths.GetPath("widgets.dat")));
|
2017-04-16 18:18:02 +00:00
|
|
|
|
|
|
|
|
|
return dict[attrib.ToString()];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2017-04-22 21:10:15 +00:00
|
|
|
|
var details = new WinForms.WidgetDetails
|
|
|
|
|
{
|
|
|
|
|
Location = new Point(-1, -1),
|
|
|
|
|
IsVisible = false
|
|
|
|
|
};
|
|
|
|
|
if (dict.ContainsKey(attrib.ToString()))
|
|
|
|
|
dict[attrib.ToString()] = details;
|
|
|
|
|
else
|
|
|
|
|
dict.Add(attrib.ToString(), details);
|
|
|
|
|
Utils.WriteAllText(Paths.GetPath("widgets.dat"), JsonConvert.SerializeObject(dict));
|
|
|
|
|
return details;
|
2017-04-16 18:18:02 +00:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2017-04-16 17:31:23 +00:00
|
|
|
|
}
|
2017-04-22 21:10:15 +00:00
|
|
|
|
|
|
|
|
|
public class WidgetDetails
|
|
|
|
|
{
|
|
|
|
|
public WidgetDetails()
|
|
|
|
|
{
|
|
|
|
|
IsVisible = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Point Location { get; set; }
|
|
|
|
|
public bool IsVisible { get; set; }
|
|
|
|
|
}
|
2017-04-16 17:31:23 +00:00
|
|
|
|
}
|