public override void GetBaseProperties()
        {
            if (Item != null)
            {
                ViewModel.ItemName         = Item.ItemName;
                ViewModel.OriginalItemName = Item.ItemName;
                ViewModel.ItemType         = Item.ItemType;
                ViewModel.ItemPath         = (Item as RecycleBinItem)?.ItemOriginalFolder ??
                                             (Path.IsPathRooted(Item.ItemPath) ? Path.GetDirectoryName(Item.ItemPath) : Item.ItemPath);
                ViewModel.ItemModifiedTimestamp = Item.ItemDateModified;
                ViewModel.ItemCreatedTimestamp  = Item.ItemDateCreated;
                ViewModel.LoadFolderGlyph       = Item.LoadFolderGlyph;
                ViewModel.LoadUnknownTypeGlyph  = Item.LoadUnknownTypeGlyph;
                ViewModel.LoadCustomIcon        = Item.LoadCustomIcon;
                ViewModel.CustomIconSource      = Item.CustomIconSource;
                ViewModel.LoadFileIcon          = Item.LoadFileIcon;

                if (Item.IsShortcutItem)
                {
                    var shortcutItem = (ShortcutItem)Item;

                    var isApplication = !string.IsNullOrWhiteSpace(shortcutItem.TargetPath) &&
                                        (shortcutItem.TargetPath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) ||
                                         shortcutItem.TargetPath.EndsWith(".msi", StringComparison.OrdinalIgnoreCase) ||
                                         shortcutItem.TargetPath.EndsWith(".bat", StringComparison.OrdinalIgnoreCase));

                    ViewModel.ShortcutItemType = isApplication ? "PropertiesShortcutTypeApplication".GetLocalized() :
                                                 Item.IsLinkItem ? "PropertiesShortcutTypeLink".GetLocalized() : "PropertiesShortcutTypeFile".GetLocalized();
                    ViewModel.ShortcutItemPath                 = shortcutItem.TargetPath;
                    ViewModel.ShortcutItemWorkingDir           = shortcutItem.WorkingDirectory;
                    ViewModel.ShortcutItemWorkingDirVisibility = Item.IsLinkItem ? Visibility.Collapsed : Visibility.Visible;
                    ViewModel.ShortcutItemArguments            = shortcutItem.Arguments;
                    ViewModel.ShortcutItemArgumentsVisibility  = Item.IsLinkItem ? Visibility.Collapsed : Visibility.Visible;
                    ViewModel.IsSelectedItemShortcut           = Item.FileExtension.Equals(".lnk", StringComparison.OrdinalIgnoreCase);
                    ViewModel.ShortcutItemOpenLinkCommand      = new RelayCommand(async() =>
                    {
                        if (Item.IsLinkItem)
                        {
                            var tmpItem = (ShortcutItem)Item;
                            await Win32Helpers.InvokeWin32ComponentAsync(ViewModel.ShortcutItemPath, AppInstance, ViewModel.ShortcutItemArguments, tmpItem.RunAsAdmin, ViewModel.ShortcutItemWorkingDir);
                        }
                        else
                        {
                            await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(
                                () => NavigationHelpers.OpenPathInNewTab(Path.GetDirectoryName(ViewModel.ShortcutItemPath)));
                        }
                    }, () =>
                    {
                        return(!string.IsNullOrWhiteSpace(ViewModel.ShortcutItemPath));
                    });
                }
            }
        }
