Switch from NAudio to CSCore.
2 // Copyright (C) 2014-2015 Stéphane Lenclud.
4 // This file is part of SharpDisplayManager.
6 // SharpDisplayManager is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // SharpDisplayManager is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with SharpDisplayManager. If not, see <http://www.gnu.org/licenses/>.
21 using System.Windows.Forms;
22 using System.Security.Principal;
23 using Hid = SharpLib.Hid;
26 namespace SharpDisplayManager
30 //WARNING: This is assuming we have a single instance of our program.
31 //That is what we want but we should enforce it somehow.
32 public static FormMain iFormMain;
37 public static HarmonyHub.Client HarmonyClient { get; set; }
42 public static HarmonyHub.Config HarmonyConfig { get; set; }
46 /// Use notably to handle green start key from IR remote control
48 public static Hid.Handler HidHandler;
51 /// The main entry point for the application.
58 if (!IsRunAsAdministrator())
60 var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase);
62 // The following properties run the new process as administrator
63 processInfo.UseShellExecute = true;
64 processInfo.Verb = "runas";
66 // Start the new process
69 Process.Start(processInfo);
73 // The user did not allow the application to run as administrator
74 MessageBox.Show("Sorry, this application must be run as Administrator.");
77 // Shut down the current process
80 //Application.Current.Shutdown();
83 Application.ApplicationExit += new EventHandler(OnApplicationExit);
85 Application.EnableVisualStyles();
86 Application.SetCompatibleTextRenderingDefault(false);
87 iFormMain = new FormMain();
88 Application.Run(iFormMain);
93 static private bool IsRunAsAdministrator()
95 var wi = WindowsIdentity.GetCurrent();
96 var wp = new WindowsPrincipal(wi);
98 return wp.IsInRole(WindowsBuiltInRole.Administrator);
102 /// Occurs after form closing.
104 /// <param name="sender"></param>
105 /// <param name="e"></param>
106 static private void OnApplicationExit(object sender, EventArgs e)