Reply to thread

[CODE=C#]        [CornerstoneSetting(

            Name = "Regular Expression Filter",

            Description = "a regular expression that matches keywords in the filename or it's parent folder indicating that the file is possible sample.",

            Groups = "|Movie Importer|Sample Filter|",

            Identifier = "importer_sample_keyword",

            Default = "sample")]

        public string SampleRegExFilter {

            get { return _sampleRegExFilter; }

            set {

                _sampleRegExFilter = value;

                OnSettingChanged("importer_sample_keyword");

            }

        }

        private string _sampleRegExFilter;[/CODE]

[CODE=C#]          public static bool isSampleFile(FileInfo file) {

            try {

                // Create the sample filter regular expression

                Regex expr = new Regex(MovingPicturesCore.Settings.SampleRegExFilter, RegexOptions.IgnoreCase);

                // Set sample max size in bytes and check the file size

                long sampleMaxSize = MovingPicturesCore.Settings.MaxSampleFilesize * 1024 * 1024;

                bool match = (file.Length < sampleMaxSize);

                if (match) {

                    // check the filename

                    match = expr.Match(file.Name).Success;

                    if (!match && MovingPicturesCore.Settings.SampleIncludeFolderName) {

                        // check the folder name if specified

                        match = expr.Match(file.DirectoryName).Success;

                    }

                }

                // Return result of given conditions 

                return match;

            }

            catch (Exception e) {

                if (e is ThreadAbortException)

                    throw e;


                logger.Warn("Sample file check failed: {0}", e.Message);

                return false;

            }

        }[/CODE]


Top Bottom