Server/Program.cs
author StephaneLenclud
Tue, 16 Aug 2016 12:59:32 +0200
changeset 235 ba14a29944c4
parent 226 91763ba41c0c
child 236 6ba20e02d04f
permissions -rw-r--r--
Removing JSON type converter from ear manager.
Using bindings for some application settings.
     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 HarmonyHub;
    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         //
    35         public static HarmonyClient HarmonyClient { get; set; }
    36         /// <summary>
    37         /// The main entry point for the application.
    38         /// </summary>
    39         [STAThread]
    40         static void Main()
    41         {
    42 
    43             /*
    44 			if (!IsRunAsAdministrator())
    45 			{
    46 				var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase);
    47 
    48 				// The following properties run the new process as administrator
    49 				processInfo.UseShellExecute = true;
    50 				processInfo.Verb = "runas";
    51 
    52 				// Start the new process
    53 				try
    54 				{
    55 					Process.Start(processInfo);
    56 				}
    57 				catch (Exception)
    58 				{
    59 					// The user did not allow the application to run as administrator
    60 					MessageBox.Show("Sorry, this application must be run as Administrator.");
    61 				}
    62 
    63 				// Shut down the current process
    64 				Application.Exit();
    65 				return;
    66 				//Application.Current.Shutdown();
    67 			}*/
    68           
    69             Application.ApplicationExit += new EventHandler(OnApplicationExit);
    70 			//
    71             Application.EnableVisualStyles();
    72             Application.SetCompatibleTextRenderingDefault(false);
    73             iFormMain = new FormMain();
    74             Application.Run(iFormMain);
    75         }
    76 
    77 
    78 
    79 		static private bool IsRunAsAdministrator()
    80 		{
    81 		  var wi = WindowsIdentity.GetCurrent();
    82 		  var wp = new WindowsPrincipal(wi);
    83 
    84 		  return wp.IsInRole(WindowsBuiltInRole.Administrator);
    85 		}
    86 
    87 		/// <summary>
    88 		/// Occurs after form closing.
    89 		/// </summary>
    90 		/// <param name="sender"></param>
    91 		/// <param name="e"></param>
    92 		static private void OnApplicationExit(object sender, EventArgs e)
    93 		{
    94 
    95 		}
    96     }
    97 }