Beispiel #1
0
        public List <string> GetThemes()
        {
            List <string> themes = new List <string>
            {
                THEME_DEFAULT
            };

            foreach (var location in THEME_LOCATIONS)
            {
                string themePath = Path.Combine(location, THEME_FOLDER);
                if (ShellHelper.Exists(themePath))
                {
                    foreach (string subStr in Directory.GetFiles(themePath).Where(s => Path.GetExtension(s).Contains(THEME_EXT)))
                    {
                        string theme = Path.GetFileNameWithoutExtension(subStr);
                        if (!themes.Contains(theme))
                        {
                            themes.Add(theme);
                        }
                    }
                }
            }

            return(themes);
        }
        private void btnBrowse_Click(object sender, RoutedEventArgs e)
        {
            string filter = "Programs and shortcuts|";

            foreach (string ext in AppGrabberService.ExecutableExtensions)
            {
                filter += $"*{ext};";
            }

            filter = filter.Substring(0, filter.Length - 2);

            using (OpenFileDialog dlg = new OpenFileDialog
            {
                Filter = filter
            })
            {
                if (dlg.SafeShowDialog() == System.Windows.Forms.DialogResult.OK && ShellHelper.Exists(dlg.FileName))
                {
                    ApplicationInfo customApp = AppGrabberService.PathToApp(dlg.FileName, true, true);
                    if (!ReferenceEquals(customApp, null))
                    {
                        if (!programsMenuAppsCollection.Contains(customApp) && !(InstalledAppsView.ItemsSource as ObservableCollection <ApplicationInfo>).Contains(customApp))
                        {
                            programsMenuAppsCollection.Add(customApp);
                        }
                        else
                        {
                            // disallow adding a duplicate
                            ShellLogger.Debug("Excluded duplicate item: " + customApp.Name + ": " + customApp.Target);
                        }
                    }
                }
            }
        }
        public void InsertByPath(string[] fileNames, int index, AppCategoryType categoryType)
        {
            int count = 0;

            foreach (string fileName in fileNames)
            {
                if (!ShellHelper.Exists(fileName))
                {
                    continue;
                }

                ApplicationInfo customApp = PathToApp(fileName, false, true);
                if (ReferenceEquals(customApp, null))
                {
                    continue;
                }

                Category category;

                if (categoryType == AppCategoryType.Uncategorized || categoryType == AppCategoryType.Standard)
                {
                    // if type is standard, drop in uncategorized
                    category = CategoryList.GetSpecialCategory(AppCategoryType.Uncategorized);
                    if (CategoryList.FlatList.Contains(customApp))
                    {
                        // disallow duplicates within all programs menu categories
                        ShellLogger.Debug($"AppGrabberService: Excluded duplicate item: {customApp.Name}: {customApp.Target}");
                        continue;
                    }
                }
                else
                {
                    category = CategoryList.GetSpecialCategory(categoryType);
                    if (category.Contains(customApp))
                    {
                        // disallow duplicates within the category
                        ShellLogger.Debug($"AppGrabberService: Excluded duplicate item: {customApp.Name}: {customApp.Target}");
                        continue;
                    }
                }

                if (index >= 0)
                {
                    category.Insert(index, customApp);
                }
                else
                {
                    category.Add(customApp);
                }
                count++;
            }

            if (count > 0)
            {
                Save();
            }
        }
        private void getPinnedApps()
        {
            // add Windows taskbar pinned apps to QuickLaunch
            string pinnedPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar";

            if (ShellHelper.Exists(pinnedPath))
            {
                QuickLaunch.AddRange(generateAppList(pinnedPath));
            }
        }
        private static XmlDocument getManifest(string path)
        {
            XmlDocument manifest = new XmlDocument();
            string      manPath  = path + "\\AppxManifest.xml";

            if (ShellHelper.Exists(manPath))
            {
                manifest.Load(manPath);
            }

            return(manifest);
        }
        public void Load()
        {
            if (ShellHelper.Exists(ConfigFile))
            {
                CategoryList = CategoryList.Deserialize(ConfigFile);
            }
            else
            {
                // config file not initialized, run first start logic
                CategoryList = new CategoryList(true);

                getPinnedApps();
            }
        }
