Server/Program.cs
author Stephane Lenclud
Thu, 18 Aug 2016 20:14:30 +0200
changeset 242 0a956121c273
parent 233 2b9541e54f7d
child 246 30a221eecc06
permissions -rw-r--r--
Weird signing crap.
     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 
    24 
    25 namespace SharpDisplayManager
    26 {
    27     static class Program
    28     {
    29         //WARNING: This is assuming we have a single instance of our program.
    30         //That is what we want but we should enforce it somehow.
    31         public static FormMain iFormMain;
    32 
    33         /// <summary>
    34         /// 
    35         /// </summary>
    36         public static HarmonyHub.Client HarmonyClient { get; set; }
    37 
    38         /// <summary>
    39         /// 
    40         /// </summary>
    41         public static HarmonyHub.Config HarmonyConfig { get; set; }
    42 
    43 
    44         /// <summary>
    45         /// The main entry point for the application.
    46         /// </summary>
    47         [STAThread]
    48         static void Main()
    49         {
    50 
    51             /*
    52 			if (!IsRunAsAdministrator())
    53 			{
    54 				var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase);
    55 
    56 				// The following properties run the new process as administrator
    57 				processInfo.UseShellExecute = true;
    58 				processInfo.Verb = "runas";
    59 
    60 				// Start the new process
    61 				try
    62 				{
    63 					Process.Start(processInfo);
    64 				}
    65 				catch (Exception)
    66 				{
    67 					// The user did not allow the application to run as administrator
    68 					MessageBox.Show("Sorry, this application must be run as Administrator.");
    69 				}
    70 
    71 				// Shut down the current process
    72 				Application.Exit();
    73 				return;
    74 				//Application.Current.Shutdown();
    75 			}*/
    76           
    77             Application.ApplicationExit += new EventHandler(OnApplicationExit);
    78 			//
    79             Application.EnableVisualStyles();
    80             Application.SetCompatibleTextRenderingDefault(false);
    81             iFormMain = new FormMain();
    82             Application.Run(iFormMain);
    83         }
    84 
    85 
    86 
    87 		static private bool IsRunAsAdministrator()
    88 		{
    89 		  var wi = WindowsIdentity.GetCurrent();
    90 		  var wp = new WindowsPrincipal(wi);
    91 
    92 		  return wp.IsInRole(WindowsBuiltInRole.Administrator);
    93 		}
    94 
    95 		/// <summary>
    96 		/// Occurs after form closing.
    97 		/// </summary>
    98 		/// <param name="sender"></param>
    99 		/// <param name="e"></param>
   100 		static private void OnApplicationExit(object sender, EventArgs e)
   101 		{
   102 
   103 		}
   104     }
   105 }