2017-04-27 18:18:03 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2018-05-22 07:07:42 +00:00
|
|
|
#include "ssrf.h"
|
2012-01-26 21:00:45 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <stdlib.h>
|
2012-01-27 01:43:33 +00:00
|
|
|
#include <string.h>
|
2012-01-26 21:00:45 +00:00
|
|
|
#include <errno.h>
|
2013-10-06 15:55:58 +00:00
|
|
|
#include "gettext.h"
|
2013-05-11 19:33:46 +00:00
|
|
|
#include <zip.h>
|
2013-10-19 05:17:13 +00:00
|
|
|
#include <time.h>
|
2012-01-26 21:00:45 +00:00
|
|
|
|
|
|
|
#include "dive.h"
|
2018-05-11 15:25:41 +00:00
|
|
|
#include "subsurface-string.h"
|
2015-12-27 18:04:05 +00:00
|
|
|
#include "divelist.h"
|
2012-01-27 20:43:40 +00:00
|
|
|
#include "file.h"
|
2015-06-13 15:01:06 +00:00
|
|
|
#include "git-access.h"
|
2018-02-24 22:28:13 +00:00
|
|
|
#include "qthelper.h"
|
2018-01-06 20:24:38 +00:00
|
|
|
#include "import-csv.h"
|
2019-03-03 21:29:40 +00:00
|
|
|
#include "parse.h"
|
2012-01-26 21:00:45 +00:00
|
|
|
|
2014-11-19 21:14:22 +00:00
|
|
|
/* For SAMPLE_* */
|
|
|
|
#include <libdivecomputer/parser.h>
|
|
|
|
|
2015-02-18 05:58:34 +00:00
|
|
|
/* to check XSLT version number */
|
|
|
|
#include <libxslt/xsltconfig.h>
|
|
|
|
|
2012-08-24 22:39:00 +00:00
|
|
|
/* Crazy windows sh*t */
|
|
|
|
#ifndef O_BINARY
|
|
|
|
#define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
2013-03-14 03:37:38 +00:00
|
|
|
int readfile(const char *filename, struct memblock *mem)
|
2012-01-26 21:00:45 +00:00
|
|
|
{
|
2012-07-12 22:28:47 +00:00
|
|
|
int ret, fd;
|
2012-01-26 21:00:45 +00:00
|
|
|
struct stat st;
|
2012-01-27 18:56:36 +00:00
|
|
|
char *buf;
|
2012-01-26 21:00:45 +00:00
|
|
|
|
|
|
|
mem->buffer = NULL;
|
|
|
|
mem->size = 0;
|
|
|
|
|
2013-12-19 13:00:51 +00:00
|
|
|
fd = subsurface_open(filename, O_RDONLY | O_BINARY, 0);
|
2012-01-26 21:00:45 +00:00
|
|
|
if (fd < 0)
|
|
|
|
return fd;
|
|
|
|
ret = fstat(fd, &st);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
ret = -EINVAL;
|
|
|
|
if (!S_ISREG(st.st_mode))
|
|
|
|
goto out;
|
|
|
|
ret = 0;
|
|
|
|
if (!st.st_size)
|
|
|
|
goto out;
|
2014-02-28 04:09:57 +00:00
|
|
|
buf = malloc(st.st_size + 1);
|
2012-01-26 21:00:45 +00:00
|
|
|
ret = -1;
|
|
|
|
errno = ENOMEM;
|
2012-01-27 18:56:36 +00:00
|
|
|
if (!buf)
|
2012-01-26 21:00:45 +00:00
|
|
|
goto out;
|
2012-01-27 18:56:36 +00:00
|
|
|
mem->buffer = buf;
|
2012-01-26 21:00:45 +00:00
|
|
|
mem->size = st.st_size;
|
2012-01-27 18:56:36 +00:00
|
|
|
ret = read(fd, buf, mem->size);
|
2012-01-26 21:00:45 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto free;
|
2012-01-27 18:56:36 +00:00
|
|
|
buf[ret] = 0;
|
2016-03-10 02:23:48 +00:00
|
|
|
if (ret == (int)mem->size) // converting to int loses a bit but size will never be that big
|
2012-01-26 21:00:45 +00:00
|
|
|
goto out;
|
|
|
|
errno = EIO;
|
|
|
|
ret = -1;
|
|
|
|
free:
|
|
|
|
free(mem->buffer);
|
|
|
|
mem->buffer = NULL;
|
|
|
|
mem->size = 0;
|
|
|
|
out:
|
|
|
|
close(fd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-01-27 01:43:33 +00:00
|
|
|
|
2019-02-28 21:45:17 +00:00
|
|
|
static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
|
2012-01-27 01:43:33 +00:00
|
|
|
{
|
|
|
|
int size = 1024, n, read = 0;
|
|
|
|
char *mem = malloc(size);
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
while ((n = zip_fread(file, mem + read, size - read)) > 0) {
|
2012-01-27 01:43:33 +00:00
|
|
|
read += n;
|
|
|
|
size = read * 3 / 2;
|
|
|
|
mem = realloc(mem, size);
|
|
|
|
}
|
2013-03-17 05:12:23 +00:00
|
|
|
mem[read] = 0;
|
2019-02-28 21:45:17 +00:00
|
|
|
(void) parse_xml_buffer(filename, mem, read, table, trips, sites, NULL);
|
2012-01-27 01:43:33 +00:00
|
|
|
free(mem);
|
|
|
|
}
|
|
|
|
|
2019-02-28 21:45:17 +00:00
|
|
|
int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
|
2012-01-27 01:43:33 +00:00
|
|
|
{
|
|
|
|
int success = 0;
|
2012-01-27 18:56:36 +00:00
|
|
|
/* Grr. libzip needs to re-open the file, it can't take a buffer */
|
2013-12-19 13:00:51 +00:00
|
|
|
struct zip *zip = subsurface_zip_open_readonly(filename, ZIP_CHECKCONS, NULL);
|
2012-01-27 01:43:33 +00:00
|
|
|
|
|
|
|
if (zip) {
|
|
|
|
int index;
|
2014-02-28 04:09:57 +00:00
|
|
|
for (index = 0;; index++) {
|
2012-01-27 01:43:33 +00:00
|
|
|
struct zip_file *file = zip_fopen_index(zip, index, 0);
|
|
|
|
if (!file)
|
|
|
|
break;
|
2014-10-13 18:31:01 +00:00
|
|
|
/* skip parsing the divelogs.de pictures */
|
|
|
|
if (strstr(zip_get_name(zip, index, 0), "pictures/"))
|
|
|
|
continue;
|
2019-02-28 21:45:17 +00:00
|
|
|
zip_read(file, filename, table, trips, sites);
|
2012-01-27 01:43:33 +00:00
|
|
|
zip_fclose(file);
|
|
|
|
success++;
|
|
|
|
}
|
2013-12-19 13:00:51 +00:00
|
|
|
subsurface_zip_close(zip);
|
2015-10-31 17:29:41 +00:00
|
|
|
|
|
|
|
if (!success)
|
|
|
|
return report_error(translate("gettextFromC", "No dives in the input file '%s'"), filename);
|
2012-01-27 01:43:33 +00:00
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2018-01-07 17:53:40 +00:00
|
|
|
static int db_test_func(void *param, int columns, char **data, char **column)
|
2014-02-15 06:36:50 +00:00
|
|
|
{
|
2018-05-22 07:07:42 +00:00
|
|
|
UNUSED(param);
|
|
|
|
UNUSED(columns);
|
|
|
|
UNUSED(column);
|
2014-02-15 06:36:50 +00:00
|
|
|
return *data[0] == '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-28 21:45:17 +00:00
|
|
|
static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
|
2013-03-05 05:10:39 +00:00
|
|
|
{
|
2014-02-15 06:36:49 +00:00
|
|
|
sqlite3 *handle;
|
2014-02-15 06:36:50 +00:00
|
|
|
char dm4_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%ProfileBlob%'";
|
2014-11-15 15:34:20 +00:00
|
|
|
char dm5_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%SampleBlob%'";
|
2014-02-15 06:36:50 +00:00
|
|
|
char shearwater_test[] = "select count(*) from sqlite_master where type='table' and name='system' and sql like '%dbVersion%'";
|
2018-12-29 19:32:55 +00:00
|
|
|
char shearwater_cloud_test[] = "select count(*) from sqlite_master where type='table' and name='SyncV3MetadataDiveLog' and sql like '%CreatedDevice%'";
|
2014-12-20 16:19:43 +00:00
|
|
|
char cobalt_test[] = "select count(*) from sqlite_master where type='table' and name='TrackPoints' and sql like '%DepthPressure%'";
|
2015-07-12 17:46:48 +00:00
|
|
|
char divinglog_test[] = "select count(*) from sqlite_master where type='table' and name='DBInfo' and sql like '%PrgName%'";
|
2014-02-15 06:36:49 +00:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = sqlite3_open(filename, &handle);
|
|
|
|
|
|
|
|
if (retval) {
|
2015-07-02 18:22:22 +00:00
|
|
|
fprintf(stderr, "Database connection failed '%s'.\n", filename);
|
2014-02-15 06:36:49 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-11-15 15:34:20 +00:00
|
|
|
/* Testing if DB schema resembles Suunto DM5 database format */
|
|
|
|
retval = sqlite3_exec(handle, dm5_test, &db_test_func, 0, NULL);
|
|
|
|
if (!retval) {
|
2019-02-28 21:45:17 +00:00
|
|
|
retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites);
|
2014-11-15 15:34:20 +00:00
|
|
|
sqlite3_close(handle);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2014-02-15 06:36:50 +00:00
|
|
|
/* Testing if DB schema resembles Suunto DM4 database format */
|
|
|
|
retval = sqlite3_exec(handle, dm4_test, &db_test_func, 0, NULL);
|
|
|
|
if (!retval) {
|
2019-02-28 21:45:17 +00:00
|
|
|
retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites);
|
2014-02-15 06:36:50 +00:00
|
|
|
sqlite3_close(handle);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Testing if DB schema resembles Shearwater database format */
|
|
|
|
retval = sqlite3_exec(handle, shearwater_test, &db_test_func, 0, NULL);
|
|
|
|
if (!retval) {
|
2019-02-28 21:45:17 +00:00
|
|
|
retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites);
|
2014-12-20 16:19:43 +00:00
|
|
|
sqlite3_close(handle);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2018-12-29 19:32:55 +00:00
|
|
|
/* Testing if DB schema resembles Shearwater cloud database format */
|
|
|
|
retval = sqlite3_exec(handle, shearwater_cloud_test, &db_test_func, 0, NULL);
|
|
|
|
if (!retval) {
|
2019-02-28 21:45:17 +00:00
|
|
|
retval = parse_shearwater_cloud_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites);
|
2018-12-29 19:32:55 +00:00
|
|
|
sqlite3_close(handle);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2014-12-20 16:19:43 +00:00
|
|
|
/* Testing if DB schema resembles Atomic Cobalt database format */
|
|
|
|
retval = sqlite3_exec(handle, cobalt_test, &db_test_func, 0, NULL);
|
|
|
|
if (!retval) {
|
2019-02-28 21:45:17 +00:00
|
|
|
retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites);
|
2014-02-15 06:36:50 +00:00
|
|
|
sqlite3_close(handle);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-07-12 17:46:48 +00:00
|
|
|
/* Testing if DB schema resembles Divinglog database format */
|
|
|
|
retval = sqlite3_exec(handle, divinglog_test, &db_test_func, 0, NULL);
|
|
|
|
if (!retval) {
|
2019-02-28 21:45:17 +00:00
|
|
|
retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites);
|
2015-07-12 17:46:48 +00:00
|
|
|
sqlite3_close(handle);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2014-02-15 06:36:49 +00:00
|
|
|
sqlite3_close(handle);
|
|
|
|
|
|
|
|
return retval;
|
2013-03-05 05:10:39 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 03:07:42 +00:00
|
|
|
/*
|
|
|
|
* Cochran comma-separated values: depth in feet, temperature in F, pressure in psi.
|
|
|
|
*
|
|
|
|
* They start with eight comma-separated fields like:
|
|
|
|
*
|
|
|
|
* filename: {C:\Analyst4\can\T036785.can},{C:\Analyst4\can\K031892.can}
|
|
|
|
* divenr: %d
|
|
|
|
* datetime: {03Sep11 16:37:22},{15Dec11 18:27:02}
|
|
|
|
* ??: 1
|
|
|
|
* serialnr??: {CCI134},{CCI207}
|
|
|
|
* computer??: {GeminiII},{CommanderIII}
|
|
|
|
* computer??: {GeminiII},{CommanderIII}
|
|
|
|
* ??: 1
|
|
|
|
*
|
|
|
|
* Followed by the data values (all comma-separated, all one long line).
|
|
|
|
*/
|
2018-11-26 23:25:15 +00:00
|
|
|
static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem,
|
2019-02-28 21:45:17 +00:00
|
|
|
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
|
2012-01-27 01:43:33 +00:00
|
|
|
{
|
2014-12-08 21:09:34 +00:00
|
|
|
// hack to be able to provide a comment for the translated string
|
|
|
|
static char *csv_warning = QT_TRANSLATE_NOOP3("gettextFromC",
|
|
|
|
"Cannot open CSV file %s; please use Import log file dialog",
|
|
|
|
"'Import log file' should be the same text as corresponding label in Import menu");
|
|
|
|
|
2013-09-17 18:23:54 +00:00
|
|
|
/* Suunto Dive Manager files: SDE, ZIP; divelogs.de files: DLD */
|
|
|
|
if (!strcasecmp(fmt, "SDE") || !strcasecmp(fmt, "ZIP") || !strcasecmp(fmt, "DLD"))
|
2019-02-28 21:45:17 +00:00
|
|
|
return try_to_open_zip(filename, table, trips, sites);
|
2012-01-27 01:43:33 +00:00
|
|
|
|
2013-09-29 12:44:38 +00:00
|
|
|
/* CSV files */
|
2014-01-15 13:59:25 +00:00
|
|
|
if (!strcasecmp(fmt, "CSV"))
|
2014-12-08 21:09:34 +00:00
|
|
|
return report_error(translate("gettextFromC", csv_warning), filename);
|
2012-01-27 20:43:40 +00:00
|
|
|
/* Truly nasty intentionally obfuscated Cochran Anal software */
|
|
|
|
if (!strcasecmp(fmt, "CAN"))
|
2019-02-28 21:45:17 +00:00
|
|
|
return try_to_open_cochran(filename, mem, table, trips, sites);
|
2012-06-20 03:07:42 +00:00
|
|
|
/* Cochran export comma-separated-value files */
|
|
|
|
if (!strcasecmp(fmt, "DPT"))
|
2019-02-28 21:45:17 +00:00
|
|
|
return try_to_open_csv(mem, CSV_DEPTH, table, trips, sites);
|
2014-11-07 16:30:44 +00:00
|
|
|
if (!strcasecmp(fmt, "LVD"))
|
2019-02-28 21:45:17 +00:00
|
|
|
return try_to_open_liquivision(filename, mem, table, trips, sites);
|
2012-06-20 03:07:42 +00:00
|
|
|
if (!strcasecmp(fmt, "TMP"))
|
2019-02-28 21:45:17 +00:00
|
|
|
return try_to_open_csv(mem, CSV_TEMP, table, trips, sites);
|
2012-06-20 03:07:42 +00:00
|
|
|
if (!strcasecmp(fmt, "HP1"))
|
2019-02-28 21:45:17 +00:00
|
|
|
return try_to_open_csv(mem, CSV_PRESSURE, table, trips, sites);
|
2012-06-20 03:07:42 +00:00
|
|
|
|
2012-01-27 01:43:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-28 21:45:17 +00:00
|
|
|
static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
|
2012-01-27 18:56:36 +00:00
|
|
|
{
|
2014-12-08 19:26:03 +00:00
|
|
|
int ret;
|
2012-01-27 18:56:36 +00:00
|
|
|
char *fmt = strrchr(filename, '.');
|
2019-02-28 21:45:17 +00:00
|
|
|
if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table, trips, sites)) != 0)
|
2014-12-08 19:26:03 +00:00
|
|
|
return ret;
|
2012-01-27 18:56:36 +00:00
|
|
|
|
2013-12-09 06:42:51 +00:00
|
|
|
if (!mem->size || !mem->buffer)
|
2014-12-08 19:26:03 +00:00
|
|
|
return report_error("Out of memory parsing file %s\n", filename);
|
2013-12-09 06:42:51 +00:00
|
|
|
|
2019-02-28 21:45:17 +00:00
|
|
|
return parse_xml_buffer(filename, mem->buffer, mem->size, table, trips, sites, NULL);
|
2012-01-27 18:56:36 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 05:51:09 +00:00
|
|
|
int check_git_sha(const char *filename, struct git_repository **git_p, const char **branch_p)
|
2016-01-05 01:48:34 +00:00
|
|
|
{
|
|
|
|
struct git_repository *git;
|
|
|
|
const char *branch = NULL;
|
|
|
|
|
2016-04-06 04:10:41 +00:00
|
|
|
char *current_sha = strdup(saved_git_id);
|
2016-01-05 01:48:34 +00:00
|
|
|
git = is_git_repository(filename, &branch, NULL, false);
|
2016-04-06 05:51:09 +00:00
|
|
|
if (git_p)
|
|
|
|
*git_p = git;
|
|
|
|
if (branch_p)
|
|
|
|
*branch_p = branch;
|
2016-01-05 01:48:34 +00:00
|
|
|
if (prefs.cloud_git_url &&
|
|
|
|
strstr(filename, prefs.cloud_git_url)
|
2016-04-06 04:10:41 +00:00
|
|
|
&& git == dummy_git_repository) {
|
2016-01-05 01:48:34 +00:00
|
|
|
/* opening the cloud storage repository failed for some reason,
|
|
|
|
* so we don't know if there is additional data in the remote */
|
2016-04-06 04:10:41 +00:00
|
|
|
free(current_sha);
|
2016-01-05 01:48:34 +00:00
|
|
|
return 1;
|
2016-04-06 04:10:41 +00:00
|
|
|
}
|
2016-01-05 01:48:34 +00:00
|
|
|
/* if this is a git repository, do we already have this exact state loaded ?
|
|
|
|
* get the SHA and compare with what we currently have */
|
|
|
|
if (git && git != dummy_git_repository) {
|
|
|
|
const char *sha = get_sha(git, branch);
|
2018-01-07 10:12:48 +00:00
|
|
|
if (!empty_string(sha) &&
|
2016-04-06 04:10:41 +00:00
|
|
|
same_string(sha, current_sha)) {
|
2016-01-05 01:48:34 +00:00
|
|
|
fprintf(stderr, "already have loaded SHA %s - don't load again\n", sha);
|
2016-04-06 04:10:41 +00:00
|
|
|
free(current_sha);
|
2016-01-05 01:48:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2016-04-06 04:10:41 +00:00
|
|
|
free(current_sha);
|
2016-01-05 01:48:34 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-28 21:45:17 +00:00
|
|
|
int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
|
2012-01-26 21:00:45 +00:00
|
|
|
{
|
2014-03-12 21:12:58 +00:00
|
|
|
struct git_repository *git;
|
2015-12-28 16:21:03 +00:00
|
|
|
const char *branch = NULL;
|
2016-03-23 20:25:10 +00:00
|
|
|
char *current_sha = copy_string(saved_git_id);
|
2012-01-26 21:00:45 +00:00
|
|
|
struct memblock mem;
|
2013-03-05 05:10:39 +00:00
|
|
|
char *fmt;
|
2014-12-08 19:26:03 +00:00
|
|
|
int ret;
|
2012-01-26 21:00:45 +00:00
|
|
|
|
2015-09-23 09:13:07 +00:00
|
|
|
git = is_git_repository(filename, &branch, NULL, false);
|
2015-06-16 13:27:12 +00:00
|
|
|
if (prefs.cloud_git_url &&
|
|
|
|
strstr(filename, prefs.cloud_git_url)
|
2016-03-23 20:25:10 +00:00
|
|
|
&& git == dummy_git_repository) {
|
2015-06-13 20:16:08 +00:00
|
|
|
/* opening the cloud storage repository failed for some reason
|
|
|
|
* give up here and don't send errors about git repositories */
|
2016-03-23 20:25:10 +00:00
|
|
|
free(current_sha);
|
2016-04-30 17:34:11 +00:00
|
|
|
return -1;
|
2016-03-23 20:25:10 +00:00
|
|
|
}
|
2015-12-28 16:21:03 +00:00
|
|
|
/* if this is a git repository, do we already have this exact state loaded ?
|
2015-12-27 18:04:05 +00:00
|
|
|
* get the SHA and compare with what we currently have */
|
2015-12-28 16:21:03 +00:00
|
|
|
if (git && git != dummy_git_repository) {
|
|
|
|
const char *sha = get_sha(git, branch);
|
2018-01-07 10:12:48 +00:00
|
|
|
if (!empty_string(sha) &&
|
2016-03-23 20:25:10 +00:00
|
|
|
same_string(sha, current_sha) &&
|
2015-12-28 16:21:03 +00:00
|
|
|
!unsaved_changes()) {
|
|
|
|
fprintf(stderr, "already have loaded SHA %s - don't load again\n", sha);
|
2016-03-23 20:25:10 +00:00
|
|
|
free(current_sha);
|
2015-12-28 16:21:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-12-27 18:04:05 +00:00
|
|
|
}
|
2016-03-23 20:25:10 +00:00
|
|
|
free(current_sha);
|
2016-02-11 01:57:01 +00:00
|
|
|
if (git)
|
|
|
|
return git_load_dives(git, branch);
|
2014-03-12 21:12:58 +00:00
|
|
|
|
2015-08-05 16:01:49 +00:00
|
|
|
if ((ret = readfile(filename, &mem)) < 0) {
|
2017-12-13 19:10:04 +00:00
|
|
|
/* we don't want to display an error if this was the default file */
|
|
|
|
if (same_string(filename, prefs.default_filename))
|
2014-03-14 18:26:07 +00:00
|
|
|
return 0;
|
2012-11-10 14:32:06 +00:00
|
|
|
|
2014-03-14 18:26:07 +00:00
|
|
|
return report_error(translate("gettextFromC", "Failed to read '%s'"), filename);
|
2015-08-05 16:01:49 +00:00
|
|
|
} else if (ret == 0) {
|
|
|
|
return report_error(translate("gettextFromC", "Empty file '%s'"), filename);
|
2012-01-26 21:00:45 +00:00
|
|
|
}
|
|
|
|
|
2013-03-05 05:10:39 +00:00
|
|
|
fmt = strrchr(filename, '.');
|
2015-07-12 17:46:47 +00:00
|
|
|
if (fmt && (!strcasecmp(fmt + 1, "DB") || !strcasecmp(fmt + 1, "BAK") || !strcasecmp(fmt + 1, "SQL"))) {
|
2019-02-28 21:45:17 +00:00
|
|
|
if (!try_to_open_db(filename, &mem, table, trips, sites)) {
|
2013-03-05 05:10:39 +00:00
|
|
|
free(mem.buffer);
|
2014-03-14 18:26:07 +00:00
|
|
|
return 0;
|
2013-03-05 05:10:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-27 20:10:44 +00:00
|
|
|
/* Divesoft Freedom */
|
|
|
|
if (fmt && (!strcasecmp(fmt + 1, "DLF"))) {
|
2019-02-28 21:45:17 +00:00
|
|
|
ret = parse_dlf_buffer(mem.buffer, mem.size, table, trips, sites);
|
2018-08-18 11:45:13 +00:00
|
|
|
free(mem.buffer);
|
|
|
|
return ret;
|
2014-12-27 20:10:44 +00:00
|
|
|
}
|
|
|
|
|
Import Datatrak/WLog files
Sequentially parses a file, expected to be a Datatrak/WLog divelog, and
converts the dive info into Subsurface's dive structure.
As my first DC, back in 90s, was an Aladin Air X, the obvious choice of log
software was DTrak (Win version). After using it for some time we moved to WLog
(shareware software more user friendly than Dtrak, printing capable, and still
better, it runs under wine, which, as linux user, was definitive for me). Then,
some years later, my last Aladin died and I moved to an OSTC, forcing me to
look for a software that support this DC.
I found JDivelog which was capable of import Dtrak logs and used it for some
time until discovered Subsurface existence and devoted to it.
The fact was that importing Dtrak dives in JDivelog and then re-importing them
in Subsurface caused a significant data loss (mainly in the profile events and
alarms) and weird location of some other info in the dive notes (mostly tag
items in the original Dtrak software). This situation can't actually be solved
with tools like divelogs.de which causes similar if no greater data loss.
Although this won't be a core feature for Subsurface, I expect it can be useful
for some other divers as has been for me.
Comments and issues:
Datatrak/Wlog files include a lot of diving data which are not directly
supported in Subsurface, in these cases we choose mostly to use "tags".
The lack of some important info in Datatrak archives (e.g. tank's initial
pressure) forces us to do some arbitrary assumptions (e.g. initial pressure =
200 bar).
There might be archives coming directly from old DOS days, as first versions
of Datatrak run on that OS; they were coded CP437 or CP850, while dive logs
coming from Win versions seems to be coded CP1252. Finally, Wlog seems to use a
mixed confusing style. Program directly converts some of the old encoded chars
to iso8859 but is expected there be some issues with non alphabetic chars, e.g.
"ª".
There are two text fields: "Other activities" and "Dive notes", both limited to
256 char size. We have merged them in Subsurface's "Dive Notes" although the
first one could be "tagged", but we're unsure that the user had filled it in
a tag friendly way.
WLog adds some information to the dive and lets the user to write more than
256 chars notes. This is achieved, while keeping compatibility with DTrak
divelogs, by adding a complementary file named equally as the .log file and
with .add extension where all this info is stored. We have, still, not worked
with this complementary files.
This work is based on the paper referenced in butracker #194 which has some
errors (e.g. beginning of log and beginning of dive are changed) and a lot of
bytes of unknown meaning. Example.log shows, at least, one more byte than those
referred in the paper for the O2 Aladin computer, this could be a byte referred
to the use of SCR but the lack of an OC dive with O2 computer makes impossible
for us to compare.
The only way we have figured out to distinguish a priori between SCR and non
SCR dives with O2 computers is that the dives are tagged with a "rebreather"
tag. Obviously this is not a very trusty way of doing things. In SCR dives,
the O2% in mix means, probably, the maximum O2% in the circuit, not the O2%
of the EAN mix in the tanks, which would be unknown in this case.
The list of DCs related in bug #194 paper seems incomplete, we have added
one or two from WLog and discarded those which are known to exist but whose
model is unknown, grouping them under the imaginative name of "unknown". The
list can easily be increased in the future if we ever know the models
identifiers.
BTW, in Example.log, 0x00 identifier is used for some DC dives and from my own
divelogs is inferred that 0x00 is used for manually entered dives, this could
easily be an error in Example.log coming from a preproduction DC model.
Example.log which is shipped in datatrak package is included in dives
directory for testing pourposes.
[Dirk Hohndel: some small cleanups, merged with latest master, support
divesites, remove the pointless memset() before free() calls
add to cmake build]
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-05 18:38:27 +00:00
|
|
|
/* DataTrak/Wlog */
|
2015-03-10 22:23:14 +00:00
|
|
|
if (fmt && !strcasecmp(fmt + 1, "LOG")) {
|
2019-02-28 21:45:17 +00:00
|
|
|
ret = datatrak_import(&mem, table, trips, sites);
|
2017-05-07 08:15:59 +00:00
|
|
|
free(mem.buffer);
|
|
|
|
return ret;
|
Import Datatrak/WLog files
Sequentially parses a file, expected to be a Datatrak/WLog divelog, and
converts the dive info into Subsurface's dive structure.
As my first DC, back in 90s, was an Aladin Air X, the obvious choice of log
software was DTrak (Win version). After using it for some time we moved to WLog
(shareware software more user friendly than Dtrak, printing capable, and still
better, it runs under wine, which, as linux user, was definitive for me). Then,
some years later, my last Aladin died and I moved to an OSTC, forcing me to
look for a software that support this DC.
I found JDivelog which was capable of import Dtrak logs and used it for some
time until discovered Subsurface existence and devoted to it.
The fact was that importing Dtrak dives in JDivelog and then re-importing them
in Subsurface caused a significant data loss (mainly in the profile events and
alarms) and weird location of some other info in the dive notes (mostly tag
items in the original Dtrak software). This situation can't actually be solved
with tools like divelogs.de which causes similar if no greater data loss.
Although this won't be a core feature for Subsurface, I expect it can be useful
for some other divers as has been for me.
Comments and issues:
Datatrak/Wlog files include a lot of diving data which are not directly
supported in Subsurface, in these cases we choose mostly to use "tags".
The lack of some important info in Datatrak archives (e.g. tank's initial
pressure) forces us to do some arbitrary assumptions (e.g. initial pressure =
200 bar).
There might be archives coming directly from old DOS days, as first versions
of Datatrak run on that OS; they were coded CP437 or CP850, while dive logs
coming from Win versions seems to be coded CP1252. Finally, Wlog seems to use a
mixed confusing style. Program directly converts some of the old encoded chars
to iso8859 but is expected there be some issues with non alphabetic chars, e.g.
"ª".
There are two text fields: "Other activities" and "Dive notes", both limited to
256 char size. We have merged them in Subsurface's "Dive Notes" although the
first one could be "tagged", but we're unsure that the user had filled it in
a tag friendly way.
WLog adds some information to the dive and lets the user to write more than
256 chars notes. This is achieved, while keeping compatibility with DTrak
divelogs, by adding a complementary file named equally as the .log file and
with .add extension where all this info is stored. We have, still, not worked
with this complementary files.
This work is based on the paper referenced in butracker #194 which has some
errors (e.g. beginning of log and beginning of dive are changed) and a lot of
bytes of unknown meaning. Example.log shows, at least, one more byte than those
referred in the paper for the O2 Aladin computer, this could be a byte referred
to the use of SCR but the lack of an OC dive with O2 computer makes impossible
for us to compare.
The only way we have figured out to distinguish a priori between SCR and non
SCR dives with O2 computers is that the dives are tagged with a "rebreather"
tag. Obviously this is not a very trusty way of doing things. In SCR dives,
the O2% in mix means, probably, the maximum O2% in the circuit, not the O2%
of the EAN mix in the tanks, which would be unknown in this case.
The list of DCs related in bug #194 paper seems incomplete, we have added
one or two from WLog and discarded those which are known to exist but whose
model is unknown, grouping them under the imaginative name of "unknown". The
list can easily be increased in the future if we ever know the models
identifiers.
BTW, in Example.log, 0x00 identifier is used for some DC dives and from my own
divelogs is inferred that 0x00 is used for manually entered dives, this could
easily be an error in Example.log coming from a preproduction DC model.
Example.log which is shipped in datatrak package is included in dives
directory for testing pourposes.
[Dirk Hohndel: some small cleanups, merged with latest master, support
divesites, remove the pointless memset() before free() calls
add to cmake build]
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-05 18:38:27 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 23:07:59 +00:00
|
|
|
/* OSTCtools */
|
|
|
|
if (fmt && (!strcasecmp(fmt + 1, "DIVE"))) {
|
2018-08-18 11:31:28 +00:00
|
|
|
free(mem.buffer);
|
2019-02-28 21:45:17 +00:00
|
|
|
ostctools_import(filename, table, trips, sites);
|
2015-04-03 23:07:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-28 21:45:17 +00:00
|
|
|
ret = parse_file_buffer(filename, &mem, table, trips, sites);
|
2012-01-26 21:00:45 +00:00
|
|
|
free(mem.buffer);
|
2014-12-08 19:26:03 +00:00
|
|
|
return ret;
|
2012-01-26 21:00:45 +00:00
|
|
|
}
|