Ejemplo n.º 1
0
        private static async Task <NamedPipeAsAppServiceConnection> BuildConnection(bool launchFullTrust)
        {
            try
            {
                if (launchFullTrust)
                {
                    // Launch fulltrust process
                    ApplicationData.Current.LocalSettings.Values["PackageSid"] =
                        WebAuthenticationBroker.GetCurrentApplicationCallbackUri().Host.ToUpperInvariant();
                    await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
                }

                var connection = new NamedPipeAsAppServiceConnection();
                if (await connection.Connect(@"LOCAL\FilesInteropService_ServerPipe", TimeSpan.FromSeconds(15)))
                {
                    return(connection);
                }
                connection.Dispose();
            }
            catch (Exception ex)
            {
                App.Logger.Warn(ex, "Could not initialize FTP connection!");
            }
            return(null);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        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);
        }