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