public void SetVisibility(BalloonVisibility visibility) { if (NotifyIcon == null) { ShellLogger.Error("NotificationBalloon: NotifyIcon is null"); return; } switch (visibility) { case BalloonVisibility.Visible: NotifyIcon.SendMessage((uint)NIN.BALLOONSHOW, 0); break; case BalloonVisibility.Hidden: NotifyIcon.SendMessage((uint)NIN.BALLOONHIDE, 0); break; case BalloonVisibility.TimedOut: NotifyIcon.SendMessage((uint)NIN.BALLOONTIMEOUT, 0); break; default: break; } }
public void SetOverlayIconDescription(IntPtr lParam) { try { if (ProcId is uint procId) { if (lParam == IntPtr.Zero) { return; } IntPtr hShared = NativeMethods.SHLockShared(lParam, procId); if (hShared == IntPtr.Zero) { return; } string str = Marshal.PtrToStringAuto(hShared); NativeMethods.SHUnlockShared(hShared); OverlayIconDescription = str; } } catch (Exception e) { ShellLogger.Error($"ApplicationWindow: Unable to get overlay icon description from process {Title}: {e.Message}"); } }
private IShellItem GetParentShellItem() { IShellItem parent = null; try { if (_shellItem?.GetParent(out parent) != NativeMethods.S_OK) { parent = null; } } catch (Exception e) { ShellLogger.Error($"ShellItem: Unable to get parent shell item: {e.Message}"); // Fall back to the root shell item via empty string try { parent = GetShellItem(string.Empty); } catch (Exception exception) { ShellLogger.Error($"ShellItem: Unable to get fallback parent shell item: {exception.Message}"); } } return(parent); }
private string GetDisplayName(SIGDN purpose) { IntPtr hString = IntPtr.Zero; string name = string.Empty; try { if (_shellItem?.GetDisplayName(purpose, out hString) == NativeMethods.S_OK) { if (hString != IntPtr.Zero) { name = Marshal.PtrToStringAuto(hString); } } } catch (Exception e) { ShellLogger.Error($"ShellItem: Unable to get {purpose} display name: {e.Message}"); } finally { Marshal.FreeCoTaskMem(hString); } return(name); }
/// <summary> /// Plays the specified system sound using the audio session for system notification sounds. /// </summary> /// <param name="app">The name of the app that the sound belongs to. For example, ".Default" contains system sounds, "Explorer" contains Explorer sounds.</param> /// <param name="name">The name of the system sound to play.</param> public static bool PlaySystemSound(string app, string name) { try { using (RegistryKey key = Registry.CurrentUser.OpenSubKey($"{SYSTEM_SOUND_ROOT_KEY}\\{app}\\{name}\\.Current")) { if (key == null) { ShellLogger.Error($"SoundHelper: Unable to find sound {name} for app {app}"); return(false); } if (key.GetValue(null) is string soundFileName) { if (string.IsNullOrEmpty(soundFileName)) { ShellLogger.Error($"SoundHelper: Missing file for sound {name} for app {app}"); return(false); } return(PlaySound(soundFileName, IntPtr.Zero, (uint)(SND_ASYNC | SND_FILENAME | SND_SYSTEM))); } else { ShellLogger.Error($"SoundHelper: Missing file for sound {name} for app {app}"); return(false); } } } catch (Exception e) { ShellLogger.Error($"SoundHelper: Unable to play sound {name} for app {app}: {e.Message}"); return(false); } }
private static IImageList imlJumbo; // 256pt private static void initIml(IconSize size) { // Initialize the appropriate IImageList for the desired icon size if it hasn't been already if (size == IconSize.Large && imlLarge == null) { SHGetImageList((int)size, ref iidImageList, out imlLarge); } else if (size == IconSize.Small && imlSmall == null) { SHGetImageList((int)size, ref iidImageList, out imlSmall); } else if (size == IconSize.ExtraLarge && imlExtraLarge == null) { SHGetImageList((int)size, ref iidImageList, out imlExtraLarge); } else if (size == IconSize.Jumbo && imlJumbo == null) { SHGetImageList((int)size, ref iidImageList, out imlJumbo); } else if (size != IconSize.Small && size != IconSize.Large && size != IconSize.ExtraLarge && size != IconSize.Jumbo) { ShellLogger.Error($"IconHelper: Unsupported icon size {size}"); } }
private void checkRunAtLogOn() { if (EnvironmentHelper.IsAppConfiguredAsShell.Equals(true)) { chkRunAtLogOn.Visibility = Visibility.Collapsed; } try { RegistryKey rKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", false); List <string> rKeyValueNames = rKey?.GetValueNames().ToList(); if (rKeyValueNames != null) { if (rKeyValueNames.Contains("CairoShell")) { chkRunAtLogOn.IsChecked = true; } else { chkRunAtLogOn.IsChecked = false; } } } catch (Exception e) { ShellLogger.Error($"SettingsWindow: Unable to load autorun setting from registry: {e.Message}"); } }
public SafeNotifyIconData(NOTIFYICONDATA nid) { cbSize = nid.cbSize; hWnd = (IntPtr)nid.hWnd; uID = nid.uID; uFlags = nid.uFlags; uCallbackMessage = nid.uCallbackMessage; try { hIcon = (IntPtr)nid.hIcon; } catch (Exception e) { ShellLogger.Error($"SafeNotifyIconData: Unable to convert icon handle: {e.Message}"); } szTip = nid.szTip; dwState = nid.dwState; dwStateMask = nid.dwStateMask; szInfo = nid.szInfo; uVersion = nid.uVersion; szInfoTitle = nid.szInfoTitle; dwInfoFlags = nid.dwInfoFlags; guidItem = nid.guidItem; hBalloonIcon = nid.hBalloonIcon; }
private void GetParentAndItem() { IParentAndItem pni = _shellItem as IParentAndItem; if (pni == null) { return; } if (pni.GetParentAndItem(out IntPtr parentAbsolutePidl, out IShellFolder parentFolder, out _relativePidl) != NativeMethods.S_OK) { ShellLogger.Error($"ShellItem: Unable to get shell item parent for {Path}"); } if (parentAbsolutePidl != IntPtr.Zero) { Marshal.FreeCoTaskMem(parentAbsolutePidl); } if (parentFolder != null) { // Other ShellItems may reference this IShellFolder so don't set refcount to 0 Marshal.ReleaseComObject(parentFolder); } }
public ChangeWatcher(List <string> pathList, FileSystemEventHandler changedEventHandler, FileSystemEventHandler createdEventHandler, FileSystemEventHandler deletedEventHandler, RenamedEventHandler renamedEventHandler) { if (pathList == null || pathList.Count < 1) { return; } _changedEventHandler = changedEventHandler; _createdEventHandler = createdEventHandler; _deletedEventHandler = deletedEventHandler; _renamedEventHandler = renamedEventHandler; try { foreach (string path in pathList) { FileSystemWatcher watcher = new FileSystemWatcher(path) { NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size }; watcher.Changed += _changedEventHandler; watcher.Created += _createdEventHandler; watcher.Deleted += _deletedEventHandler; watcher.Renamed += _renamedEventHandler; _watchers.Add(watcher); } } catch (Exception e) { ShellLogger.Error($"ChangeWatcher: Unable to instantiate watcher: {e.Message}"); } }
public static ApplicationInfo PathToApp(string filePath, string fileDisplayName, bool allowNonApps, bool allowExcludedNames) { ApplicationInfo ai = new ApplicationInfo(); string fileExt = Path.GetExtension(filePath); if (allowNonApps || ExecutableExtensions.Contains(fileExt, StringComparer.OrdinalIgnoreCase)) { try { ai.Name = fileDisplayName; ai.Path = filePath; string target; if (fileExt.Equals(".lnk", StringComparison.OrdinalIgnoreCase)) { Link link = new Link(filePath); target = link.Target; } else { target = filePath; } ai.Target = target; // remove items that we can't execute. if (!allowNonApps) { if (!string.IsNullOrEmpty(target) && !ExecutableExtensions.Contains(Path.GetExtension(target), StringComparer.OrdinalIgnoreCase)) { ShellLogger.Debug($"AppGrabberService: Not an app: {filePath}: {target}"); return(null); } // remove things that aren't apps (help, uninstallers, etc) if (!allowExcludedNames) { foreach (string word in excludedNames) { if (ai.Name.ToLower().Contains(word)) { ShellLogger.Debug($"AppGrabberService: Excluded item: {filePath}: {target}"); return(null); } } } } return(ai); } catch (Exception ex) { ShellLogger.Error($"AppGrabberService: Error creating ApplicationInfo object: {ex.Message}"); return(null); } } return(null); }
public static ApplicationInfo PathToApp(string file, bool allowNonApps, bool allowExcludedNames) { ApplicationInfo ai = new ApplicationInfo(); string fileExt = Path.GetExtension(file); if (allowNonApps || ExecutableExtensions.Contains(fileExt, StringComparer.OrdinalIgnoreCase)) { try { ai.Name = ShellHelper.GetDisplayName(file); ai.Path = file; string target = string.Empty; if (fileExt.Equals(".lnk", StringComparison.OrdinalIgnoreCase)) { Shell.Link link = new Shell.Link(file); target = link.Target; } else { target = file; } ai.Target = target; // remove items that we can't execute. if (!allowNonApps) { if (!string.IsNullOrEmpty(target) && !ExecutableExtensions.Contains(Path.GetExtension(target), StringComparer.OrdinalIgnoreCase)) { ShellLogger.Debug("Not an app: " + file + ": " + target); return(null); } // remove things that aren't apps (help, uninstallers, etc) if (!allowExcludedNames) { foreach (string word in excludedNames) { if (ai.Name.ToLower().Contains(word)) { ShellLogger.Debug("Excluded item: " + file + ": " + target); return(null); } } } } return(ai); } catch (Exception ex) { ShellLogger.Error("Error creating ApplicationInfo object in appgrabber. " + ex.Message, ex); return(null); } } return(null); }
private ImageSource GetDisplayIcon(IconSize size) { ImageSource icon = null; IShellItemImageFactory imageFactory = GetImageFactory(AbsolutePidl); if (imageFactory == null) { icon = IconImageConverter.GetDefaultIcon(); } else { try { int iconPoints = IconHelper.GetSize(size); SIZE imageSize = new SIZE { cx = (int)(iconPoints * DpiHelper.DpiScale), cy = (int)(iconPoints * DpiHelper.DpiScale) }; IntPtr hBitmap = IntPtr.Zero; SIIGBF flags = 0; if (size == IconSize.Small) { // for 16pt icons, thumbnails are too small flags = SIIGBF.ICONONLY; } if (imageFactory?.GetImage(imageSize, flags, out hBitmap) == NativeMethods.S_OK) { if (hBitmap != IntPtr.Zero) { icon = IconImageConverter.GetImageFromHBitmap(hBitmap); } } } catch (Exception e) { ShellLogger.Error($"ShellItem: Unable to get icon from ShellItemImageFactory: {e.Message}"); } finally { Marshal.FinalReleaseComObject(imageFactory); } } if (icon == null) { // Fall back to SHGetFileInfo icon = IconImageConverter.GetImageFromAssociatedIcon(AbsolutePidl, size); } if (icon == null) { icon = IconImageConverter.GetDefaultIcon(); } return(icon); }
private bool isModernStartMenuOpen() { if (_appVisibilityHelper == null) { ShellLogger.Error("StartMenuMonitor: AppVisibilityHelper is null"); return(false); } return(_appVisibilityHelper.IsLauncherVisible()); }
public void Click() { if (NotifyIcon == null) { ShellLogger.Error("NotificationBalloon: NotifyIcon is null"); return; } NotifyIcon.SendMessage((uint)NIN.BALLOONUSERCLICK, 0); }
void fileWatcher_Renamed(object sender, RenamedEventArgs e) { try { changeFile(e.OldFullPath, e.FullPath); } catch (Exception ex) { ShellLogger.Error("Error in fileWatcher_Renamed.", ex); } }
public static void Raise(EventHandler handler, object sender, EventArgs e) { try { handler?.Invoke(sender, e); } catch (Exception ex) { ShellLogger.Error("Error raising event.", ex); } }
/// <summary> /// Calls the specified delegate, using traditional event raising methodologies. /// </summary> /// <typeparam name="TEventArgs">The EventArgs Type that will be provided to the generic method.</typeparam> /// <param name="handler">The delegate to call.</param> /// <param name="sender">The sender to the delegate..</param> /// <param name="e">The EventArgs to the delegate.</param> public static void Raise <TEventArgs>(EventHandler <TEventArgs> handler, object sender, TEventArgs e) where TEventArgs : EventArgs { try { handler?.Invoke(sender, e); } catch (Exception ex) { ShellLogger.Error("Error raising event.", ex); } }
void fileWatcher_Deleted(object sender, FileSystemEventArgs e) { try { removeFile(e.FullPath); } catch (Exception ex) { ShellLogger.Error("Error in fileWatcher_Deleted.", ex); } }
protected IShellItem GetShellItem(string parsingName) { try { Interop.SHCreateItemFromParsingName(parsingName, IntPtr.Zero, typeof(IShellItem).GUID, out IShellItem ppv); return(ppv); } catch (Exception e) { ShellLogger.Error($"ShellItem: Unable to get shell item for {parsingName}: {e.Message}"); return(null); } }
private IShellItem GetShellItem(IntPtr parentPidl, IShellFolder parentShellFolder, IntPtr relativePidl) { try { Interop.SHCreateItemWithParent(parentPidl, parentShellFolder, relativePidl, typeof(IShellItem).GUID, out IShellItem ppv); return(ppv); } catch (Exception e) { ShellLogger.Error($"ShellItem: Unable to get shell item for {relativePidl}: {e.Message}"); return(null); } }
private IShellFolder GetShellFolder(IntPtr folderPidl) { IShellFolder desktop = GetShellFolder(); Guid guid = typeof(IShellFolder).GUID; if (desktop.BindToObject(folderPidl, IntPtr.Zero, ref guid, out _shellFolderPtr) == NativeMethods.S_OK) { Marshal.ReleaseComObject(desktop); return((IShellFolder)Marshal.GetTypedObjectForIUnknown(_shellFolderPtr, typeof(IShellFolder))); } ShellLogger.Error($"ShellFolder: Unable to bind IShellFolder for {folderPidl}"); return(null); }
public static IServiceCollection LoadDependencies(this IServiceCollection serviceCollection, string path, string pattern = null) { if (string.IsNullOrWhiteSpace(path)) { return(serviceCollection); } if (!Directory.Exists(path)) { return(serviceCollection); } var directoryCatalog = string.IsNullOrWhiteSpace(pattern) ? new DirectoryCatalog(path) : new DirectoryCatalog(path, pattern); var importDefinition = BuildImportDefinition(); try { using (var aggregateCatalog = new AggregateCatalog()) { aggregateCatalog.Catalogs.Add(directoryCatalog); using (var compositionContainer = new CompositionContainer(aggregateCatalog)) { IEnumerable <Export> exports = compositionContainer.GetExports(importDefinition); IEnumerable <IDependencyRegistrant> modules = exports.Select(export => export.Value as IDependencyRegistrant).Where(m => m != null); var registerComponent = new DependencyRegistrar(serviceCollection); foreach (IDependencyRegistrant module in modules) { module.Register(registerComponent); } } } } catch (ReflectionTypeLoadException typeLoadException) { var builder = new StringBuilder(); foreach (Exception loaderException in typeLoadException.LoaderExceptions) { builder.AppendFormat("{0}\n", loaderException.Message); } // TODO: Logging isn't set up at this point in startup ShellLogger.Error($"DependencyLoader: Error registering module: {builder}"); } return(serviceCollection); }
public void AddSubMenu(ShellFolder folder, int position, ref IntPtr parentNativeMenuPtr) { if (GetNewContextMenu(folder)) { iContextMenu.QueryContextMenu( parentNativeMenuPtr, (uint)position, Interop.CMD_FIRST, Interop.CMD_LAST, CMF.NORMAL); nativeMenuPtr = Interop.GetSubMenu(parentNativeMenuPtr, position); if (Marshal.QueryInterface(iContextMenuPtr, ref Interop.IID_IContextMenu2, out iContextMenu2Ptr) == NativeMethods.S_OK) { if (iContextMenu2Ptr != IntPtr.Zero) { try { iContextMenu2 = (IContextMenu2)Marshal.GetTypedObjectForIUnknown(iContextMenu2Ptr, typeof(IContextMenu2)); } catch (Exception e) { ShellLogger.Error($"ShellContextMenu: Error retrieving IContextMenu2 interface: {e.Message}"); } } } if (Marshal.QueryInterface(iContextMenuPtr, ref Interop.IID_IContextMenu3, out iContextMenu3Ptr) == NativeMethods.S_OK) { if (iContextMenu3Ptr != IntPtr.Zero) { try { iContextMenu3 = (IContextMenu3)Marshal.GetTypedObjectForIUnknown(iContextMenu3Ptr, typeof(IContextMenu3)); } catch (Exception e) { ShellLogger.Error($"ShellContextMenu: Error retrieving IContextMenu3 interface: {e.Message}"); } } } } }
private void Enumerate() { IntPtr hEnum = IntPtr.Zero; Files.Clear(); try { if (ShellFolderInterface?.EnumObjects(_hwndInput, SHCONTF.FOLDERS | SHCONTF.NONFOLDERS, out hEnum) == NativeMethods.S_OK) { try { IEnumIDList enumIdList = (IEnumIDList)Marshal.GetTypedObjectForIUnknown(hEnum, typeof(IEnumIDList)); while (enumIdList.Next(1, out var pidlChild, out var numFetched) == NativeMethods.S_OK && numFetched == 1) { if (_isDisposed) { break; } AddFile(pidlChild); } Marshal.FinalReleaseComObject(enumIdList); } catch (Exception e) { ShellLogger.Error($"ShellFolder: Exception while enumerating IShellFolder: {e.Message}"); } finally { Marshal.Release(hEnum); } } else { ShellLogger.Error($"ShellFolder: Unable to enumerate IShellFolder"); } } catch (Exception e) { ShellLogger.Error($"ShellFolder: Unable to enumerate IShellFolder: {e.Message}"); } }
public void ShowDialog() { try { if (uiInstance == null) { uiInstance = new AppGrabberUI(this); uiInstance.Show(); } uiInstance.Activate(); } catch (Exception e) { ShellLogger.Error($"AppGrabberService: Error creating AppGrabberUI: {e.Message}", e); } }
public static bool StartProcess(string filename, string args = "", string verb = "", string workingDirectory = "") { try { if (!Environment.Is64BitProcess) { filename.Replace("system32", "sysnative"); } if (filename.StartsWith("appx:")) { filename = "shell:appsFolder\\" + filename.Substring(5); } else if (filename.Contains("://") && string.IsNullOrEmpty(args)) { args = filename; filename = "explorer.exe"; } else if (EnvironmentHelper.IsAppRunningAsShell && filename.ToLower().EndsWith("explorer.exe") && string.IsNullOrEmpty(args)) { // if we are shell and launching explorer, give it a parameter so that it doesn't do shell things. // this opens My Computer args = ShellFolderPath.ComputerFolder.Value; } ProcessStartInfo psi = new ProcessStartInfo { UseShellExecute = true, FileName = filename, Arguments = args, Verb = verb, WorkingDirectory = workingDirectory }; Process.Start(psi); return(true); } catch (Exception ex) { ShellLogger.Error($"Error running the {verb} verb on {filename}. ({ex.Message})"); return(false); } }
private void TextBlock_PreviewMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed && !isDragging) { isDragging = true; TextBlock sourceBlock = sender as TextBlock; Category selectedCategory = sourceBlock.DataContext as Category; try { DragDrop.DoDragDrop(sourceBlock, selectedCategory, DragDropEffects.Move); } catch (Exception ex) { //Output the reason to the debugger ShellLogger.Error("Error doing Drag-Drop from AppGrabber TextBlock. Details: " + ex.Message, ex); } } }
private IntPtr GetAbsolutePidl() { IntPtr pidl = IntPtr.Zero; try { if (_shellItem != null) { Interop.SHGetIDListFromObject(_shellItem, out pidl); } } catch (Exception e) { ShellLogger.Error($"ShellItem: Unable to get absolute pidl: {e.Message}"); } return(pidl); }
private IShellItemImageFactory GetImageFactory(IntPtr absolutePidl) { if (_shellItem == null) { return(null); } try { Interop.SHCreateItemFromIDList(absolutePidl, typeof(IShellItemImageFactory).GUID, out IShellItemImageFactory ppv); return(ppv); } catch (Exception e) { ShellLogger.Error($"ShellItem: Unable to get shell item image factory for {absolutePidl}: {e.Message}"); return(null); } }