Пример #1
0
        private void OnButtonClickedEdit(object sender, RoutedEventArgs e)
        {
            MenuItem           sen    = (MenuItem)sender;
            ApplicationDetails detail = (ApplicationDetails)sen.DataContext;

            DetailsWindow detailsDialog = new DetailsWindow(detail);
            bool?         success       = detailsDialog.ShowDialog();

            if (success == true && detailsDialog.ApplicationDetails != null)
            {
                WriteToDisk();
            }
        }
Пример #2
0
        private void OnButtonClickedAdd(object sender, RoutedEventArgs e)
        {
            var picker = new Microsoft.Win32.OpenFileDialog();

            picker.Filter     = "Executables(.exe) | *.exe";
            picker.DefaultExt = ".exe";

            bool?result = picker.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                // Open document
                string file = picker.FileName;
                if (file != null)
                {
                    DetailsWindow detailsDialog = new DetailsWindow(file);
                    detailsDialog.ShowDialog();

                    if (detailsDialog.ApplicationDetails != null)
                    {
                        //Extract the icon from the executable
                        using (System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(file))
                        {
                            //Create an image from the icon
                            BitmapSource iconImage = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                            string       iconPath  = Path.Combine(LocalApplicationDataDirectory, detailsDialog.ApplicationDetails.Name + ".png");

                            //Save the icon to disk
                            using (var fileStream = new FileStream(iconPath, FileMode.Create))
                            {
                                PngBitmapEncoder encoder = new PngBitmapEncoder();
                                encoder.Frames.Add(BitmapFrame.Create(iconImage));
                                encoder.Save(fileStream);
                                fileStream.Close();

                                //Set the icon path, which will cause the icon to load from disk automatically
                                detailsDialog.ApplicationDetails.IconPath = iconPath;
                            }
                        }

                        Programs.Add(detailsDialog.ApplicationDetails);
                        WriteToDisk();
                    }
                }
            }
        }