/// <summary>
 ///     Safely try to extract icon from specified file. Return null if failed.
 /// </summary>
 internal static Icon TryExtractAssociatedIcon(string path)
 {
     if (path != null && File.Exists(path))
     {
         try
         {
             return(DrawingTools.ExtractAssociatedIcon(path));
         }
         catch (Exception ex)
         {
             Debug.Fail(ex.Message);
         }
     }
     return(null);
 }
Exemple #2
0
        public MainWindow()
        {
            _handler = new UninstallHandler();
            InitializeComponent();

            try
            {
                Icon = DrawingTools.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            _timeSinceStart = Process.GetCurrentProcess().StartTime.ToUniversalTime();
        }
Exemple #3
0
        public UninstallSelection(DirectoryInfo target)
        {
            InitializeComponent();
            targetList1.Populate(target);

            try
            {
                Icon = DrawingTools.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
            }
            catch (Exception ex)
            {
                /* Fall back to a low quality icon */
                var handle = Resources.icon.GetHicon();
                Icon = Icon.FromHandle(handle);

                Console.WriteLine(ex);
                LogWriter.WriteMessageToLog(ex.ToString());
            }

            Text = string.Format(Localisation.UninstallSelection_Title, target.Name);
        }
        private void SetNodes(int[] processIDs, bool processChildren)
        {
            var results = new List <TreeNode>();
            var il      = new ImageList();

            il.Images.Add(DefaultImageKey, SystemIcons.Application);
            treeView1.ImageKey = DefaultImageKey;

            foreach (var id in processIDs)
            {
                try
                {
                    var p = Process.GetProcessById(id);
                    if (p.HasExited)
                    {
                        continue;
                    }

                    var mainPrName = string.IsNullOrEmpty(p.MainWindowTitle) ? p.ProcessName : p.MainWindowTitle;
                    var node       = new TreeNode(mainPrName)
                    {
                        SelectedImageKey = mainPrName,
                        ImageKey         = mainPrName,
                        Tag = p
                    };
                    results.Add(node);

                    try
                    {
                        var ico = DrawingTools.ExtractAssociatedIcon(p.MainModule.FileName);
                        if (ico != null)
                        {
                            il.Images.Add(mainPrName, ico);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }

                    if (!processChildren)
                    {
                        continue;
                    }
                    try
                    {
                        var children = ProcessTools.GetChildProcesses(id);
                        node.Nodes.AddRange(children.Select(x =>
                        {
                            var pr   = Process.GetProcessById(x);
                            var name = string.IsNullOrEmpty(pr.MainWindowTitle)
                                ? pr.ProcessName
                                : pr.MainWindowTitle;
                            return(new TreeNode(name)
                            {
                                SelectedImageKey = mainPrName,
                                ImageKey = mainPrName,
                                Tag = pr
                            });
                        }).ToArray());
                    }
                    catch (Exception ex)
                    {
                        // Ignore, probably the process exited by now. The child nodes are not important
                        Console.WriteLine(ex);
                    }
                }
                catch (Exception ex)
                {
                    // Probably the main process exited, remove it from the task
                    Console.WriteLine(ex);
                }
            }

            treeView1.Nodes.Clear();
            var prev = treeView1.ImageList;

            treeView1.ImageList = il;
            prev?.Dispose();

            treeView1.Nodes.AddRange(results.ToArray());
        }