2020-09-04 11:56:52 +03:00
|
|
|
// Copyright (c) Microsoft Corporation
|
2020-04-07 14:19:33 -07: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-23 17:11:02 -07:00
|
|
|
using interop;
|
2020-08-17 10:00:56 -07:00
|
|
|
using ManagedCommon;
|
2020-04-07 14:19:33 -07:00
|
|
|
|
2021-02-11 19:29:56 +03:00
|
|
|
namespace PowerToys.Settings
|
2020-04-07 14:19:33 -07:00
|
|
|
{
|
2020-10-26 11:09:18 -07:00
|
|
|
public static class Program
|
2020-04-07 14:19:33 -07:00
|
|
|
{
|
2021-02-18 16:11:57 +03:00
|
|
|
private enum Arguments
|
|
|
|
|
{
|
|
|
|
|
PTPipeName = 0,
|
|
|
|
|
SettingsPipeName,
|
|
|
|
|
PTPid,
|
|
|
|
|
Theme, // used in the old settings
|
|
|
|
|
ElevatedStatus,
|
|
|
|
|
IsUserAdmin,
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-14 12:36:27 +03:00
|
|
|
// Quantity of arguments
|
2021-02-18 16:11:57 +03:00
|
|
|
private const int ArgumentsQty = 6;
|
2020-05-14 12:36:27 +03:00
|
|
|
|
2020-04-07 14:19:33 -07:00
|
|
|
// Create an instance of the IPC wrapper.
|
2020-04-23 17:11:02 -07:00
|
|
|
private static TwoWayPipeMessageIPCManaged ipcmanager;
|
2020-04-07 14:19:33 -07:00
|
|
|
|
2020-05-05 10:02:31 -07:00
|
|
|
public static bool IsElevated { get; set; }
|
|
|
|
|
|
2020-05-14 12:36:27 +03:00
|
|
|
public static bool IsUserAnAdmin { get; set; }
|
|
|
|
|
|
2020-06-10 20:58:34 +03:00
|
|
|
public static int PowerToysPID { get; set; }
|
|
|
|
|
|
2020-09-04 11:56:52 +03:00
|
|
|
public static Action<string> IPCMessageReceivedCallback { get; set; }
|
|
|
|
|
|
2020-04-10 15:22:07 -07:00
|
|
|
[STAThread]
|
2020-04-07 14:19:33 -07:00
|
|
|
public static void Main(string[] args)
|
|
|
|
|
{
|
2021-02-11 19:29:56 +03:00
|
|
|
using (new Microsoft.PowerToys.Settings.UI.App())
|
2020-04-07 14:19:33 -07:00
|
|
|
{
|
|
|
|
|
App app = new App();
|
|
|
|
|
app.InitializeComponent();
|
|
|
|
|
|
2020-10-26 11:09:18 -07:00
|
|
|
if (args != null && args.Length >= ArgumentsQty)
|
2020-04-07 14:19:33 -07:00
|
|
|
{
|
2021-02-18 16:11:57 +03:00
|
|
|
_ = int.TryParse(args[(int)Arguments.PTPid], out int powerToysPID);
|
2020-06-10 20:58:34 +03:00
|
|
|
PowerToysPID = powerToysPID;
|
|
|
|
|
|
2021-02-18 16:11:57 +03:00
|
|
|
IsElevated = args[(int)Arguments.ElevatedStatus] == "true";
|
|
|
|
|
IsUserAnAdmin = args[(int)Arguments.IsUserAdmin] == "true";
|
2020-05-14 12:36:27 +03:00
|
|
|
|
2020-08-17 10:00:56 -07:00
|
|
|
RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
|
|
|
|
|
{
|
2020-06-25 16:03:50 -07:00
|
|
|
Environment.Exit(0);
|
|
|
|
|
});
|
2020-06-10 20:58:34 +03:00
|
|
|
|
2021-02-18 16:11:57 +03:00
|
|
|
ipcmanager = new TwoWayPipeMessageIPCManaged(args[(int)Arguments.SettingsPipeName], args[(int)Arguments.PTPipeName], (string message) =>
|
2020-09-04 11:56:52 +03:00
|
|
|
{
|
|
|
|
|
if (IPCMessageReceivedCallback != null && message.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
|
|
|
|
|
{
|
|
|
|
|
IPCMessageReceivedCallback(message);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-04-23 17:11:02 -07:00
|
|
|
ipcmanager.Start();
|
2020-04-07 14:19:33 -07: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-23 17:11:02 -07:00
|
|
|
public static TwoWayPipeMessageIPCManaged GetTwoWayIPCManager()
|
2020-04-07 14:19:33 -07:00
|
|
|
{
|
|
|
|
|
return ipcmanager;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|