Server/Program.cs
author StephaneLenclud
Sun, 08 Jan 2017 12:19:35 +0100
changeset 278 2481c46d1f93
parent 236 6ba20e02d04f
permissions -rw-r--r--
Reading audio output is stopped when audio visualizers are not in used.
StephaneLenclud@123
     1
//
StephaneLenclud@123
     2
// Copyright (C) 2014-2015 Stéphane Lenclud.
StephaneLenclud@123
     3
//
StephaneLenclud@123
     4
// This file is part of SharpDisplayManager.
StephaneLenclud@123
     5
//
StephaneLenclud@123
     6
// SharpDisplayManager is free software: you can redistribute it and/or modify
StephaneLenclud@123
     7
// it under the terms of the GNU General Public License as published by
StephaneLenclud@123
     8
// the Free Software Foundation, either version 3 of the License, or
StephaneLenclud@123
     9
// (at your option) any later version.
StephaneLenclud@123
    10
//
StephaneLenclud@123
    11
// SharpDisplayManager is distributed in the hope that it will be useful,
StephaneLenclud@123
    12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
StephaneLenclud@123
    13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
StephaneLenclud@123
    14
// GNU General Public License for more details.
StephaneLenclud@123
    15
//
StephaneLenclud@123
    16
// You should have received a copy of the GNU General Public License
StephaneLenclud@123
    17
// along with SharpDisplayManager.  If not, see <http://www.gnu.org/licenses/>.
StephaneLenclud@123
    18
//
StephaneLenclud@123
    19
StephaneLenclud@123
    20
using System;
sl@0
    21
using System.Windows.Forms;
sl@92
    22
using System.Security.Principal;
StephaneLenclud@246
    23
using Hid = SharpLib.Hid;
StephaneLenclud@233
    24
sl@0
    25
sl@0
    26
namespace SharpDisplayManager
sl@0
    27
{
sl@0
    28
    static class Program
sl@0
    29
    {
sl@31
    30
        //WARNING: This is assuming we have a single instance of our program.
sl@31
    31
        //That is what we want but we should enforce it somehow.
StephaneLenclud@226
    32
        public static FormMain iFormMain;
StephaneLenclud@233
    33
StephaneLenclud@236
    34
        /// <summary>
StephaneLenclud@236
    35
        /// 
StephaneLenclud@236
    36
        /// </summary>
StephaneLenclud@236
    37
        public static HarmonyHub.Client HarmonyClient { get; set; }
StephaneLenclud@236
    38
StephaneLenclud@236
    39
        /// <summary>
StephaneLenclud@236
    40
        /// 
StephaneLenclud@236
    41
        /// </summary>
StephaneLenclud@236
    42
        public static HarmonyHub.Config HarmonyConfig { get; set; }
StephaneLenclud@236
    43
StephaneLenclud@236
    44
sl@0
    45
        /// <summary>
StephaneLenclud@246
    46
        /// Use notably to handle green start key from IR remote control
StephaneLenclud@246
    47
        /// </summary>
StephaneLenclud@246
    48
        public static Hid.Handler HidHandler;
StephaneLenclud@246
    49
StephaneLenclud@246
    50
        /// <summary>
sl@0
    51
        /// The main entry point for the application.
sl@0
    52
        /// </summary>
sl@0
    53
        [STAThread]
sl@0
    54
        static void Main()
sl@92
    55
        {
sl@92
    56
StephaneLenclud@201
    57
            /*
sl@92
    58
			if (!IsRunAsAdministrator())
sl@92
    59
			{
sl@92
    60
				var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase);
sl@92
    61
sl@92
    62
				// The following properties run the new process as administrator
sl@92
    63
				processInfo.UseShellExecute = true;
sl@92
    64
				processInfo.Verb = "runas";
sl@92
    65
sl@92
    66
				// Start the new process
sl@92
    67
				try
sl@92
    68
				{
sl@92
    69
					Process.Start(processInfo);
sl@92
    70
				}
sl@92
    71
				catch (Exception)
sl@92
    72
				{
sl@92
    73
					// The user did not allow the application to run as administrator
sl@92
    74
					MessageBox.Show("Sorry, this application must be run as Administrator.");
sl@92
    75
				}
sl@92
    76
sl@92
    77
				// Shut down the current process
sl@92
    78
				Application.Exit();
sl@92
    79
				return;
sl@92
    80
				//Application.Current.Shutdown();
sl@92
    81
			}*/
StephaneLenclud@201
    82
          
StephaneLenclud@201
    83
            Application.ApplicationExit += new EventHandler(OnApplicationExit);
sl@86
    84
			//
sl@0
    85
            Application.EnableVisualStyles();
sl@0
    86
            Application.SetCompatibleTextRenderingDefault(false);
StephaneLenclud@226
    87
            iFormMain = new FormMain();
StephaneLenclud@226
    88
            Application.Run(iFormMain);
sl@0
    89
        }
sl@86
    90
sl@92
    91
sl@92
    92
sl@92
    93
		static private bool IsRunAsAdministrator()
sl@92
    94
		{
sl@92
    95
		  var wi = WindowsIdentity.GetCurrent();
sl@92
    96
		  var wp = new WindowsPrincipal(wi);
sl@92
    97
sl@92
    98
		  return wp.IsInRole(WindowsBuiltInRole.Administrator);
sl@92
    99
		}
sl@92
   100
sl@86
   101
		/// <summary>
sl@86
   102
		/// Occurs after form closing.
sl@86
   103
		/// </summary>
sl@86
   104
		/// <param name="sender"></param>
sl@86
   105
		/// <param name="e"></param>
sl@86
   106
		static private void OnApplicationExit(object sender, EventArgs e)
sl@86
   107
		{
sl@86
   108
sl@86
   109
		}
sl@0
   110
    }
sl@0
   111
}