Beispiel #7
0
        /// <summary>
        /// Gets an ImageSource object representing the associated icon of a file.
        /// </summary>
        public ImageSource GetIconImageSource(IconSize size, bool useCache)
        {
            if (IsStoreApp)
            {
                string iconUri = IconPath;

                if (!useCache || string.IsNullOrEmpty(iconUri) || !ShellHelper.Exists(iconUri))
                {
                    try
                    {
                        string[] icon = ManagedShell.UWPInterop.StoreAppHelper.GetAppIcon(Target, (int)size);
                        iconUri   = icon[0];
                        IconColor = icon[1];

                        if (useCache)
                        {
                            IconPath = iconUri;
                        }
                    }
                    catch
                    {
                        return(IconImageConverter.GetDefaultIcon());
                    }
                }

                try
                {
                    BitmapImage img = new BitmapImage();
                    img.BeginInit();
                    img.UriSource   = new Uri(iconUri, UriKind.Absolute);
                    img.CacheOption = BitmapCacheOption.OnLoad;
                    img.EndInit();
                    img.Freeze();
                    return(img);
                }
                catch
                {
                    return(IconImageConverter.GetDefaultIcon());
                }
            }
            else
            {
                return(IconImageConverter.GetImageFromAssociatedIcon(Path, size));
            }
        }
        private void DoOperation(BackgroundFileOperation operation, string path)
        {
            try
            {
                if (!ShellHelper.Exists(path))
                {
                    return;
                }

                FileAttributes attr = File.GetAttributes(path);
                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    DoDirectoryOperation(operation, path);
                }
                else
                {
                    DoFileOperation(operation, path);
                }
            }
            catch (Exception e)
            {
                ShellLogger.Error($"FileOperationWorker: Unable to perform {operation.Operation} on {path} into {operation.TargetPath}: {e.Message}");
            }
        }
        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);
        }
Beispiel #10
0
        private Brush GetCairoBackgroundBrush_Image(string wallpaper, CairoWallpaperStyle wallpaperStyle)
        {
            ImageBrush backgroundImageBrush = null;

            if (!string.IsNullOrWhiteSpace(wallpaper) && ShellHelper.Exists(wallpaper))
            {
                try
                {
                    Uri         backgroundImageUri    = new Uri(wallpaper, UriKind.Absolute);
                    BitmapImage backgroundBitmapImage = new BitmapImage(backgroundImageUri);
                    backgroundBitmapImage.Freeze();
                    backgroundImageBrush = new ImageBrush(backgroundBitmapImage);

                    switch (wallpaperStyle)
                    {
                    case CairoWallpaperStyle.Tile:
                        backgroundImageBrush.AlignmentX = AlignmentX.Left;
                        backgroundImageBrush.AlignmentY = AlignmentY.Top;
                        backgroundImageBrush.TileMode   = TileMode.Tile;
                        backgroundImageBrush.Stretch    =
                            Stretch
                            .Fill;         // stretch to fill viewport, which is pixel size of image, as WPF is DPI-aware
                        backgroundImageBrush.Viewport = new Rect(0, 0,
                                                                 (backgroundImageBrush.ImageSource as BitmapSource).PixelWidth,
                                                                 (backgroundImageBrush.ImageSource as BitmapSource).PixelHeight);
                        backgroundImageBrush.ViewportUnits = BrushMappingMode.Absolute;
                        break;

                    case CairoWallpaperStyle.Center:
                        // need to find a way to ignore image DPI for this case
                        backgroundImageBrush.AlignmentX = AlignmentX.Center;
                        backgroundImageBrush.AlignmentY = AlignmentY.Center;
                        backgroundImageBrush.TileMode   = TileMode.None;
                        backgroundImageBrush.Stretch    = Stretch.None;
                        break;

                    case CairoWallpaperStyle.Fit:
                        backgroundImageBrush.AlignmentX = AlignmentX.Center;
                        backgroundImageBrush.AlignmentY = AlignmentY.Center;
                        backgroundImageBrush.TileMode   = TileMode.None;
                        backgroundImageBrush.Stretch    = Stretch.Uniform;
                        break;

                    case CairoWallpaperStyle.Fill:
                    case CairoWallpaperStyle.Span:     // TODO: Impliment multiple monitor backgrounds
                        backgroundImageBrush.AlignmentX = AlignmentX.Center;
                        backgroundImageBrush.AlignmentY = AlignmentY.Center;
                        backgroundImageBrush.TileMode   = TileMode.None;
                        backgroundImageBrush.Stretch    = Stretch.UniformToFill;
                        break;

                    case CairoWallpaperStyle.Stretch:
                    default:
                        backgroundImageBrush.AlignmentX = AlignmentX.Center;
                        backgroundImageBrush.AlignmentY = AlignmentY.Center;
                        backgroundImageBrush.TileMode   = TileMode.None;
                        backgroundImageBrush.Stretch    = Stretch.Fill;
                        break;
                    }

                    backgroundImageBrush.Freeze();
                }
                catch
                {
                    backgroundImageBrush = null;
                }
            }
            return(backgroundImageBrush);
        }
