Beispiel #1
0
        public AppInfo(string file, string IconSource = "Default") : this()
        {
            //To get the original exe file instead of shortcut
            ShortCutLocation = Path.GetExtension(file).ToLower() == ".lnk" ? LayoutObjects.GetOriginalFileURL(file) : file;
            FileName         = LayoutObjects.CreateTextBlock(System.IO.Path.GetFileName(ShortCutLocation));

            //Check if a directory
            try
            {
                if (((FileAttributes)System.IO.File.GetAttributes(file)).HasFlag(FileAttributes.Directory))
                {
                    CreateIconFromImage("pack://application:,,,/Resources/Folder_Icon.png");
                }
                else
                {
                    //check If Icon is new created or loaded
                    file = IconSource == "Default" ? file : IconSource; //if loaded the Icon will Be change
                    IconSourceLocation = GetExtensionIconUrl(file);

                    if (!Object.ReferenceEquals(IconSourceLocation, null))
                    {
                        IconSourceLocation = IconSourceLocation != "" ? IconSourceLocation : file;
                        CreateIconFromImage(IconSourceLocation != "" ? IconSourceLocation : file);
                    }
                    else
                    {
                        IconSourceLocation = ShortCutLocation;
                        CreateIconFromexe(ShortCutLocation);
                    }
                }

                AddElements();
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("A file is missing\nCan't find " + file);
                IsThereisErrors = true;
            }
            catch (DirectoryNotFoundException)
            {
                MessageBox.Show("Directory is missing\n Cant find " + file);
                IsThereisErrors = true;
            }
            catch (Exception e)
            {
                MessageBox.Show("Error happened while adding " + file + " \nMay save File corrupted or no permission to access this file\ndeleted shortcut from DM\nerror: " + e.Message);
                IsThereisErrors = true;
            }


            return;
        }
        private void LoadDefaultDesign()
        {
            IconSourceLocation = "Default";
            //add them to the holder
            Viewbox   viewbox = new Viewbox();
            TextBlock tb      = LayoutObjects.CreateTextBlock(System.IO.Path.GetFileNameWithoutExtension(ShortCutLocation));

            tb.Foreground = new SolidColorBrush((System.Windows.Media.Color)
                                                System.Windows.Media.ColorConverter.ConvertFromString
                                                    (AppTheme.Foreground));
            viewbox.Child = tb;
            TheEventsHolder.Children.Add(viewbox);
        }