Skip to content

Commit

Permalink
Merge pull request #7 from Snoothy/develop
Browse files Browse the repository at this point in the history
Merge develop for v0.3.0 release
  • Loading branch information
Snoothy authored Apr 11, 2018
2 parents 022a6af + 0f9436c commit a148257
Show file tree
Hide file tree
Showing 154 changed files with 3,982 additions and 2,281 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
[Rr]elease/
[Rr]eleases/
x64/
build/
bld/
[Bb]in/
[Oo]bj/
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "submodules/IOWrapper"]
path = submodules/IOWrapper
url = https://github.com/evilC/IOWrapper.git
Binary file added .nuke
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Universal Control Remapper
[![GitHub release](https://img.shields.io/badge/release-v0.2.0-blue.svg)](https://github.com/Snoothy/UCR/releases/tag/v0.2.0) [![IOWrapper version](https://img.shields.io/badge/IOWrapper-v0.3.1-blue.svg)](https://github.com/evilC/IOWrapper) [![license](https://img.shields.io/github/license/snoothy/ucr.svg)](https://github.com/Snoothy/UCR/blob/master/LICENSE) [![Github All Releases](https://img.shields.io/github/downloads/snoothy/ucr/total.svg)](https://github.com/Snoothy/UCR/releases)
[![GitHub release](https://img.shields.io/badge/release-v0.3.0-blue.svg)](https://github.com/Snoothy/UCR/releases/tag/v0.3.0) [![IOWrapper version](https://img.shields.io/badge/IOWrapper-v0.5.1-blue.svg)](https://github.com/evilC/IOWrapper) [![license](https://img.shields.io/github/license/snoothy/ucr.svg)](https://github.com/Snoothy/UCR/blob/master/LICENSE) [![Github All Releases](https://img.shields.io/github/downloads/snoothy/ucr/total.svg)](https://github.com/Snoothy/UCR/releases)

Universal Control Remapper is a complete rewrite of the original [UCR](https://github.com/evilC/UCR), created in collaboration with [evilC](https://github.com/evilC/).

Expand Down
24 changes: 24 additions & 0 deletions UCR.Core/Attributes/PluginAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace HidWizards.UCR.Core.Attributes
{
public class PluginAttribute : Attribute
{
private string name;
private bool disabled;

public PluginAttribute(string name)
{
this.name = name;
disabled = false;
}

public virtual string Name => name;

public virtual bool Disabled
{
get => disabled;
set => disabled = value;
}
}
}
33 changes: 33 additions & 0 deletions UCR.Core/Attributes/PluginGuiAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;

namespace HidWizards.UCR.Core.Attributes
{
[AttributeUsage(AttributeTargets.Property)]
public class PluginGuiAttribute : Attribute
{
private string name;
private int rowOrder;
private int columnOrder;

public PluginGuiAttribute(string name)
{
this.name = name;
rowOrder = 0;
columnOrder = 0;
}

public virtual string Name => name;

public virtual int RowOrder
{
get => rowOrder;
set => rowOrder = value;
}

public virtual int ColumnOrder
{
get => columnOrder;
set => columnOrder = value;
}
}
}
12 changes: 12 additions & 0 deletions UCR.Core/Attributes/PluginInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using HidWizards.UCR.Core.Models;
using HidWizards.UCR.Core.Models.Binding;

namespace HidWizards.UCR.Core.Attributes
{
public class PluginInput : PluginIoAttribute
{
public PluginInput(DeviceBindingCategory deviceBindingCategory, string name) : base(DeviceIoType.Input, deviceBindingCategory, name)
{
}
}
}
27 changes: 27 additions & 0 deletions UCR.Core/Attributes/PluginIoAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using HidWizards.UCR.Core.Models;
using HidWizards.UCR.Core.Models.Binding;

namespace HidWizards.UCR.Core.Attributes
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class PluginIoAttribute : Attribute
{
private DeviceIoType deviceIoType;
private DeviceBindingCategory deviceBindingCategory;
private string name;

public PluginIoAttribute(DeviceIoType deviceIoType, DeviceBindingCategory deviceBindingCategory, string name)
{
this.deviceIoType = deviceIoType;
this.deviceBindingCategory = deviceBindingCategory;
this.name = name;
}

public virtual DeviceIoType DeviceIoType => deviceIoType;

public virtual DeviceBindingCategory DeviceBindingCategory => deviceBindingCategory;

public virtual string Name => name;
}
}
12 changes: 12 additions & 0 deletions UCR.Core/Attributes/PluginOutput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using HidWizards.UCR.Core.Models;
using HidWizards.UCR.Core.Models.Binding;

namespace HidWizards.UCR.Core.Attributes
{
public class PluginOutput : PluginIoAttribute
{
public PluginOutput(DeviceBindingCategory deviceBindingCategory, string name) : base(DeviceIoType.Output, deviceBindingCategory, name)
{
}
}
}
23 changes: 11 additions & 12 deletions UCR.Core/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,26 @@
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;
using IOWrapper;
using HidWizards.IOWrapper.Core;
using HidWizards.UCR.Core.Managers;
using HidWizards.UCR.Core.Models;
using Mono.Options;
using NLog;
using UCR.Core.Managers;
using UCR.Core.Models.Device;
using UCR.Core.Models.Plugin;
using UCR.Core.Models.Profile;

namespace UCR.Core
namespace HidWizards.UCR.Core
{
public class Context : IDisposable
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private const string ContextName = "context.xml";
private const string PluginPath = "Plugins";

// Persistence
/* Persistence */
public List<Profile> Profiles { get; set; }
public List<DeviceGroup> InputGroups { get; set; }
public List<DeviceGroup> OutputGroups { get; set; }

// Runtime
/* Runtime */
[XmlIgnore]
public Profile ActiveProfile { get; set; }
[XmlIgnore]
Expand All @@ -36,11 +34,12 @@ public class Context : IDisposable
public DeviceGroupsManager DeviceGroupsManager { get; set; }
[XmlIgnore]
public SubscriptionsManager SubscriptionsManager { get; set; }
[XmlIgnore]
public PluginsManager PluginManager { get; set; }

internal bool IsNotSaved { get; private set; }
internal IOController IOController { get; set; }
internal readonly List<Action> ActiveProfileCallbacks = new List<Action>();
private PluginLoader _pluginLoader;
private OptionSet options;

public Context()
Expand All @@ -61,7 +60,7 @@ private void Init()
DevicesManager = new DevicesManager(this);
DeviceGroupsManager = new DeviceGroupsManager(this, InputGroups, OutputGroups);
SubscriptionsManager = new SubscriptionsManager(this);
_pluginLoader = new PluginLoader(PluginPath);
PluginManager = new PluginsManager(PluginPath);
}

private void SetCommandLineOptions()
Expand Down Expand Up @@ -91,7 +90,7 @@ public void SetActiveProfileCallback(Action profileActivated)

public List<Plugin> GetPlugins()
{
return _pluginLoader.Plugins;
return PluginManager.Plugins.Where(p => !p.IsDisabled).ToList();
}

public void ContextChanged()
Expand Down Expand Up @@ -148,7 +147,7 @@ private static XmlSerializer GetXmlSerializer(List<Type> additionalPluginTypes)

private static XmlSerializer GetXmlSerializer(List<Type> additionalPluginTypes, Type type)
{
var plugins = new PluginLoader(PluginPath);
var plugins = new PluginsManager(PluginPath);
var pluginTypes = plugins.Plugins.Select(p => p.GetType()).ToList();
if (additionalPluginTypes != null) pluginTypes.AddRange(additionalPluginTypes);
return new XmlSerializer(type, pluginTypes.ToArray());
Expand Down
4 changes: 2 additions & 2 deletions UCR.Core/Managers/DeviceGroupsManager.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UCR.Core.Models.Device;
using HidWizards.UCR.Core.Models;

namespace UCR.Core.Managers
namespace HidWizards.UCR.Core.Managers
{
public class DeviceGroupsManager
{
Expand Down
5 changes: 2 additions & 3 deletions UCR.Core/Managers/DevicesManager.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Collections.Generic;
using UCR.Core.Models.Binding;
using UCR.Core.Models.Device;
using HidWizards.UCR.Core.Models;

namespace UCR.Core.Managers
namespace HidWizards.UCR.Core.Managers
{
public class DevicesManager
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.IO;
using HidWizards.UCR.Core.Models;

namespace UCR.Core.Models.Plugin
namespace HidWizards.UCR.Core.Managers
{
internal class PluginLoader
public class PluginsManager
{
private CompositionContainer _Container;

[ImportMany(typeof(Plugin))]
public List<Plugin> Plugins { get; set; }

public PluginLoader(string basePath)
public PluginsManager(string basePath)
{
var catalog = new AggregateCatalog();

Expand All @@ -28,5 +30,10 @@ public PluginLoader(string basePath)
_Container = new CompositionContainer(catalog);
_Container.ComposeParts(this);
}

public Plugin GetNewPlugin(Plugin plugin)
{
return (Plugin)Activator.CreateInstance(plugin.GetType());
}
}
}
24 changes: 22 additions & 2 deletions UCR.Core/Managers/ProfilesManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using HidWizards.UCR.Core.Models;
using NLog;
using UCR.Core.Models.Profile;

namespace UCR.Core.Managers
namespace HidWizards.UCR.Core.Managers
{
public class ProfilesManager
{
Expand All @@ -18,13 +18,33 @@ public ProfilesManager(Context context, List<Profile> profiles)
_profiles = profiles;
}

public Profile CreateProfile()
{
return Profile.CreateProfile(_context, "");
}

public bool AddProfile(string title)
{
_profiles.Add(Profile.CreateProfile(_context, title));
_context.ContextChanged();
return true;
}

public bool AddProfile(Profile newProfile, Profile parentProfile = null)
{
if (parentProfile != null)
{
parentProfile.AddChildProfile(newProfile);
}
else
{
_profiles.Add(newProfile);
}

_context.ContextChanged();
return true;
}

public bool CopyProfile(Profile profile, string title = "Untitled")
{
var newProfile = Context.DeepXmlClone<Profile>(profile);
Expand Down
Loading

0 comments on commit a148257

Please sign in to comment.