From: <ny...@us...> - 2007-01-18 19:44:37
|
Revision: 272 http://svn.sourceforge.net/pmplib/?rev=272&view=rev Author: nyaochi Date: 2007-01-18 11:44:24 -0800 (Thu, 18 Jan 2007) Log Message: ----------- Improved page handling for db.dat. This revision is not stable yet, but it could generate multiple continuous Object pages successfully. Although this revision does not work without a playlist, my time is up. Modified Paths: -------------- trunk/pmplib/lib/pmp_iriverplus3/dat.c trunk/pmplib/lib/pmp_iriverplus3/dic.c trunk/pmplib/lib/pmp_iriverplus3/dic.h trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.c Modified: trunk/pmplib/lib/pmp_iriverplus3/dat.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/dat.c 2007-01-18 17:34:30 UTC (rev 271) +++ trunk/pmplib/lib/pmp_iriverplus3/dat.c 2007-01-18 19:44:24 UTC (rev 272) @@ -377,7 +377,7 @@ int dat_read(dat_t* dat, const dic_t* dic, FILE *fpi) { - uint32_t i = 0; + uint32_t i = 0, page = 0; page_header_t ph; long buffer_size = 0; uint8_t* buffer = NULL; @@ -392,9 +392,10 @@ dat_list_finish(&dat->objects); /* Read Objects page(s) */ - dat_list_read(&dat->objects, &ph, &dic->objects, buffer, PAGESIZE * 0); - while (ph.next_page) { - dat_list_read(&dat->objects, &ph, &dic->objects, buffer, PAGESIZE * (ph.next_page - 1)); + page = dic->objects.dat_page; + while (page) { + dat_list_read(&dat->objects, &ph, &dic->objects, buffer, PAGESIZE * (page - 1)); + page = ph.next_page; } /* Construct Object UID -> dat->objects[i] mapping table. */ @@ -405,9 +406,10 @@ dat_list_finish(&dat->musics); /* Read Music page(s) */ - dat_list_read(&dat->musics, &ph, &dic->music, buffer, PAGESIZE * 1); - while (ph.next_page) { - dat_list_read(&dat->musics, &ph, &dic->music, buffer, PAGESIZE * (ph.next_page - 1)); + page = dic->music.dat_page; + while (page) { + dat_list_read(&dat->musics, &ph, &dic->music, buffer, PAGESIZE * (page - 1)); + page = ph.next_page; } /* Set filename and pathname fields. */ @@ -452,10 +454,11 @@ } } - /* Read Music page(s) */ - dat_list_read(&dat->references, &ph, &dic->references, buffer, PAGESIZE * 2); - while (ph.next_page) { - dat_list_read(&dat->references, &ph, &dic->references, buffer, PAGESIZE * (ph.next_page - 1)); + /* Read References page(s) */ + page = dic->references.dat_page; + while (page) { + dat_list_read(&dat->references, &ph, &dic->references, buffer, PAGESIZE * (page - 1)); + page = ph.next_page; } free(buffer); @@ -464,29 +467,29 @@ int dat_write(dat_t* dat, dic_t* dic, FILE *fpo) { - uint32_t i = 0; + uint32_t i = 0, page = 0; page_header_t ph; - long buffer_size = PAGESIZE * 3; - uint8_t* buffer = (uint8_t*)calloc(buffer_size, sizeof(uint8_t)); + long buffer_size = 0; + uint8_t* buffer = NULL; - if (!buffer) { - return 1; - } + dic->header.num_dat_pages = 0; + memset(&ph, 0, sizeof(ph)); + /* Write Objects page(s) */ i = 0; - memset(&ph, 0, sizeof(ph)); - ph.next_page = 3; - dat_list_write(&dat->objects, i, &ph, buffer, PAGESIZE * 0); - dic->header.num_dat_pages = 1; - while (ph.next_page) { - uint32_t page = ph.next_page++; + dic->objects.dat_page = page = (dic->header.num_dat_pages + 1); + while (page) { buffer_size = PAGESIZE * page; buffer = (uint8_t*)realloc(buffer, sizeof(uint8_t) * buffer_size); memset(buffer + PAGESIZE * (page - 1), 0, PAGESIZE); + + ph.next_page = page + 1; + dat_list_write(&dat->objects, i, &ph, buffer, PAGESIZE * (page - 1)); + i += ph.num_entries; - dat_list_write(&dat->objects, i, &ph, buffer, PAGESIZE * (page - 1)); dic->header.num_dat_pages += 1; + page = ph.next_page; } /* Clear filepath and filename */ @@ -499,36 +502,36 @@ /* Write Music page(s) */ i = 0; - ph.next_page = dic->header.num_dat_pages + 2; - dat_list_write(&dat->musics, i, &ph, buffer, PAGESIZE * 1); - dic->header.num_dat_pages += 1; - while (ph.next_page) { - uint32_t page = ph.next_page++; + dic->music.dat_page = page = (dic->header.num_dat_pages+1); + while (page) { buffer_size = PAGESIZE * page; buffer = (uint8_t*)realloc(buffer, sizeof(uint8_t) * buffer_size); memset(buffer + PAGESIZE * (page - 1), 0, PAGESIZE); + + ph.next_page = page + 1; + dat_list_write(&dat->musics, i, &ph, buffer, PAGESIZE * (page - 1)); + i += ph.num_entries; - dat_list_write(&dat->musics, i, &ph, buffer, PAGESIZE * (page - 1)); dic->header.num_dat_pages += 1; + page = ph.next_page; } /* Write References page(s) */ i = 0; - memset(&ph, 0, sizeof(ph)); - ph.next_page = dic->header.num_dat_pages + 2; - dat_list_write(&dat->references, i, &ph, buffer, PAGESIZE * 2); - dic->header.num_dat_pages += 1; - while (ph.next_page) { - uint32_t page = ph.next_page++; + dic->references.dat_page = page = (dic->header.num_dat_pages+1); + while (page) { buffer_size = PAGESIZE * page; buffer = (uint8_t*)realloc(buffer, sizeof(uint8_t) * buffer_size); memset(buffer + PAGESIZE * (page - 1), 0, PAGESIZE); + + ph.next_page = page + 1; + dat_list_write(&dat->references, i, &ph, buffer, PAGESIZE * (page - 1)); + i += ph.num_entries; - dat_list_write(&dat->references, i, &ph, buffer, PAGESIZE * (page - 1)); dic->header.num_dat_pages += 1; + page = ph.next_page; } - if (fwrite(buffer, 1, buffer_size, fpo) != buffer_size) { free(buffer); return 1; Modified: trunk/pmplib/lib/pmp_iriverplus3/dic.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/dic.c 2007-01-18 17:34:30 UTC (rev 271) +++ trunk/pmplib/lib/pmp_iriverplus3/dic.c 2007-01-18 19:44:24 UTC (rev 272) @@ -117,22 +117,65 @@ for (i = 0;i < list->num_fields;++i) { dic_field_finish(&list->fields[i]); } + free(list->name); free(list->fields); } static void dic_table_dump(dic_table_t* list, FILE *fp) { int i; + + fprints(fp, "%s = {\n", list->name); + fprintf(fp, " unknown0: 0x%08X\n", list->unknown0); + fprintf(fp, " next: 0x%08X\n", list->next); + fprintf(fp, " unknown1: 0x%08X\n", list->unknown1); + fprintf(fp, " dat_page: 0x%08X\n", list->dat_page); + fprintf(fp, " offset_fields: 0x%08X\n", list->offset_fields); + fprintf(fp, " offset_indices: 0x%08X\n", list->offset_indices); + for (i = 0;i < list->num_fields;++i) { const dic_field_t* entry = &list->fields[i]; fprintf(fp, " FIELD %d = {\n", i); dic_field_dump(entry, fp); fprintf(fp, " }\n"); } + + fprintf(fp, "}\n"); } +static size_t dic_table_serialize(uint8_t* buffer, uint32_t start, dic_table_t* list, int is_storing) +{ + uint32_t i, next; + uint8_t *p = buffer + start; + p += serialize_uint32be(p, &list->unknown0, is_storing); + p += serialize_uint32be(p, &list->next, is_storing); + p += serialize_uint32be(p, &list->unknown1, is_storing); + p += serialize_uint32be(p, &list->dat_page, is_storing); + p += serialize_uint32be(p, &list->offset_fields, is_storing); + p += serialize_uint32be(p, &list->offset_indices, is_storing); + if (is_storing) { + p += (serialize_ucs2be_string_var(p, list->name, is_storing) + 1) * sizeof(ucs2char_t); + } else { + p += (serialize_ucs2be_string_var_alloc(p, &list->name) + 1) * sizeof(ucs2char_t); + } + next = list->offset_fields; + for (i = 0;i < list->num_fields;++i) { + dic_field_serialize(buffer + next, &list->fields[i], is_storing); + next = list->fields[i].next; + } + + for (i = 0;i < list->num_indices;++i) { + uint32_t offset = list->indices[i].offset + sizeof(uint32_t) * 2; + serialize_uint32be(buffer + offset, &list->indices[i].idx_root, is_storing); + } + + return (size_t)(p - (buffer + start)); +} + + + dic_t* dic_new() { uint8_t* dic_template = NULL; @@ -203,7 +246,6 @@ static int dic_serialize(dic_t* dic, uint8_t* buffer, int is_storing) { - int i; uint32_t next = 0; uint8_t* p = buffer; @@ -212,54 +254,19 @@ p += serialize_uint32be(p, &dic->header.num_idx_pages, is_storing); p += serialize_uint32be(p, &dic->header.unknown1, is_storing); - next = 0x0000003C; - for (i = 0;i < dic->music.num_fields;++i) { - dic_field_serialize(buffer + next, &dic->music.fields[i], is_storing); - next = dic->music.fields[i].next; - } + dic_table_serialize(buffer, 0x0018, &dic->music, is_storing); + dic_table_serialize(buffer, 0x0736, &dic->references, is_storing); + dic_table_serialize(buffer, 0x0972, &dic->objects, is_storing); - next = 0x00000764; - for (i = 0;i < dic->references.num_fields;++i) { - dic_field_serialize(buffer + next, &dic->references.fields[i], is_storing); - next = dic->references.fields[i].next; - } - - next = 0x0000099A; - for (i = 0;i < dic->objects.num_fields;++i) { - dic_field_serialize(buffer + next, &dic->objects.fields[i], is_storing); - next = dic->objects.fields[i].next; - } - - for (i = 0;i < dic->music.num_indices;++i) { - uint32_t offset = dic->music.indices[i].offset + sizeof(uint32_t) * 2; - serialize_uint32be(buffer + offset, &dic->music.indices[i].idx_root, is_storing); - } - - for (i = 0;i < dic->references.num_indices;++i) { - uint32_t offset = dic->references.indices[i].offset + sizeof(uint32_t) * 2; - serialize_uint32be(buffer + offset, &dic->references.indices[i].idx_root, is_storing); - } - - for (i = 0;i < dic->objects.num_indices;++i) { - uint32_t offset = dic->objects.indices[i].offset + sizeof(uint32_t) * 2; - serialize_uint32be(buffer + offset, &dic->objects.indices[i].idx_root, is_storing); - } - return 0; } void dic_dump(dic_t* dic, FILE *fp) { fprintf(fp, "===== db.dic =====\n"); - fprintf(fp, "MUSIC = {\n"); dic_table_dump(&dic->music, fp); - fprintf(fp, "}\n"); - fprintf(fp, "REFERENCES = {\n"); dic_table_dump(&dic->references, fp); - fprintf(fp, "}\n"); - fprintf(fp, "OBJECTS = {\n"); dic_table_dump(&dic->objects, fp); - fprintf(fp, "}\n"); fprintf(fp, "\n"); } Modified: trunk/pmplib/lib/pmp_iriverplus3/dic.h =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/dic.h 2007-01-18 17:34:30 UTC (rev 271) +++ trunk/pmplib/lib/pmp_iriverplus3/dic.h 2007-01-18 19:44:24 UTC (rev 272) @@ -45,6 +45,14 @@ } dic_index_t; typedef struct { + uint32_t unknown0; + uint32_t next; + uint32_t unknown1; + uint32_t dat_page; + uint32_t offset_fields; + uint32_t offset_indices; + ucs2char_t* name; + int num_fields; dic_field_t *fields; int num_indices; Modified: trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.c 2007-01-18 17:34:30 UTC (rev 271) +++ trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.c 2007-01-18 19:44:24 UTC (rev 272) @@ -71,7 +71,7 @@ "System\\E10.SYS", "System\\db.dat", "System\\db.dic", "System\\db.idx", ".mp3\0.ogg\0.wma\0.wav\0", {PMPCODEC_MPEGLAYER3, PMPCODEC_VORBIS, PMPCODEC_WMA, PMPCODEC_WAV, 0, 0, 0, 0}, - "System\\", "Music2\\", "Playlists\\", + "System\\", "", "Playlists\\", ".plp", }, { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |