コード例 #1
0
ファイル: data_provider.cpp プロジェクト: omako/s
void DataProvider::DeleteReader(Readers::iterator reader_iter) {
  if (next_reader_ == reader_iter)
    MoveNextReader();
  if (next_reader_ == reader_iter)
    next_reader_ = readers_.end();
  readers_.erase(reader_iter);
  OpenNextFile();
}
コード例 #2
0
ファイル: data_provider.cpp プロジェクト: omako/s
void DataProvider::Start() {
  for (unsigned i = 0; i < max_parallel_reads_; ++i) {
    io_buffers_.emplace_back(new IOBuffer());
    IOBuffer* io_buffer = io_buffers_.back().get();
    io_buffer->buffer.resize(kBlockSize);
    io_buffer->is_busy = false;
  }
  OpenNextFile();
  next_reader_ = readers_.begin();
}
コード例 #3
0
ファイル: makeinstall.c プロジェクト: dror-g/nn-colletion
int main()
{
  HANDLE fout, fin;
  DWORD bytes_read, bytes_written;
  InstData *idata;
  InstFiles *filept;
  char *inbuf, *outbuf;
  int status, count;
  bstr *str;
#ifdef LIBBZ2
  bz_stream z;
#else
  z_stream z;
#endif

  idata = ReadInstallData();

  fout = CreateFile("installfiles.z", GENERIC_WRITE, 0, NULL,
                    CREATE_ALWAYS, 0, NULL);

  outbuf = bmalloc(BUFFER_SIZE);
  inbuf = bmalloc(BUFFER_SIZE);

#ifdef LIBBZ2
  z.bzalloc = NULL;
  z.bzfree = NULL;
  z.opaque = NULL;
  BZ2_bzCompressInit(&z, COMPRESSION, 0, 30);
#else
  z.zalloc = Z_NULL;
  z.zfree  = Z_NULL;
  z.opaque = Z_NULL;
  deflateInit(&z, COMPRESSION);
#endif
  z.avail_in = 0;
  z.next_out = outbuf;
  z.avail_out = BUFFER_SIZE;

  filept = NULL;
  fin = NULL;
  OpenNextFile(idata->instfiles, &filept, &fin);
  if (fin == INVALID_HANDLE_VALUE) {
    return 1;
  }

  while (fin != INVALID_HANDLE_VALUE) {
    if (z.avail_in == 0) {
      z.next_in = inbuf;
      bytes_read = 0;
      while (!bytes_read && fin) {
        if (!ReadFile(fin, inbuf, BUFFER_SIZE, &bytes_read, NULL)) {
          printf("Read error\n");
          break;
        }
        filept->filesize += bytes_read;
        if (!bytes_read)
          OpenNextFile(idata->instfiles, &filept, &fin);
      }
      z.avail_in = bytes_read;
    }
#ifdef LIBBZ2
    status = BZ2_bzCompress(&z, z.avail_in == 0 ? BZ_FINISH : BZ_RUN);
#else
    status = deflate(&z, z.avail_in == 0 ? Z_FINISH : Z_NO_FLUSH);
#endif
    count = BUFFER_SIZE - z.avail_out;
    if (!WriteFile(fout, outbuf, count, &bytes_written, NULL)) {
      printf("Write error\n");
    }
    z.next_out = outbuf;
    z.avail_out = BUFFER_SIZE;

#ifdef LIBBZ2
    if (status == BZ_STREAM_END) {
      break;
    } else if (status != BZ_RUN_OK && status != BZ_FINISH_OK) {
      printf("Unexpected bzlib status: %d\n", status);
      break;
    }
#else
    if (status == Z_STREAM_END) {
      break;
    } else if (status != Z_OK) {
      printf("Unexpected libz status: %d\n", status);
      break;
    }
#endif
  }

#ifdef LIBBZ2
  printf("Written compressed data: raw %d, compressed %d\n",
         z.total_in_lo32, z.total_out_lo32);
  bytes_written = z.total_out_lo32;
  BZ2_bzCompressEnd(&z);
#else
  printf("Written compressed data: raw %ld, compressed %ld\n",
         z.total_in, z.total_out);
  bytes_written = z.total_out;
  deflateEnd(&z);
#endif

  CloseHandle(fout);

  fout = CreateFile("manifest", GENERIC_WRITE, 0, NULL,
                    CREATE_ALWAYS, 0, NULL);
  if (fout == INVALID_HANDLE_VALUE)
    printf("Cannot create file list\n");

  str = bstr_new();
  bstr_setlength(str, 0);
  bstr_append_long(str, bytes_written);
  if (!WriteFile(fout, str->text, str->length + 1, &bytes_written, NULL)) {
    printf("Write error\n");
  }

  if (!WriteFile(fout, idata->product, strlen(idata->product) + 1,
                 &bytes_written, NULL)) {
    printf("Write error\n");
  }
  if (!WriteFile(fout, idata->installdir, strlen(idata->installdir) + 1,
                 &bytes_written, NULL)) {
    printf("Write error\n");
  }
  if (!WriteFile
      (fout, idata->startmenudir, strlen(idata->startmenudir) + 1,
       &bytes_written, NULL)) {
    printf("Write error\n");
  }

  WriteFileList(fout, idata->instfiles);
  WriteFileList(fout, idata->extrafiles);

  WriteLinkList(fout, idata->startmenu);
  WriteLinkList(fout, idata->desktop);

  WriteServiceDetails(fout, idata->service);
  WriteFileList(fout, idata->keepfiles);

  CloseHandle(fout);
  bfree(inbuf);
  bfree(outbuf);

  FreeInstData(idata, TRUE);

  return 0;
}