Beispiel #1
0
        /// <summary>
        /// Constructor for movie and/or show data.
        /// </summary>
        /// <param name="fileInfo">The file to process.</param>
        public FileInfoParser(FileInfo fileInfo, HelperDictionary dict = null)
        {
            if (dict == null)
            {
                helperDictionary = new HelperDictionary();
            }
            else
            {
                helperDictionary = dict;
            }

            Index = new List<StringLocation>();
            //Some obvious shit first
            fileName = fileInfo.Name;
            fileSize = fileInfo.Length;
            fileExt = fileInfo.Extension;
            fileDirName = fileInfo.Directory.Name;

            //TODO rewrite to 1 function call
            Parse(fileName, false);
            Parse(fileDirName, true);

            String[] tmptitles = GetStringInfo();
            TmpTitle = tmptitles[0];
            TmpDirTitle = tmptitles[1];
        }
Beispiel #2
0
 void scanBackgroundWorkerF_DoWork(object sender, DoWorkEventArgs e)
 {
     DirectoryInfo dirinfo = (DirectoryInfo)e.Argument;
     FileInfo[] files = dirinfo.GetFiles("*.m??", SearchOption.AllDirectories);
     files = dirinfo.GetFiles("*.m??", SearchOption.AllDirectories);
     double count = files.Count();
     double filenum = 0;
     scanBackgroundWorkerF.ReportProgress((int)Math.Round(filenum / count * 100), "Count: " + count);
     //Timer
     Stopwatch swProcessTime = new Stopwatch();
     swProcessTime.Start();
     StringBuilder progress = new StringBuilder();
     HelperDictionary helperDictionary = new HelperDictionary();
     foreach (FileInfo file in files)
     {
         if (scanBackgroundWorkerF.CancellationPending)
         {
             break;
         }
         filenum++;
         try
         {
             progress.AppendFormat("\r\n{0}\r\n", file.Name);
             TagLib.File fileTag = TagLib.File.Create(file.FullName);
             //Timer
             Stopwatch swFileTime = new Stopwatch();
             swFileTime.Start();
             //Parse results
             FileInfoParser fileInfoParser = new FileInfoParser(file, helperDictionary);
             //FileInfoParser fileInfoParser = new FileInfoParser(file);
             progress.AppendFormat("Parse result: {0}\n", fileInfoParser);
             progress.AppendFormat("TagType: {0}\r", fileTag.TagTypes.ToString());
             progress.AppendFormat("Title: {0}; Year: {1}\n", fileTag.Tag.Title, fileTag.Tag.Year);
             //Timer output
             swFileTime.Stop();
             TimeSpan fileTime = swFileTime.Elapsed;
             progress.AppendFormat("Parsed in {0}ms.\n", fileTime.TotalMilliseconds);
             fileInfoParser = null;
             fileTag.Dispose();
             fileTag = null;
         }
         catch (UnsupportedFormatException Exception)
         {
             progress.Append("File format not supported.\r\n");
             ExceptionHandler.TriggerException(Exception.Message);
         }
         /*catch (Exception Exception)
         {
             progress.Append("ERROR processing file.\r\n");
             ExceptionHandler.TriggerException(Exception.Message);
             throw Exception;
         }*/
         if ((Int32)filenum % (Int32)Math.Round(count / 20) == 0)
         {
             scanBackgroundWorkerF.ReportProgress((int)Math.Round(filenum / count * 100), progress.ToString());
             progress.Clear();
         }
     }
     scanBackgroundWorkerF.ReportProgress((int)Math.Round(filenum / count * 100), progress.ToString());
     swProcessTime.Stop();
     TimeSpan processTime = swProcessTime.Elapsed;
     scanBackgroundWorkerF.ReportProgress(100, "All files (" + files.Count() + ") parsed in " + processTime.TotalMilliseconds + " ms");
     files = null;
     dirinfo = null;
 }