Esempio n. 1
0
        public ApplicationDockItem(DesktopEntry entry)
        {
            WindowHandles = new List <IntPtr>();

            DesktopEntry = entry;

            Autorun = false;
            Pinned  = true;

            Name = entry.Name;

            Image = entry.Icon;

            if (entry.Type == DesktopEntryType.Application)
            {
                var possitiblities = AppUserModelId.Find(entry.TryExec);
                AppId = AppUserModelId.Find(entry.TryExec).Where(a => File.Exists(a.DestinationList)).FirstOrDefault();
                if (AppId == null)
                {
                    AppId = possitiblities.FirstOrDefault();
                }
            }
            else
            {
                AppId = AppUserModelId.FromExplicitAppId("C:\\Windows\\explorer.exe", "Microsoft.Windows.Explorer").First();
            }
        }
Esempio n. 2
0
        public ApplicationDockItem(IntPtr windowHandle)
        {
            WindowHandles = new List <IntPtr> {
                windowHandle
            };

            Autorun = false;
            Pinned  = false;

            var possibleIds = AppUserModelId.Find(windowHandle);

            AppId = possibleIds.Where(a => File.Exists(a.DestinationList)).FirstOrDefault();
            if (AppId == null)
            {
                AppId = possibleIds.FirstOrDefault();
            }

            if (AppId != null)
            {
                DesktopEntry = new DesktopEntry()
                {
                    TryExec = AppId.Executable
                };
            }
        }
Esempio n. 3
0
        public Taskbar()
        {
            var pinned = LoadPinnedItems().ToList();
            var visibleWindowsHandles = LoadTopLevelWindows().ToList();

            Items = new List <ApplicationDockItem>();

            foreach (var item in pinned)
            {
                var entry    = DesktopEntryManager.FromFile(item);
                var dockItem = new ApplicationDockItem(entry);
                dockItem.Pinned = true;
                Items.Add(dockItem);
            }

            foreach (var hWnd in visibleWindowsHandles)
            {
                var  id    = AppUserModelId.Find(hWnd).Where(a => File.Exists(a.DestinationList)).FirstOrDefault();
                bool match = false;

                if (id != null)
                {
                    foreach (var item in Items)
                    {
                        if (item.AppId != null && item.AppId.Id == id.Id)
                        {
                            item.RegisterWindowHandle(hWnd);
                            match = true;
                            break;
                        }
                    }
                }

                if (!match)
                {
                    var dockItem = new ApplicationDockItem(hWnd);
                    //Items.Add(dockItem);
                }
            }
        }
Esempio n. 4
0
        private void LoadIcons()
        {
            // Load application shortcuts from existing folder if possible
            if (Directory.Exists(PinnedIconsFolder) && Directory.GetFiles(PinnedIconsFolder).Where(s => new FileInfo(s).Attributes.HasFlag(FileAttributes.Hidden) == false).Count() > 0)
            {
                foreach (var appIconShortcutFile in Directory.GetFiles(PinnedIconsFolder))
                {
                    var entry = DesktopEntryManager.FromFile(appIconShortcutFile);
                    try
                    {
                        var possibleAppIds = AppUserModelId.Find(entry.TryExec);
                        var appId          = possibleAppIds.FirstOrDefault(a => File.Exists(a.DestinationList)) ?? possibleAppIds.First();

                        if (appId != null)
                        {
                            var item = new ApplicationDockItem(entry);
                            items.Add(item);
                            OnItemsChanged(this, ItemsChangedEventArgs <DockItem> .BuildAddedEvents(new List <DockItem> {
                                item
                            }));
                        }
                    }
                    catch { }
                }
            }
            else // No existing items found, try to load icons from the Taskbar
            {
                using (var taskbar = new Taskbar())
                {
                    items.AddRange(taskbar.Items);
                }
            }

            hook = new Hook();
            var timer = new System.Timers.Timer(100);

            timer.Elapsed += (object o, System.Timers.ElapsedEventArgs e) =>
            {
                while (hook.HasCreatedWindow())
                {
                    var hwnd    = hook.PopCreatedWindow();
                    var process = Process.GetProcesses().Where(p => p.MainWindowHandle == hwnd).SingleOrDefault();
                    if (process == null)
                    {
                        continue;
                    }
                    foreach (var item in Items)
                    {
                        if (((ApplicationDockItem)item).DesktopEntry.TryExec == process.MainModule.FileName)
                        {
                            ((ApplicationDockItem)item).RegisterWindowHandle(hwnd);
                            break;
                        }
                    }
                }

                while (hook.HasDestroyedWindow())
                {
                    var hwnd = hook.PopDestroyedWindow();
                    foreach (var item in Items)
                    {
                        if (((ApplicationDockItem)item).HasRegisteredWindowHandle(hwnd))
                        {
                            ((ApplicationDockItem)item).UnregisterWindowHandle(hwnd);
                            break;
                        }
                    }
                }
            };
            timer.Enabled = true;
        }
