Write an H10 database.
Definition at line 523 of file h10db.c. { int ret, i, num_valid_idx = 0, idx_count = 0; struct bfile *bfp = NULL; ucs2_char_t filename[MAX_PATH+1]; ucs2_char_t filepart[MAX_PATH+1]; /* Notify the start of database writing. */ h10db_progress(h10db, H10DB_PROGRESS_WRITE_START, 0, 0); /* Count the number of valid indexes (only for progress report). */ for (i = 0;i < H10DB_NUM_DAT_FIELDS;i++) { if (h10db->hdr->fd[i].has_index && h10db->hdr->fd[i].index_pathname) { num_valid_idx++; } } /* Generate *.idx files. */ idx_count = 0; for (i = 0;i < H10DB_NUM_DAT_FIELDS;i++) { h10db_idx_t* idx = h10db->idx[i]; if (idx) { if (h10db->hdr->fd[i].has_index && h10db->hdr->fd[i].index_pathname) { /* Notify the current progress. */ h10db_progress(h10db, H10DB_PROGRESS_IDX_COUNT, idx_count++, num_valid_idx); /* Open H10DB_*.idx. */ h10db->msg = H10DB_PROGRESS_WRITE_IDX; get_filepart(filepart, MAX_PATH, h10db->hdr->fd[i].index_pathname, H10DB_PATHLENGTH); combine_path(filename, MAX_PATH, path, filepart); bfp = bf_open(filename, 1, h10db, h10db_write_progress); if (!bfp) { return H10DBE_IDX_OPENW; } else { /* Notify the start of an index file writing. */ h10db_progress(h10db, H10DB_PROGRESS_GENERATE_IDX, 0, 1); ret = h10db_idx_write(bfp, idx, h10db->hdr->num_dat_entries); bf_close(bfp); if (ret != 0) { return ret; } /* Notify the end of writing. */ h10db_progress(h10db, H10DB_PROGRESS_GENERATE_IDX, 1, 1); } } } } /* Notify the end of index writing. */ h10db_progress(h10db, H10DB_PROGRESS_IDX_COUNT, idx_count, num_valid_idx); /* Open H10DB.dat */ h10db->msg = H10DB_PROGRESS_WRITE_DAT; get_filepart(filepart, MAX_PATH, h10db->hdr->pathname_dat, H10DB_PATHLENGTH); combine_path(filename, MAX_PATH, path, filepart); bfp = bf_open(filename, 1, h10db, h10db_write_progress); if (!bfp) { return H10DBE_DAT_OPENW; } else { h10db_progress(h10db, H10DB_PROGRESS_GENERATE_DAT, 0, 1); /* Write H10DB.dat */ ret = h10db_dat_write(bfp, h10db->dat, h10db->hdr->num_dat_entries, h10db->hdr); bf_close(bfp); if (ret != 0) { return ret; } h10db_progress(h10db, H10DB_PROGRESS_GENERATE_DAT, 1, 1); } /* Generate H10DB.hdr */ h10db->msg = H10DB_PROGRESS_WRITE_HDR; get_filepart(filepart, MAX_PATH, h10db->hdr->pathname_hdr, H10DB_PATHLENGTH); combine_path(filename, MAX_PATH, path, filepart); bfp = bf_open(filename, 1, h10db, h10db_write_progress); if (!bfp) { return H10DBE_HDR_OPENW; } else { h10db->hdr->num_dat_inactive_entries = count_invalid_entries(h10db->dat, h10db->hdr->num_dat_entries); h10db_progress(h10db, H10DB_PROGRESS_WRITE_HDR, 0, 1); ret = h10db_hdr_serialize(bfp, h10db->hdr, 1, 0); bf_close(bfp); if (ret != 0) { return H10DBE_HDR_WRITE; } h10db_progress(h10db, H10DB_PROGRESS_WRITE_HDR, 1, 1); } /* Disabled the usage of H10DB.upd. */ #ifdef H10DB_USE_UPD /* Write H10DB.upd */ h10db->msg = H10DB_PROGRESS_WRITE_UPD; if (h10db->upd && (h10db->flags & H10DB_FLAG_INCREMENTAL)) { combine_path(filename, MAX_PATH, path, ucs2cs_upd_filename); bfp = bf_open(filename, 1, h10db, h10db_write_progress); if (!bfp) { return H10DBE_UPD_OPENW; } else { h10db_progress(h10db, H10DB_PROGRESS_GENERATE_UPD, 0, 1); h10db_progress(h10db, H10DB_PROGRESS_GENERATE_UPD, 1, 1); h10db_upd_write(h10db->upd, bfp); /* Don't care about error as for H10DB.upd. */ } } #endif h10db_progress(h10db, H10DB_PROGRESS_WRITE_END, 0, 0); return 0; }
|