Beispiel #11
0
        public static CategoryList Deserialize(string ConfigFile)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(ConfigFile);
            XmlElement   root    = doc.ChildNodes[0] as XmlElement;
            CategoryList catList = new CategoryList();

            foreach (XmlElement catElement in root.ChildNodes)
            {
                // get category
                Category cat = new Category();
                cat.Name = catElement.Attributes["Name"].Value;
                if (catElement.Attributes["Type"] != null)
                {
                    cat.Type = (AppCategoryType)Convert.ToInt32(catElement.Attributes["Type"].Value);
                }
                else
                {
                    // migration
                    if (cat.Name == "Uncategorized")
                    {
                        cat.Type = AppCategoryType.Uncategorized;
                    }
                    else if (cat.Name == "Quick Launch")
                    {
                        cat.Type = AppCategoryType.QuickLaunch;
                    }
                }
                if (catElement.Attributes["ShowInMenu"] != null)
                {
                    cat.ShowInMenu = Convert.ToBoolean(catElement.Attributes["ShowInMenu"].Value);
                }
                else
                {
                    // force hide quick launch and uncategorized
                    if (cat.Type == AppCategoryType.Uncategorized || cat.Type == AppCategoryType.QuickLaunch)
                    {
                        cat.ShowInMenu = false;
                    }
                }

                catList.Add(cat);

                foreach (XmlElement appElement in catElement.ChildNodes)
                {
                    // get application
                    ApplicationInfo app = new ApplicationInfo
                    {
                        Name = appElement.ChildNodes[0].InnerText,
                        Path = appElement.ChildNodes[1].InnerText
                    };

                    if (appElement.Attributes["AskAlwaysAdmin"] != null)
                    {
                        app.AskAlwaysAdmin = Convert.ToBoolean(appElement.Attributes["AskAlwaysAdmin"].Value);
                    }

                    if (appElement.Attributes["AlwaysAdmin"] != null)
                    {
                        app.AlwaysAdmin = Convert.ToBoolean(appElement.Attributes["AlwaysAdmin"].Value);
                    }

                    if (appElement.ChildNodes.Count > 2)
                    {
                        app.Target = appElement.ChildNodes[2].InnerText;
                    }

                    if (!app.IsStoreApp && !ShellHelper.Exists(app.Path))
                    {
                        ShellLogger.Debug(app.Path + " does not exist");
                        continue;
                    }

                    cat.Add(app);
                }
            }
            return(catList);
        }
        private void setIcon()
        {
            if (!_iconLoading && ShowInTaskbar)
            {
                _iconLoading = true;

                Task.Factory.StartNew(() =>
                {
                    if (IsUWP && !string.IsNullOrEmpty(AppUserModelID))
                    {
                        // UWP apps
                        try
                        {
                            var storeApp = UWPInterop.StoreAppHelper.AppList.GetAppByAumid(AppUserModelID);

                            if (storeApp != null)
                            {
                                Icon = storeApp.GetIconImageSource(_tasksService.TaskIconSize);
                            }
                            else
                            {
                                Icon = IconImageConverter.GetDefaultIcon();
                            }
                        }
                        catch
                        {
                            if (_icon == null)
                            {
                                Icon = IconImageConverter.GetDefaultIcon();
                            }
                        }
                    }
                    else
                    {
                        // non-UWP apps
                        IntPtr hIco           = default;
                        uint WM_GETICON       = (uint)NativeMethods.WM.GETICON;
                        uint WM_QUERYDRAGICON = (uint)NativeMethods.WM.QUERYDRAGICON;
                        int GCL_HICON         = -14;
                        int GCL_HICONSM       = -34;
                        IconSize sizeSetting  = _tasksService.TaskIconSize;

                        if (sizeSetting == IconSize.Small)
                        {
                            NativeMethods.SendMessageTimeout(Handle, WM_GETICON, 2, 0, 2, 1000, ref hIco);
                            if (hIco == IntPtr.Zero)
                            {
                                NativeMethods.SendMessageTimeout(Handle, WM_GETICON, 0, 0, 2, 1000, ref hIco);
                            }
                        }
                        else
                        {
                            NativeMethods.SendMessageTimeout(Handle, WM_GETICON, 1, 0, 2, 1000, ref hIco);
                        }

                        if (hIco == IntPtr.Zero && sizeSetting == IconSize.Small)
                        {
                            if (!Environment.Is64BitProcess)
                            {
                                hIco = NativeMethods.GetClassLong(Handle, GCL_HICONSM);
                            }
                            else
                            {
                                hIco = NativeMethods.GetClassLongPtr(Handle, GCL_HICONSM);
                            }
                        }

                        if (hIco == IntPtr.Zero)
                        {
                            if (!Environment.Is64BitProcess)
                            {
                                hIco = NativeMethods.GetClassLong(Handle, GCL_HICON);
                            }
                            else
                            {
                                hIco = NativeMethods.GetClassLongPtr(Handle, GCL_HICON);
                            }
                        }

                        if (hIco == IntPtr.Zero)
                        {
                            NativeMethods.SendMessageTimeout(Handle, WM_QUERYDRAGICON, 0, 0, 0, 1000, ref hIco);
                        }

                        if (hIco == IntPtr.Zero && _icon == null)
                        {
                            // last resort: find icon by executable. if we already have an icon from a previous fetch, then just skip this
                            if (ShellHelper.Exists(WinFileName))
                            {
                                IconSize size = IconSize.Small;
                                if (sizeSetting != size)
                                {
                                    size = IconSize.Large;
                                }

                                hIco = IconHelper.GetIconByFilename(WinFileName, size);
                            }
                        }

                        if (hIco != IntPtr.Zero)
                        {
                            if (_hIcon != hIco)
                            {
                                _hIcon             = hIco;
                                bool returnDefault = (_icon == null); // only return a default icon if we don't already have one. otherwise let's use what we have.
                                ImageSource icon   = IconImageConverter.GetImageFromHIcon(hIco, returnDefault);
                                if (icon != null)
                                {
                                    icon.Freeze();
                                    Icon = icon;
                                }
                            }
                            else
                            {
                                NativeMethods.DestroyIcon(hIco);
                            }
                        }
                    }

                    _iconLoading = false;
                }, CancellationToken.None, TaskCreationOptions.None, IconHelper.IconScheduler);
            }
        }
