Exemple #1
0
 /// <summary>
 /// Detects the type of the library from the selected path.
 /// </summary>
 /// <returns>true if valid detection successful</returns>
 private bool detectLibraryType()
 {
     try
     {
         FileAttributes attr = File.GetAttributes(LibraryFile);
         if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
         {
             libraryType = LibraryFileType.Directory;
         }
         else
         {
             if (!Regex.IsMatch(Path.GetFileName(LibraryFile).ToLower(), "itunes (music)? library\\.xml"))
             {
                 throw new IOException();
             }
             libraryType = LibraryFileType.iTunes;
         }
     }
     catch
     {
         MessageBox.Show("Invalid file selected");
         return(false);
     }
     return(true);
 }
        public static LibraryFileType GetFileType(string fileName)
        {
            LibraryFileType fileType = LibraryFileType.None;

            if (!string.IsNullOrEmpty(fileName))
            {
                string ext = Path.GetExtension(fileName);
                if (!string.IsNullOrEmpty(ext))
                {
                    switch (ext.ToLower())
                    {
                    case ".doc":
                    case ".docx":
                        fileType = LibraryFileType.Word;
                        break;

                    case ".xls":
                    case ".xlsx":
                        fileType = LibraryFileType.Excel;
                        break;

                    case ".ppt":
                    case ".pptx":
                        fileType = LibraryFileType.PowerPoint;
                        break;

                    case ".jpg":
                    case ".png":
                    case ".jpeg":
                    case ".bmp":
                    case ".gif":
                        fileType = LibraryFileType.Image;
                        break;

                    case ".txt":
                        fileType = LibraryFileType.Text;
                        break;

                    case ".pdf":
                        fileType = LibraryFileType.Pdf;
                        break;

                    default:
                        fileType = LibraryFileType.Other;
                        break;
                    }
                }
            }
            return(fileType);
        }