Ejemplo n.º 2
0
 public static IntPtr SendMessage(this Process p, out IntPtr hwnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
 {
     hwnd = p.WindowHandles().FirstOrDefault();
     if (hwnd != IntPtr.Zero)
     {
         return(Win32Helpers.SendMessage(hwnd, msg, wParam, lParam));
     }
     else
     {
         return(IntPtr.Zero);
     }
 }
Ejemplo n.º 3
0
    /// <summary>
    /// Gets the Game View window's top left position.
    /// </summary>
    /// <remarks>Overridden in test project. Do not remove without updating tests.</remarks>
    protected virtual Vector2 GetWindowPosition()
    {
        if (IntPtr.Zero == _gameViewWindowHandle)
        {
            return(new Vector2(float.NaN, float.NaN));
        }

        var windowPosition = new Win32Helpers.POINT();

        Win32Helpers.ClientToScreen(_gameViewWindowHandle, ref windowPosition);
        return(new Vector2(windowPosition.x, windowPosition.y));
    }
Ejemplo n.º 4
0
        public static IEnumerable <IntPtr> GetAllWindows(this Process p)
        {
            var handles = new List <IntPtr>();

            System.Threading.Thread.Sleep(100);
            foreach (ProcessThread thread in p.Threads)
            {
                Win32Helpers.EnumThreadWindows((uint)thread.Id,
                                               (hWnd, lParam) => { handles.Add(hWnd); return(true); }, IntPtr.Zero);
            }

            return(handles);
        }
Ejemplo n.º 5
0
        public void Init(PluginInitContext context)
        {
            _context = context;
            _context.API.ThemeChanged += OnThemeChanged;
            UpdateIconTheme(_context.API.GetCurrentTheme());
            IsBootedInUefiMode = Win32Helpers.GetSystemFirmwareType() == FirmwareType.Uefi;

            // Log info if the system hasn't boot in uefi mode.
            // (Because this is only going into the log we can ignore the fact that normally UEFI and BIOS are written upper case. No need to convert the enumeration value to upper case.)
            if (!IsBootedInUefiMode)
            {
                Wox.Plugin.Logger.Log.Info($"The UEFI command will not show to the user. The system has not booted in UEFI mode or the system does not have an UEFI firmware! (Detected type: {Win32Helpers.GetSystemFirmwareType()})", typeof(Main));
            }
        }
        /// <summary>
        ///     Gets the eye tracked monitor's screen bounds on the Virtual Screen.
        /// </summary>
        /// <returns>
        ///     Rect populated with upper-left corner location (x,y), and
        ///     screen size (width, height) in pixels on the Virtual Screen.
        /// </returns>
        public Rect GetMonitorScreenBounds()
        {
            var monitorHandle = Win32Helpers.MonitorFromWindow(Hwnd,
                                                               Win32Helpers.MONITOR_DEFAULTTONEAREST);
            var monitorInfo = new Win32Helpers.MONITORINFO();

            monitorInfo.cbSize = Marshal.SizeOf(monitorInfo);

            Win32Helpers.GetMonitorInfo(monitorHandle, ref monitorInfo);
            var rc = monitorInfo.rcMonitor;

            return(new Rect(rc.left, rc.top, rc.right - rc.left,
                            rc.bottom - rc.top));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets a boolean value indicating whether the access to a process using the AllAccess flag is denied or not.
        /// </summary>
        /// <param name="pid">The process ID of the process</param>
        /// <returns>True if denied and false if not.</returns>
        private static bool TestProcessAccessUsingAllAccessFlag(uint pid)
        {
            IntPtr processHandle = NativeMethods.OpenProcess(ProcessAccessFlags.AllAccess, true, (int)pid);

            if (Win32Helpers.GetLastError() == 5)
            {
                // Error 5 = ERROR_ACCESS_DENIED
                _ = Win32Helpers.CloseHandleIfNotNull(processHandle);
                return(true);
            }
            else
            {
                _ = Win32Helpers.CloseHandleIfNotNull(processHandle);
                return(false);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the process name for the process ID
        /// </summary>
        /// <param name="pid">The id of the process/param>
        /// <returns>A string representing the process name or an empty string if the function fails</returns>
        internal static string GetProcessNameFromProcessID(uint pid)
        {
            IntPtr        processHandle = NativeMethods.OpenProcess(ProcessAccessFlags.QueryLimitedInformation, true, (int)pid);
            StringBuilder processName   = new StringBuilder(MaximumFileNameLength);

            if (NativeMethods.GetProcessImageFileName(processHandle, processName, MaximumFileNameLength) != 0)
            {
                _ = Win32Helpers.CloseHandleIfNotNull(processHandle);
                return(processName.ToString().Split('\\').Reverse().ToArray()[0]);
            }
            else
            {
                _ = Win32Helpers.CloseHandleIfNotNull(processHandle);
                return(string.Empty);
            }
        }
        /// <summary>
        ///     Gets the Game View window's bottom right corner Position.
        /// </summary>
        /// <remarks>Overridden in test project. Do not remove without updating tests.</remarks>
        protected virtual Vector2 GetWindowBottomRight()
        {
            var clientRect = new Win32Helpers.RECT();

            Win32Helpers.GetClientRect(Hwnd, ref clientRect);

            var bottomRight = new Win32Helpers.POINT
            {
                x = clientRect.right,
                y = clientRect.bottom
            };

            Win32Helpers.ClientToScreen(Hwnd, ref bottomRight);

            return(new Vector2(bottomRight.x, bottomRight.y));
        }
Ejemplo n.º 10
0
    /// <summary>
    /// Maps from logical pixels to physical desktop pixels.
    /// </summary>
    /// <param name="rect">Rectangle to be transformed.</param>
    /// <returns>Transformed rectangle.</returns>
    protected virtual Rect LogicalToPhysical(Rect rect)
    {
        var topLeft = new Win32Helpers.POINT {
            x = (int)rect.x, y = (int)rect.y
        };

        Win32Helpers.LogicalToPhysicalPoint(_hwnd, ref topLeft);

        var bottomRight = new Win32Helpers.POINT {
            x = (int)(rect.x + rect.width), y = (int)(rect.y + rect.height)
        };

        Win32Helpers.LogicalToPhysicalPoint(_hwnd, ref bottomRight);

        return(new Rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y));
    }
Ejemplo n.º 11
0
    protected override Rect GetViewportLogicalBounds()
    {
        var clientRect = new Win32Helpers.RECT();

        Win32Helpers.GetClientRect(_hwnd, ref clientRect);

        var topLeft = new Win32Helpers.POINT();

        Win32Helpers.ClientToScreen(_hwnd, ref topLeft);

        var bottomRight = new Win32Helpers.POINT {
            x = clientRect.right, y = clientRect.bottom
        };

        Win32Helpers.ClientToScreen(_hwnd, ref bottomRight);

        return(new Rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y));
    }
Ejemplo n.º 12
0
 private async void RecentFilesWidget_RecentFileInvoked(object sender, UserControls.PathNavigationEventArgs e)
 {
     try
     {
         var directoryName = Path.GetDirectoryName(e.ItemPath);
         await Win32Helpers.InvokeWin32ComponentAsync(e.ItemPath, AppInstance, workingDirectory : directoryName);
     }
     catch (UnauthorizedAccessException)
     {
         DynamicDialog dialog = DynamicDialogFactory.GetFor_ConsentDialog();
         await dialog.ShowAsync();
     }
     catch (ArgumentException)
     {
         if (new DirectoryInfo(e.ItemPath).Root.ToString().Contains(@"C:\"))
         {
             AppInstance.NavigateWithArguments(FolderSettings.GetLayoutType(e.ItemPath), new NavigationArguments()
             {
                 NavPathParam = e.ItemPath
             });
         }
         else
         {
             foreach (DriveItem drive in Enumerable.Concat(App.DrivesManager.Drives, AppSettings.CloudDrivesManager.Drives))
             {
                 if (drive.Path.ToString() == new DirectoryInfo(e.ItemPath).Root.ToString())
                 {
                     AppInstance.NavigateWithArguments(FolderSettings.GetLayoutType(e.ItemPath), new NavigationArguments()
                     {
                         NavPathParam = e.ItemPath
                     });
                     return;
                 }
             }
         }
     }
     catch (COMException)
     {
         await DialogDisplayHelper.ShowDialogAsync(
             "DriveUnpluggedDialog/Title".GetLocalized(),
             "DriveUnpluggedDialog/Text".GetLocalized());
     }
 }
Ejemplo n.º 13
0
    /// <summary>
    /// Gets the Game View window's bottom right corner position.
    /// </summary>
    /// <remarks>Overridden in test project. Do not remove without updating tests.</remarks>
    protected virtual Vector2 GetWindowBottomRight()
    {
        if (IntPtr.Zero == _gameViewWindowHandle)
        {
            return(new Vector2(float.NaN, float.NaN));
        }

        var clientRect = new Win32Helpers.RECT();

        Win32Helpers.GetClientRect(_gameViewWindowHandle, ref clientRect);

        var bottomRight = new Win32Helpers.POINT {
            x = clientRect.right, y = clientRect.bottom
        };

        Win32Helpers.ClientToScreen(_gameViewWindowHandle, ref bottomRight);

        return(new Vector2(bottomRight.x, bottomRight.y));
    }
Ejemplo n.º 14
0
    /// <summary>
    /// Maps from logical pixels to physical desktop pixels.
    /// </summary>
    /// <param name="rect">Rectangle to be transformed.</param>
    /// <returns>Transformed rectangle.</returns>
    protected virtual Rect LogicalToPhysical(Rect rect)
    {
        if (float.IsNaN(rect.x))
        {
            return(rect);
        }

        var topLeft = new Win32Helpers.POINT {
            x = (int)rect.x, y = (int)rect.y
        };

        Win32Helpers.LogicalToPhysicalPoint(_gameViewWindowHandle, ref topLeft);

        var bottomRight = new Win32Helpers.POINT {
            x = (int)(rect.x + rect.width), y = (int)(rect.y + rect.height)
        };

        Win32Helpers.LogicalToPhysicalPoint(_gameViewWindowHandle, ref bottomRight);

        return(new Rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y));
    }
Ejemplo n.º 15
0
    /// <summary>
    /// Shows the current window.
    /// </summary>
    public static void ShowCurrentWindow()
    {
        IntPtr hwnd = FindWindowWithThreadProcessId(Process.GetCurrentProcess().Id);

        Win32Helpers.ShowWindowAsync(hwnd, Win32Helpers.SW_SHOWDEFAULT);
    }