From c888a1727e250c27a8d494dac7d340c8b7475867 Mon Sep 17 00:00:00 2001 From: Salvador Cuñat Date: Wed, 26 Aug 2020 12:37:33 +0200 Subject: DataTrak import: Add support for WLog extensions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WLog is a Win32 based ancient shareware program whose target was: 1) fully support divelogs coming from DataTrak (DOS or Win) 2) fill some meaningful data which wasn't supported by Uwatec software 3) have a more user-friendly GUI than Datatrak had The problem achieving goals 1) and 2) at the same time was solved by adding a complementary file with .add extension and - mandatory - same base name than .log file (including directory tree). This .add file has a fixed structure composed of a 12 bytes header, including file type check and Nº of dives following; then a fixed 850 bytes size for each dive in the log file. Data fields size and position are fixed inside these blocks and heavily zero padded, so they are easy to parse. A serious restriction imposed to the WLog user was *Do not edit the logs with other software than Wlog*; this was due the order of dives in .log file being the same than the order of dives in .add file. Thought you could show a WLog divelog in Datatrak, editing it resulted in mixing all extended data for dives following the edited one. Thus, we have to trust files are correct and is to the user ensure this is so. If extended data are mangled, they are mangled in WLog too and we are not trying to fix the mess, just importing. On the technical side, we try to be smart about tank names as neither DataTrak nor WLog record them. So we just take the first tank in users list matching the volume recorded in WLog. For weights we add a translatable "unknown" string as an empty string results in weight not being shown in subsurface-mobile (which could be a reportable issue, BTW). Signed-off-by: Salvador Cuñat --- core/file.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'core/file.c') diff --git a/core/file.c b/core/file.c index 0fece03a9..ed00b7948 100644 --- a/core/file.c +++ b/core/file.c @@ -338,8 +338,20 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table /* DataTrak/Wlog */ if (fmt && !strcasecmp(fmt + 1, "LOG")) { - ret = datatrak_import(&mem, table, trips, sites); + struct memblock wl_mem; + const char *t = strrchr(filename, '.'); + char *wl_name = memcpy(calloc(t - filename + 1, 1), filename, t - filename); + wl_name = realloc(wl_name, strlen(wl_name) + 5); + wl_name = strcat(wl_name, ".add"); + if((ret = readfile(wl_name, &wl_mem)) < 0) { + fprintf(stderr, "No file %s found. No WLog extensions.\n", wl_name); + ret = datatrak_import(&mem, NULL, table, trips, sites); + } else { + ret = datatrak_import(&mem, &wl_mem, table, trips, sites); + free(wl_mem.buffer); + } free(mem.buffer); + free(wl_name); return ret; } -- cgit v1.2.3-70-g09d2