diff options
Diffstat (limited to 'save-xml.c')
-rw-r--r-- | save-xml.c | 90 |
1 files changed, 50 insertions, 40 deletions
diff --git a/save-xml.c b/save-xml.c index 8ca2bfd38..15c667d35 100644 --- a/save-xml.c +++ b/save-xml.c @@ -110,38 +110,8 @@ static void save_salinity(struct membuffer *b, struct divecomputer *dc) put_string(b, " />\n"); } -static void show_location(struct membuffer *b, struct dive *dive) -{ - degrees_t latitude = dive->latitude; - degrees_t longitude = dive->longitude; - - /* Should we write a location tag at all? */ - if (!(latitude.udeg || longitude.udeg) && !dive->location) - return; - - put_string(b, " <location"); - - /* - * Ok, theoretically I guess you could dive at - * exactly 0,0. But we don't support that. So - * if you do, just fudge it a bit, and say that - * you dove a few meters away. - */ - if (latitude.udeg || longitude.udeg) { - put_degrees(b, latitude, " gps='", " "); - put_degrees(b, longitude, "", "'"); - } - - /* Do we have a location name or should we write a empty tag? */ - if (dive->location && dive->location[0] != '\0') - show_utf8(b, dive->location, ">", "</location>\n", 0); - else - put_string(b, "/>\n"); -} - static void save_overview(struct membuffer *b, struct dive *dive) { - show_location(b, dive); show_utf8(b, dive->divemaster, " <divemaster>", "</divemaster>\n", 0); show_utf8(b, dive->buddy, " <buddy>", "</buddy>\n", 0); show_utf8(b, dive->notes, " <notes>", "</notes>\n", 0); @@ -389,6 +359,8 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer put_format(b, " </divecomputer>\n"); } +extern char * hashstring(char * filename); + static void save_picture(struct membuffer *b, struct picture *pic) { put_string(b, " <picture filename='"); @@ -407,10 +379,13 @@ static void save_picture(struct membuffer *b, struct picture *pic) put_degrees(b, pic->latitude, " gps='", " "); put_degrees(b, pic->longitude, "", "'"); } + if (hashstring(pic->filename)) + put_format(b, " hash='%s'", hashstring(pic->filename)); + put_string(b, "/>\n"); } -void save_one_dive(struct membuffer *b, struct dive *dive) +void save_one_dive_to_mb(struct membuffer *b, struct dive *dive) { struct divecomputer *dc; @@ -424,7 +399,8 @@ void save_one_dive(struct membuffer *b, struct dive *dive) if (dive->visibility) put_format(b, " visibility='%d'", dive->visibility); save_tags(b, dive->tag_list); - + if (dive->dive_site_uuid) + put_format(b, " divesiteid='%8x'", dive->dive_site_uuid); show_date(b, dive->when); put_format(b, " duration='%u:%02u min'>\n", FRACTION(dive->dc.duration.seconds, 60)); @@ -444,7 +420,7 @@ int save_dive(FILE *f, struct dive *dive) { struct membuffer buf = { 0 }; - save_one_dive(&buf, dive); + save_one_dive_to_mb(&buf, dive); flush_buffer(&buf, f); /* Error handling? */ return 0; @@ -469,7 +445,7 @@ static void save_trip(struct membuffer *b, dive_trip_t *trip) */ for_each_dive(i, dive) { if (dive->divetrip == trip) - save_one_dive(b, dive); + save_one_dive_to_mb(b, dive); } put_format(b, "</trip>\n"); @@ -507,7 +483,7 @@ static void save_one_device(void *_f, const char *model, uint32_t deviceid, put_format(b, "/>\n"); } -#define VERSION 2 +#define VERSION 3 int save_dives(const char *filename) { @@ -529,8 +505,34 @@ void save_dives_buffer(struct membuffer *b, const bool select_only) call_for_each_dc(b, save_one_device); if (autogroup) put_format(b, " <autogroup state='1' />\n"); - put_format(b, "</settings>\n<dives>\n"); - + put_format(b, "</settings>\n"); + + /* save the dive sites */ + put_format(b, "<divesites>\n"); + for (i = 0; i < dive_site_table.nr; i++) { + struct dive_site *ds = get_dive_site(i); + if (dive_site_is_empty(ds)) { + int j; + struct dive *d; + for_each_dive(j, d) { + if (d->dive_site_uuid == ds->uuid) + d->dive_site_uuid = 0; + } + delete_dive_site(get_dive_site(i)->uuid); + i--; // since we just deleted that one + continue; + } + put_format(b, "<site uuid='%8x'", ds->uuid); + show_utf8(b, ds->name, " name='", "'", 1); + if (ds->latitude.udeg || ds->longitude.udeg) { + put_degrees(b, ds->latitude, " gps='", " "); + put_degrees(b, ds->longitude, "", "'"); + } + show_utf8(b, ds->description, " description='", "'", 1); + show_utf8(b, ds->notes, " notes='", "'", 1); + put_format(b, "/>\n"); + } + put_format(b, "</divesites>\n<dives>\n"); for (trip = dive_trip_list; trip != NULL; trip = trip->next) trip->index = 0; @@ -540,14 +542,14 @@ void save_dives_buffer(struct membuffer *b, const bool select_only) if (!dive->selected) continue; - save_one_dive(b, dive); + save_one_dive_to_mb(b, dive); } else { trip = dive->divetrip; /* Bare dive without a trip? */ if (!trip) { - save_one_dive(b, dive); + save_one_dive_to_mb(b, dive); continue; } @@ -605,7 +607,15 @@ static void try_to_backup(const char *filename) while (extension[i][0] != '\0') { int elen = strlen(extension[i]); if (strcasecmp(filename + flen - elen, extension[i]) == 0) { - save_backup(filename, extension[i], "bak"); + if (last_xml_version < VERSION) { + int se_len = strlen(extension[i]) + 5; + char *special_ext = malloc(se_len); + snprintf(special_ext, se_len, "%s.v%d", extension[i], last_xml_version); + save_backup(filename, extension[i], special_ext); + free(special_ext); + } else { + save_backup(filename, extension[i], "bak"); + } break; } i++; |