private SafeNotifyIconData GetTrayItemIconData(TrayItem trayItem)
        {
            SafeNotifyIconData nid = new SafeNotifyIconData();

            nid.hWnd             = trayItem.hWnd;
            nid.uID              = trayItem.uID;
            nid.uCallbackMessage = trayItem.uCallbackMessage;
            nid.szTip            = trayItem.szIconText;
            nid.hIcon            = trayItem.hIcon;
            nid.uVersion         = trayItem.uVersion;
            nid.guidItem         = trayItem.guidItem;
            nid.dwState          = (int)trayItem.dwState;
            nid.uFlags           = NIF.GUID | NIF.MESSAGE | NIF.TIP | NIF.STATE;

            if (nid.hIcon != IntPtr.Zero)
            {
                nid.uFlags |= NIF.ICON;
            }
            else
            {
                ShellLogger.Warning($"ExplorerTrayService: Unable to use {trayItem.szIconText} icon handle for NOTIFYICONDATA struct");
            }

            return(nid);
        }
 private void btnBrowse_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog
         {
             Description = Localization.DisplayString.sDesktop_BrowseTitle,
             ShowNewFolderButton = false,
             SelectedPath = NavigationManager.CurrentItem.Path
         })
         {
             NativeMethods.SetForegroundWindow(helper.Handle); // bring browse window to front
             if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 if (Directory.Exists(fbd.SelectedPath))
                 {
                     NavigationManager.NavigateTo(fbd.SelectedPath);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         ShellLogger.Warning($"DesktopNavigationToolbar: Exception in FolderBrowserDialog: {exception.Message}");
     }
 }
Пример #3
0
        private void SetSearchProvider()
        {
            var thread = new Thread(() =>
            {
                // this sometimes takes a while
                Type provider = typeof(SearchHelper);

                _cairoApplication.Dispatch(() =>
                {
                    CairoSearchMenu.DataContext = new ObjectDataProvider
                    {
                        ObjectType = provider
                    };

                    Binding bSearchText = new Binding("SearchText")
                    {
                        Mode = BindingMode.Default,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    };

                    Binding bSearchResults = new Binding("Results")
                    {
                        Mode    = BindingMode.Default,
                        IsAsync = true
                    };

                    searchStr.SetBinding(TextBox.TextProperty, bSearchText);
                    lstSearchResults.SetBinding(ListView.ItemsSourceProperty, bSearchResults);
                });
            })
            {
                IsBackground = true
            };

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();

            try
            {
                if (_isPrimaryScreen && !isSearchHotkeyRegistered)
                {
                    new HotKey(Key.S, HotKeyModifier.Win | HotKeyModifier.NoRepeat, OnShowSearchHotkey);
                    isSearchHotkeyRegistered = true;
                }
            }
            catch (Exception ex)
            {
                ShellLogger.Warning($"Search: Unable to bind hotkey: {ex.Message}");
            }
        }
Пример #4
0
        private static string getParent(string fileName)
        {
            string parent = null;

            try
            {
                parent = Directory.GetParent(fileName).FullName;
            }
            catch (Exception e)
            {
                ShellLogger.Warning($"CustomCommands: Unable to get parent folder for {fileName}: {e.Message}");
            }

            return(parent);
        }
Пример #5
0
        private string getFileDescription()
        {
            string desc;

            try
            {
                desc = FileVersionInfo.GetVersionInfo(WinFileName).FileDescription;
            }
            catch (Exception e)
            {
                ShellLogger.Warning($"ApplicationWindow: Unable to get file description for {WinFileName} ({Title}): {e.Message}");
                desc = Title;
            }

            return(desc);
        }
Пример #6
0
        public static bool TryCast <T>(object value, out T result, T defaultValue) where T : struct
        {
            result = defaultValue;
            try
            {
                // TODO: look at doing cast without throwing exception.
                // typeof(T).IsAssignableFrom(value.GetType());
                result = (T)value;
                return(true);
            }
            catch (Exception ex)
            {
                ShellLogger.Warning($"Unable to perform cast: {ex.Message}");
            }

            return(false);
        }
Пример #7
0
        public static ApplicationInfo PathToApp(string filePath, bool allowNonApps, bool allowExcludedNames)
        {
            string fileDisplayName = ShellHelper.GetDisplayName(filePath);

            if (filePath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    fileDisplayName = FileVersionInfo.GetVersionInfo(filePath).FileDescription;
                }
                catch (Exception e)
                {
                    ShellLogger.Warning($"AppGrabberService: Unable to get file description for {filePath}: {e.Message}");
                }
            }

            return(PathToApp(filePath, fileDisplayName, allowNonApps, allowExcludedNames));
        }
