StephaneLenclud@123: // StephaneLenclud@123: // Copyright (C) 2014-2015 Stéphane Lenclud. StephaneLenclud@123: // StephaneLenclud@123: // This file is part of SharpDisplayManager. StephaneLenclud@123: // StephaneLenclud@123: // SharpDisplayManager is free software: you can redistribute it and/or modify StephaneLenclud@123: // it under the terms of the GNU General Public License as published by StephaneLenclud@123: // the Free Software Foundation, either version 3 of the License, or StephaneLenclud@123: // (at your option) any later version. StephaneLenclud@123: // StephaneLenclud@123: // SharpDisplayManager is distributed in the hope that it will be useful, StephaneLenclud@123: // but WITHOUT ANY WARRANTY; without even the implied warranty of StephaneLenclud@123: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the StephaneLenclud@123: // GNU General Public License for more details. StephaneLenclud@123: // StephaneLenclud@123: // You should have received a copy of the GNU General Public License StephaneLenclud@123: // along with SharpDisplayManager. If not, see . StephaneLenclud@123: // StephaneLenclud@123: StephaneLenclud@123: using System; sl@0: using System.Windows.Forms; sl@92: using System.Security.Principal; StephaneLenclud@246: using Hid = SharpLib.Hid; StephaneLenclud@233: sl@0: sl@0: namespace SharpDisplayManager sl@0: { sl@0: static class Program sl@0: { sl@31: //WARNING: This is assuming we have a single instance of our program. sl@31: //That is what we want but we should enforce it somehow. StephaneLenclud@226: public static FormMain iFormMain; StephaneLenclud@233: StephaneLenclud@236: /// StephaneLenclud@236: /// StephaneLenclud@236: /// StephaneLenclud@236: public static HarmonyHub.Client HarmonyClient { get; set; } StephaneLenclud@236: StephaneLenclud@236: /// StephaneLenclud@236: /// StephaneLenclud@236: /// StephaneLenclud@236: public static HarmonyHub.Config HarmonyConfig { get; set; } StephaneLenclud@236: StephaneLenclud@236: sl@0: /// StephaneLenclud@246: /// Use notably to handle green start key from IR remote control StephaneLenclud@246: /// StephaneLenclud@246: public static Hid.Handler HidHandler; StephaneLenclud@246: StephaneLenclud@246: /// sl@0: /// The main entry point for the application. sl@0: /// sl@0: [STAThread] sl@0: static void Main() sl@92: { sl@92: StephaneLenclud@201: /* sl@92: if (!IsRunAsAdministrator()) sl@92: { sl@92: var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase); sl@92: sl@92: // The following properties run the new process as administrator sl@92: processInfo.UseShellExecute = true; sl@92: processInfo.Verb = "runas"; sl@92: sl@92: // Start the new process sl@92: try sl@92: { sl@92: Process.Start(processInfo); sl@92: } sl@92: catch (Exception) sl@92: { sl@92: // The user did not allow the application to run as administrator sl@92: MessageBox.Show("Sorry, this application must be run as Administrator."); sl@92: } sl@92: sl@92: // Shut down the current process sl@92: Application.Exit(); sl@92: return; sl@92: //Application.Current.Shutdown(); sl@92: }*/ StephaneLenclud@201: StephaneLenclud@201: Application.ApplicationExit += new EventHandler(OnApplicationExit); sl@86: // sl@0: Application.EnableVisualStyles(); sl@0: Application.SetCompatibleTextRenderingDefault(false); StephaneLenclud@226: iFormMain = new FormMain(); StephaneLenclud@226: Application.Run(iFormMain); sl@0: } sl@86: sl@92: sl@92: sl@92: static private bool IsRunAsAdministrator() sl@92: { sl@92: var wi = WindowsIdentity.GetCurrent(); sl@92: var wp = new WindowsPrincipal(wi); sl@92: sl@92: return wp.IsInRole(WindowsBuiltInRole.Administrator); sl@92: } sl@92: sl@86: /// sl@86: /// Occurs after form closing. sl@86: /// sl@86: /// sl@86: /// sl@86: static private void OnApplicationExit(object sender, EventArgs e) sl@86: { sl@86: sl@86: } sl@0: } sl@0: }