protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); if (mutex.WaitOne(TimeSpan.Zero, true)) { #if DEBUG Global.isDebug = true; #endif Global.Initialize(); string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Directory.SetCurrentDirectory(path); string logiDll = Path.Combine(path, "LogitechLed.dll"); if (File.Exists(logiDll)) { File.Delete(logiDll); } StringBuilder systeminfo_sb = new StringBuilder(string.Empty); systeminfo_sb.Append("\r\n========================================\r\n"); try { var win_reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"); string productName = (string)win_reg.GetValue("ProductName"); systeminfo_sb.AppendFormat("Operation System: {0}\r\n", productName); } catch (Exception exc) { systeminfo_sb.AppendFormat("Operation System: Could not be retrieved. [Exception: {0}]\r\n", exc.Message); } systeminfo_sb.AppendFormat("System Architecture: " + (Environment.Is64BitOperatingSystem ? "64 bit" : "32 bit") + "\r\n"); systeminfo_sb.AppendFormat("Environment OS Version: {0}\r\n", Environment.OSVersion); systeminfo_sb.AppendFormat("System Directory: {0}\r\n", Environment.SystemDirectory); systeminfo_sb.AppendFormat("Executing Directory: {0}\r\n", Global.ExecutingDirectory); systeminfo_sb.AppendFormat("Launch Directory: {0}\r\n", Directory.GetCurrentDirectory()); systeminfo_sb.AppendFormat("Processor Count: {0}\r\n", Environment.ProcessorCount); //systeminfo_sb.AppendFormat("User DomainName: {0}\r\n", Environment.UserDomainName); //systeminfo_sb.AppendFormat("User Name: {0}\r\n", Environment.UserName); systeminfo_sb.AppendFormat("SystemPageSize: {0}\r\n", Environment.SystemPageSize); systeminfo_sb.AppendFormat("Environment Version: {0}\r\n", Environment.Version); System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent(); System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity); systeminfo_sb.AppendFormat("Is Elevated: {0}\r\n", principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)); systeminfo_sb.AppendFormat("Aurora Assembly Version: {0}\r\n", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version); systeminfo_sb.AppendFormat("Aurora File Version: {0}\r\n", System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion); systeminfo_sb.Append("========================================\r\n"); Global.logger.Info(systeminfo_sb.ToString()); string arg = ""; for (int arg_i = 0; arg_i < e.Args.Length; arg_i++) { arg = e.Args[arg_i]; switch (arg) { case ("-debug"): Global.isDebug = true; Global.logger.Info("Program started in debug mode."); break; case ("-silent"): isSilent = true; Global.logger.Info("Program started with '-silent' parameter"); break; case ("-ignore_update"): ignore_update = true; Global.logger.Info("Program started with '-ignore_update' parameter"); break; case ("-delay"): isDelayed = true; if (arg_i + 1 < e.Args.Length && int.TryParse(e.Args[arg_i + 1], out delayTime)) { arg_i++; } else { delayTime = 5000; } Global.logger.Info("Program started with '-delay' parameter with delay of " + delayTime + " ms"); break; case ("-install_logitech"): Global.logger.Info("Program started with '-install_logitech' parameter"); try { InstallLogitech(); } catch (Exception exc) { System.Windows.MessageBox.Show("Could not patch Logitech LED SDK. Error: \r\n\r\n" + exc, "Aurora Error"); } Environment.Exit(0); break; } } AppDomain currentDomain = AppDomain.CurrentDomain; if (!Global.isDebug) { currentDomain.UnhandledException += CurrentDomain_UnhandledException; } if (isDelayed) { System.Threading.Thread.Sleep((int)delayTime); } this.ShutdownMode = ShutdownMode.OnExplicitShutdown; //AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit); if (Environment.Is64BitProcess) { currentDomain.AppendPrivatePath("x64"); } else { currentDomain.AppendPrivatePath("x86"); } Global.StartTime = Utils.Time.GetMillisecondsSinceEpoch(); Global.dev_manager = new DeviceManager(); Global.effengine = new Effects(); //Load config Global.logger.Info("Loading Configuration"); try { Global.Configuration = ConfigManager.Load(); } catch (Exception exc) { Global.logger.Error("Exception during ConfigManager.Load(). Error: " + exc); System.Windows.MessageBox.Show("Exception during ConfigManager.Load().Error: " + exc.Message + "\r\n\r\n Default configuration loaded.", "Aurora - Error"); Global.Configuration = new Configuration(); } Global.Configuration.PropertyChanged += (sender, eventArgs) => { ConfigManager.Save(Global.Configuration); }; Process.GetCurrentProcess().PriorityClass = Global.Configuration.HighPriority ? ProcessPriorityClass.High : ProcessPriorityClass.Normal; if (Global.Configuration.updates_check_on_start_up && !ignore_update) { string updater_path = System.IO.Path.Combine(Global.ExecutingDirectory, "Aurora-Updater.exe"); if (File.Exists(updater_path)) { try { ProcessStartInfo updaterProc = new ProcessStartInfo(); updaterProc.FileName = updater_path; updaterProc.Arguments = "-silent"; Process.Start(updaterProc); } catch (Exception exc) { Global.logger.Error("Could not start Aurora Updater. Error: " + exc); } } } Global.logger.Info("Loading Plugins"); (Global.PluginManager = new PluginManager()).Initialize(); Global.logger.Info("Loading KB Layouts"); Global.kbLayout = new KeyboardLayoutManager(); Global.kbLayout.LoadBrandDefault(); Global.logger.Info("Loading Input Hooking"); Global.InputEvents = new InputEvents(); Global.Configuration.PropertyChanged += SetupVolumeAsBrightness; SetupVolumeAsBrightness(Global.Configuration, new PropertyChangedEventArgs(nameof(Global.Configuration.UseVolumeAsBrightness))); Utils.DesktopUtils.StartSessionWatch(); Global.key_recorder = new KeyRecorder(Global.InputEvents); Global.logger.Info("Loading RazerSdkManager"); if (RzHelper.IsSdkVersionSupported(RzHelper.GetSdkVersion())) { try { Global.razerSdkManager = new RzSdkManager() { KeyboardEnabled = true, MouseEnabled = true, MousepadEnabled = true, AppListEnabled = true, }; Global.logger.Info("RazerSdkManager loaded successfully!"); } catch (Exception exc) { Global.logger.Fatal("RazerSdkManager failed to load!"); Global.logger.Fatal(exc.ToString()); } } else { Global.logger.Warn("Currently installed razer sdk version \"{0}\" is not supported by the RazerSdkManager!", RzHelper.GetSdkVersion()); } Global.logger.Info("Loading Applications"); (Global.LightingStateManager = new LightingStateManager()).Initialize(); if (Global.Configuration.GetPointerUpdates) { Global.logger.Info("Fetching latest pointers"); Task.Run(() => Utils.PointerUpdateUtils.FetchDevPointers("master")); } Global.logger.Info("Loading Device Manager"); Global.dev_manager.RegisterVariables(); Global.dev_manager.Initialize(); /*Global.logger.LogLine("Starting GameEventHandler", Logging_Level.Info); * Global.geh = new GameEventHandler(); * if (!Global.geh.Init()) * { * Global.logger.LogLine("GameEventHander could not initialize", Logging_Level.Error); * return; * }*/ Global.logger.Info("Starting GameStateListener"); try { Global.net_listener = new NetworkListener(9088); Global.net_listener.NewGameState += new NewGameStateHandler(Global.LightingStateManager.GameStateUpdate); Global.net_listener.WrapperConnectionClosed += new WrapperConnectionClosedHandler(Global.LightingStateManager.ResetGameState); } catch (Exception exc) { Global.logger.Error("GameStateListener Exception, " + exc); System.Windows.MessageBox.Show("GameStateListener Exception.\r\n" + exc); Environment.Exit(0); } if (!Global.net_listener.Start()) { Global.logger.Error("GameStateListener could not start"); System.Windows.MessageBox.Show("GameStateListener could not start. Try running this program as Administrator.\r\nExiting."); Environment.Exit(0); } Global.logger.Info("Listening for game integration calls..."); Global.logger.Info("Loading ResourceDictionaries..."); this.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("Themes/MetroDark/MetroDark.MSControls.Core.Implicit.xaml", UriKind.Relative) }); this.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("Themes/MetroDark/MetroDark.MSControls.Toolkit.Implicit.xaml", UriKind.Relative) }); Global.logger.Info("Loaded ResourceDictionaries"); Global.logger.Info("Loading ConfigUI..."); MainWindow = new ConfigUI(); ((ConfigUI)MainWindow).Display(); //Debug Windows on Startup if (Global.Configuration.BitmapWindowOnStartUp) { Window_BitmapView.Open(); } if (Global.Configuration.HttpWindowOnStartUp) { Window_GSIHttpDebug.Open(); } } else { try { NamedPipeClientStream client = new NamedPipeClientStream(".", "aurora\\interface", PipeDirection.Out); client.Connect(30); if (!client.IsConnected) { throw new Exception(); } byte[] command = System.Text.Encoding.ASCII.GetBytes("restore"); client.Write(command, 0, command.Length); client.Close(); } catch { //Global.logger.LogLine("Aurora is already running.", Logging_Level.Error); System.Windows.MessageBox.Show("Aurora is already running.\r\nExiting.", "Aurora - Error"); } } }
public Control_Settings() { InitializeComponent(); this.tabMain.DataContext = Global.Configuration; if (runRegistryPath.GetValue("Aurora") != null) { runRegistryPath.DeleteValue("Aurora"); } try { using (TaskService service = new TaskService()) { Microsoft.Win32.TaskScheduler.Task task = service.FindTask(StartupTaskID); if (task != null) { TaskDefinition definition = task.Definition; //Update path of startup task string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; definition.Actions.Clear(); definition.Actions.Add(new ExecAction(exePath, "-silent", Path.GetDirectoryName(exePath))); service.RootFolder.RegisterTaskDefinition(StartupTaskID, definition); this.run_at_win_startup.IsChecked = task.Enabled; startDelayAmount.Value = task.Definition.Triggers.FirstOrDefault(t => t.TriggerType == TaskTriggerType.Logon) is LogonTrigger trigger ? (int)trigger.Delay.TotalSeconds : 0; } else { TaskDefinition td = service.NewTask(); td.RegistrationInfo.Description = "Start Aurora on Startup"; td.Triggers.Add(new LogonTrigger { Enabled = true }); string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; td.Actions.Add(new ExecAction(exePath, "-silent", Path.GetDirectoryName(exePath))); td.Principal.RunLevel = TaskRunLevel.Highest; td.Settings.DisallowStartIfOnBatteries = false; td.Settings.DisallowStartOnRemoteAppSession = false; td.Settings.ExecutionTimeLimit = TimeSpan.Zero; service.RootFolder.RegisterTaskDefinition(StartupTaskID, td); this.run_at_win_startup.IsChecked = true; } } } catch (Exception exc) { Global.logger.Error("Error caught when updating startup task. Error: " + exc.ToString()); } string v = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion; this.lblVersion.Content = ((int.Parse(v[0].ToString()) > 0) ? "" : "beta ") + $"v{v}"; this.start_silently_enabled.IsChecked = Global.Configuration.start_silently; this.app_exit_mode.SelectedIndex = (int)Global.Configuration.close_mode; this.app_detection_mode.SelectedIndex = (int)Global.Configuration.detection_mode; this.chkOverlayPreview.IsChecked = Global.Configuration.OverlaysInPreview; load_excluded_listbox(); this.volume_as_brightness_enabled.IsChecked = Global.Configuration.UseVolumeAsBrightness; this.timed_dimming_checkbox.IsChecked = Global.Configuration.time_based_dimming_enabled; this.timed_dimming_start_hour_updown.Value = Global.Configuration.time_based_dimming_start_hour; this.timed_dimming_start_minute_updown.Value = Global.Configuration.time_based_dimming_start_minute; this.timed_dimming_end_hour_updown.Value = Global.Configuration.time_based_dimming_end_hour; this.timed_dimming_end_minute_updown.Value = Global.Configuration.time_based_dimming_end_minute; this.timed_dimming_with_games_checkbox.IsChecked = Global.Configuration.time_based_dimming_affect_games; this.nighttime_enabled_checkbox.IsChecked = Global.Configuration.nighttime_enabled; this.nighttime_start_hour_updown.Value = Global.Configuration.nighttime_start_hour; this.nighttime_start_minute_updown.Value = Global.Configuration.nighttime_start_minute; this.nighttime_end_hour_updown.Value = Global.Configuration.nighttime_end_hour; this.nighttime_end_minute_updown.Value = Global.Configuration.nighttime_end_minute; this.idle_effects_type.SelectedIndex = (int)Global.Configuration.idle_type; this.idle_effects_delay.Value = Global.Configuration.idle_delay; this.idle_effects_primary_color_colorpicker.SelectedColor = Utils.ColorUtils.DrawingColorToMediaColor(Global.Configuration.idle_effect_primary_color); this.idle_effects_secondary_color_colorpicker.SelectedColor = Utils.ColorUtils.DrawingColorToMediaColor(Global.Configuration.idle_effect_secondary_color); this.idle_effects_speed_label.Text = "x " + Global.Configuration.idle_speed; this.idle_effects_speed_slider.Value = (float)Global.Configuration.idle_speed; this.idle_effects_amount.Value = Global.Configuration.idle_amount; this.idle_effects_frequency.Value = (int)Global.Configuration.idle_frequency; this.devices_kb_brand.SelectedItem = Global.Configuration.keyboard_brand; this.devices_kb_layout.SelectedIndex = (int)Global.Configuration.keyboard_localization; this.devices_mouse_brand.SelectedItem = Global.Configuration.mouse_preference; this.devices_mouse_orientation.SelectedItem = Global.Configuration.mouse_orientation; this.ComboBox_virtualkeyboard_keycap_type.SelectedItem = Global.Configuration.virtualkeyboard_keycap_type; this.wrapper_allow_in_background_enabled.IsChecked = Global.Configuration.allow_wrappers_in_background; this.devices_disable_keyboard_lighting.IsChecked = Global.Configuration.devices_disable_keyboard; this.devices_disable_mouse_lighting.IsChecked = Global.Configuration.devices_disable_mouse; this.devices_disable_headset_lighting.IsChecked = Global.Configuration.devices_disable_headset; this.updates_autocheck_on_start.IsChecked = Global.Configuration.updates_check_on_start_up; var rzVersion = RzHelper.GetSdkVersion(); var rzSdkEnabled = RzHelper.IsSdkEnabled(); this.razer_wrapper_installed_version_label.Content = rzVersion.ToString(); this.razer_wrapper_installed_version_label.Foreground = new SolidColorBrush(RzHelper.IsSdkVersionSupported(rzVersion) ? Colors.LightGreen : Colors.PaleVioletRed); this.razer_wrapper_supported_versions_label.Content = $"[{RzHelper.SupportedFromVersion}-{RzHelper.SupportedToVersion}]"; if (rzVersion == new RzSdkVersion()) { this.razer_wrapper_uninstall_button.Visibility = Visibility.Hidden; } this.razer_wrapper_enabled_label.Content = rzSdkEnabled ? "Enabled" : "Disabled"; this.razer_wrapper_enabled_label.Foreground = rzSdkEnabled ? new SolidColorBrush(Colors.LightGreen) : new SolidColorBrush(Colors.PaleVioletRed); if (Global.razerSdkManager != null) { this.razer_wrapper_connection_status_label.Content = "Success"; this.razer_wrapper_connection_status_label.Foreground = new SolidColorBrush(Colors.LightGreen); { var appList = Global.razerSdkManager.GetDataProvider <RzAppListDataProvider>(); appList.Update(); this.razer_wrapper_current_application_label.Content = $"{appList.CurrentAppExecutable ?? "None"} [{appList.CurrentAppPid}]"; } Global.razerSdkManager.DataUpdated += (s, _) => { if (!(s is RzAppListDataProvider appList)) { return; } appList.Update(); Global.logger.Debug("RazerManager current app: {0} [{1}]", appList.CurrentAppExecutable ?? "None", appList.CurrentAppPid); Dispatcher.BeginInvoke(DispatcherPriority.Background, (System.Action)(() => this.razer_wrapper_current_application_label.Content = $"{appList.CurrentAppExecutable} [{appList.CurrentAppPid}]")); }; } else { this.razer_wrapper_connection_status_label.Content = "Failure"; this.razer_wrapper_connection_status_label.Foreground = new SolidColorBrush(Colors.PaleVioletRed); } }
public Control_Settings() { InitializeComponent(); this.tabMain.DataContext = Global.Configuration; if (runRegistryPath.GetValue("Aurora") != null) { runRegistryPath.DeleteValue("Aurora"); } try { using (TaskService service = new TaskService()) { Microsoft.Win32.TaskScheduler.Task task = service.FindTask(StartupTaskID); if (task != null) { TaskDefinition definition = task.Definition; //Update path of startup task string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; definition.Actions.Clear(); definition.Actions.Add(new ExecAction(exePath, "-silent", Path.GetDirectoryName(exePath))); service.RootFolder.RegisterTaskDefinition(StartupTaskID, definition); RunAtWinStartup.IsChecked = task.Enabled; startDelayAmount.Value = task.Definition.Triggers.FirstOrDefault(t => t.TriggerType == TaskTriggerType.Logon) is LogonTrigger trigger ? (int)trigger.Delay.TotalSeconds : 0; } else { TaskDefinition td = service.NewTask(); td.RegistrationInfo.Description = "Start Aurora on Startup"; td.Triggers.Add(new LogonTrigger { Enabled = true }); string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; td.Actions.Add(new ExecAction(exePath, "-silent", Path.GetDirectoryName(exePath))); td.Principal.RunLevel = TaskRunLevel.Highest; td.Settings.DisallowStartIfOnBatteries = false; td.Settings.DisallowStartOnRemoteAppSession = false; td.Settings.ExecutionTimeLimit = TimeSpan.Zero; service.RootFolder.RegisterTaskDefinition(StartupTaskID, td); RunAtWinStartup.IsChecked = true; } } } catch (Exception exc) { Global.logger.Error("Error caught when updating startup task. Error: " + exc.ToString()); } string v = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion; this.lblVersion.Content = ((int.Parse(v[0].ToString()) > 0) ? "" : "beta ") + $"v{v}"; var rzVersion = RzHelper.GetSdkVersion(); var rzSdkEnabled = RzHelper.IsSdkEnabled(); this.razer_wrapper_installed_version_label.Content = rzVersion.ToString(); this.razer_wrapper_installed_version_label.Foreground = new SolidColorBrush(RzHelper.IsSdkVersionSupported(rzVersion) ? Colors.LightGreen : Colors.PaleVioletRed); this.razer_wrapper_supported_versions_label.Content = $"[{RzHelper.SupportedFromVersion}-{RzHelper.SupportedToVersion}]"; if (rzVersion == new RzSdkVersion()) { this.razer_wrapper_uninstall_button.Visibility = Visibility.Hidden; } this.razer_wrapper_enabled_label.Content = rzSdkEnabled ? "Enabled" : "Disabled"; this.razer_wrapper_enabled_label.Foreground = rzSdkEnabled ? new SolidColorBrush(Colors.LightGreen) : new SolidColorBrush(Colors.PaleVioletRed); if (Global.razerSdkManager != null) { this.razer_wrapper_connection_status_label.Content = "Success"; this.razer_wrapper_connection_status_label.Foreground = new SolidColorBrush(Colors.LightGreen); { var appList = Global.razerSdkManager.GetDataProvider <RzAppListDataProvider>(); appList.Update(); this.razer_wrapper_current_application_label.Content = $"{appList.CurrentAppExecutable ?? "None"} [{appList.CurrentAppPid}]"; } Global.razerSdkManager.DataUpdated += (s, _) => { if (!(s is RzAppListDataProvider appList)) { return; } appList.Update(); Global.logger.Debug("RazerManager current app: {0} [{1}]", appList.CurrentAppExecutable ?? "None", appList.CurrentAppPid); Dispatcher.BeginInvoke(DispatcherPriority.Background, (System.Action)(() => this.razer_wrapper_current_application_label.Content = $"{appList.CurrentAppExecutable} [{appList.CurrentAppPid}]")); }; } else { this.razer_wrapper_connection_status_label.Content = "Failure"; this.razer_wrapper_connection_status_label.Foreground = new SolidColorBrush(Colors.PaleVioletRed); } }