Beispiel #1
0
        public static string GetIcon(ElementAssociationType type, string fileFullName)
        {
            switch (type)
            {
            case ElementAssociationType.File:
                return(GetFileIcon(fileFullName));

            case ElementAssociationType.FileShortcut:
                return(GetFileShortcutIcon(fileFullName));

            case ElementAssociationType.Folder:
                return(GetFolderIcon());

            case ElementAssociationType.FolderShortcut:
                return(GetFolderShortcutIcon());

            case ElementAssociationType.Web:
                return(GetWebShortcutIcon());

            case ElementAssociationType.Tweet:
                return(GetTweetShortcutIcon());

            case ElementAssociationType.Email:
                return(GetEmailShortcutIcon());

            case ElementAssociationType.Appointment:
                return(GetAppointmentShortcutIcon());

            default:
                return(String.Empty);
            }
            ;
        }
Beispiel #2
0
        public static int GetFileType(string fileFullName)
        {
            ElementAssociationType eat = ElementAssociationType.File;
            string ext = System.IO.Path.GetExtension(fileFullName).ToLower();

            switch (ext)
            {
            case ".lnk":
                try
                {
                    WshShellClass wshShell = new WshShellClass();
                    IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(fileFullName);
                    string targetPath = shortcut.TargetPath;
                    if (Directory.Exists(targetPath))
                    {
                        eat = ElementAssociationType.FolderShortcut;
                    }
                    else
                    {
                        eat = ElementAssociationType.FileShortcut;
                    }
                }
                catch (Exception)
                {
                    eat = ElementAssociationType.FileShortcut;
                }
                break;

            default:
                eat = ElementAssociationType.File;
                break;
            }
            ;
            return((int)eat);
        }
Beispiel #3
0
 public static string GetIcon(ElementAssociationType type, string fileFullName)
 {
     switch (type)
     {
         case ElementAssociationType.File:
             return GetFileIcon(fileFullName);
         case ElementAssociationType.FileShortcut:
             return GetFileShortcutIcon(fileFullName);
         case ElementAssociationType.Folder:
             return GetFolderIcon();
         case ElementAssociationType.FolderShortcut:
             return GetFolderShortcutIcon();
         case ElementAssociationType.Web:
             return GetWebShortcutIcon();
         case ElementAssociationType.Tweet:
             return GetTweetShortcutIcon();
         case ElementAssociationType.Email:
             return GetEmailShortcutIcon();
         case ElementAssociationType.Appointment:
             return GetAppointmentShortcutIcon();
         default:
             return String.Empty;
     };
 }
