/ src / modules / MouseWithoutBorders / App / Helper / Program.cs
Program.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using System;
 6  using System.Diagnostics;
 7  using System.IO;
 8  using System.Windows.Forms;
 9  
10  using ManagedCommon;
11  using Microsoft.PowerToys.Telemetry;
12  
13  namespace MouseWithoutBorders
14  {
15      internal static class Program
16      {
17          internal static FormHelper FormHelper;
18  
19          private static FormDot dotForm;
20  
21          internal static FormDot DotForm
22          {
23              get
24              {
25                  return dotForm != null && !dotForm.IsDisposed ? dotForm : (dotForm = new FormDot());
26              }
27          }
28  
29          /// <summary>
30          /// The main entry point for the application.
31          /// </summary>
32          [STAThread]
33          private static void Main()
34          {
35              if (PowerToys.GPOWrapper.GPOWrapper.GetConfiguredMouseWithoutBordersEnabledValue() == PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
36              {
37                  // TODO: Add logging.
38                  // Logger.LogWarning("Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.");
39                  return;
40              }
41  
42              ETWTrace etwTrace = new ETWTrace();
43  
44              RunnerHelper.WaitForPowerToysRunnerExitFallback(() =>
45              {
46                  etwTrace?.Dispose();
47                  Application.Exit();
48              });
49  
50              string[] args = Environment.GetCommandLineArgs();
51  
52              if (args.Length > 1 && !string.IsNullOrEmpty(args[1]))
53              {
54                  string command = args[1];
55                  string arg = args.Length > 2 && !string.IsNullOrEmpty(args[2]) ? args[2] : string.Empty;
56  
57                  if (command.Equals("SvcExec", StringComparison.OrdinalIgnoreCase))
58                  {
59                      Process.Start(Path.GetDirectoryName(Application.ExecutablePath) + "\\MouseWithoutBorders.exe", "\"" + arg + "\"");
60                  }
61                  else if (command.Equals("install", StringComparison.OrdinalIgnoreCase))
62                  {
63                      Process.Start(Path.GetDirectoryName(Application.ExecutablePath) + "\\MouseWithoutBorders.exe");
64                  }
65                  else if (command.Equals("help-ex", StringComparison.OrdinalIgnoreCase))
66                  {
67                      Process.Start(@"http://www.aka.ms/mm");
68                  }
69                  else if (command.Equals("InternalError", StringComparison.OrdinalIgnoreCase))
70                  {
71                      MessageBox.Show(arg, Application.ProductName);
72                  }
73  
74                  return;
75              }
76  
77              Application.EnableVisualStyles();
78              Application.SetHighDpiMode(HighDpiMode.SystemAware);
79              Application.SetCompatibleTextRenderingDefault(false);
80  
81              dotForm = new FormDot();
82              Application.Run(FormHelper = new FormHelper());
83  
84              etwTrace?.Dispose();
85          }
86      }
87  }