Add settings section to XML file format and store dive computer IDs

We only store the model/deviceid/nickname for those dive computers that
are mentioned in the XML file. This should make the XML files nicely
selfcontained.

This also changes the code to consistently use model & deviceid to
identify a dive computer. The deviceid is NOT guaranteed to be collision
free between different libdivecomputer backends...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2012-12-26 13:47:54 -08:00
parent 1bd6f72d31
commit e726c9d65c
5 changed files with 139 additions and 39 deletions

View file

@ -443,13 +443,14 @@ static void save_dive(FILE *f, struct dive *dive)
fprintf(f, "</dive>\n");
}
#define VERSION 1
#define VERSION 2
void save_dives(const char *filename)
{
int i;
struct dive *dive;
dive_trip_t *trip = NULL;
char *dc_xml = strdup("");
FILE *f = g_fopen(filename, "w");
@ -459,8 +460,16 @@ void save_dives(const char *filename)
/* Flush any edits of current dives back to the dives! */
update_dive(current_dive);
fprintf(f, "<dives>\n<program name='subsurface' version='%d'></program>\n", VERSION);
fprintf(f, "<divelog program='subsurface' version='%d'>\n<settings>\n", VERSION);
for_each_dive(i, dive) {
struct divecomputer *dc = &dive->dc;
while (dc) {
add_dc_to_string(&dc_xml, dc);
dc = dc->next;
}
}
fprintf(f, dc_xml);
fprintf(f, "</settings>\n<dives>\n");
/* save the dives */
for_each_dive(i, dive) {
dive_trip_t *thistrip = dive->divetrip;
@ -477,6 +486,6 @@ void save_dives(const char *filename)
}
if (trip)
fprintf(f, "</trip>\n");
fprintf(f, "</dives>\n");
fprintf(f, "</dives>\n</divelog>\n");
fclose(f);
}