forked from antonpup/Aurora
-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aytackydln
committed
Jul 9, 2024
1 parent
46e868e
commit 7710197
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
Project-Aurora/AuroraDeviceManager/Devices/RGBNet/Implementations/NewCorsairRgbNetDevice.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using AuroraDeviceManager.Utils; | ||
using Common.Devices; | ||
using Common.Utils; | ||
using RGB.NET.Core; | ||
using RGB.NET.Devices.Corsair; | ||
|
||
namespace AuroraDeviceManager.Devices.RGBNet.Implementations; | ||
|
||
public class NewCorsairRgbNetDevice : RgbNetDevice | ||
{ | ||
protected override CorsairDeviceProvider Provider => CorsairDeviceProvider.Instance; | ||
|
||
public override string DeviceName => "Corsair v4 (RGB.NET)"; | ||
|
||
protected override void RegisterVariables(VariableRegistry variableRegistry) | ||
{ | ||
base.RegisterVariables(variableRegistry); | ||
|
||
variableRegistry.Register($"{DeviceName}_exclusive", false, "Request exclusive control"); | ||
} | ||
|
||
public override bool HotplugEnabled() | ||
{ | ||
return true; | ||
} | ||
|
||
protected override bool OnShutdown() | ||
{ | ||
base.OnShutdown(); | ||
|
||
return !App.Closing; | ||
} | ||
|
||
protected override async Task ConfigureProvider(CancellationToken cancellationToken) | ||
{ | ||
await base.ConfigureProvider(cancellationToken); | ||
|
||
var waitSessionUnlock = await DesktopUtils.WaitSessionUnlock(); | ||
if (waitSessionUnlock) | ||
{ | ||
Global.Logger.Information("Waiting for Corsair to load after unlock"); | ||
await Task.Delay(5000, cancellationToken); | ||
} | ||
|
||
var isIcueRunning = ProcessUtils.IsProcessRunning("icue"); | ||
if (!isIcueRunning) | ||
{ | ||
throw new DeviceProviderException(new ApplicationException("iCUE is not running!"), false); | ||
} | ||
|
||
if (!IsNamedPipeOpen("iCUESDKv4")) | ||
{ | ||
throw new DeviceProviderException(new ApplicationException("iCUE SDK not started yet!"), false); | ||
} | ||
|
||
var exclusive = Global.DeviceConfig.VarRegistry.GetVariable<bool>($"{DeviceName}_exclusive"); | ||
|
||
CorsairDeviceProvider.ExclusiveAccess = exclusive; | ||
CorsairDeviceProvider.ConnectionTimeout = new TimeSpan(0, 0, 5); | ||
|
||
Provider.SessionStateChanged += SessionStateChanged; | ||
} | ||
|
||
|
||
private void SessionStateChanged(object? sender, CorsairSessionState e) | ||
{ | ||
if (e != CorsairSessionState.Closed) return; | ||
Provider.SessionStateChanged -= SessionStateChanged; | ||
|
||
IsInitialized = false; | ||
} | ||
|
||
private static bool IsNamedPipeOpen(string pipeName) | ||
{ | ||
try | ||
{ | ||
using var fileStream = new FileStream(@"\\.\pipe\" + pipeName, FileMode.Open, FileAccess.ReadWrite, FileShare.None); | ||
// If the FileStream can be opened, the named pipe exists and is open | ||
return true; | ||
} | ||
catch (IOException) | ||
{ | ||
// IOException will be thrown if the pipe does not exist or is not available | ||
return false; | ||
} | ||
catch (UnauthorizedAccessException) | ||
{ | ||
// Handle access issues if necessary | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-1.5 KB
(97%)
Project-Aurora/AuroraDeviceManager/RGB.NET.Devices.Corsair.dll
Binary file not shown.
Binary file modified
BIN
+512 Bytes
(100%)
Project-Aurora/AuroraDeviceManager/x64/iCUESDK.x64_2019.dll
Binary file not shown.