Esempio n. 5
0
        private static DesktopEntry FromShellLinkFileAlt(string linkFilePath)
        {
            var shl = new Shell32.Shell();
            var dir = shl.NameSpace(System.IO.Path.GetDirectoryName(linkFilePath));
            var itm = dir.Items().Item(System.IO.Path.GetFileName(linkFilePath));
            var lnk = (Shell32.ShellLinkObject)itm.GetLink;

            if (lnk != null)
            {
                lnk.Resolve(0);
                var entryType = GetLinkTypeAlt(lnk);

                if (entryType == DesktopEntryType.Application)
                {
                    AppUserModelId appId = null;
                    try
                    {
                        appId = AppUserModelId.Find(lnk.Target.Path).FirstOrDefault();
                    }
                    catch { }
                    Dictionary <string, DesktopAction> actions = null;
                    if (appId != null && appId.DestinationList != null)
                    {
                        actions = ExtractJumpListActions(appId.DestinationList);
                    }

                    Image icon = null;

                    try
                    {
                        icon = WindowsManagedApi.User32.Helpers.ExtractIcon(lnk.Target.Path) ?? WindowsManagedApi.User32.Helpers.ExtractIcon(linkFilePath);
                    }
                    catch { }

                    if (icon == null)
                    {
                        icon = OldResolve(linkFilePath).ToBitmap();
                    }

                    return(new DesktopEntry
                    {
                        Icon = icon,
                        TryExec = lnk.Target.Path,
                        Exec = lnk.Target.Path + " " + lnk.Arguments,
                        Comment = lnk.Description,
                        Name = global::System.IO.Path.GetFileNameWithoutExtension(linkFilePath),
                        Actions = actions,
                        Version = new Version(1, 0),
                        Path = Environment.ExpandEnvironmentVariables(lnk.WorkingDirectory),
                        Type = DesktopEntryType.Application
                    });
                }
                if (entryType == DesktopEntryType.Directory)
                {
                    return(new DesktopEntry
                    {
                        Icon = WindowsManagedApi.User32.Helpers.ExtractIcon(Path.Combine(Environment.SystemDirectory, "..", "explorer.exe"), 0),
                        Name = global::System.IO.Path.GetFileNameWithoutExtension(linkFilePath),
                        Version = new Version(1, 0),
                        Path = lnk.Target.Path,
                        Type = DesktopEntryType.Directory
                    });
                }
            }

            return(DesktopEntry.Invalid);
        }
Esempio n. 6
0
        public static DesktopEntry FromShellLinkFile(string linkFilePath)
        {
            var shellLink = GetShellLink(linkFilePath);
            var entryType = GetLinkType(shellLink);

            if (entryType == DesktopEntryType.Invalid)
            {
                return(FromShellLinkFileAlt(linkFilePath));
            }

            if (entryType == DesktopEntryType.Application)
            {
                AppUserModelId appId = null;
                try
                {
                    appId = AppUserModelId.Find(shellLink.TargetPath).FirstOrDefault();
                }
                catch { }
                Dictionary <string, DesktopAction> actions = null;
                if (appId != null && appId.DestinationList != null)
                {
                    actions = ExtractJumpListActions(appId.DestinationList);
                }

                Image icon = null;

                try
                {
                    icon = WindowsManagedApi.User32.Helpers.ExtractIcon(shellLink.TargetPath) ?? WindowsManagedApi.User32.Helpers.ExtractIcon(linkFilePath);
                }
                catch { }

                if (icon == null)
                {
                    icon = OldResolve(linkFilePath).ToBitmap();
                }

                return(new DesktopEntry
                {
                    Icon = icon,
                    TryExec = shellLink.TargetPath,
                    Exec = shellLink.TargetPath + " " + shellLink.Arguments,
                    Comment = shellLink.Description,
                    Name = global::System.IO.Path.GetFileNameWithoutExtension(shellLink.FullName),
                    Actions = actions,
                    Version = new Version(1, 0),
                    Path = Environment.ExpandEnvironmentVariables(shellLink.WorkingDirectory),
                    Type = DesktopEntryType.Application
                });
            }
            if (entryType == DesktopEntryType.Directory)
            {
                return(new DesktopEntry
                {
                    Icon = WindowsManagedApi.User32.Helpers.ExtractIcon(Paths.SystemIconFile, 5),
                    Name = global::System.IO.Path.GetFileNameWithoutExtension(shellLink.FullName),
                    Version = new Version(1, 0),
                    Path = shellLink.TargetPath,
                    Type = DesktopEntryType.Directory
                });
            }

            return(DesktopEntry.Invalid);
        }