1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00

Refactoring

This commit is contained in:
Darth Affe 2017-05-13 08:17:01 +02:00
parent 7264731eb1
commit 59e0344c68
32 changed files with 82 additions and 176 deletions

View File

@ -26,7 +26,7 @@ namespace RGB.NET.Core
/// </summary>
protected Size InternalSize
{
get { return _internalSize; }
get => _internalSize;
set
{
// ReSharper disable once ExplicitCallerInfoArgument
@ -39,8 +39,8 @@ namespace RGB.NET.Core
/// <inheritdoc />
public Point Location
{
get { return _location; }
set { SetProperty(ref _location, value ?? new Point()); }
get => _location;
set => SetProperty(ref _location, value ?? new Point());
}
/// <summary>

View File

@ -2,12 +2,12 @@
using System.Globalization;
using System.Runtime.InteropServices;
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Core
{
/// <summary>
/// Offers some helper-methods for culture related things.
/// </summary>
internal static class CultureHelper
public static class CultureHelper
{
#region DLLImports
@ -26,7 +26,7 @@ namespace RGB.NET.Devices.Logitech
/// Gets the current keyboard-layout from the OS.
/// </summary>
/// <returns>The current keyboard-layout</returns>
internal static CultureInfo GetCurrentCulture()
public static CultureInfo GetCurrentCulture()
{
try
{

View File

@ -1,24 +1,29 @@
using System.IO;
using System.Reflection;
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Core
{
/// <summary>
/// Offers some helper-methods for file-path related things.
/// </summary>
internal static class PathHelper
public static class PathHelper
{
#region Methods
/// <summary>
/// Returns an absolute path created from an relative path relatvie to the location of the executung assembly.
/// </summary>
/// <param name="relativePath">The relative path to convert.</param>
/// <returns>The absolute path.</returns>
internal static string GetAbsolutePath(string relativePath)
public static string GetAbsolutePath(string relativePath)
{
string assemblyLocation = Assembly.GetEntryAssembly()?.Location;
if (assemblyLocation == null) return relativePath;
return Path.Combine(Path.GetDirectoryName(assemblyLocation), relativePath);
string directoryName = Path.GetDirectoryName(assemblyLocation);
return directoryName == null ? null : Path.Combine(directoryName, relativePath);
}
#endregion
}
}

View File

@ -31,7 +31,7 @@ namespace RGB.NET.Core
/// </summary>
public byte A
{
get { return _a; }
get => _a;
set
{
if (SetProperty(ref _a, value))
@ -45,8 +45,8 @@ namespace RGB.NET.Core
/// </summary>
public double APercent
{
get { return A / (double)byte.MaxValue; }
set { A = GetByteValueFromPercentage(value); }
get => A / (double)byte.MaxValue;
set => A = GetByteValueFromPercentage(value);
}
private byte _r;
@ -55,7 +55,7 @@ namespace RGB.NET.Core
/// </summary>
public byte R
{
get { return _r; }
get => _r;
set
{
if (SetProperty(ref _r, value))
@ -72,8 +72,8 @@ namespace RGB.NET.Core
/// </summary>
public double RPercent
{
get { return R / (double)byte.MaxValue; }
set { R = GetByteValueFromPercentage(value); }
get => R / (double)byte.MaxValue;
set => R = GetByteValueFromPercentage(value);
}
private byte _g;
@ -82,7 +82,7 @@ namespace RGB.NET.Core
/// </summary>
public byte G
{
get { return _g; }
get => _g;
set
{
if (SetProperty(ref _g, value))
@ -100,8 +100,8 @@ namespace RGB.NET.Core
/// </summary>
public double GPercent
{
get { return G / (double)byte.MaxValue; }
set { G = GetByteValueFromPercentage(value); }
get => G / (double)byte.MaxValue;
set => G = GetByteValueFromPercentage(value);
}
private byte _b;
@ -110,7 +110,7 @@ namespace RGB.NET.Core
/// </summary>
public byte B
{
get { return _b; }
get => _b;
set
{
if (SetProperty(ref _b, value))
@ -128,8 +128,8 @@ namespace RGB.NET.Core
/// </summary>
public double BPercent
{
get { return B / (double)byte.MaxValue; }
set { B = GetByteValueFromPercentage(value); }
get => B / (double)byte.MaxValue;
set => B = GetByteValueFromPercentage(value);
}
#endregion
@ -142,7 +142,7 @@ namespace RGB.NET.Core
/// </summary>
public double Hue
{
get { return _hue ?? (_hue = CaclulateHueFromRGB()).Value; }
get => _hue ?? (_hue = CaclulateHueFromRGB()).Value;
set
{
if (SetProperty(ref _hue, value))
@ -156,7 +156,7 @@ namespace RGB.NET.Core
/// </summary>
public double Saturation
{
get { return _saturation ?? (_saturation = CaclulateSaturationFromRGB()).Value; }
get => _saturation ?? (_saturation = CaclulateSaturationFromRGB()).Value;
set
{
if (SetProperty(ref _saturation, value))
@ -170,7 +170,7 @@ namespace RGB.NET.Core
/// </summary>
public double Value
{
get { return _value ?? (_value = CaclulateValueFromRGB()).Value; }
get => _value ?? (_value = CaclulateValueFromRGB()).Value;
set
{
if (SetProperty(ref _value, value))

View File

@ -29,8 +29,8 @@ namespace RGB.NET.Core
/// </summary>
public Shape Shape
{
get { return _shape; }
set { SetProperty(ref _shape, value); }
get => _shape;
set => SetProperty(ref _shape, value);
}
private string _shapeData;
@ -39,8 +39,8 @@ namespace RGB.NET.Core
/// </summary>
public string ShapeData
{
get { return _shapeData; }
set { SetProperty(ref _shapeData, value); }
get => _shapeData;
set => SetProperty(ref _shapeData, value);
}
/// <summary>
@ -59,7 +59,7 @@ namespace RGB.NET.Core
/// </summary>
public Color RequestedColor
{
get { return new Color(_requestedColor); }
get => new Color(_requestedColor);
private set
{
SetProperty(ref _requestedColor, value);
@ -75,7 +75,7 @@ namespace RGB.NET.Core
/// </summary>
public Color Color
{
get { return _color; }
get => _color;
set
{
if (!IsLocked)
@ -97,8 +97,8 @@ namespace RGB.NET.Core
/// </summary>
public bool IsLocked
{
get { return _isLocked; }
set { SetProperty(ref _isLocked, value); }
get => _isLocked;
set => SetProperty(ref _isLocked, value);
}
/// <summary>

View File

@ -19,8 +19,8 @@ namespace RGB.NET.Core
/// </summary>
public double X
{
get { return _x; }
set { SetProperty(ref _x, value); }
get => _x;
set => SetProperty(ref _x, value);
}
private double _y;
@ -29,8 +29,8 @@ namespace RGB.NET.Core
/// </summary>
public double Y
{
get { return _y; }
set { SetProperty(ref _y, value); }
get => _y;
set => SetProperty(ref _y, value);
}
#endregion

View File

@ -22,7 +22,7 @@ namespace RGB.NET.Core
/// </summary>
public Point Location
{
get { return _location; }
get => _location;
set
{
if (SetProperty(ref _location, value))
@ -37,7 +37,7 @@ namespace RGB.NET.Core
/// </summary>
public Size Size
{
get { return _size; }
get => _size;
set
{
if (SetProperty(ref _size, value))
@ -152,13 +152,13 @@ namespace RGB.NET.Core
if (points != null)
foreach (Point point in points)
{
hasPoint = true;
posX = Math.Min(posX, point.X);
posY = Math.Min(posY, point.Y);
posX2 = Math.Max(posX2, point.X);
posY2 = Math.Max(posY2, point.Y);
}
{
hasPoint = true;
posX = Math.Min(posX, point.X);
posY = Math.Min(posY, point.Y);
posX2 = Math.Max(posX2, point.X);
posY2 = Math.Max(posY2, point.Y);
}
if (hasPoint)
InitializeFromPoints(new Point(posX, posY), new Point(posX2, posY2));

View File

@ -19,8 +19,8 @@ namespace RGB.NET.Core
/// </summary>
public double Width
{
get { return _width; }
set { SetProperty(ref _width, value); }
get => _width;
set => SetProperty(ref _width, value);
}
private double _height;
@ -29,8 +29,8 @@ namespace RGB.NET.Core
/// </summary>
public double Height
{
get { return _height; }
set { SetProperty(ref _height, value); }
get => _height;
set => SetProperty(ref _height, value);
}
#endregion

View File

@ -51,6 +51,8 @@
<Compile Include="Devices\Layout\LedImage.cs" />
<Compile Include="Devices\Layout\LedImageLayout.cs" />
<Compile Include="Devices\RGBDeviceLighting.cs" />
<Compile Include="Helper\CultureHelper.cs" />
<Compile Include="Helper\PathHelper.cs" />
<Compile Include="Positioning\Shape.cs" />
<Compile Include="Devices\Layout\LedLayout.cs" />
<Compile Include="Devices\Layout\DeviceLayout.cs" />

View File

@ -6,6 +6,7 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=events/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=extensions/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=groups/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=helper/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=leds/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mvvm/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=positioning/@EntryIndexedValue">True</s:Boolean>

View File

@ -12,14 +12,16 @@ namespace RGB.NET.Core
private CancellationToken _updateToken;
private Task _updateTask;
// ReSharper disable MemberCanBePrivate.Global
private double _updateFrequency = 1.0 / 30.0;
/// <summary>
/// Gets or sets the update-frequency in seconds. (Calculate by using '1.0 / updates per second')
/// </summary>
public double UpdateFrequency
{
get { return _updateFrequency; }
set { SetProperty(ref _updateFrequency, value); }
get => _updateFrequency;
set => SetProperty(ref _updateFrequency, value);
}
private UpdateMode _updateMode = UpdateMode.Manual;
@ -28,7 +30,7 @@ namespace RGB.NET.Core
/// </summary>
public UpdateMode UpdateMode
{
get { return _updateMode; }
get => _updateMode;
set
{
if (SetProperty(ref _updateMode, value))
@ -36,6 +38,7 @@ namespace RGB.NET.Core
}
}
// ReSharper restore MemberCanBePrivate.Global
#endregion
#region Methods

View File

@ -1,44 +0,0 @@
using System;
using System.Globalization;
using System.Runtime.InteropServices;
namespace RGB.NET.Devices.CoolerMaster.Helper
{
/// <summary>
/// Offers some helper-methods for culture related things.
/// </summary>
internal static class CultureHelper
{
#region DLLImports
[DllImport("user32.dll")]
private static extern IntPtr GetKeyboardLayout(uint thread);
#endregion
#region Constructors
#endregion
#region Methods
/// <summary>
/// Gets the current keyboard-layout from the OS.
/// </summary>
/// <returns>The current keyboard-layout</returns>
internal static CultureInfo GetCurrentCulture()
{
try
{
int keyboardLayout = GetKeyboardLayout(0).ToInt32() & 0xFFFF;
return new CultureInfo(keyboardLayout);
}
catch
{
return new CultureInfo(1033); // en-US on error.
}
}
#endregion
}
}

View File

@ -1,24 +0,0 @@
using System.IO;
using System.Reflection;
namespace RGB.NET.Devices.CoolerMaster.Helper
{
/// <summary>
/// Offers some helper-methods for file-path related things.
/// </summary>
internal static class PathHelper
{
/// <summary>
/// Returns an absolute path created from an relative path relatvie to the location of the executung assembly.
/// </summary>
/// <param name="relativePath">The relative path to convert.</param>
/// <returns>The absolute path.</returns>
internal static string GetAbsolutePath(string relativePath)
{
string assemblyLocation = Assembly.GetEntryAssembly()?.Location;
if (assemblyLocation == null) return relativePath;
return Path.Combine(Path.GetDirectoryName(assemblyLocation), relativePath);
}
}
}

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.CoolerMaster.Helper;
namespace RGB.NET.Devices.CoolerMaster
{

View File

@ -1,7 +1,6 @@
using System;
using System.Globalization;
using RGB.NET.Core;
using RGB.NET.Devices.CoolerMaster.Helper;
namespace RGB.NET.Devices.CoolerMaster
{

View File

@ -57,9 +57,7 @@
<Compile Include="Generic\CoolerMasterLedId.cs" />
<Compile Include="Generic\CoolerMasterRGBDevice.cs" />
<Compile Include="Generic\CoolerMasterRGBDeviceInfo.cs" />
<Compile Include="Helper\CultureHelper.cs" />
<Compile Include="Helper\EnumExtension.cs" />
<Compile Include="Helper\PathHelper.cs" />
<Compile Include="Keyboard\CoolerMasterKeyboardRGBDevice.cs" />
<Compile Include="Keyboard\CoolerMasterKeyboardRGBDeviceInfo.cs" />
<Compile Include="Keyboard\CoolerMasterKeyboardLedMappings.cs" />

View File

@ -2,7 +2,6 @@
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Helper;
namespace RGB.NET.Devices.Corsair
{

View File

@ -1,5 +1,5 @@
using System;
using RGB.NET.Devices.Corsair.Helper;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
@ -17,7 +17,7 @@ namespace RGB.NET.Devices.Corsair
/// <param name="deviceIndex">The index of the <see cref="CorsairHeadsetRGBDevice"/>.</param>
/// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
internal CorsairHeadsetRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
: base(deviceIndex, Core.RGBDeviceType.Headset, nativeInfo)
: base(deviceIndex, RGBDeviceType.Headset, nativeInfo)
{
Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Corsair\Headsets\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Absolute);
}

View File

@ -1,24 +0,0 @@
using System.IO;
using System.Reflection;
namespace RGB.NET.Devices.Corsair.Helper
{
/// <summary>
/// Offers some helper-methods for file-path related things.
/// </summary>
internal static class PathHelper
{
/// <summary>
/// Returns an absolute path created from an relative path relatvie to the location of the executung assembly.
/// </summary>
/// <param name="relativePath">The relative path to convert.</param>
/// <returns>The absolute path.</returns>
internal static string GetAbsolutePath(string relativePath)
{
string assemblyLocation = Assembly.GetEntryAssembly()?.Location;
if (assemblyLocation == null) return relativePath;
return Path.Combine(Path.GetDirectoryName(assemblyLocation), relativePath);
}
}
}

View File

@ -4,7 +4,6 @@
using System;
using System.Runtime.InteropServices;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Helper;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair

View File

@ -2,7 +2,7 @@
// ReSharper disable UnusedMember.Global
using System;
using RGB.NET.Devices.Corsair.Helper;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
@ -34,7 +34,7 @@ namespace RGB.NET.Devices.Corsair
/// <param name="deviceIndex">The index of the <see cref="CorsairKeyboardRGBDevice"/>.</param>
/// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
internal CorsairKeyboardRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
: base(deviceIndex, Core.RGBDeviceType.Keyboard, nativeInfo)
: base(deviceIndex, RGBDeviceType.Keyboard, nativeInfo)
{
this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout;
this.LogicalLayout = (CorsairLogicalKeyboardLayout)nativeInfo.logicalLayout;

View File

@ -3,7 +3,6 @@
using RGB.NET.Core;
using RGB.NET.Core.Exceptions;
using RGB.NET.Devices.Corsair.Helper;
namespace RGB.NET.Devices.Corsair
{

View File

@ -1,5 +1,5 @@
using System;
using RGB.NET.Devices.Corsair.Helper;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
@ -26,7 +26,7 @@ namespace RGB.NET.Devices.Corsair
/// <param name="deviceIndex">The index of the <see cref="CorsairMouseRGBDevice"/>.</param>
/// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
internal CorsairMouseRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
: base(deviceIndex, Core.RGBDeviceType.Mouse, nativeInfo)
: base(deviceIndex, RGBDeviceType.Mouse, nativeInfo)
{
this.PhysicalLayout = (CorsairPhysicalMouseLayout)nativeInfo.physicalLayout;

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Helper;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair

View File

@ -1,5 +1,5 @@
using System;
using RGB.NET.Devices.Corsair.Helper;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
@ -17,7 +17,7 @@ namespace RGB.NET.Devices.Corsair
/// <param name="deviceIndex">The index if the <see cref="CorsairMousematRGBDevice"/>.</param>
/// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
internal CorsairMousematRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
: base(deviceIndex, Core.RGBDeviceType.Mousemat, nativeInfo)
: base(deviceIndex, RGBDeviceType.Mousemat, nativeInfo)
{
Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Corsair\Mousemat\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Absolute);
}

View File

@ -62,7 +62,6 @@
<Compile Include="Generic\CorsairRGBDevice.cs" />
<Compile Include="Headset\CorsairHeadsetRGBDevice.cs" />
<Compile Include="Headset\CorsairHeadsetRGBDeviceInfo.cs" />
<Compile Include="Helper\PathHelper.cs" />
<Compile Include="Keyboard\CorsairKeyboardRGBDevice.cs" />
<Compile Include="Keyboard\CorsairKeyboardRGBDeviceInfo.cs" />
<Compile Include="Mouse\CorsairMouseRGBDevice.cs" />

View File

@ -1,8 +1,7 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System.IO;
using System.Reflection;
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
{

View File

@ -1,16 +1,15 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RGB.NET.Devices.Logitech")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Logitech-Device-Implementations of RGB.NET")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Wyrez")]
[assembly: AssemblyProduct("RGB.NET.Devices.Logitech")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyCopyright("Copyright © Wyrez 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

View File

@ -58,8 +58,6 @@
<Compile Include="Generic\LogitechRGBDevice.cs" />
<Compile Include="Generic\LogitechRGBDeviceInfo.cs" />
<Compile Include="Helper\BitmapMapping.cs" />
<Compile Include="Helper\CultureHelper.cs" />
<Compile Include="Helper\PathHelper.cs" />
<Compile Include="HID\DeviceChecker.cs" />
<Compile Include="Keyboard\LogitechKeyboardRGBDevice.cs" />
<Compile Include="Keyboard\LogitechKeyboardRGBDeviceInfo.cs" />

View File

@ -23,7 +23,7 @@ namespace RGB.NET.Groups
/// </summary>
public Rectangle Rectangle
{
get { return _rectangle; }
get => _rectangle;
set
{
_rectangle = value;
@ -37,7 +37,7 @@ namespace RGB.NET.Groups
/// </summary>
public double MinOverlayPercentage
{
get { return _minOverlayPercentage; }
get => _minOverlayPercentage;
set
{
_minOverlayPercentage = value;

View File

@ -23,8 +23,8 @@ namespace RGB.NET.WPF.Controls
/// </summary>
public Led Led
{
get { return (Led)GetValue(LedProperty); }
set { SetValue(LedProperty, value); }
get => (Led)GetValue(LedProperty);
set => SetValue(LedProperty, value);
}
// ReSharper restore InconsistentNaming

View File

@ -36,8 +36,8 @@ namespace RGB.NET.WPF.Controls
/// </summary>
public IRGBDevice Device
{
get { return (IRGBDevice)GetValue(DeviceProperty); }
set { SetValue(DeviceProperty, value); }
get => (IRGBDevice)GetValue(DeviceProperty);
set => SetValue(DeviceProperty, value);
}
// ReSharper restore InconsistentNaming