Пример #1
0
        public static bool IsOpticalDrive(string path)
        {
            DriveInfo driveInfo = DeviceManager.GetDriveInfo(path);

            return(driveInfo != null && driveInfo.IsOptical());
        }
Пример #2
0
        public static List <parseResult> Parse(List <PathPair> files, bool includeFailed)
        {
            MPTVSeriesLog.Write(string.Format("Starting Local Filename Parsing, processing {0} files", files.Count.ToString()));
            List <parseResult> results = new List <parseResult>();
            parseResult        progressReporter;
            int            nFailed = 0;
            FilenameParser parser  = null;
            ListViewItem   item    = null;

            paths = null;
            foreach (PathPair file in files)
            {
                parser = new FilenameParser(file.m_sMatch_FileName);

                // title case the seriesname
                if (parser.Matches.ContainsKey(DBSeries.cParsedName))
                {
                    parser.Matches[DBSeries.cParsedName] = parser.Matches[DBSeries.cParsedName].ToString().ToTitleCase();
                }

                // set volumelabel for drive so can be prompted to insert CD/DVD disk or removable harddrive
                // populate with import path name if can not get volume label
                string volumeLabel = DeviceManager.GetVolumeLabel(file.m_sFull_FileName);

                if (string.IsNullOrEmpty(volumeLabel))
                {
                    volumeLabel = LocalParse.getImportPath(file.m_sFull_FileName);
                }

                parser.Matches.Add(DBEpisode.cVolumeLabel, volumeLabel);

                item = new ListViewItem(file.m_sMatch_FileName);
                item.UseItemStyleForSubItems = true;

                progressReporter = new parseResult();

                // make sure we have all the necessary data for a full match
                if (!parser.Matches.ContainsKey(DBEpisode.cSeasonIndex) ||
                    !parser.Matches.ContainsKey(DBEpisode.cEpisodeIndex))
                {
                    if (parser.Matches.ContainsKey(DBSeries.cParsedName) &&
                        parser.Matches.ContainsKey(DBOnlineEpisode.cFirstAired))
                    {
                        try{ System.DateTime.Parse(parser.Matches[DBOnlineEpisode.cFirstAired]); }
                        catch (System.FormatException)
                        {
                            nFailed++;
                            progressReporter.failedAirDate = true;
                            progressReporter.success       = false;
                            progressReporter.exception     = "Air Date is not valid";
                        }
                    }
                    else
                    {
                        progressReporter.success   = false;
                        progressReporter.exception = "Parsing failed for: " + file;

                        nFailed++;
                    }
                }
                else
                {
                    // make sure episode & season are properly matched (numerical values)
                    try { Convert.ToInt32(parser.Matches[DBEpisode.cSeasonIndex]); }
                    catch (System.FormatException)
                    {
                        nFailed++;
                        progressReporter.failedSeason = true;
                        progressReporter.success      = false;
                        progressReporter.exception   += "Season is not numerical ";
                    }
                    try { Convert.ToInt32(parser.Matches[DBEpisode.cEpisodeIndex]); }
                    catch (System.FormatException)
                    {
                        nFailed++;
                        progressReporter.failedEpisode = true;
                        progressReporter.success       = false;
                        progressReporter.exception    += "Episode is not numerical ";
                    }
                }

                progressReporter.match_filename = file.m_sMatch_FileName;
                progressReporter.full_filename  = file.m_sFull_FileName;
                progressReporter.parser         = parser;
                progressReporter.PathPair       = file;
                if (includeFailed || progressReporter.success)
                {
                    results.Add(progressReporter);
                }
            }
            MPTVSeriesLog.Write("Finished Local Filename Parsing");
            return(results);
        }