<commit_before>﻿using CUE.NET;
using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Devices.Headset;
using CUE.NET.Devices.Headset.Enums;
using CUE.NET.Devices.Keyboard;
using CUE.NET.Devices.Keyboard.Enums;
using CUE.NET.Devices.Mouse;
using CUE.NET.Devices.Mouse.Enums;
using CUE.NET.Devices.Mousemat;
using CUE.NET.Exceptions;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Aurora.Settings;
using Microsoft.Win32.TaskScheduler;

namespace Aurora.Devices.Corsair
{
    class CorsairDevice : Device
    {
        private String devicename = "Corsair";
        private bool isInitialized = false;
        private bool wasInitializedOnce = false;

        private bool keyboard_updated = false;
        private bool peripheral_updated = false;

        CorsairKeyboard keyboard;
        CorsairMouse mouse;
        CorsairHeadset headset;
        CorsairMousemat mousemat;

        private readonly object action_lock = new object();

        private System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
        private long lastUpdateTime = 0;

        //Previous data
        private Color previous_peripheral_Color = Color.Black;

        public string GetDeviceName()
        {
            return devicename;
        }

        public string GetDeviceDetails()
        {
            if (isInitialized)
            {
                return devicename + ": " + (keyboard != null ? keyboard.DeviceInfo.Model + " " : "") + (mouse != null ? mouse.DeviceInfo.Model + " " : "") + (headset != null ? headset.DeviceInfo.Model + " " : "") + (mousemat != null ? mousemat.DeviceInfo.Model + " " : "");
            }
            else
            {
                return devicename + ": Not initialized";
            }
        }

        public bool Initialize()
        {
            lock (action_lock)
            {
                if (!isInitialized)
                {
                    try
                    {
                        if (wasInitializedOnce)
                            CueSDK.Reinitialize(true);
                        else
                            CueSDK.Initialize(true);

                        Global.logger.Info("Corsair device, Initialized with " + CueSDK.LoadedArchitecture + "-SDK");

                        keyboard = CueSDK.KeyboardSDK;
                        mouse = CueSDK.MouseSDK;
                        headset = CueSDK.HeadsetSDK;
                        mousemat = CueSDK.MousematSDK;


                        if (keyboard == null && mouse == null && headset == null && mousemat == null)
                            throw new WrapperException("No devices found");
                        else
                        {
                            if (Global.Configuration.corsair_first_time)
                            {
                                CorsairInstallInstructions instructions = new CorsairInstallInstructions();
                                instructions.ShowDialog();

                                Global.Configuration.corsair_first_time = false;
                                Settings.ConfigManager.Save(Global.Configuration);
                            }

                            //SaveLeds();
                            isInitialized = true;
                            wasInitializedOnce = true;
                            return true;
                        }
                    }
                    catch (CUEException ex)
                    {
                        Global.logger.Error("Corsair device, CUE Exception! ErrorCode: " + Enum.GetName(typeof(CorsairError), ex.Error));
                    }
                    catch (WrapperException ex)
                    {<commit_msg>Fixed Corsair keyboards not being lit correctly<commit_after>﻿using CUE.NET;
using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Devices.Headset;
using CUE.NET.Devices.Headset.Enums;
using CUE.NET.Devices.Keyboard;
using CUE.NET.Devices.Keyboard.Enums;
using CUE.NET.Devices.Mouse;
using CUE.NET.Devices.Mouse.Enums;
using CUE.NET.Devices.Mousemat;
using CUE.NET.Exceptions;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Aurora.Settings;
using Microsoft.Win32.TaskScheduler;

namespace Aurora.Devices.Corsair
{
    class CorsairDevice : Device
    {
        private String devicename = "Corsair";
        private bool isInitialized = false;
        private bool wasInitializedOnce = false;

        private bool keyboard_updated = false;
        private bool peripheral_updated = false;

        CorsairKeyboard keyboard;
        CorsairMouse mouse;
        CorsairHeadset headset;
        CorsairMousemat mousemat;

        private readonly object action_lock = new object();

        private System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
        private long lastUpdateTime = 0;

        //Previous data
        private Color previous_peripheral_Color = Color.Black;

        public string GetDeviceName()
        {
            return devicename;
        }

        public string GetDeviceDetails()
        {
            if (isInitialized)
            {
                return devicename + ": " + (keyboard != null ? keyboard.DeviceInfo.Model + " " : "") + (mouse != null ? mouse.DeviceInfo.Model + " " : "") + (headset != null ? headset.DeviceInfo.Model + " " : "") + (mousemat != null ? mousemat.DeviceInfo.Model + " " : "");
            }
            else
            {
                return devicename + ": Not initialized";
            }
        }

        public bool Initialize()
        {
            lock (action_lock)
            {
                if (!isInitialized)
                {
                    try
                    {
                        if (wasInitializedOnce)
                            CueSDK.Reinitialize(true);
                        else
                            CueSDK.Initialize(true);

                        Global.logger.Info("Corsair device, Initialized with " + CueSDK.LoadedArchitecture + "-SDK");

                        keyboard = CueSDK.KeyboardSDK;
                        mouse = CueSDK.MouseSDK;
                        headset = CueSDK.HeadsetSDK;
                        mousemat = CueSDK.MousematSDK;
                        keyboard.Brush = (CUE.NET.Brushes.SolidColorBrush)Color.Transparent;


                        if (keyboard == null && mouse == null && headset == null && mousemat == null)
                            throw new WrapperException("No devices found");
                        else
                        {
                            if (Global.Configuration.corsair_first_time)
                            {
                                CorsairInstallInstructions instructions = new CorsairInstallInstructions();
                                instructions.ShowDialog();

                                Global.Configuration.corsair_first_time = false;
                                Settings.ConfigManager.Save(Global.Configuration);
                            }

                            //SaveLeds();
                            isInitialized = true;
                            wasInitializedOnce = true;
                            return true;
                        }
                    }
                    catch (CUEException ex)
                    {
                        Global.logger.Error("Corsair device, CUE Exception! ErrorCode: " + Enum.GetName(typeof(CorsairError), ex.Error));
                    }
                    catch (WrapperException ex)
                    {
{'fraction_non_alphanumeric': 0.08267358857884491, 'fraction_numerical': 0.0007787151200519143, 'mean_word_length': 1.3968895800933125, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1790911', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1838, 'n_words': 390}