2020-09-04 16:56:52 +08:00
|
|
|
// Copyright (c) Microsoft Corporation
|
2020-04-08 05:19:33 +08:00
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Windows;
|
2020-04-24 08:11:02 +08:00
|
|
|
using interop;
|
2020-08-18 01:00:56 +08:00
|
|
|
using ManagedCommon;
|
2020-04-08 05:19:33 +08:00
|
|
|
|
2021-02-12 00:29:56 +08:00
|
|
|
namespace PowerToys.Settings
|
2020-04-08 05:19:33 +08:00
|
|
|
{
|
2020-10-27 02:09:18 +08:00
|
|
|
public static class Program
|
2020-04-08 05:19:33 +08:00
|
|
|
{
|
2021-02-18 21:11:57 +08:00
|
|
|
private enum Arguments
|
|
|
|
{
|
|
|
|
PTPipeName = 0,
|
|
|
|
SettingsPipeName,
|
|
|
|
PTPid,
|
|
|
|
Theme, // used in the old settings
|
|
|
|
ElevatedStatus,
|
|
|
|
IsUserAdmin,
|
2021-03-03 01:56:37 +08:00
|
|
|
ShowOobeWindow,
|
2021-02-18 21:11:57 +08:00
|
|
|
}
|
|
|
|
|
2020-05-14 17:36:27 +08:00
|
|
|
// Quantity of arguments
|
2021-03-03 01:56:37 +08:00
|
|
|
private const int RequiredArgumentsQty = 6;
|
|
|
|
private const int RequiredAndOptionalArgumentsQty = 7;
|
2020-05-14 17:36:27 +08:00
|
|
|
|
2020-04-08 05:19:33 +08:00
|
|
|
// Create an instance of the IPC wrapper.
|
2020-04-24 08:11:02 +08:00
|
|
|
private static TwoWayPipeMessageIPCManaged ipcmanager;
|
2020-04-08 05:19:33 +08:00
|
|
|
|
2020-05-06 01:02:31 +08:00
|
|
|
public static bool IsElevated { get; set; }
|
|
|
|
|
2020-05-14 17:36:27 +08:00
|
|
|
public static bool IsUserAnAdmin { get; set; }
|
|
|
|
|
2020-06-11 01:58:34 +08:00
|
|
|
public static int PowerToysPID { get; set; }
|
|
|
|
|
2020-09-04 16:56:52 +08:00
|
|
|
public static Action<string> IPCMessageReceivedCallback { get; set; }
|
|
|
|
|
2020-04-11 06:22:07 +08:00
|
|
|
[STAThread]
|
2020-04-08 05:19:33 +08:00
|
|
|
public static void Main(string[] args)
|
|
|
|
{
|
2021-02-12 00:29:56 +08:00
|
|
|
using (new Microsoft.PowerToys.Settings.UI.App())
|
2020-04-08 05:19:33 +08:00
|
|
|
{
|
|
|
|
App app = new App();
|
|
|
|
app.InitializeComponent();
|
|
|
|
|
2021-03-03 01:56:37 +08:00
|
|
|
if (args != null && args.Length >= RequiredArgumentsQty)
|
2020-04-08 05:19:33 +08:00
|
|
|
{
|
2021-02-18 21:11:57 +08:00
|
|
|
_ = int.TryParse(args[(int)Arguments.PTPid], out int powerToysPID);
|
2020-06-11 01:58:34 +08:00
|
|
|
PowerToysPID = powerToysPID;
|
|
|
|
|
2021-02-18 21:11:57 +08:00
|
|
|
IsElevated = args[(int)Arguments.ElevatedStatus] == "true";
|
|
|
|
IsUserAnAdmin = args[(int)Arguments.IsUserAdmin] == "true";
|
2020-05-14 17:36:27 +08:00
|
|
|
|
2021-03-03 01:56:37 +08:00
|
|
|
if (args.Length == RequiredAndOptionalArgumentsQty)
|
|
|
|
{
|
|
|
|
// open oobe window
|
|
|
|
app.ShowOobe = args[(int)Arguments.ShowOobeWindow] == "true";
|
|
|
|
}
|
|
|
|
|
2020-08-18 01:00:56 +08:00
|
|
|
RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
|
|
|
|
{
|
2020-06-26 07:03:50 +08:00
|
|
|
Environment.Exit(0);
|
|
|
|
});
|
2020-06-11 01:58:34 +08:00
|
|
|
|
2021-02-18 21:11:57 +08:00
|
|
|
ipcmanager = new TwoWayPipeMessageIPCManaged(args[(int)Arguments.SettingsPipeName], args[(int)Arguments.PTPipeName], (string message) =>
|
2020-09-04 16:56:52 +08:00
|
|
|
{
|
|
|
|
if (IPCMessageReceivedCallback != null && message.Length > 0)
|
|
|
|
{
|
|
|
|
Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
|
|
|
|
{
|
|
|
|
IPCMessageReceivedCallback(message);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
});
|
2020-04-24 08:11:02 +08:00
|
|
|
ipcmanager.Start();
|
2020-04-08 05:19:33 +08:00
|
|
|
app.Run();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MessageBox.Show(
|
|
|
|
"The application cannot be run as a standalone process. Please start the application through the runner.",
|
|
|
|
"Forbidden",
|
|
|
|
MessageBoxButton.OK);
|
|
|
|
app.Shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 08:11:02 +08:00
|
|
|
public static TwoWayPipeMessageIPCManaged GetTwoWayIPCManager()
|
2020-04-08 05:19:33 +08:00
|
|
|
{
|
|
|
|
return ipcmanager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|