void ProcessFile(string fileName)
        {
            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("Trying to load {0}", fileName);
            }

            if (PathEx.HasExtension(fileName, FileExtensions.Executable) ||
                PathEx.HasExtension(fileName, FileExtensions.Shortcut) ||
                PathEx.HasExtension(fileName, FileExtensions.ClickOnce))
            {
                try
                {
                    ApplicationModel model = ApplicationModel.FromFile(fileName, SelectedTab.Title, true);

                    if (model == null)
                    {
                        return;
                    }

                    if (model.FilePath.StartsWith(@"C:\Windows", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return; // Don't add anything from the windows directory
                    }
                    if (!PathEx.HasExtension(model.FilePath, FileExtensions.Executable))
                    {
                        return; // Only take executable files
                    }
                    if (model.Title.Contains("Install", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return; // Ignore installers
                    }
                    if (model.Title.Contains("Uninstall", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return; // Ignore uninstallers
                    }
                    ApplicationViewModel application = new ApplicationViewModel(model);
                    if (Tabs.Any(obj => obj.Applications.Contains(application)))
                    {
                        return; // Ignore applications already added to the dock
                    }
                    AddApplication(new ApplicationViewModel(model));
                }
                catch (Exception ex)
                {
                    if (Log.IsDebugEnabled)
                    {
                        Log.DebugFormat("Failed to add file to search view - {0}", ex.Message);
                    }
                }
            }
        }
Esempio n. 2
0
        public Bitmap GetImage(IconSize imageSize)
        {
            if (!File.Exists(_imagePath))
            {
                return(null);
            }

            if (PathEx.HasExtension(_imagePath, FileExtensions.Executable) ||
                PathEx.HasExtension(_imagePath, FileExtensions.Shortcut) ||
                PathEx.HasExtension(_imagePath, FileExtensions.Icon))
            {
                return(GetIcon(imageSize));
            }

            try
            {
                return(new Bitmap(_imagePath));
            }
            catch (ArgumentException ex)
            {
                // Unable to convert to an image, assume it's an exe/ico/lnk file even though the extension is wrong.
                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat("Failed to convert {0} to a image, trying to convert to an icon instead: {1}", _imagePath, ex);
                }

                return(GetIcon(imageSize));
            }
            catch (IOException ex)
            {
                // Unable to convert to an image, assume it's an exe/ico/lnk file even though the extension is wrong.
                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat("Failed to convert {0} to a image, trying to convert to an icon instead: {1}", _imagePath, ex);
                }

                return(GetIcon(imageSize));
            }
        }