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 RazerManager"); if (RzHelper.IsSdkVersionSupported(RzHelper.GetSdkVersion())) { try { Global.razerManager = new RzManager() { KeyboardEnabled = true, MouseEnabled = true, MousepadEnabled = true, AppListEnabled = true, }; Global.logger.Info("RazerManager loaded successfully!"); } catch (Exception exc) { Global.logger.Fatal("RazerManager failed to load!"); Global.logger.Fatal(exc.ToString()); } } else { Global.logger.Warn("Currently installed razer sdk version \"{0}\" is not supported!", 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(); } 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"); } } }