Skip to content

Commit

Permalink
Merge pull request #14 from sll552/fix_settings_conv
Browse files Browse the repository at this point in the history
Fix settings restore for Hex colors
  • Loading branch information
sll552 authored Jan 15, 2020
2 parents 9f767b3 + 98a46c2 commit 49b5524
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
12 changes: 9 additions & 3 deletions CorsairLED.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public PluginInfo Initialise(IntPtr apiInterfacePtr)
_about.Type = PluginType.General;
_about.VersionMajor = 1; // your plugin version
_about.VersionMinor = 0;
_about.Revision = 3;
_about.Revision = 4;
_about.MinInterfaceVersion = MinInterfaceVersion;
_about.MinApiRevision = MinApiRevision;
_about.ReceiveNotifications = (ReceiveNotificationFlags.PlayerEvents | ReceiveNotificationFlags.TagEvents);
Expand All @@ -61,8 +61,7 @@ public PluginInfo Initialise(IntPtr apiInterfacePtr)
Console.WriteLine(@"CUE Exception! ErrorCode: " + Enum.GetName(typeof(CorsairError), ex.Error));
throw;
}
if (!DeviceController.IsInitialized) return null;


// migrate old config
if (File.Exists(_mbApiInterface.Setting_GetPersistentStoragePath() + "CorsairLED\\CorsairLED.config"))
{
Expand All @@ -77,6 +76,12 @@ public PluginInfo Initialise(IntPtr apiInterfacePtr)

Debug.WriteLine(_about.Name + " loaded");
Debug.WriteLine("MusicBee Version" + _mbApiInterface.MusicBeeVersion);

if (!DeviceController.IsInitialized)
{
Console.WriteLine("Could not initialize CUE SDK");
}

return _about;
}

Expand Down Expand Up @@ -119,6 +124,7 @@ public void Uninstall()
// you need to set about.ReceiveNotificationFlags = PlayerEvents to receive all notifications, and not just the startup event
public void ReceiveNotification(string sourceFileUrl, NotificationType type)
{
if (!DeviceController.IsInitialized) return;
// perform some action depending on the notification type
switch (type)
{
Expand Down
4 changes: 2 additions & 2 deletions CorsairLED.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
<Reference Include="CUE.NET, Version=1.2.0.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\CUE.NET.1.2.0.1\lib\net45\CUE.NET.dll</HintPath>
</Reference>
<Reference Include="SharpConfig, Version=3.2.5.0, Culture=neutral, PublicKeyToken=c1deedac91bd7724, processorArchitecture=MSIL">
<HintPath>packages\sharpconfig.3.2.5\lib\net20\SharpConfig.dll</HintPath>
<Reference Include="SharpConfig, Version=3.2.8.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\sharpconfig.3.2.8\lib\net20\SharpConfig.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
Expand Down
16 changes: 15 additions & 1 deletion Settings/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public SettingsManager(string config)
{
ConfigFile = config ?? throw new ArgumentNullException();

Configuration.IgnoreInlineComments = true;
Configuration.IgnorePreComments = true;

RegisterConverter(new ColorStringConverter());
RegisterConverter(new ColoringModeStringConverter());
RegisterConverter(new EffectStringConverter());
Expand Down Expand Up @@ -163,7 +166,18 @@ public SpectrumBrushFactory.ColoringMode GetColoringMode(string device)
{
const string key = "ColoringMode";
var section = GetSectionForDev(device, key);
return section?[key].GetValue<SpectrumBrushFactory.ColoringMode>() ?? SpectrumBrushFactory.ColoringMode.Solid;
SpectrumBrushFactory.ColoringMode ret;

try
{
ret = section?[key]?.GetValue<SpectrumBrushFactory.ColoringMode>() ?? SpectrumBrushFactory.ColoringMode.Solid;
}
catch (SettingValueCastException)
{
ret = SpectrumBrushFactory.ColoringMode.Solid;
}

return ret;
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions UI/SettingsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public SettingsWindow(Plugin.PluginInfo about, DeviceController dc, SettingsMana

InitializeComponent();

_devices = new List<AbstractEffectDevice>(0);
if (DeviceController.IsInitialized)
{
_devices = new List<AbstractEffectDevice>(_deviceController.Devices);
Expand Down
2 changes: 1 addition & 1 deletion packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CUE.NET" version="1.2.0.1" targetFramework="net45" />
<package id="sharpconfig" version="3.2.5" targetFramework="net45" />
<package id="sharpconfig" version="3.2.8" targetFramework="net45" />
</packages>

0 comments on commit 49b5524

Please sign in to comment.