Esempio n. 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;
        }
 public ShortcutItem(string file, string IconSource = "Default") : this()
 {
     ShortCutLocation = System.IO.Path.GetExtension(file).ToLower() == ".lnk" ? LayoutObjects.GetOriginalFileURL(file) : file;
     // FileName = LayoutObjects.CreateTextBlock(System.IO.Path.GetFileNameWithoutExtension(ShortCutLocation));
     FileName_beta = CreateTextBox(System.IO.Path.GetFileNameWithoutExtension(ShortCutLocation));
     LoadGeneralDesign();
     //Check if a directory
     try
     {
         //set the default folder Image
         if (((FileAttributes)System.IO.File.GetAttributes(file)).HasFlag(FileAttributes.Directory))
         {
             //CreateIconFromImage("pack://application:,,,/Resources/Folder_Icon.png");
             ShortcutIcon.Source = LayoutObjects.GetImageSource("pack://application:,,,/Resources/Folder_Icon.png");
             LoadFolderDesign();
         }
         //else set the the Default Design
         else
         {
             if (IconSource == "Default")
             {
                 //LoadDefaultDesign();
                 LoadDefaultIcon(ShortCutLocation);
             }
             else
             {
                 LoadCustomDesign(IconSource);
             }
             //to save Icons location when its loaded
             IconSourceLocation = IconSource;
         }
     }
     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;
     }
     SizeChanged += ShortcutItem_SizeChanged;
     return;
 }