public static async Task <List <ContextMenuFlyoutItemViewModel> > GetShellContextmenuAsync(bool showOpenMenu, bool shiftPressed, NamedPipeAsAppServiceConnection connection, string workingDirectory, List <ListedItem> selectedItems)
        {
            bool IsItemSelected = selectedItems?.Count > 0;

            var menuItemsList = new List <ContextMenuFlyoutItemViewModel>();

            if (connection != null)
            {
                var(status, response) = await connection.SendMessageForResponseAsync(new ValueSet()
                {
                    { "Arguments", "LoadContextMenu" },
                    { "FilePath", IsItemSelected ?
                      string.Join('|', selectedItems.Select(x => x.ItemPath)) :
                      workingDirectory },
                    { "ExtendedMenu", shiftPressed },
                    { "ShowOpenMenu", showOpenMenu }
                });

                if (status == AppServiceResponseStatus.Success &&
                    response.ContainsKey("Handle"))
                {
                    var contextMenu = JsonConvert.DeserializeObject <Win32ContextMenu>((string)response["ContextMenu"]);
                    if (contextMenu != null)
                    {
                        LoadMenuFlyoutItem(menuItemsList, contextMenu.Items, (string)response["Handle"], true);
                    }
                }
            }

            return(menuItemsList);
        }
示例#2
0
        public static async Task <bool> Elevate(this NamedPipeAsAppServiceConnection connection)
        {
            if (connection == null)
            {
                App.MainViewModel.IsFullTrustElevated = false;
                return(false);
            }

            bool wasElevated = false;

            var(status, response) = await connection.SendMessageForResponseAsync(new ValueSet()
            {
                { "Arguments", "Elevate" }
            });

            if (status == AppServiceResponseStatus.Success)
            {
                var res = response.Get("Success", 1L);
                switch (res)
                {
                case 0:     // FTP is restarting as admin
                    var nullConn = Task.FromResult <NamedPipeAsAppServiceConnection>(null);
                    ConnectionChanged?.Invoke(null, nullConn);
                    (await Instance)?.Dispose();
                    Instance = BuildConnection(false);     // Fulltrust process is already running
                    _        = await Instance;
                    ConnectionChanged?.Invoke(null, Instance);
                    wasElevated = true;
                    break;

                case -1:     // FTP is already admin
                    wasElevated = true;
                    break;

                default:     // Failed (e.g canceled UAC)
                    wasElevated = false;
                    break;
                }
            }

            App.MainViewModel.IsFullTrustElevated = wasElevated;

            return(wasElevated);
        }