mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2026-11-12 05:28:14 +00:00
Added basic CoolerMaster support
This commit is contained in:
1 parent
8446b9a47b
commit
8cc4688932
23 files changed
+1220
-2
No files matched your search
@@ -0,0 +1,44 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.CoolerMaster.Attributes;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// Offers some extensions and helper-methods for enum related things.
|
||||
/// </summary>
|
||||
internal static class EnumExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the value of the <see cref="DescriptionAttribute"/>.
|
||||
/// </summary>
|
||||
/// <param name="source">The enum value to get the description from.</param>
|
||||
/// <typeparam name="T">The generic enum-type</typeparam>
|
||||
/// <returns>The value of the <see cref="DescriptionAttribute"/> or the <see cref="Enum.ToString()" /> result of the source.</returns>
|
||||
internal static string GetDescription<T>(this T source)
|
||||
where T : struct
|
||||
{
|
||||
return source.GetAttribute<DescriptionAttribute, T>()?.Description ?? source.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the <see cref="DeviceTypeAttribute"/>.
|
||||
/// </summary>
|
||||
/// <param name="source">The enum value to get the description from.</param>
|
||||
/// <typeparam name="T">The generic enum-type</typeparam>
|
||||
/// <returns>The value of the <see cref="DeviceTypeAttribute"/> or the <see cref="Enum.ToString()" /> result of the source.</returns>
|
||||
internal static RGBDeviceType GetDeviceType<T>(this T source)
|
||||
where T : struct
|
||||
{
|
||||
return source.GetAttribute<DeviceTypeAttribute, T>()?.DeviceType ?? RGBDeviceType.Unknown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the attribute of type T.
|
||||
/// </summary>
|
||||
/// <param name="source">The enum value to get the attribute from</param>
|
||||
/// <typeparam name="T">The generic attribute type</typeparam>
|
||||
/// <typeparam name="TEnum">The generic enum-type</typeparam>
|
||||
/// <returns>The <see cref="Attribute"/>.</returns>
|
||||
private static T GetAttribute<T, TEnum>(this TEnum source)
|
||||
where T : Attribute
|
||||
where TEnum : struct
|
||||
{
|
||||
FieldInfo fi = source.GetType().GetField(source.ToString());
|
||||
T[] attributes = (T[])fi.GetCustomAttributes(typeof(T), false);
|
||||
return attributes.Length > 0 ? attributes[0] : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user