Beispiel #13
0
        private void ListView_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(ApplicationInfo)))
            {
                ShellLogger.Debug(e.Data.GetData(typeof(ApplicationInfo)).ToString());
                ApplicationInfo dropData   = e.Data.GetData(typeof(ApplicationInfo)) as ApplicationInfo;
                ListView        dropTarget = sender as ListView;

                if (dropTarget.ItemsSource is Category)
                {
                    Category target = dropTarget.ItemsSource as Category;

                    if (target.Type == AppCategoryType.QuickLaunch)
                    {
                        e.Effects = DragDropEffects.Copy;

                        // Do not duplicate entries
                        if (!target.Contains(dropData))
                        {
                            ApplicationInfo dropClone = dropData.Clone();

                            if (e.OriginalSource != null && e.OriginalSource is FrameworkElement && (e.OriginalSource as FrameworkElement).DataContext != null && (e.OriginalSource as FrameworkElement).DataContext is ApplicationInfo)
                            {
                                target.Insert(target.IndexOf((e.OriginalSource as FrameworkElement).DataContext as ApplicationInfo), dropClone);
                            }
                            else
                            {
                                target.Add(dropClone);
                            }

                            dropClone.Icon = null; // icon may differ depending on category
                        }
                        else
                        {
                            // reorder existing
                            if (e.OriginalSource != null && e.OriginalSource is FrameworkElement && (e.OriginalSource as FrameworkElement).DataContext != null && (e.OriginalSource as FrameworkElement).DataContext is ApplicationInfo)
                            {
                                target.Move(target.IndexOf(dropData), target.IndexOf((e.OriginalSource as FrameworkElement).DataContext as ApplicationInfo));
                            }
                        }
                    }
                    else if (sourceView != null && sourceView != sender)
                    {
                        e.Effects = DragDropEffects.Move;

                        Category source = sourceView.ItemsSource as Category;

                        source.Remove(dropData);

                        if (source.Type != AppCategoryType.QuickLaunch)
                        {
                            target.Add(dropData); // if coming from quick launch, simply remove from quick launch

                            if (dropTarget.Items.Contains(dropData))
                            {
                                dropTarget.ScrollIntoView(dropTarget.Items[dropTarget.Items.IndexOf(dropData)]);
                            }
                        }
                    }
                }
                else
                {
                    e.Effects = DragDropEffects.Move;

                    (sourceView.ItemsSource as IList <ApplicationInfo>).Remove(dropData);
                    (dropTarget.ItemsSource as IList <ApplicationInfo>).Add(dropData);

                    if (dropTarget.Items.Contains(dropData))
                    {
                        dropTarget.ScrollIntoView(dropTarget.Items[dropTarget.Items.IndexOf(dropData)]);
                    }
                }
            }
            else if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] fileNames = e.Data.GetData(DataFormats.FileDrop) as string[];
                if (fileNames != null)
                {
                    ListView dropTarget = sender as ListView;

                    if (!(dropTarget.ItemsSource is Category))
                    {
                        foreach (String fileName in fileNames)
                        {
                            ShellLogger.Debug(fileName);

                            if (ShellHelper.Exists(fileName))
                            {
                                ApplicationInfo customApp = AppGrabberService.PathToApp(fileName, false, false);
                                if (!object.ReferenceEquals(customApp, null))
                                {
                                    (dropTarget.ItemsSource as IList <ApplicationInfo>).Add(customApp);

                                    if (dropTarget.Items.Contains(customApp))
                                    {
                                        dropTarget.ScrollIntoView(dropTarget.Items[dropTarget.Items.IndexOf(customApp)]);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            sourceView = null;
            isDragging = false;
        }