summaryrefslogtreecommitdiffstats
path: root/uemis-downloader.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-28 22:02:03 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-28 22:02:03 -0700
commita79b74ed36f6a52db947ff24761a3fd331c75cdc (patch)
treec5986baa8d28be329ae8396d31f2e8d15739ccac /uemis-downloader.c
parent10fac7a6af7e95b45029372f32ce544c705f6887 (diff)
downloadsubsurface-a79b74ed36f6a52db947ff24761a3fd331c75cdc.tar.gz
Track Uemis last dive downloaded on a per data-file basis
Actually, it's even better than that. Thanks to the new divecomputer datastructure we can now simply look up in the dive_table which dives have been downloaded from this specific Uemis SDA. This patch removes the old gconf based code - which leads to one unfortunate problem: the first time a Uemis SDA owner runs this version of Subsurface against their data file ALL dives will be downloaded again (which may not be a bad thing as we have improved a few other details of Uemis support so now they get their deco information, surface pressure and other data that we have started to support since 2.1). Still, this is not ideal. But I didn't want to keep the legacy code around since this new solution is so much cleaner. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'uemis-downloader.c')
-rw-r--r--uemis-downloader.c84
1 files changed, 15 insertions, 69 deletions
diff --git a/uemis-downloader.c b/uemis-downloader.c
index ac45940b5..9577c48cc 100644
--- a/uemis-downloader.c
+++ b/uemis-downloader.c
@@ -44,7 +44,6 @@ static int mbuf_size = 0;
struct argument_block {
const char *mountpath;
- char **max_dive_data;
char **xml_buffer;
progressbar_t *progress;
gboolean force_download;
@@ -720,78 +719,26 @@ static char *process_raw_buffer(char *inbuf, char **max_divenr)
return strdup(conv_buffer);
}
-/* to keep track of multiple computers we simply encode the last dive read
- in tuples "{deviceid,nr},{deviceid,nr}..." no spaces to make parsing easier */
-
-static char *find_deviceid(char *max_dive_data, char *deviceid)
+static char *get_divenr(char *deviceidstr)
{
- char *pattern;
- char *result;
- if (! deviceid || *deviceid == '\0')
- return NULL;
- pattern = malloc(3 + strlen(deviceid));
- sprintf(pattern, "{%s,", deviceid);
- result = strstr(max_dive_data, pattern);
- free(pattern);
- return result;
-}
-
-static char *get_divenr(char *max_dive_data, char *deviceid)
-{
- char *q, *p = max_dive_data;
- char *result = NULL;
-
- if (!p || !deviceid)
- return strdup("0");
- p = find_deviceid(max_dive_data, deviceid);
- if (p) {
- p += strlen(deviceid) + 2;
- q = strchr(p, '}');
- if (!q)
- return result;
- result = malloc(q - p + 1);
- strncpy(result, p, q - p);
- result[q - p] = '\0';
+ int deviceid, i, maxdiveid = 0;
+ char divenr[10];
+
+ if (sscanf(deviceidstr, "%d", &deviceid) != 1)
+ return "0";
+ for (i = 0; i < dive_table.nr; i++) {
+ struct divecomputer *dc = &dive_table.dives[i]->dc;
+ if (dc->deviceid == deviceid && dc->diveid > maxdiveid)
+ maxdiveid = dc->diveid;
}
- if (!result)
- result = strdup("0");
- return result;
-}
-
-static char *update_max_dive_data(char *max_dive_data, char *deviceid, char *newmax)
-{
- char *p;
- char *result;
- int len;
+ snprintf(divenr, 10, "%d", maxdiveid);
- if (! newmax || *newmax == '\0')
- return max_dive_data;
- p = find_deviceid(max_dive_data, deviceid);
- if (p) {
- /* if there are more entries after this one, copy them,
- otherwise just remove the existing entry for this device */
- char *q = strstr(p, "},{");
- if (q) {
- memcpy(p + 1, q + 3, strlen(q + 3) + 1);
- } else {
- if (p > max_dive_data)
- *(p-1) = '\0';
- else
- *p = '\0';
- }
- }
- /* now add the new one at the end */
- len = strlen(max_dive_data) + strlen(deviceid) + strlen(newmax) + 4 + (strlen(max_dive_data) ? 1 : 0);
- result = malloc(len);
- snprintf(result, len, "%s%s{%s,%s}", max_dive_data, strlen(max_dive_data) ? "," : "", deviceid, newmax);
- free(max_dive_data);
- return result;
+ return strdup(divenr);
}
static char *do_uemis_download(struct argument_block *args)
{
const char *mountpath = args->mountpath;
- char **max_dive_data = args->max_dive_data;
char **xml_buffer = args->xml_buffer;
int xml_buffer_size;
char *newmax = NULL;
@@ -827,7 +774,7 @@ static char *do_uemis_download(struct argument_block *args)
* the Uemis; otherwise check which was the last dive
* downloaded */
if (!args->force_download && dive_table.nr > 0)
- newmax = get_divenr(*max_dive_data, deviceid);
+ newmax = get_divenr(deviceid);
else
newmax = strdup("0");
@@ -862,7 +809,6 @@ static char *do_uemis_download(struct argument_block *args)
if (endptr)
*(endptr + 2) = '\0';
}
- *args->max_dive_data = update_max_dive_data(*max_dive_data, deviceid, newmax);
if (sscanf(newmax, "%d", &end) != 1)
end = start;
#if UEMIS_DEBUG > 1
@@ -920,12 +866,12 @@ static gboolean timeout_func(gpointer _data)
return FALSE;
}
-GError *uemis_download(const char *mountpath, char **max_dive_data, char **xml_buffer, progressbar_t *progress,
+GError *uemis_download(const char *mountpath, char **xml_buffer, progressbar_t *progress,
GtkDialog *dialog, gboolean force_download)
{
pthread_t pthread;
void *retval;
- struct argument_block args = {mountpath, max_dive_data, xml_buffer, progress, force_download};
+ struct argument_block args = {mountpath, xml_buffer, progress, force_download};
/* I'm sure there is some better interface for waiting on a thread in a UI main loop */
import_thread_done = 0;