public void ParseFileTest1() { IReadOnlyList <Bit> data = BitListHelper.CreateBuilder() .AddInt(0x10) .AddChar('f') .AddChar('i') .AddChar('l') .AddChar('e') .AddChar('.') .AddChar('b') .AddChar('i') .AddChar('n') .AddLong(0x0).BitList; FileSegment segment = streamParser.ParseFile(new TestIDecodingInputStream(data), new WeightsTable()); Assert.IsNotNull(segment); Assert.AreEqual("file.bin", segment.Name); Assert.IsNull(segment.Path); IFileDecoder decoder = segment.FileDecoder; Assert.IsNotNull(decoder); TestIDecodingOutputStream outputStream = new TestIDecodingOutputStream(); decoder.Decode(outputStream, CancellationToken.None, null); CollectionAssert.IsEmpty(outputStream.ByteList); }
public void SetNewFile(Uri newFileUri) { fileLocation = newFileUri; targetPackageData = null; fileExtension = Path.GetExtension(newFileUri.AbsolutePath); fileExtension = fileExtension.Trim('.'); if (string.IsNullOrEmpty(fileExtension)) { return; } if (currentFileDecoder != null) { currentFileDecoder.decodeProgressCallbackEvent -= GetDataFromDecoder; } currentFileDecoder = decoderDict[fileExtension]; if (currentFileDecoder != null) { currentFileDecoder.decodeProgressCallbackEvent += GetDataFromDecoder; currentFileDecoder.SetFilePath(newFileUri); currentFileDecoder.Decode(); isDecoding = true; } }
public FileSegment(string name, IFileDecoder fileDecoder) { Guard.IsNotNullOrEmpty(name, nameof(name)); Guard.IsNotNull(fileDecoder, nameof(fileDecoder)); Name = name; FileDecoder = fileDecoder; }
private void MapPathToFile(string suffixExp, IFileDecoder file) { string[] suffixes = suffixExp.Split('|'); foreach (var suffix in suffixes) { _suffixToDecoderDic.Add(suffix, file); } }
/// <summary> /// 解析一个Path为控件 /// </summary> /// <returns></returns> public FrameworkElement Decode(string filePath) { string suffix = Path.GetExtension(filePath); IFileDecoder decoder = _suffixToFileMap.GetDecoder(suffix); if (decoder == null) { decoder = this.BinaryFile; } decoder.Decode(filePath); return(decoder.Element); }
public FileDecoderCollection() { //建立 各种不同类型文件解码器 AudioFile = new AudioFileDecoder(); BinaryFile = new BinaryFileDecoder(); HtmlFile = new HtmlFileDecoder(); PictureFile = new PictureFileDecoder(); TextFile = new TextFileDecoder(); VideoFile = new VideoFileDecoder(); //建立后缀与文件解码器的关系,根据映射关系某一后缀就能被某种文件解码器默认打开。eg:.txt -->被TextFileEncoder打开 _suffixToFileMap = new SuffixToFileDecoderMap(this); }
public void SetDecoder(IFileDecoder newApkDecoder, IFileDecoder newAabDecoder, IFileDecoder newIpaDecoder) { if (newApkDecoder != null) { decoderDict.Add(StringConstant.FileExtension_APK, newApkDecoder); } if (newAabDecoder != null) { decoderDict.Add(StringConstant.FileExtension_AAB, newAabDecoder); } if (newIpaDecoder != null) { decoderDict.Add(StringConstant.FileExtension_IPA, newIpaDecoder); } OnPropertyChanged(nameof(localizedSupportFiles)); }
public void ParseFileTest2() { IReadOnlyList <Bit> data = BitListHelper.CreateBuilder() .AddInt(0x10) .AddChar('d') .AddChar('a') .AddChar('t') .AddChar('a') .AddChar('.') .AddChar('b') .AddChar('i') .AddChar('n') .AddLong(0x19) .AddByte(0x20) .AddByte(0x55) .AddByte(0xFF) .AddByte(0x01).BitList; WeightsTable weightsTable = new WeightsTable(); weightsTable.TrackSymbol(1, 1); weightsTable.TrackSymbol(2, 2); weightsTable.TrackSymbol(3, 4); weightsTable.TrackSymbol(4, 8); FileSegment segment = streamParser.ParseFile(new TestIDecodingInputStream(data), weightsTable); Assert.IsNotNull(segment); Assert.AreEqual("data.bin", segment.Name); Assert.IsNull(segment.Path); IFileDecoder decoder = segment.FileDecoder; Assert.IsNotNull(decoder); TestIDecodingOutputStream outputStream = new TestIDecodingOutputStream(); decoder.Decode(outputStream, CancellationToken.None, null); byte[] expectedData = { 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 }; Assert.AreEqual(expectedData, outputStream.ByteList); }
// Added possibility to decode file via a custom file decoder, written by the library user. public string ReadEncodedFile(string pathName, IFileDecoder fileDecoder) { return(fileDecoder.Decode(File.ReadAllText(path: pathName))); }
public RevisionDefinition(IFileDecoder decoder, IFileStorage fileStorage) { _decoder = decoder ?? throw new ArgumentNullException(nameof(decoder)); _fileStorage = fileStorage ?? throw new ArgumentNullException(nameof(fileStorage)); }