Example #1
0
File: nomad.c Project: eddie/clearn
void 
write_pack(nd_file *f, char *path)
{
  FILE *fp;
  fp = fopen(path,"wb");

  if(!fp){
    die("couldn't open file for writing");
  }

  calculate_offsets(f);

  // write the header
  // TODO: Learn to write part of structure
  fwrite(f,sizeof(nd_file),1,fp);

  // Loop headers and write
  nd_header *h = f->headers;

  while(h != NULL){

    fwrite(h,1,sizeof(nd_header),fp);
    h = h->next;
  }

  h = f->headers;

  while(h != NULL){

    fwrite(h->body->data,1,h->length,fp);
    h = h->next;
  }

  fclose(fp);
}
Example #2
0
void wwd_write(const wap_wwd *wwd, std::vector<char> &out_wwd_buffer) {
    wwd_offsets offsets;
    std::vector<wwd_plane_offsets> planes_offsets;
    calculate_offsets(offsets, planes_offsets, *wwd);

    std::vector<char> wwd_buffer;
    const wap_wwd_properties &wwdp = wwd->properties;

    if (wwdp.flags & WAP_WWD_FLAG_COMPRESS) {
        std::vector<char> main_block(offsets.eof_offset -
                                     offsets.main_block_offset);
        wap::OutputStream main_block_stream(main_block.data(),
                                            main_block.size());
        write_main_block(main_block_stream, wwd->planes, planes_offsets,
                         wwd->tile_descriptions);
        std::vector<char> compressed_main_block =
            compress_buffer(main_block.data(), main_block.size());
        wwd_buffer.resize(offsets.main_block_offset +
                          compressed_main_block.size());
        wap::OutputStream stream(wwd_buffer.data(), wwd_buffer.size());
        uint32_t checksum = wwd_checksum(main_block.data(), main_block.size());
        write_header(stream, *wwd, offsets, main_block.size(), checksum);
        stream.write_buffer(compressed_main_block.data(),
                            compressed_main_block.size());
    } else {
        wwd_buffer.resize(offsets.eof_offset);
        wap::OutputStream stream(wwd_buffer.data(), wwd_buffer.size());
        stream.seek(offsets.main_block_offset);
        write_main_block(stream, wwd->planes, planes_offsets,
                         wwd->tile_descriptions);
        char *main_block = wwd_buffer.data() + offsets.main_block_offset;
        size_t main_block_size = wwd_buffer.size() - offsets.main_block_offset;
        uint32_t checksum = wwd_checksum(main_block, main_block_size);
        stream.seek(0);
        write_header(stream, *wwd, offsets, 0, checksum);
    }

    std::swap(wwd_buffer, out_wwd_buffer);
}