Пример #8
0
        private void Close()
        {
            try
            {
                // For some reason the framework throws an NRE here if you attempt to drag a non-filesystem file, so catch it
                if (ParentMenuItem != null)
                {
                    ParentMenuItem.IsSubmenuOpen = false;

                    // Stacks capture the mouse; need to release so that mouse events go to the intended recipient after closing
                    Mouse.Capture(null);
                }
            }
            catch (Exception e)
            {
                ShellLogger.Warning($"StacksScroller: Unable to close stack: {e.Message}");
            }
        }
Пример #9
0
        private string getAppParentDirectory(ApplicationInfo app)
        {
            if (app.IsStoreApp)
            {
                return(null);
            }

            string parent = null;

            try
            {
                parent = Directory.GetParent(app.Path).FullName;
            }
            catch (Exception e)
            {
                ShellLogger.Warning($"AppGrabberService: Unable to get parent folder for {app.Path}: {e.Message}");
            }

            return(parent);
        }
Пример #10
0
        private List <string> GetDisallowedItems(StartupLocation location, StartupEntryScope?overrideScope = null)
        {
            List <string> disallowedApps = new List <string>();

            if (!string.IsNullOrEmpty(location.ApprovedLocation))
            {
                StartupEntryScope scope = overrideScope ?? location.Scope;
                RegistryKey[]     roots = ScopeToRoots(scope);

                foreach (var root in roots)
                {
                    try
                    {
                        RegistryKey registryKey =
                            root.OpenSubKey(location.ApprovedLocation, false);

                        if (registryKey != null && registryKey.ValueCount > 0)
                        {
                            foreach (var valueName in registryKey.GetValueNames())
                            {
                                if (((byte[])registryKey.GetValue(valueName))[0] % 2 != 0) // if value is odd number, item is disabled
                                {
                                    disallowedApps.Add(valueName);
                                    ShellLogger.Debug($"StartupRunner: Skipping disabled entry: {valueName}");
                                }
                            }
                        }

                        // close key when finished
                        registryKey?.Close();
                    }
                    catch
                    {
                        ShellLogger.Warning($"StartupRunner: Unable to load allowed startup items list from registry key {location.ApprovedLocation}");
                    }
                }
            }

            return(disallowedApps);
        }
