mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Fix "prefer download" behavior
When this was first implemented the assumption was that a downloaded dive that is to be merged with an existing dive would have the same time stamp. But as Linus pointed out even back then, this does fail if a dive has been merged with a download from a different dive computer before (think: download from computer a, then download same dive from b, then improve something in the parsing from computer a and try to redownload; the time stamp could have changed). This commit also fixes a silly omission in the merge_dives() function (which ended up ALWAYS prefering the downloaded dive) and finally implements the necessary changes to mark dives downloaded from a Uemis SDA as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
d872a5c8aa
commit
10ce60e212
5 changed files with 14 additions and 11 deletions
12
dive.c
12
dive.c
|
@ -1077,8 +1077,6 @@ struct dive *try_to_merge(struct dive *a, struct dive *b, gboolean prefer_downlo
|
|||
*/
|
||||
if ((a->when >= b->when + 60) || (a->when <= b->when - 60))
|
||||
return NULL;
|
||||
if (prefer_downloaded && a->when != b->when)
|
||||
return NULL;
|
||||
if (!prefer_downloaded) {
|
||||
/* Dive 'a' is 'offset' seconds before dive 'b' */
|
||||
offset = find_sample_offset(a, b);
|
||||
|
@ -1093,10 +1091,12 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean pr
|
|||
struct dive *res = alloc_dive();
|
||||
struct dive *dl = NULL;
|
||||
|
||||
if (a->downloaded)
|
||||
dl = a;
|
||||
else if (b->downloaded)
|
||||
dl = b;
|
||||
if (prefer_downloaded) {
|
||||
if (a->downloaded)
|
||||
dl = a;
|
||||
else if (b->downloaded)
|
||||
dl = b;
|
||||
}
|
||||
res->when = a->when;
|
||||
res->selected = a->selected || b->selected;
|
||||
merge_trip(res, a, b);
|
||||
|
|
2
dive.h
2
dive.h
|
@ -392,7 +392,7 @@ static inline struct dive *get_dive(int nr)
|
|||
for ((_i) = 0; ((_x) = get_dive(_i)) != NULL; (_i)++)
|
||||
|
||||
extern void parse_xml_init(void);
|
||||
extern void parse_xml_buffer(const char *url, const char *buf, int size, GError **error);
|
||||
extern void parse_xml_buffer(const char *url, const char *buf, int size, gboolean downloaded, GError **error);
|
||||
extern void parse_xml_exit(void);
|
||||
extern void set_filename(const char *filename, gboolean force);
|
||||
|
||||
|
|
4
file.c
4
file.c
|
@ -72,7 +72,7 @@ static void suunto_read(struct zip_file *file, GError **error)
|
|||
size = read * 3 / 2;
|
||||
mem = realloc(mem, size);
|
||||
}
|
||||
parse_xml_buffer(_("SDE file"), mem, read, error);
|
||||
parse_xml_buffer(_("SDE file"), mem, read, FALSE, error);
|
||||
free(mem);
|
||||
}
|
||||
#endif
|
||||
|
@ -246,7 +246,7 @@ static void parse_file_buffer(const char *filename, struct memblock *mem, GError
|
|||
if (fmt && open_by_filename(filename, fmt+1, mem, error))
|
||||
return;
|
||||
|
||||
parse_xml_buffer(filename, mem->buffer, mem->size, error);
|
||||
parse_xml_buffer(filename, mem->buffer, mem->size, FALSE, error);
|
||||
}
|
||||
|
||||
void parse_file(const char *filename, GError **error, gboolean possible_default_filename)
|
||||
|
|
|
@ -1685,7 +1685,7 @@ static GError *setup_uemis_import(device_data_t *data)
|
|||
#if UEMIS_DEBUG > 3
|
||||
fprintf(debugfile, "xml buffer \"%s\"\n\n", buf);
|
||||
#endif
|
||||
parse_xml_buffer("Uemis Download", buf, strlen(buf), &error);
|
||||
parse_xml_buffer("Uemis Download", buf, strlen(buf), TRUE, &error);
|
||||
set_uemis_last_dive(uemis_max_dive_data);
|
||||
#if UEMIS_DEBUG > 2
|
||||
fprintf(debugfile, "uemis_max_dive_data: %s\n", uemis_max_dive_data);
|
||||
|
|
|
@ -168,6 +168,7 @@ static struct {
|
|||
} cur_event;
|
||||
static struct tm cur_tm;
|
||||
static int cur_cylinder_index, cur_ws_index;
|
||||
static gboolean from_download;
|
||||
|
||||
static enum import_source {
|
||||
UNKNOWN,
|
||||
|
@ -1219,6 +1220,7 @@ static void dive_start(void)
|
|||
add_dive_to_trip(cur_dive, cur_trip);
|
||||
cur_dive->tripflag = IN_TRIP;
|
||||
}
|
||||
cur_dive->downloaded = from_download;
|
||||
}
|
||||
|
||||
static void dive_end(void)
|
||||
|
@ -1499,9 +1501,10 @@ static void reset_all(void)
|
|||
import_source = UNKNOWN;
|
||||
}
|
||||
|
||||
void parse_xml_buffer(const char *url, const char *buffer, int size, GError **error)
|
||||
void parse_xml_buffer(const char *url, const char *buffer, int size, gboolean downloaded, GError **error)
|
||||
{
|
||||
xmlDoc *doc;
|
||||
from_download = downloaded;
|
||||
|
||||
doc = xmlReadMemory(buffer, size, url, NULL, 0);
|
||||
if (!doc) {
|
||||
|
|
Loading…
Reference in a new issue