예제 #1
0
        public string GetChunkAbsolutePath(EcfFileChunkDefinition chunk)
        {
            Contract.Requires(chunk != null && chunk.Parent == this);

            Contract.Assert(WorkingDirectory.IsNotNullOrEmpty());
            string abs_path = Path.Combine(WorkingDirectory, chunk.FilePath);

            abs_path = Path.GetFullPath(abs_path);
            return(abs_path);
        }
예제 #2
0
        public EcfFileChunkDefinition Add(EcfChunk rawChunk, int rawChunkIndex)
        {
            Contract.Requires(rawChunk != null);

            var chunk = new EcfFileChunkDefinition();

            chunk.Initialize(this, rawChunk, rawChunkIndex);
            Chunks.Add(chunk);

            return(chunk);
        }
        bool BuildChunkToStream(IO.EndianStream ecfStream, EcfFileChunkDefinition chunk)
        {
            bool success = true;

            var raw_chunk = mEcfFile.GetChunk(chunk.RawChunkIndex);

            using (var chunk_ms = EcfDefinition.GetChunkFileDataStream(chunk))
            {
                raw_chunk.BuildBuffer(ecfStream, chunk_ms);
            }

            return(success);
        }
        void ExpandChunkToFile(EcfFileChunkDefinition chunk, EcfChunk rawChunk)
        {
            string file_path = EcfDefinition.GetChunkAbsolutePath(chunk);

            if (!ExpanderOptions.Test(EcfFileExpanderOptions.DontOverwriteExistingFiles))
            {
                if (File.Exists(file_path))
                {
                    if (VerboseOutput != null)
                    {
                        VerboseOutput.WriteLine("\tSkipping chunk, output file already exists: {0}", file_path);
                    }

                    return;
                }
            }

            using (var fs = File.OpenWrite(file_path))
            {
                var chunk_bytes = rawChunk.GetBuffer(mEcfStream);
                fs.Write(chunk_bytes, 0, chunk_bytes.Length);
            }
        }
예제 #5
0
        internal MemoryStream GetChunkFileDataStream(EcfFileChunkDefinition chunk)
        {
            Contract.Assume(chunk != null && chunk.Parent == this);

            MemoryStream ms;

            if (chunk.FileBytes != null)
            {
                ms = new MemoryStream(chunk.FileBytes, writable: false);
            }
            else
            {
                var source_file = GetChunkAbsolutePath(chunk);
                using (var fs = File.OpenRead(source_file))
                {
                    ms = new MemoryStream((int)fs.Length);
                    fs.CopyTo(ms);
                }
            }

            ms.Position = 0;
            return(ms);
        }