Beispiel #4
0
        public void AddAssociation(Element element, string fileFullName, ElementAssociationType type, string text)
        {
            string noteText = String.Empty;
            string shortcutName = String.Empty;
            string folderPath = element.Path;
            string title = string.Empty;

            List<Element> emailAttachmentElementList = new List<Element>();

            if (text != null)
            {
                noteText = text;
                if (noteText.Length > StartProcess.MAX_EXTRACTTEXT_LENGTH)
                {
                    noteText = noteText.Substring(0, StartProcess.MAX_EXTRACTTEXT_LENGTH) + "...";
                }
                title = noteText.Replace("/", "").Replace("\\", "").Replace("*", "").Replace("?", "").Replace("\"", "").Replace("<", "").Replace(">", "").Replace("|", "").Replace(":", "");
                if (title.Length > StartProcess.MAX_EXTRACTNAME_LENGTH)
                    title = title.Substring(0, StartProcess.MAX_EXTRACTNAME_LENGTH);
                while (title.EndsWith("."))
                    title.TrimEnd('.');
            }

            if (type == ElementAssociationType.File)
            {

            }
            else if (type == ElementAssociationType.FileShortcut)
            {
                if (text == null)
                {
                    noteText = noteText = System.IO.Path.GetFileNameWithoutExtension(fileFullName);
                    title = noteText;
                }

                string fs_fileName = title + System.IO.Path.GetExtension(fileFullName);
                shortcutName = ShortcutNameConverter.GenerateShortcutNameFromFileName(fs_fileName, folderPath);
            }
            else if (type == ElementAssociationType.FolderShortcut)
            {
                if (fileFullName.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
                {
                    fileFullName = fileFullName.Substring(0, fileFullName.Length - 1);
                }
                noteText = System.IO.Path.GetFileName(fileFullName);

                string fs_fileName = noteText;
                shortcutName = ShortcutNameConverter.GenerateShortcutNameFromFileName(fs_fileName, folderPath);
            }
            else if (type == ElementAssociationType.Web)
            {
                if (text == null)
                {
                    ActiveWindow activeWindow = new ActiveWindow();
                    title = activeWindow.GetActiveWindowText(activeWindow.GetActiveWindowHandle());
                    if(title.Contains(" - Windows Internet Explorer"))
                    {
                        // IE
                        int labelIndex1 = title.LastIndexOf(" - Windows Internet Explorer");
                        if (labelIndex1 != -1)
                        {
                            title = title.Remove(labelIndex1);
                            noteText = title;
                        }
                    }else if(title.Contains(" - Mozilla Firefox"))
                    {
                        // Firefox
                        int labelIndex2 = title.LastIndexOf(" - Mozilla Firefox");
                        if (labelIndex2 != -1)
                        {
                            title = title.Remove(labelIndex2);
                            noteText = title;
                        }
                    }else
                    {
                        noteText = fileFullName;
                        title = string.Empty;
                    }

                    if (noteText.Length > StartProcess.MAX_EXTRACTTEXT_LENGTH)
                    {
                        noteText = noteText.Substring(0, StartProcess.MAX_EXTRACTTEXT_LENGTH) + "...";
                    }
                }
                shortcutName = ShortcutNameConverter.GenerateShortcutNameFromWebTitle(title, folderPath);

            }
            else if (type == ElementAssociationType.Email)
            {
                Outlook.Application outlookApp = new Outlook.Application();
                Outlook.MailItem mailItem = null;
                if (outlookApp.ActiveExplorer().Selection.Count > 0)
                {
                    mailItem = outlookApp.ActiveExplorer().Selection[1] as Outlook.MailItem;

                    if (mailItem == null)
                        return;

                    if (mailItem != null)
                    {
                        Element associatedElement = element;
                        if (element.IsHeading && element.IsCollapsed)
                        {
                            associatedElement = element.ParentElement;
                        }

                        Regex byproduct = new Regex("att[0-9]+[.txt|.c]");

                        foreach (Outlook.Attachment attachment in mailItem.Attachments)
                        {
                            string attachmentFileName = attachment.FileName;

                            if (!byproduct.IsMatch(attachmentFileName.ToLower()))
                            {
                                string fileNameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(attachmentFileName);
                                string fileNameExt = System.IO.Path.GetExtension(attachmentFileName);
                                string copyPath = associatedElement.Path + attachmentFileName;
                                int index = 2;
                                while (FileNameChecker.Exist(copyPath))
                                {
                                    copyPath = associatedElement.Path + fileNameWithoutExt + " (" + index.ToString() + ")" + fileNameExt;
                                    index++;
                                }
                                attachment.SaveAsFile(copyPath);

                                Element attachmentElement = CreateNewElement(ElementType.Note, " --- " + fileNameWithoutExt);
                                attachmentElement.AssociationType = ElementAssociationType.File;
                                attachmentElement.AssociationURI = System.IO.Path.GetFileName(copyPath);
                                attachmentElement.TailImageSource = FileTypeHandler.GetIcon((ElementAssociationType)attachmentElement.AssociationType, copyPath);
                                emailAttachmentElementList.Add(attachmentElement);
                            }
                        }
                    }
                }
                if ((fileFullName == null) && (mailItem != null))
                {
                    noteText = mailItem.Subject;
                    if (noteText.Length > StartProcess.MAX_EXTRACTTEXT_LENGTH)
                    {
                        noteText = noteText.Substring(0, StartProcess.MAX_EXTRACTTEXT_LENGTH) + "...";
                    }
                    fileFullName = mailItem.EntryID;
                    shortcutName = ShortcutNameConverter.GenerateShortcutNameFromEmailSubject(mailItem.Subject, folderPath);
                }
                else
                {
                    shortcutName = ShortcutNameConverter.GenerateShortcutNameFromEmailSubject(title, folderPath);
                }
            }

            switch (element.Type)
            {
                case ElementType.Heading:
                    if (element.IsExpanded)
                    {
                        Element firstElement = CreateNewElement(ElementType.Note, noteText);
                        InsertElement(firstElement, element, 0);
                        AssignAssociationInfo(firstElement, fileFullName, shortcutName, type);
                        currentElement = firstElement;
                    }
                    else
                    {
                        Element newElement = CreateNewElement(ElementType.Note, noteText);
                        InsertElement(newElement, element.ParentElement, element.Position + 1);
                        AssignAssociationInfo(newElement, fileFullName, shortcutName, type);
                        currentElement = newElement;
                    }
                    break;
                case ElementType.Note:
                    if (element.HasAssociation == false)
                    {
                        if (element.NoteText.Trim() == String.Empty)
                        {
                            element.NoteText = noteText;
                        }
                        AssignAssociationInfo(element, fileFullName, shortcutName, type);
                        currentElement = element;
                    }
                    else
                    {
                        Element newElement = CreateNewElement(ElementType.Note, noteText);
                        InsertElement(newElement, element.ParentElement, element.Position + 1);
                        AssignAssociationInfo(newElement, fileFullName, shortcutName, type);
                        currentElement = newElement;
                    }
                    break;
            };

            int curr_index = currentElement.Position;
            foreach (Element emailAttachmentElement in emailAttachmentElementList)
            {
                InsertElement(emailAttachmentElement, currentElement.ParentElement, curr_index);
                curr_index++;
            }
        }
Beispiel #5
0
        private void AssignAssociationInfo(Element element, string fileFullName, string shortcutName, ElementAssociationType type)
        {
            string element_path = element.Path;
            string shortcut_path = element_path + shortcutName;

            element.AssociationType = type;
            element.AssociationURI = shortcutName;

            CreateShortcut(element, fileFullName, shortcut_path);

            element.TailImageSource = FileTypeHandler.GetIcon((ElementAssociationType)element.AssociationType, element.AssociationURIFullPath);

            UpdateElement(element);
        }