public FileData(string path,IFileType fileType)
 {
     this.FileType = fileType;
     var fileInfo = new FileInfo(path);
     this.CreateDate = fileInfo.CreationTime;
     this.Path=new List<string> {fileInfo.FullName};
     this.Checksum = CheckSum.Calculate(path);
     if (fileType.FileContentExtractor!=null)
     {
         this.Content = fileType.FileContentExtractor.Extract(path);
     }
 }
        public FileExtensionProvider(string path)
        {
            infos = new InfoCollection();

            var fileTypes = new IFileType[] {
                //new MpegAudioFileType(),
                //new MpegVideoFileType(),
                //new WavFileType(),
                new SrtFileType(),
                new AssSsaFileType(),
                new IdxFileType(),
                new SamiFileType(),
                new C7zFileType(),
                new ZipFileType(),
                new RarFileType(),
                new RaFileType(),
                new FlacFileType(),
                new LrcFileType(),
                new AviFileType(),
                new SubFileType(),
                new TmpFileType(),
                new PJSFileType(),
                new JSFileType(),
                new RTFileType(),
                new SMILFileType(),
                new TTSFileType(),
                new XSSFileType(),
                new ZeroGFileType(),
                new SUPFileType(),
                new FanSubberFileType(),
                new Sasami2kFileType()
            };

            using(Stream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                int b;
                bool needMoreBytes = true;
                while(needMoreBytes) {
                    b = stream.ReadByte();
                    if(b == -1 || stream.Position > 1 << 30) return;

                    needMoreBytes = false;
                    foreach(var fileType in fileTypes.Where(f => f.IsCandidate)) {
                        fileType.CheckMagicByte((byte)b);
                        needMoreBytes |= fileType.NeedsMoreMagicBytes;
                    }
                }

                foreach(var fileType in fileTypes.Where(f => f.IsCandidate)) {
                    stream.Position = 0;
                    fileType.ElaborateCheck(stream);
                }
            }

            var exts = fileTypes.Where(f => f.IsCandidate);

            if(exts.Count() != 1) {
                if(exts.Any(ft => ft.PossibleExtensions[0].Equals("zip"))) exts = new List<IFileType>(new IFileType[] { new ZipFileType() });
                if(exts.Any(ft => ft.PossibleExtensions[0].Equals("7z"))) exts = new List<IFileType>(new IFileType[] { new C7zFileType() });
                if(exts.Any(ft => ft.PossibleExtensions[0].Equals("rar"))) exts = new List<IFileType>(new IFileType[] { new RarFileType() });
            }

            string extsStr;
            if(fileTypes.Any(f => f.IsCandidate)) {
                extsStr = exts.Aggregate<IFileType, IEnumerable<string>>(new string[0], (acc, f) => acc.Concat(f.PossibleExtensions)).Aggregate((acc, str) => acc + " " + str);
            } else {
                extsStr = null;
            }

            Add(EntryKey.Extension, extsStr, null);

            if(exts.Count() == 1) exts.Single().AddInfo(Add);
        }
Beispiel #3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public FileTypeController()
 {
     _ctrl = GetCtrl<IFileType>("FileType");
 }
Beispiel #4
0
 public Viewmodel(IFileType fileType)
 {
     FileType = fileType;
     Configure();
     FileType.Initialize();
 }
Beispiel #5
0
 public Modelconfig(IFileType fileType)
 {
     FileType = fileType;
     Configure();
     FileType.Initialize();
 }
Beispiel #6
0
        /// <summary>
        /// @param IFileType
        /// @return
        /// </summary>
        public IFileType SetFileType(IFileType type)
        {
            this.file = type;

            return(file);
        }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the NewFileEventArgs class with
 /// the IFileType of the file that should be created.
 /// </summary>
 /// <param name="fileType">See <see cref="FileType" /></param>
 public NewFileEventArgs(IFileType fileType)
 {
     FileType = fileType;
 }
Beispiel #8
0
 public static bool IsValidExtension(this IFileType type, string extension)
 {
     return(type.Extensions.Contains(extension, StringComparer.OrdinalIgnoreCase));
 }
Beispiel #9
0
 public MatchScore(IFileType fileType, int score)
 {
     this.Type  = fileType;
     this.Score = score;
 }
Beispiel #10
0
 public Serviceapp(IFileType fileType)
 {
     FileType = fileType;
     Configure();
     FileType.Initialize();
 }
Beispiel #11
0
 public StreamProgressInfo(IFileType file)
 {
     this.fileType = file;
 }