2017-04-27 18:18:03 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-09-09 08:59:03 +00:00
|
|
|
#include "subsurfacestartup.h"
|
2018-05-11 15:25:41 +00:00
|
|
|
#include "subsurface-string.h"
|
2015-02-15 18:25:18 +00:00
|
|
|
#include "version.h"
|
2019-08-05 17:41:15 +00:00
|
|
|
#include "errorhelper.h"
|
2013-10-06 15:55:58 +00:00
|
|
|
#include "gettext.h"
|
2018-02-24 22:28:13 +00:00
|
|
|
#include "qthelper.h"
|
2015-09-23 09:13:07 +00:00
|
|
|
#include "git-access.h"
|
2021-01-02 13:03:25 +00:00
|
|
|
#include "pref.h"
|
2016-03-06 14:52:55 +00:00
|
|
|
#include "libdivecomputer/version.h"
|
2015-09-23 09:13:07 +00:00
|
|
|
|
2021-01-02 13:03:25 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
2023-12-03 21:59:21 +00:00
|
|
|
#include <stdlib.h>
|
2020-11-15 21:12:21 +00:00
|
|
|
|
2021-01-02 13:03:25 +00:00
|
|
|
extern void show_computer_list();
|
2011-09-07 02:07:17 +00:00
|
|
|
|
2020-10-25 12:57:18 +00:00
|
|
|
int quit, force_root, ignore_bt;
|
2019-11-23 12:02:41 +00:00
|
|
|
#ifdef SUBSURFACE_MOBILE_DESKTOP
|
2024-02-28 19:07:39 +00:00
|
|
|
std::string testqml;
|
2019-11-23 12:02:41 +00:00
|
|
|
#endif
|
2014-06-14 21:45:42 +00:00
|
|
|
|
2011-10-05 21:09:49 +00:00
|
|
|
/*
|
|
|
|
* track whether we switched to importing dives
|
|
|
|
*/
|
2014-01-15 18:54:41 +00:00
|
|
|
bool imported = false;
|
2011-10-05 21:09:49 +00:00
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
void print_version()
|
2014-02-28 04:09:57 +00:00
|
|
|
{
|
2020-03-04 21:08:22 +00:00
|
|
|
static bool version_printed = false;
|
2017-11-15 21:55:42 +00:00
|
|
|
if (version_printed)
|
|
|
|
return;
|
2020-11-14 03:04:17 +00:00
|
|
|
#if defined(SUBSURFACE_DOWNLOADER)
|
2024-01-07 22:32:02 +00:00
|
|
|
printf("Subsurface-downloader v%s,\n", subsurface_canonical_version());
|
2020-11-14 03:04:17 +00:00
|
|
|
#else
|
2024-01-07 22:32:02 +00:00
|
|
|
printf("Subsurface v%s,\n", subsurface_canonical_version());
|
2020-11-14 03:04:17 +00:00
|
|
|
#endif
|
2013-05-29 11:50:38 +00:00
|
|
|
printf("built with libdivecomputer v%s\n", dc_version(NULL));
|
2017-11-09 14:43:38 +00:00
|
|
|
print_qt_versions();
|
|
|
|
int git_maj, git_min, git_rev;
|
|
|
|
git_libgit2_version(&git_maj, &git_min, &git_rev);
|
|
|
|
printf("built with libgit2 %d.%d.%d\n", git_maj, git_min, git_rev);
|
2017-11-15 21:55:42 +00:00
|
|
|
version_printed = true;
|
2013-05-29 11:50:38 +00:00
|
|
|
}
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
void print_files()
|
2015-09-23 09:13:07 +00:00
|
|
|
{
|
2024-03-11 20:41:14 +00:00
|
|
|
struct git_info info;
|
2024-03-24 21:05:28 +00:00
|
|
|
std::optional<std::string> filename;
|
2015-09-23 09:13:07 +00:00
|
|
|
|
|
|
|
printf("\nFile locations:\n\n");
|
2024-06-13 20:59:32 +00:00
|
|
|
printf("Cloud email:%s\n", prefs.cloud_storage_email.c_str());
|
|
|
|
if (!prefs.cloud_storage_email.empty() && !prefs.cloud_storage_password.empty()) {
|
2024-03-24 21:05:28 +00:00
|
|
|
filename = getCloudURL();
|
|
|
|
if (filename)
|
|
|
|
is_git_repository(filename->c_str(), &info);
|
2017-10-26 13:52:45 +00:00
|
|
|
}
|
2024-03-24 21:05:28 +00:00
|
|
|
if (!filename)
|
|
|
|
filename = std::string("No valid cloud credentials set.\n");
|
2024-03-11 20:41:14 +00:00
|
|
|
if (!info.localdir.empty()) {
|
|
|
|
printf("Local git storage: %s\n", info.localdir.c_str());
|
2015-10-06 09:10:08 +00:00
|
|
|
} else {
|
|
|
|
printf("Unable to get local git directory\n");
|
|
|
|
}
|
2024-03-24 21:05:28 +00:00
|
|
|
printf("Cloud URL: %s\n", filename->c_str());
|
2024-06-11 15:06:27 +00:00
|
|
|
printf("Image filename table: %s\n", hashfile_name().c_str());
|
2015-09-23 09:13:07 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
static void print_help()
|
|
|
|
{
|
2013-05-29 11:50:38 +00:00
|
|
|
print_version();
|
|
|
|
printf("\nUsage: subsurface [options] [logfile ...] [--import logfile ...]");
|
|
|
|
printf("\n\noptions include:");
|
|
|
|
printf("\n --help|-h This help text");
|
2020-01-12 04:59:08 +00:00
|
|
|
printf("\n --ignore-bt Don't enable Bluetooth support");
|
2013-05-29 11:50:38 +00:00
|
|
|
printf("\n --import logfile ... Logs before this option is treated as base, everything after is imported");
|
|
|
|
printf("\n --verbose|-v Verbose debug (repeat to increase verbosity)");
|
2014-03-25 14:55:56 +00:00
|
|
|
printf("\n --version Prints current version");
|
2017-01-06 10:23:13 +00:00
|
|
|
printf("\n --user=<test> Choose configuration space for user <test>");
|
2019-11-23 12:02:41 +00:00
|
|
|
#ifdef SUBSURFACE_MOBILE_DESKTOP
|
|
|
|
printf("\n --testqml=<dir> Use QML files from <dir> instead of QML resources");
|
2020-11-15 03:22:14 +00:00
|
|
|
#elif SUBSURFACE_DOWNLOADER
|
|
|
|
printf("\n --dc-vendor=vendor Set the dive computer to download from");
|
|
|
|
printf("\n --dc-product=product Set the dive computer to download from");
|
|
|
|
printf("\n --device=device Set the device to download from");
|
2019-11-23 12:02:41 +00:00
|
|
|
#endif
|
2017-12-23 18:39:06 +00:00
|
|
|
printf("\n --cloud-timeout=<nr> Set timeout for cloud connection (0 < timeout < 60)\n\n");
|
2013-05-29 11:50:38 +00:00
|
|
|
}
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
void parse_argument(const char *arg)
|
2011-08-31 01:40:25 +00:00
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
const char *p = arg + 1;
|
2011-08-31 01:40:25 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
switch (*p) {
|
2013-05-29 11:50:38 +00:00
|
|
|
case 'h':
|
|
|
|
print_help();
|
|
|
|
exit(0);
|
2011-08-31 01:40:25 +00:00
|
|
|
case 'v':
|
2017-11-09 14:21:18 +00:00
|
|
|
print_version();
|
2011-08-31 01:40:25 +00:00
|
|
|
verbose++;
|
|
|
|
continue;
|
2013-11-02 19:00:16 +00:00
|
|
|
case 'q':
|
|
|
|
quit++;
|
|
|
|
continue;
|
2011-10-05 18:36:15 +00:00
|
|
|
case '-':
|
|
|
|
/* long options with -- */
|
2016-04-29 13:17:02 +00:00
|
|
|
/* first test for --user=bla which allows the use of user specific settings */
|
|
|
|
if (strncmp(arg, "--user=", sizeof("--user=") - 1) == 0) {
|
2024-06-13 20:59:32 +00:00
|
|
|
settings_suffix = arg + sizeof("--user=") - 1;
|
2016-04-29 13:17:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-07-23 03:54:30 +00:00
|
|
|
if (strncmp(arg, "--cloud-timeout=", sizeof("--cloud-timeout=") - 1) == 0) {
|
|
|
|
const char *timeout = arg + sizeof("--cloud-timeout=") - 1;
|
|
|
|
int to = strtol(timeout, NULL, 10);
|
|
|
|
if (0 < to && to < 60)
|
|
|
|
default_prefs.cloud_timeout = to;
|
|
|
|
return;
|
|
|
|
}
|
2013-05-29 11:50:38 +00:00
|
|
|
if (strcmp(arg, "--help") == 0) {
|
|
|
|
print_help();
|
|
|
|
exit(0);
|
|
|
|
}
|
2020-01-12 04:59:08 +00:00
|
|
|
if (strcmp(arg, "--ignore-bt") == 0) {
|
|
|
|
ignore_bt = true;
|
|
|
|
return;
|
|
|
|
}
|
2013-05-29 11:50:38 +00:00
|
|
|
if (strcmp(arg, "--import") == 0) {
|
2014-01-15 18:54:41 +00:00
|
|
|
imported = true; /* mark the dives so far as the base, * everything after is imported */
|
2011-10-05 18:36:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-05-29 11:50:38 +00:00
|
|
|
if (strcmp(arg, "--verbose") == 0) {
|
2017-11-09 14:21:18 +00:00
|
|
|
print_version();
|
2013-05-29 11:50:38 +00:00
|
|
|
verbose++;
|
|
|
|
return;
|
|
|
|
}
|
2013-05-27 10:15:34 +00:00
|
|
|
if (strcmp(arg, "--version") == 0) {
|
2013-05-29 11:50:38 +00:00
|
|
|
print_version();
|
2013-05-27 10:15:34 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
2016-03-25 08:21:45 +00:00
|
|
|
if (strcmp(arg, "--allow_run_as_root") == 0) {
|
|
|
|
++force_root;
|
|
|
|
return;
|
|
|
|
}
|
2020-11-15 03:22:14 +00:00
|
|
|
#if SUBSURFACE_DOWNLOADER
|
|
|
|
if (strncmp(arg, "--dc-vendor=", sizeof("--dc-vendor=") - 1) == 0) {
|
2024-06-13 20:59:32 +00:00
|
|
|
prefs.dive_computer.vendor = arg + sizeof("--dc-vendor=") - 1;
|
2020-11-15 03:22:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (strncmp(arg, "--dc-product=", sizeof("--dc-product=") - 1) == 0) {
|
2024-06-13 20:59:32 +00:00
|
|
|
prefs.dive_computer.product = arg + sizeof("--dc-product=") - 1;
|
2020-11-15 03:22:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (strncmp(arg, "--device=", sizeof("--device=") - 1) == 0) {
|
2024-06-13 20:59:32 +00:00
|
|
|
prefs.dive_computer.device = arg + sizeof("--device=") - 1;
|
2020-11-15 03:22:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-11-15 21:12:21 +00:00
|
|
|
if (strncmp(arg, "--list-dc", sizeof("--list-dc") - 1) == 0) {
|
|
|
|
show_computer_list();
|
2020-11-28 13:33:20 +00:00
|
|
|
exit(0);
|
2020-11-15 21:12:21 +00:00
|
|
|
}
|
2020-11-15 03:22:14 +00:00
|
|
|
#elif SUBSURFACE_MOBILE_DESKTOP
|
2019-11-23 12:02:41 +00:00
|
|
|
if (strncmp(arg, "--testqml=", sizeof("--testqml=") - 1) == 0) {
|
2024-02-28 19:07:39 +00:00
|
|
|
testqml = arg + sizeof("--testqml=") - 1;
|
2019-11-23 12:02:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-28 04:09:57 +00:00
|
|
|
/* fallthrough */
|
2011-10-30 19:56:28 +00:00
|
|
|
case 'p':
|
|
|
|
/* ignore process serial number argument when run as native macosx app */
|
2013-10-06 15:55:58 +00:00
|
|
|
if (strncmp(arg, "-psQT_TR_NOOP(", 5) == 0) {
|
2011-10-30 19:56:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-28 04:09:57 +00:00
|
|
|
/* fallthrough */
|
2011-08-31 01:40:25 +00:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "Bad argument '%s'\n", arg);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} while (*++p);
|
|
|
|
}
|
|
|
|
|
2013-01-11 01:55:44 +00:00
|
|
|
/*
|
|
|
|
* Under a POSIX setup, the locale string should have a format
|
|
|
|
* like [language[_territory][.codeset][@modifier]].
|
|
|
|
*
|
|
|
|
* So search for the underscore, and see if the "territory" is
|
|
|
|
* US, and turn on imperial units by default.
|
|
|
|
*
|
|
|
|
* I guess Burma and Liberia should trigger this too. I'm too
|
|
|
|
* lazy to look up the territory names, though.
|
|
|
|
*/
|
2024-05-04 16:53:41 +00:00
|
|
|
void setup_system_prefs()
|
2013-01-11 01:55:44 +00:00
|
|
|
{
|
2013-01-12 01:07:22 +00:00
|
|
|
const char *env;
|
2013-01-11 01:55:44 +00:00
|
|
|
|
2018-06-20 19:45:53 +00:00
|
|
|
subsurface_OS_pref_setup();
|
2024-06-13 20:59:32 +00:00
|
|
|
default_prefs.divelist_font = system_divelist_default_font;
|
2014-03-21 17:56:10 +00:00
|
|
|
default_prefs.font_size = system_divelist_default_font_size;
|
2024-06-13 20:59:32 +00:00
|
|
|
default_prefs.ffmpeg_executable = "ffmpeg";
|
2024-10-23 15:57:56 +00:00
|
|
|
default_prefs.subtitles_format_string = "[time] D=[depth] T=[temperature] sGF=[surface_gf]";
|
2013-01-12 01:07:22 +00:00
|
|
|
|
2016-04-29 13:17:02 +00:00
|
|
|
#if !defined(SUBSURFACE_MOBILE)
|
2024-06-13 20:59:32 +00:00
|
|
|
default_prefs.default_filename = system_default_filename();
|
2016-04-29 13:17:02 +00:00
|
|
|
#endif
|
2013-01-12 01:07:22 +00:00
|
|
|
env = getenv("LC_MEASUREMENT");
|
2013-01-11 01:55:44 +00:00
|
|
|
if (!env)
|
|
|
|
env = getenv("LC_ALL");
|
|
|
|
if (!env)
|
|
|
|
env = getenv("LANG");
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
env = strchr(env, '_');
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
env++;
|
|
|
|
if (strncmp(env, "US", 2))
|
|
|
|
return;
|
|
|
|
|
|
|
|
default_prefs.units = IMPERIAL_units;
|
|
|
|
}
|