/// <summary> /// Find free space before a point in the file /// </summary> /// <param name="pos"></param> /// <returns></returns> protected FileSegment FindFreeSegmentBefore(long pos) { FileSegment seg; pruneLock.EnterWriteLock(); try { LinkedListNode <FileSegment> node = FreeList.First; while (node != null) { // this free space is DIRECTLY before the position if ((node.Value.Position + node.Value.Length) == pos) { FileSegment s = node.Value; // remove from free list so someone else doesnt use it FreeList.Remove(node); return(s); } node = node.Next; } } finally { pruneLock.ExitWriteLock(); } // couldn't find one return(null); }
private static CompressionState AnalyzeSecondGen(IReader reader, EngineDescription engineInfo) { // H2 header is uncompressed, so the cache file needs to be loaded enough to check if the tag table is readable var segmenter = new FileSegmenter(engineInfo.SegmentAlignment); reader.SeekTo(0); StructureValueCollection headerValues = StructureReader.ReadStructure(reader, engineInfo.Layouts.GetLayout("header")); var metaOffset = (int)headerValues.GetInteger("meta offset"); var metaSize = (int)headerValues.GetInteger("meta size"); uint metaOffsetMask = (uint)headerValues.GetInteger("meta offset mask"); var metaSegment = new FileSegment( segmenter.DefineSegment(metaOffset, metaSize, 0x200, SegmentResizeOrigin.Beginning), segmenter); var MetaArea = new FileSegmentGroup(new MetaOffsetConverter(metaSegment, metaOffsetMask)); MetaArea.AddSegment(metaSegment); if (MetaArea.Offset >= reader.Length) { return(CompressionState.Compressed); } reader.SeekTo(MetaArea.Offset); StructureValueCollection tagTableValues = StructureReader.ReadStructure(reader, engineInfo.Layouts.GetLayout("meta header")); if ((uint)tagTableValues.GetInteger("magic") != CharConstant.FromString("tags")) { return(CompressionState.Compressed); } return(CompressionState.Decompressed); }
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 AddFile(FileSegment segment, CancellationToken cancellationToken, IProgressHandler progress) { string name = segment.Name; string path = segment.Path; Guard.IsNotNullOrEmpty(name, nameof(name)); Guard.IsNotNullOrEmpty(path, nameof(path)); stream.Write(StreamKind.FS_CODE); stream.Write(2 * name.Length); for (int n = 0; n < name.Length; n++) { stream.Write(name[n]); } IStreamPosition sizePosition = stream.SavePosition(); stream.Write(0L); using (FileEncodingInputStream fileStream = new FileEncodingInputStream(path, platform)) { long sequenceLength = encoder.Encode(fileStream, stream, encodingToken, cancellationToken, progress); LayoutStreamInMemory(sequenceLength); IStreamPosition endPosition = stream.SavePosition(); stream.RestorePosition(sizePosition); stream.Write(sequenceLength); stream.RestorePosition(endPosition); } }
private void Load(StructureValueCollection values, FileSegmenter segmenter) { segmenter.DefineSegment(0, HeaderSize, 1, SegmentResizeOrigin.Beginning); // Define a segment for the header _eofSegment = segmenter.WrapEOF((int)values.GetInteger("file size")); Type = (CacheFileType)values.GetInteger("type"); LoadInteropData(values); RawTable = CalculateRawTableSegment(segmenter); InternalName = values.GetString("internal name"); ScenarioName = values.GetString("scenario name"); XDKVersion = (int)values.GetInteger("xdk version"); FileSegment metaSegment = CalculateTagDataSegment(values, segmenter); if (metaSegment != null) { ulong virtualBase = values.GetInteger("virtual base address"); MetaArea = new FileSegmentGroup(new MetaAddressConverter(metaSegment, (long)virtualBase)); MetaArea.AddSegment(metaSegment); IndexHeaderLocation = SegmentPointer.FromPointer((long)values.GetInteger("index header address"), MetaArea); Partitions = LoadPartitions(values.GetArray("partitions")); } else { Partitions = new Partition[0]; } CalculateStringGroup(values, segmenter); Checksum = (uint)values.GetInteger("checksum"); }
public void Initialize() { this.analysisSettings = new AnalysisSettings(); this.analysisSettings.AnalysisOutputDirectory = this.TestOutputDirectory.Combine("output"); this.analysisSettings.AnalysisTempDirectory = this.TestOutputDirectory.Combine("tmp"); var fakeSource = this.TestOutputDirectory.CombineFile("abc_min1.wav"); fakeSource.Touch(); this.segment = new FileSegment(fakeSource, 123456, 60.0.Seconds()) { SegmentStartOffset = TimeSpan.Zero, SegmentEndOffset = 60.0.Seconds(), }; var fakePrepared = this.TestOutputDirectory.CombineFile("abc_min1.wav"); fakePrepared.Touch(); this.preparedSegment = new FileSegment(fakePrepared, 123456, 30.Seconds()) { SegmentStartOffset = 0.Seconds(), SegmentEndOffset = 59.999.Seconds(), }; this.segmentSettings = new SegmentSettings <FileInfo>( this.analysisSettings, this.segment, (this.analysisSettings.AnalysisOutputDirectory, this.analysisSettings.AnalysisTempDirectory), this.preparedSegment); }
public override MetadataStream CreateStream() { using (var stream = new MemoryStream()) { var writer = new BinaryStreamWriter(stream); writer.WriteByte(0); var processedSignatures = new HashSet <BlobSignature>(); var agenda = new Queue <BlobSignature>(_signatureOffsetMapping.Keys); while (agenda.Count > 0) { var signature = agenda.Dequeue(); if (processedSignatures.Add(signature)) { writer.WriteCompressedUInt32(signature.GetPhysicalLength()); int count = _signatureOffsetMapping.Count; signature.Write(_parentBuffer, writer); // TODO: find more efficient way of adding newly created signatures to the queue. if (count != _signatureOffsetMapping.Count) { foreach (var sig in _signatureOffsetMapping.Keys) { agenda.Enqueue(sig); } } } } writer.WriteZeroes((int)(FileSegment.Align(_length, 4) - _length)); return(new BlobStream(new MemoryStreamReader(stream.ToArray()))); } }
/// <summary> /// Compares two sets of file segments and the segment contents. /// </summary> /// <param name="originalSegments">The original set of file segments.</param> /// <param name="originalReader">The stream to use to read from the original file.</param> /// <param name="newSegments">The modified set of file segments.</param> /// <param name="newReader">The stream to use to read from the modified file.</param> /// <returns>The differences that were found.</returns> public static List <SegmentChange> CompareSegments(IEnumerable <FileSegment> originalSegments, IReader originalReader, IEnumerable <FileSegment> newSegments, IReader newReader) { List <FileSegment> originalList = originalSegments.ToList(); List <FileSegment> newList = newSegments.ToList(); if (originalList.Count != newList.Count) { throw new InvalidOperationException("The files have different segment counts"); } var results = new List <SegmentChange>(); for (int i = 0; i < originalList.Count; i++) { FileSegment originalSegment = originalList[i]; FileSegment newSegment = newList[i]; List <DataChange> changes = DataComparer.CompareData(originalReader, (uint)originalSegment.Offset, originalSegment.ActualSize, newReader, (uint)newSegment.Offset, newSegment.ActualSize, originalSegment.ResizeOrigin != SegmentResizeOrigin.Beginning); if (changes.Count > 0 || originalSegment.Size != newSegment.Size) { var change = new SegmentChange((uint)originalSegment.Offset, originalSegment.ActualSize, (uint)newSegment.Offset, newSegment.ActualSize, originalSegment.ResizeOrigin != SegmentResizeOrigin.Beginning); change.DataChanges.AddRange(changes); results.Add(change); } } return(results); }
/// <summary> /// Mark the segment as free and available for use /// This will update the FreeList and merge nearby /// entries /// </summary> /// <param name="seg">segment to mark as free</param> protected void MarkFreeSpace(FileSegment seg) { usedSize -= seg.Length; LinkedListNode <FileSegment> node = FreeList.First; // Find where in the freelist to insert this segment // the list should be in order, so find the entry // just after this while (node != null) { // node is to the right if (node == null || node.Value.Position > seg.Position) { FreeList.AddBefore(node, seg); break; } node = node.Next; } // end of file.. if (node.Value.Position + node.Value.Length == long.MaxValue) { // truncate file using (FileStream fs = File.Open(dataFile, FileMode.Open, FileAccess.Write, FileShare.ReadWrite)) { fs.SetLength(node.Value.Position); } } node = node.Previous; // walk backwards from this node, and compare it to its NEXT node // if they touch, merge them. and remove one of them while (node != null) { FileSegment nextSeg = node.Next.Value; LinkedListNode <FileSegment> prev = node.Previous; // this node touches the next node if ((node.Value.Position + node.Value.Length) == nextSeg.Position) { node.Next.Value.Position = node.Value.Position; node.Next.Value.Length += node.Value.Length; FreeList.Remove(node); } else { if (node.Previous == null || (node.Previous.Value.Position + node.Previous.Value.Length) != node.Value.Position) { // nodes dont merge, give up merging.. break; } } node = prev; } }
public void ShouldDoBasicSplits() { var source = TestHelper.AudioDetails[this.sourceFile.Name]; var fileSegment = new FileSegment(this.sourceFile, source.SampleRate.Value, source.Duration.Value); var analysisSegments = this.preparer.CalculateSegments(new[] { fileSegment }, this.settings).ToArray(); var expected = new[]
private void DecodeFile(FileDecodingInputStream inputStream, BootstrapSegment bootstrapSegment, CancellationToken cancellationToken, IProgressHandler progressHandler) { FileSegment file = streamParser.ParseFile(inputStream, bootstrapSegment.WeightsTable); string path = Path.Combine(currentDirectory, file.Name); using (FileDecodingOutputStream outputStream = new FileDecodingOutputStream(path, platform)) { file.FileDecoder.Decode(outputStream, cancellationToken, progressHandler); } }
public override void SummariseResults( AnalysisSettings settings, FileSegment inputFileSegment, EventBase[] events, SummaryIndexBase[] indices, SpectralIndexBase[] spectralIndices, AnalysisResult2[] results) { }
/// <summary> /// 写入文件,可不等待 /// </summary> /// <param name="fileStartPoint">从文件的哪里开始写</param> /// <param name="data">写入的数据</param> /// <param name="dataOffset"></param> /// <param name="dataLength"></param> public async Task WriteAsync(long fileStartPoint, byte[] data, int dataOffset, int dataLength) { var task = new TaskCompletionSource <bool>(); var fileSegment = new FileSegment(fileStartPoint, data, dataOffset, dataLength, task); DownloadSegmentList.Enqueue(fileSegment); await task.Task; }
public static FileSegment ToSegment(this AudioUtilityInfo info, FileSegment.FileDateBehavior dateBehavior = FileSegment.FileDateBehavior.Try) { var source = new FileSegment( info.SourceFile, info.SampleRate.Value, info.Duration.Value, dateBehavior); return(source); }
private IReader DecryptData(IReader reader, FileSegment dataLocation, AESKey key) { reader.SeekTo(dataLocation.Offset); byte[] data = reader.ReadBlock(AES.AlignSize(dataLocation.Size)); if (key != null) { data = AES.Decrypt(data, key.Key, key.IV); } return(new EndianReader(new MemoryStream(data), Endian.BigEndian)); }
public static async Task <int> Execute(Arguments arguments) { if (arguments == null) { throw new NoDeveloperMethodException(); } var sw = new Stopwatch(); sw.Start(); ISourcePreparer sourcePreparer = new LocalSourcePreparer(filterShortSegments: true, useOldNamingFormat: false); //create analysis settings using arguments AnalysisSettings settings = new AnalysisSettings() { AnalysisMaxSegmentDuration = TimeSpan.FromSeconds(arguments.SegmentDuration), SegmentMediaType = MediaTypes.GetMediaType(arguments.SegmentFileExtension), AnalysisMinSegmentDuration = TimeSpan.FromSeconds(arguments.SegmentDurationMinimum), SegmentOverlapDuration = TimeSpan.FromSeconds(arguments.SegmentOverlap), AnalysisTargetSampleRate = arguments.SampleRate, AnalysisTempDirectory = (arguments.TemporaryFilesDir ?? arguments.OutputDir).ToDirectoryInfo(), }; // create segments from file var fileSegment = new FileSegment(arguments.InputFile.ToFileInfo(), TimeAlignment.None, dateBehavior: FileSegment.FileDateBehavior.None) { SegmentStartOffset = TimeSpan.FromSeconds(arguments.StartOffset), }; if (arguments.EndOffset.HasValue) { fileSegment.SegmentEndOffset = TimeSpan.FromSeconds(arguments.EndOffset.Value); } var fileSegments = sourcePreparer.CalculateSegments(new[] { fileSegment }, settings).ToList(); LoggedConsole.WriteLine( "Started segmenting at {0} {1}: {2}.", DateTime.Now, arguments.Parallel ? "in parallel" : "sequentially", arguments.InputFile); if (arguments.Parallel) { RunParallel(fileSegments, sourcePreparer, settings, arguments); } else { var runTime = await RunSequential(fileSegments, sourcePreparer, settings, arguments); } sw.Stop(); LoggedConsole.WriteLine("Took {0}. Done.", sw.Elapsed); return(ExceptionLookup.Ok); }
private int[] ReadOffsets(IReader reader, FileSegment indexTable, int count) { reader.SeekTo(indexTable.Offset); var offsets = new int[count]; for (int i = 0; i < count; i++) { offsets[i] = reader.ReadInt32(); } return(offsets); }
public uint GetSegmentRelativeOffset(FileSegment segment) { uint offset = 0; foreach (var existingSegment in Segments) { if (segment == existingSegment) return offset; offset += existingSegment.GetPhysicalLength(); } return offset; }
/// <summary> /// Summarize your results. This method is invoked exactly once per original file. /// </summary> public override void SummariseResults( AnalysisSettings settings, FileSegment inputFileSegment, EventBase[] events, SummaryIndexBase[] indices, SpectralIndexBase[] spectralIndices, AnalysisResult2[] results) { // No operation - do nothing. Feel free to add your own logic. base.SummariseResults(settings, inputFileSegment, events, indices, spectralIndices, results); }
public void FileSegment_Test() { var fs = new FileSegment(1, 2, 10, FileSegmentType.Tail, null); var fs2 = new FileSegment(fs, 15); fs2.Index.ShouldBeEquivalentTo(fs.Index); fs2.Start.ShouldBeEquivalentTo(fs.Start); fs2.End.ShouldBeEquivalentTo(15); fs2.Type.ShouldBeEquivalentTo(fs.Type); fs2.Key.Should().Be(fs.Key); fs2.Size.Should().Be(13); }
public override void SummariseResults( AnalysisSettings settings, FileSegment inputFileSegment, EventBase[] events, SummaryIndexBase[] indices, SpectralIndexBase[] spectralIndices, AnalysisResult2[] results) { // no operation // TODO: michael edit as you like // called once after all analysis segments have been completed }
public FileUploadResult Parse() { var lines = Text.Split(Environment.NewLine); if (lines.Length == 0) { return(new FileUploadResult()); } if (Options.IgnoreHeaderLine) { lines = lines.TakeLast(lines.Length - 1).ToArray(); } var fileSegments = new List <FileSegment>(); FileSegment currentSegment = null; foreach (var line in lines) { if (Options.IgnoreBlankLines && String.IsNullOrWhiteSpace(line)) { continue; } var trimmedLine = line.Trim(' ', '\t'); if (IsHeader(trimmedLine)) { if (currentSegment != null) { fileSegments.Add(currentSegment); } currentSegment = new FileSegment { HeaderSegment = new HeaderSegment(trimmedLine) }; } else { currentSegment.LineSegments.Add(new LineSegment(trimmedLine)); } } if (currentSegment != null) { fileSegments.Add(currentSegment); } return(new FileUploadResult { FileSegments = fileSegments }); }
public uint GetSegmentRelativeOffset(FileSegment segment) { uint offset = 0; foreach (var existingSegment in Segments) { if (segment == existingSegment) { return(offset); } offset += existingSegment.GetPhysicalLength(); } return(offset); }
public void UpdateMetrics(int uncompressedContentSize, int contentOffset, Compression compression) { using (FileSegment stream = ParentArchive.GetMetricFileStream(MemoryMappedFileAccess.ReadWrite)) using (BinaryWriter bw = stream.GetBinaryWriter()) { stream.Seek(Index * 12, SeekOrigin.Begin); bw.Write(uncompressedContentSize); bw.Write(contentOffset); bw.Write((int)compression); } UncompressedContentSize = uncompressedContentSize; ContentOffset = contentOffset; Compression = compression; }
private void Load(StructureValueCollection values, FileSegmenter segmenter) { _eofSegment = segmenter.WrapEOF((int)values.GetInteger("file size")); var metaOffset = (int)values.GetInteger("meta offset"); int metaSize; // TODO (Dragon): hack for h2 alpha if (BuildString == "02.01.07.4998") { metaSize = (int)values.GetInteger("tag data offset") + (int)values.GetInteger("tag data size"); // hack to rewrite the "meta size" value even though its not actually the meta size //_saved_meta_size_hack = (uint)values.GetInteger("meta size"); } else { metaSize = (int)values.GetInteger("meta size"); } var metaSegment = new FileSegment( segmenter.DefineSegment(metaOffset, metaSize, 0x4, SegmentResizeOrigin.Beginning), segmenter); // we hacked in a meta header size into the values earlier in the cache load uint metaOffsetMask = (uint)(values.GetInteger("tag table offset") - values.GetInteger("meta header size")); MetaArea = new FileSegmentGroup(new MetaOffsetConverter(metaSegment, metaOffsetMask)); IndexHeaderLocation = MetaArea.AddSegment(metaSegment); Type = (CacheFileType)values.GetInteger("type"); var headerGroup = new FileSegmentGroup(); headerGroup.AddSegment(segmenter.WrapSegment(0, HeaderSize, 1, SegmentResizeOrigin.None)); InternalName = values.GetString("internal name"); Checksum = (uint)values.GetInteger("checksum"); // dummy partition Partitions = new Partition[1]; Partitions[0] = new Partition(SegmentPointer.FromOffset(MetaArea.Offset, MetaArea), (uint)MetaArea.Size); // dummy stringids StringIDCount = 0; StringIDData = _eofSegment; StringIDIndexTable = _eofSegment; }
private string GetFileSegmentContents(FileSegment fileSegment) { if (fileSegment == null) { throw new ArgumentNullException(nameof(fileSegment)); } if (!_fileSegments.Contains(fileSegment)) { throw new ArgumentOutOfRangeException(nameof(fileSegment)); } var length = fileSegment.Length ?? _output.Length; return(_output.ToString(fileSegment.Start, length)); }
public void FailsWithInvalidSegment() { // an empty non-existent file var source = TempFileHelper.NewTempFile(this.TestOutputDirectory).Touch(); var segment = new FileSegment(source, duration: 65.Seconds(), sampleRate: 123456) { SegmentEndOffset = 0.Seconds(), SegmentStartOffset = 25.Seconds(), }; Assert.ThrowsException <InvalidSegmentException>(() => { this.TestAnalysisCoordinator(new ISegment <FileInfo>[] { segment }); }); }
/* * private void AdjustPartitions() * { * if (MetaArea == null) * return; * * // Find the first partition with a non-null address and change it to the meta area's base address * Partition partition = Partitions.First(p => p.BasePointer != null); * if (partition != null) * partition.BasePointer = SegmentPointer.FromPointer(MetaArea.BasePointer, MetaArea); * * // Recalculate the size of each partition * int partitionEnd = MetaArea.Offset + MetaArea.Size; * for (int i = Partitions.Length - 1; i >= 0; i--) * { * if (Partitions[i].BasePointer == null) * continue; * * int offset = Partitions[i].BasePointer.AsOffset(); * Partitions[i].Size = (uint) (partitionEnd - offset); * partitionEnd = offset; * } * } */ /* * private StructureValueCollection[] SerializePartitions() * { * if (Partitions == null) * return new StructureValueCollection[0]; * * var results = new StructureValueCollection[Partitions.Length]; * for (int i = 0; i < Partitions.Length; i++) * { * var values = new StructureValueCollection(); * values.SetInteger("load address", Partitions[i].BasePointer != null ? Partitions[i].BasePointer.AsPointer() : 0); * values.SetInteger("size", Partitions[i].Size); * results[i] = values; * } * return results; * } */ /// <summary> /// Rebuilds the interop data table in a cache file. /// </summary> /// <param name="localeArea">The localization area of the file.</param> /* * private void RebuildInteropData(FileSegmentGroup localeArea) * { * * FourthGenInteropSection debugSection = Sections[(int) FourthGenInteropSectionType.Debug]; * FourthGenInteropSection rsrcSection = Sections[(int) FourthGenInteropSectionType.Resource]; * FourthGenInteropSection tagSection = Sections[(int) FourthGenInteropSectionType.Tag]; * FourthGenInteropSection localeSection = Sections[(int) FourthGenInteropSectionType.Localization]; * * // Recompute base addresses * // Section addresses are usually in the following order: resource, locale, tag, debug. * // Each address can immediately follow after the previous non-null section, * // even though this isn't the case in some of the official files (because of removed debug data). * // * // TODO: This could possibly be made into a for loop and cleaned up if the pointer converters are stored in an array. * // I just want to get this working for now. * rsrcSection.VirtualAddress = 0; // This is always zero * rsrcSection.Size = (ResourcePointerConverter != null) ? (uint) RawTable.Size : 0; * localeSection.VirtualAddress = (LocalePointerConverter != null) ? rsrcSection.VirtualAddress + rsrcSection.Size : 0; * localeSection.Size = (LocalePointerConverter != null) ? (uint) localeArea.Size : 0; * tagSection.VirtualAddress = (TagBufferPointerConverter != null) * ? rsrcSection.VirtualAddress + rsrcSection.Size + localeSection.Size * : 0; * tagSection.Size = (TagBufferPointerConverter != null) ? (uint) MetaArea.Size : 0; * debugSection.VirtualAddress = (DebugPointerConverter != null) * ? rsrcSection.VirtualAddress + rsrcSection.Size + localeSection.Size + tagSection.Size * : 0; * debugSection.Size = (DebugPointerConverter != null) ? (uint) StringArea.Size : 0; * * // If the offset mask for the debug section wasn't originally zero, then we have to subtract the first partition size from the debug base address * // Not entirely sure why this is the case, but that's what the official files do * if (debugSection.VirtualAddress != 0 && SectionOffsetMasks[(int) FourthGenInteropSectionType.Debug] != 0) * debugSection.VirtualAddress -= Partitions[0].Size; * * // Recompute offset masks * SectionOffsetMasks[(int) FourthGenInteropSectionType.Debug] = (debugSection.Size > 0) * ? (uint) (StringArea.Offset - debugSection.VirtualAddress) * : 0; * SectionOffsetMasks[(int) FourthGenInteropSectionType.Resource] = (rsrcSection.Size > 0) * ? (uint) (RawTable.Offset - rsrcSection.VirtualAddress) * : 0; * SectionOffsetMasks[(int) FourthGenInteropSectionType.Tag] = (tagSection.Size > 0) * ? (uint) (MetaArea.Offset - tagSection.VirtualAddress) * : 0; * SectionOffsetMasks[(int) FourthGenInteropSectionType.Localization] = (localeSection.Size > 0) * ? (uint) (localeArea.Offset - localeSection.VirtualAddress) * : 0; * * // Update pointer converters * if (DebugPointerConverter != null) * DebugPointerConverter.BasePointer = debugSection.VirtualAddress; * if (ResourcePointerConverter != null) * ResourcePointerConverter.BasePointer = rsrcSection.VirtualAddress; * if (TagBufferPointerConverter != null) * TagBufferPointerConverter.BasePointer = tagSection.VirtualAddress; * if (LocalePointerConverter != null) * LocalePointerConverter.BasePointer = localeSection.VirtualAddress; * } */ private void Load(StructureValueCollection map_values, StructureValueCollection tag_values, StructureValueCollection string_values, FileSegmenter map_segmenter) { map_segmenter.DefineSegment(0, HeaderSize, 1, SegmentResizeOrigin.Beginning); // Define a segment for the header _eofSegment = map_segmenter.WrapEOF((int)map_values.GetInteger("file size")); //LoadInteropData(map_values, tag_values); //RawTable = CalculateRawTableSegment(segmenter); Type = (CacheFileType)map_values.GetInteger("type"); InternalName = map_values.GetString("internal name"); ScenarioPath = map_values.GetString("scenario path"); uint index_header_address = map_values.GetInteger("index header address"); // File Segment FileSegmenter tags_segmenter = new FileSegmenter(); tags_segmenter.DefineSegment(0, (int)EngineInfo.TagsDataSize, 0x1, SegmentResizeOrigin.Beginning); // Define a segment for the header FileSegment metaSegment = new FileSegment(0, tags_segmenter); //FileSegment metaSegment = CalculateTagDataSegment(tag_values, segmenter); MetaArea = new FileSegmentGroup(new MetaAddressConverter(metaSegment, index_header_address)); MetaArea.AddSegment(metaSegment); IndexHeaderLocation = SegmentPointer.FromPointer(index_header_address, MetaArea); //XDKVersion = (int) values.GetInteger("xdk version"); /* * FileSegment metaSegment = CalculateTagDataSegment(values, segmenter); * if (metaSegment != null) * { * uint virtualBase = values.GetInteger("virtual base address"); * MetaArea = new FileSegmentGroup(new MetaAddressConverter(metaSegment, virtualBase)); * MetaArea.AddSegment(metaSegment); * * IndexHeaderLocation = SegmentPointer.FromPointer(values.GetInteger("index header address"), MetaArea); * Partitions = LoadPartitions(values.GetArray("partitions")); * } * else * { * Partitions = new Partition[0]; * } */ CalculateStringGroup(string_values, map_segmenter); }
protected void Compact() { pruneLock.EnterWriteLock(); try { foreach (FileEntry e in data.Values.ToArray()) { // is there free space before this entry? FileSegment before = FindFreeSegmentBefore(e.Segment.Position); // no free space directy before? if (before == null) { continue; } lock (e) { using (Stream st = File.Open(dataFile, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) { st.Position = e.Segment.Position; byte[] buff = new byte[e.Segment.Length]; st.Read(buff, 0, buff.Length); // mark the ending as free space FileSegment oldSpace = new FileSegment(before.Position + e.Segment.Length, before.Length); MarkFreeSpace(oldSpace); st.Position = before.Position; st.Write(buff, 0, buff.Length); st.Flush(); // move our spot back e.Segment.Position = before.Position; if (e.Segment.Position == 154) { e.Segment = e.Segment; } } } } } finally { pruneLock.ExitWriteLock(); } }
public void SecondConstructorAutomaticallyExtractsInfo() { string testFile = "Currawongs_curlew_West_Knoll_Bees_20091102-183000.mp3"; var asset = PathHelper.ResolveAsset(testFile); var info = TestHelper.AudioDetails[testFile]; FileSegment s = new FileSegment(asset, TimeAlignment.None, null, FileSegment.FileDateBehavior.Try); Assert.AreEqual(null, s.SegmentStartOffset); Assert.AreEqual(null, s.SegmentEndOffset); Assert.AreEqual(0, s.StartOffsetSeconds); Assert.AreEqual(info.Duration.Value.TotalSeconds, s.EndOffsetSeconds, 1.0); Assert.That.AreEqual(info.Duration.Value, s.TargetFileDuration.Value, 0.1.Seconds()); Assert.AreEqual(info.SampleRate, s.TargetFileSampleRate); Assert.AreEqual("Currawongs_curlew_West_Knoll_Bees_20091102-183000", s.SourceMetadata.Identifier); Assert.IsNull(s.TargetFileStartDate); }
public (AnalysisSettings, SegmentSettings <FileInfo>) ToAnalysisSettings( AnalysisSettings defaults = null, bool outputIntermediate = false, FileSegment sourceSegment = null, FileSegment preparedSegment = null) { var analysisSettings = base.ToAnalysisSettings(defaults, true); var segment = sourceSegment ?? new FileSegment(this.Source, TimeAlignment.None); var segmentSettings = new SegmentSettings <FileInfo>( analysisSettings, segment, (analysisSettings.AnalysisOutputDirectory, analysisSettings.AnalysisTempDirectory), preparedSegment ?? segment); return(analysisSettings, segmentSettings); }