translatr.CineFile.rebuild C# (CSharp) Method

rebuild() public method

public rebuild ( String path ) : void
path String
return void
        public void rebuild(String path)
        {
            FileStream patched = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);

            // Must have original file path to rebuild!
            if (this.sourcePath == "")
                throw new NullReferenceException("Source path is empty");

            var s = new FileStream(this.sourcePath + this.name, FileMode.Open);
            BinaryReader br = new BinaryReader(s);

            byte[] buf;

            // Copy header
            buf = br.ReadBytes(0x800);
            patched.Write(buf, 0, buf.Length);

            // Do blocks
            UInt32 type;
            UInt32 len;
            UInt32 blockno = 0;
            while (br.BaseStream.Position < br.BaseStream.Length)
            {
                type = s.readuint(isBE);
                len = s.readuint(isBE);
                br.BaseStream.Position -= 8;

                if (type == 0)
                {
                    // Copy audio block as is
                    buf = br.ReadBytes((int)len + 16);
                    patched.Write(buf, 0, buf.Length);
                }
                else
                {
                    int changedEntryNo = findChangedEntry(blockno);
                    if (changedEntryNo >= 0)
                    {
                        // Change sub
                        buf = br.ReadBytes((int)len + 16);
                        buf = blockChangeSub(buf, subEntries[changedEntryNo], (int)blockno);
                        patched.Write(buf, 0, buf.Length);
                    }
                    else
                    {
                        // Copy cine block as is
                        buf = br.ReadBytes((int)len + 16);
                        patched.Write(buf, 0, buf.Length);
                    }
                    blockno++;
                }
            }

            patched.Close();
        }