Пример #11
0
        private List <ApplicationInfo> generateAppList(string directory)
        {
            List <ApplicationInfo> rval   = new List <ApplicationInfo>();
            ShellFolder            folder = null;

            try
            {
                folder = new ShellFolder(directory, IntPtr.Zero, false, false);

                foreach (var file in folder.Files)
                {
                    if (file.IsFolder)
                    {
                        if (!file.Path.ToLower().EndsWith("\\startup"))
                        {
                            rval.AddRange(generateAppList(file.Path));
                        }
                    }
                    else
                    {
                        ApplicationInfo app = PathToApp(file.Path, file.DisplayName, false, false);
                        if (!ReferenceEquals(app, null))
                        {
                            rval.Add(app);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ShellLogger.Warning($"AppGrabberService: Unable to enumerate files: {e.Message}");
            }
            finally
            {
                folder?.Dispose();
            }

            return(rval);
        }
Пример #12
0
        public new void Dispose()
        {
            _isDisposed = true;
            _changeWatcher?.Dispose();

            try
            {
                if (_files != null)
                {
                    foreach (var file in Files)
                    {
                        file.Dispose();
                    }

                    Files.Clear();
                }
            }
            catch (Exception e)
            {
                ShellLogger.Warning($"ShellFolder: Unable to dispose files: {e.Message}");
            }

            if (_shellFolder != null)
            {
                Marshal.ReleaseComObject(_shellFolder);
                _shellFolder = null;
            }

            if (_shellFolderPtr != IntPtr.Zero)
            {
                Marshal.Release(_shellFolderPtr);
                _shellFolderPtr = IntPtr.Zero;
            }

            base.Dispose();
        }
Пример #13
0
        private List <StartupEntry> GetAppsFromDirectory(StartupLocation location)
        {
            List <StartupEntry> startupApps     = new List <StartupEntry>();
            List <string>       disallowedItems = GetDisallowedItems(location);
            string locationExpanded             = Environment.ExpandEnvironmentVariables(location.Location);

            try
            {
                if (ShellHelper.Exists(locationExpanded))
                {
                    foreach (string startupFile in Directory.EnumerateFiles(locationExpanded))
                    {
                        if (!ShellHelper.IsFileVisible(startupFile))
                        {
                            continue;
                        }

                        // only add items that are not disabled
                        if (!disallowedItems.Contains(Path.GetFileName(startupFile)))
                        {
                            startupApps.Add(new StartupEntry
                            {
                                Location = location,
                                Path     = startupFile
                            });
                        }
                    }
                }
            }
            catch
            {
                ShellLogger.Warning($"StartupRunner: Unable to load startup items from directory {location}");
            }

            return(startupApps);
        }
Пример #14
0
        private void btnFile_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (file == null)
            {
                return;
            }

            if (!file.IsFileSystem)
            {
                // we can only perform file operations on filesystem objects
                return;
            }

            if (!IsRenaming)
            {
                if (!inDrag && startPoint != null)
                {
                    inDrag = true;

                    Point mousePos = e.GetPosition(this);

                    if (mousePos.X == 0 && mousePos.Y == 0)
                    {
                        // sometimes we get an invalid position, ignore it so we don't start a drag operation
                        startPoint = null;
                        return;
                    }

                    Vector diff = (Point)startPoint - mousePos;

                    if (mousePos.Y <= ActualHeight && ((Point)startPoint).Y <= ActualHeight &&
                        (e.LeftButton == MouseButtonState.Pressed || e.RightButton == MouseButtonState.Pressed) &&
                        (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                         Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
                    {
                        Button     button     = sender as Button;
                        DataObject dragObject = new DataObject();

                        try
                        {
                            dragObject.SetFileDropList(
                                new System.Collections.Specialized.StringCollection {
                                file.Path
                            });

                            DragDrop.DoDragDrop(button, dragObject,
                                                (e.RightButton == MouseButtonState.Pressed
                                    ? DragDropEffects.All
                                    : DragDropEffects.Move));
                        }
                        catch (Exception exception)
                        {
                            ShellLogger.Warning($"Icon: Unable to perform drag-drop operation: {exception.Message}");
                        }

                        // reset the stored mouse position
                        startPoint = null;
                    }
                    else if (e.LeftButton != MouseButtonState.Pressed && e.RightButton != MouseButtonState.Pressed)
                    {
                        // reset the stored mouse position
                        startPoint = null;
                    }

                    inDrag = false;
                }

                e.Handled = true;
            }
        }
Пример #15
0
        private List <StartupEntry> GetAppsFromRegistryKey(StartupLocation location)
        {
            RegistryKey[]       roots       = ScopeToRoots(location.Scope);
            List <StartupEntry> startupApps = new List <StartupEntry>();

            foreach (var root in roots)
            {
                bool isRunOnce = location.Location.Contains("RunOnce");

                try
                {
                    if (isRunOnce && root == Registry.LocalMachine)
                    {
                        continue; // skip HKLM RunOnce since we cannot delete these items, and would run them each startup
                    }
                    RegistryKey registryKey =
                        root.OpenSubKey(location.Location, root == Registry.CurrentUser); // open as writeable if HKCU

                    if (registryKey != null && registryKey.ValueCount > 0)
                    {
                        // get list of disallowed entries
                        List <string> disallowedItems = GetDisallowedItems(location, root == Registry.LocalMachine ? StartupEntryScope.Machine : StartupEntryScope.User);

                        // add items from registry key
                        foreach (var valueName in registryKey.GetValueNames())
                        {
                            // only add items that are not disabled
                            if (!disallowedItems.Contains(valueName))
                            {
                                startupApps.Add(new StartupEntry
                                {
                                    Location = location,
                                    Path     = ((string)registryKey.GetValue(valueName)).Replace("\"", "")
                                });

                                // if this is a runonce key, remove the value after we grab it
                                if (isRunOnce)
                                {
                                    try
                                    {
                                        registryKey.DeleteValue(valueName);
                                    }
                                    catch
                                    {
                                        ShellLogger.Warning($"StartupRunner: Unable to delete RunOnce startup item {valueName}");
                                    }
                                }
                            }
                        }
                    }

                    // close key when finished
                    registryKey?.Close();
                }
                catch
                {
                    ShellLogger.Warning($"StartupRunner: Unable to load startup items from registry key {location.Location}");
                }
            }

            return(startupApps);
        }