Server/Program.cs
author StephaneLenclud
Wed, 31 Aug 2016 17:28:30 +0200
changeset 264 4a08e1b7ba64
parent 236 6ba20e02d04f
permissions -rw-r--r--
EAR: Actions now support multiple iterations.
     1 //
     2 // Copyright (C) 2014-2015 Stéphane Lenclud.
     3 //
     4 // This file is part of SharpDisplayManager.
     5 //
     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.
    10 //
    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.
    15 //
    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/>.
    18 //
    19 
    20 using System;
    21 using System.Windows.Forms;
    22 using System.Security.Principal;
    23 using Hid = SharpLib.Hid;
    24 
    25 
    26 namespace SharpDisplayManager
    27 {
    28     static class Program
    29     {
    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;
    33 
    34         /// <summary>
    35         /// 
    36         /// </summary>
    37         public static HarmonyHub.Client HarmonyClient { get; set; }
    38 
    39         /// <summary>
    40         /// 
    41         /// </summary>
    42         public static HarmonyHub.Config HarmonyConfig { get; set; }
    43 
    44 
    45         /// <summary>
    46         /// Use notably to handle green start key from IR remote control
    47         /// </summary>
    48         public static Hid.Handler HidHandler;
    49 
    50         /// <summary>
    51         /// The main entry point for the application.
    52         /// </summary>
    53         [STAThread]
    54         static void Main()
    55         {
    56 
    57             /*
    58 			if (!IsRunAsAdministrator())
    59 			{
    60 				var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase);
    61 
    62 				// The following properties run the new process as administrator
    63 				processInfo.UseShellExecute = true;
    64 				processInfo.Verb = "runas";
    65 
    66 				// Start the new process
    67 				try
    68 				{
    69 					Process.Start(processInfo);
    70 				}
    71 				catch (Exception)
    72 				{
    73 					// The user did not allow the application to run as administrator
    74 					MessageBox.Show("Sorry, this application must be run as Administrator.");
    75 				}
    76 
    77 				// Shut down the current process
    78 				Application.Exit();
    79 				return;
    80 				//Application.Current.Shutdown();
    81 			}*/
    82           
    83             Application.ApplicationExit += new EventHandler(OnApplicationExit);
    84 			//
    85             Application.EnableVisualStyles();
    86             Application.SetCompatibleTextRenderingDefault(false);
    87             iFormMain = new FormMain();
    88             Application.Run(iFormMain);
    89         }
    90 
    91 
    92 
    93 		static private bool IsRunAsAdministrator()
    94 		{
    95 		  var wi = WindowsIdentity.GetCurrent();
    96 		  var wp = new WindowsPrincipal(wi);
    97 
    98 		  return wp.IsInRole(WindowsBuiltInRole.Administrator);
    99 		}
   100 
   101 		/// <summary>
   102 		/// Occurs after form closing.
   103 		/// </summary>
   104 		/// <param name="sender"></param>
   105 		/// <param name="e"></param>
   106 		static private void OnApplicationExit(object sender, EventArgs e)
   107 		{
   108 
   109 		}
   110     }
   111 }