2023-11-01 21:11:11 +00:00
|
|
|
|
// This file Copyright © Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
|
// License text can be found in the licenses/ folder.
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
|
#pragma once
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
2023-12-24 17:02:54 +00:00
|
|
|
|
#include <algorithm> // for std::for_each()
|
2021-11-14 05:23:19 +00:00
|
|
|
|
#include <cctype>
|
2022-04-08 01:50:26 +00:00
|
|
|
|
#include <cstddef> // size_t
|
2023-12-24 17:02:54 +00:00
|
|
|
|
#include <cstdint> // uint8_t, uint32_t, uint64_t
|
2022-04-08 01:50:26 +00:00
|
|
|
|
#include <ctime> // time_t
|
2023-10-17 00:36:37 +00:00
|
|
|
|
#include <locale>
|
2023-07-06 03:05:03 +00:00
|
|
|
|
#include <memory>
|
2021-10-31 18:48:32 +00:00
|
|
|
|
#include <optional>
|
2021-10-31 16:38:10 +00:00
|
|
|
|
#include <string>
|
2021-10-01 22:55:19 +00:00
|
|
|
|
#include <string_view>
|
2021-10-31 16:38:10 +00:00
|
|
|
|
#include <type_traits>
|
2021-09-25 19:37:28 +00:00
|
|
|
|
#include <vector>
|
2007-07-14 05:28:35 +00:00
|
|
|
|
|
2015-04-11 14:54:01 +00:00
|
|
|
|
struct tr_error;
|
|
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
|
/**
|
|
|
|
|
* @addtogroup utils Utilities
|
2009-08-10 20:04:08 +00:00
|
|
|
|
* @{
|
2009-05-29 19:17:12 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
#if !defined(_)
|
2022-03-14 04:43:35 +00:00
|
|
|
|
#if defined(HAVE_GETTEXT) && !defined(__APPLE__)
|
2017-04-19 12:04:45 +00:00
|
|
|
|
#include <libintl.h>
|
|
|
|
|
#define _(a) gettext(a)
|
|
|
|
|
#else
|
|
|
|
|
#define _(a) (a)
|
|
|
|
|
#endif
|
2008-03-05 01:05:42 +00:00
|
|
|
|
#endif
|
2008-03-04 02:02:25 +00:00
|
|
|
|
|
2022-12-26 21:13:21 +00:00
|
|
|
|
#if defined(HAVE_NGETTEXT)
|
|
|
|
|
#define tr_ngettext ngettext
|
|
|
|
|
#else
|
|
|
|
|
#define tr_ngettext(singular, plural, count) ((count) == 1 ? (singular) : (plural))
|
2022-03-14 04:43:35 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2008-08-21 21:04:57 +00:00
|
|
|
|
/* #define DISABLE_GETTEXT */
|
2010-06-21 16:44:35 +00:00
|
|
|
|
#ifndef DISABLE_GETTEXT
|
2023-01-01 22:24:12 +00:00
|
|
|
|
#if defined(_WIN32)
|
2017-04-19 12:04:45 +00:00
|
|
|
|
#define DISABLE_GETTEXT
|
|
|
|
|
#endif
|
2008-10-22 17:16:12 +00:00
|
|
|
|
#endif
|
2008-08-21 21:04:57 +00:00
|
|
|
|
#ifdef DISABLE_GETTEXT
|
2017-04-19 12:04:45 +00:00
|
|
|
|
#undef _
|
2022-12-26 21:13:21 +00:00
|
|
|
|
#undef tr_ngettext
|
2022-04-07 13:23:04 +00:00
|
|
|
|
#define _(a) (a)
|
2022-12-26 21:13:21 +00:00
|
|
|
|
#define tr_ngettext(singular, plural, count) ((count) == 1 ? (singular) : (plural))
|
2008-08-21 21:04:57 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2023-10-17 00:36:37 +00:00
|
|
|
|
std::optional<std::locale> tr_locale_set_global(char const* locale_name) noexcept;
|
|
|
|
|
|
|
|
|
|
std::optional<std::locale> tr_locale_set_global(std::locale const& locale) noexcept;
|
2023-04-27 14:10:33 +00:00
|
|
|
|
|
2023-01-22 19:21:30 +00:00
|
|
|
|
// ---
|
2008-10-13 22:45:05 +00:00
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
|
[[nodiscard]] std::string_view tr_get_mime_type_for_filename(std::string_view filename);
|
2020-10-13 15:33:56 +00:00
|
|
|
|
|
2023-11-04 16:39:41 +00:00
|
|
|
|
bool tr_file_read(std::string_view filename, std::vector<char>& contents, tr_error* error = nullptr);
|
2008-10-13 22:26:02 +00:00
|
|
|
|
|
2024-08-13 04:26:09 +00:00
|
|
|
|
/**
|
2024-08-13 05:19:36 +00:00
|
|
|
|
* Tries to move a file by renaming, and [optionally] if that fails, by copying.
|
2024-08-13 04:26:09 +00:00
|
|
|
|
*
|
|
|
|
|
* Creates the destination directory if it doesn't exist.
|
|
|
|
|
*/
|
2024-08-13 05:19:36 +00:00
|
|
|
|
bool tr_file_move(std::string_view oldpath, std::string_view newpath, bool allow_copy, tr_error* error = nullptr);
|
2021-11-16 06:15:13 +00:00
|
|
|
|
|
2023-11-04 16:39:41 +00:00
|
|
|
|
bool tr_file_save(std::string_view filename, std::string_view contents, tr_error* error = nullptr);
|
2022-03-26 00:31:27 +00:00
|
|
|
|
|
|
|
|
|
template<typename ContiguousRange>
|
2023-11-04 16:39:41 +00:00
|
|
|
|
constexpr auto tr_file_save(std::string_view filename, ContiguousRange const& x, tr_error* error = nullptr)
|
2022-03-26 00:31:27 +00:00
|
|
|
|
{
|
2023-06-30 14:49:58 +00:00
|
|
|
|
return tr_file_save(filename, std::string_view{ std::data(x), std::size(x) }, error);
|
2022-03-26 00:31:27 +00:00
|
|
|
|
}
|
2021-12-05 01:32:35 +00:00
|
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
|
/** @brief return the current date in milliseconds */
|
2022-08-19 02:31:53 +00:00
|
|
|
|
[[nodiscard]] uint64_t tr_time_msec();
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
2014-11-30 20:08:20 +00:00
|
|
|
|
#ifdef _WIN32
|
2014-07-03 21:58:39 +00:00
|
|
|
|
|
2022-08-19 02:31:53 +00:00
|
|
|
|
[[nodiscard]] std::string tr_win32_format_message(uint32_t code);
|
|
|
|
|
[[nodiscard]] std::string tr_win32_native_to_utf8(std::wstring_view);
|
|
|
|
|
[[nodiscard]] std::wstring tr_win32_utf8_to_native(std::string_view);
|
2022-08-03 23:07:38 +00:00
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
|
int tr_main_win32(int argc, char** argv, int (*real_main)(int, char**));
|
2015-04-21 10:07:57 +00:00
|
|
|
|
|
|
|
|
|
#define tr_main(...) \
|
2017-04-19 12:04:45 +00:00
|
|
|
|
main_impl(__VA_ARGS__); \
|
|
|
|
|
int main(int argc, char* argv[]) \
|
|
|
|
|
{ \
|
2017-04-30 16:30:03 +00:00
|
|
|
|
return tr_main_win32(argc, argv, &main_impl); \
|
2017-04-19 12:04:45 +00:00
|
|
|
|
} \
|
|
|
|
|
int main_impl(__VA_ARGS__)
|
2015-04-21 10:07:57 +00:00
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
#define tr_main main
|
|
|
|
|
|
2014-07-03 21:58:39 +00:00
|
|
|
|
#endif
|
2009-01-10 22:48:58 +00:00
|
|
|
|
|
2023-01-22 19:21:30 +00:00
|
|
|
|
// ---
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
2023-01-23 16:26:11 +00:00
|
|
|
|
/** @brief Convenience wrapper around `strerorr()` guaranteed to not return nullptr
|
2016-03-29 03:04:54 +00:00
|
|
|
|
@param errnum the error number to describe */
|
2022-04-05 03:51:56 +00:00
|
|
|
|
[[nodiscard]] char const* tr_strerror(int errnum);
|
2008-02-19 04:16:04 +00:00
|
|
|
|
|
2021-11-14 05:23:19 +00:00
|
|
|
|
template<typename T>
|
2022-04-05 03:51:56 +00:00
|
|
|
|
[[nodiscard]] std::string tr_strlower(T in)
|
2021-11-14 05:23:19 +00:00
|
|
|
|
{
|
2023-08-22 02:59:47 +00:00
|
|
|
|
auto out = std::string{ std::move(in) };
|
2021-11-14 05:23:19 +00:00
|
|
|
|
std::for_each(std::begin(out), std::end(out), [](char& ch) { ch = std::tolower(ch); });
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-08 23:41:05 +00:00
|
|
|
|
template<typename T>
|
2022-04-05 03:51:56 +00:00
|
|
|
|
[[nodiscard]] std::string tr_strupper(T in)
|
2022-01-08 23:41:05 +00:00
|
|
|
|
{
|
2023-08-22 02:59:47 +00:00
|
|
|
|
auto out = std::string{ std::move(in) };
|
2022-01-08 23:41:05 +00:00
|
|
|
|
std::for_each(std::begin(out), std::end(out), [](char& ch) { ch = std::toupper(ch); });
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-22 19:21:30 +00:00
|
|
|
|
// --- std::string_view utils
|
2021-11-10 00:13:47 +00:00
|
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief Rich Salz's classic implementation of shell-style pattern matching for `?`, `\`, `[]`, and `*` characters.
|
|
|
|
|
* @return 1 if the pattern matches, 0 if it doesn't, or -1 if an error occurred
|
|
|
|
|
*/
|
|
|
|
|
[[nodiscard]] bool tr_wildmat(std::string_view text, std::string_view pattern);
|
|
|
|
|
|
2021-11-10 00:13:47 +00:00
|
|
|
|
template<typename T>
|
2023-06-30 14:49:58 +00:00
|
|
|
|
[[nodiscard]] constexpr bool tr_strv_contains(std::string_view sv, T key) noexcept // c++23
|
2021-11-10 00:13:47 +00:00
|
|
|
|
{
|
2023-01-28 23:58:20 +00:00
|
|
|
|
return sv.find(key) != std::string_view::npos;
|
2021-11-10 00:13:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
|
[[nodiscard]] constexpr bool tr_strv_starts_with(std::string_view sv, char key) // c++20
|
2021-11-10 02:42:18 +00:00
|
|
|
|
{
|
|
|
|
|
return !std::empty(sv) && sv.front() == key;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
|
[[nodiscard]] constexpr bool tr_strv_starts_with(std::string_view sv, std::string_view key) // c++20
|
2021-11-10 00:13:47 +00:00
|
|
|
|
{
|
|
|
|
|
return std::size(key) <= std::size(sv) && sv.substr(0, std::size(key)) == key;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
|
[[nodiscard]] constexpr bool tr_strv_starts_with(std::wstring_view sv, std::wstring_view key) // c++20
|
2022-08-05 16:36:01 +00:00
|
|
|
|
{
|
|
|
|
|
return std::size(key) <= std::size(sv) && sv.substr(0, std::size(key)) == key;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
|
[[nodiscard]] constexpr bool tr_strv_ends_with(std::string_view sv, std::string_view key) // c++20
|
2021-11-10 00:13:47 +00:00
|
|
|
|
{
|
|
|
|
|
return std::size(key) <= std::size(sv) && sv.substr(std::size(sv) - std::size(key)) == key;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
|
[[nodiscard]] constexpr bool tr_strv_ends_with(std::string_view sv, char key) // c++20
|
2021-11-10 02:42:18 +00:00
|
|
|
|
{
|
|
|
|
|
return !std::empty(sv) && sv.back() == key;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-06 23:51:08 +00:00
|
|
|
|
template<typename T>
|
|
|
|
|
[[nodiscard]] constexpr int tr_compare_3way(T const& left, T const& right)
|
|
|
|
|
{
|
|
|
|
|
if (left < right)
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (right < left)
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
|
constexpr std::string_view tr_strv_sep(std::string_view* sv, char delim)
|
2021-11-10 00:13:47 +00:00
|
|
|
|
{
|
|
|
|
|
auto pos = sv->find(delim);
|
|
|
|
|
auto const ret = sv->substr(0, pos);
|
2022-02-18 17:52:01 +00:00
|
|
|
|
sv->remove_prefix(pos != std::string_view::npos ? pos + 1 : std::size(*sv));
|
2021-11-10 00:13:47 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
|
constexpr bool tr_strv_sep(std::string_view* sv, std::string_view* token, char delim)
|
2021-11-10 00:13:47 +00:00
|
|
|
|
{
|
2022-02-18 17:52:01 +00:00
|
|
|
|
if (std::empty(*sv))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
|
*token = tr_strv_sep(sv, delim);
|
2022-02-18 17:52:01 +00:00
|
|
|
|
return true;
|
2021-11-10 00:13:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
|
[[nodiscard]] std::string_view tr_strv_strip(std::string_view str);
|
2021-11-10 00:13:47 +00:00
|
|
|
|
|
2023-03-19 15:36:16 +00:00
|
|
|
|
[[nodiscard]] std::string tr_strv_convert_utf8(std::string_view sv);
|
|
|
|
|
|
2023-01-09 16:52:19 +00:00
|
|
|
|
[[nodiscard]] std::string tr_strv_replace_invalid(std::string_view sv, uint32_t replacement = 0xFFFD /*<2A>*/);
|
2022-08-17 02:47:07 +00:00
|
|
|
|
|
2022-08-17 00:28:57 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief copies `src` into `buf`.
|
|
|
|
|
*
|
|
|
|
|
* - Always returns std::size(src).
|
|
|
|
|
* - `src` will be copied into `buf` iff `buflen >= std::size(src)`
|
|
|
|
|
* - `buf` will also be zero terminated iff `buflen >= std::size(src) + 1`.
|
|
|
|
|
*/
|
2023-06-30 14:49:58 +00:00
|
|
|
|
size_t tr_strv_to_buf(std::string_view src, char* buf, size_t buflen);
|
2022-08-17 00:28:57 +00:00
|
|
|
|
|
2023-01-22 19:21:30 +00:00
|
|
|
|
// ---
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
2023-11-21 15:02:03 +00:00
|
|
|
|
template<typename T, std::enable_if_t<std::is_integral_v<T>, bool> = true>
|
2023-06-30 14:49:58 +00:00
|
|
|
|
[[nodiscard]] std::optional<T> tr_num_parse(std::string_view str, std::string_view* setme_remainder = nullptr, int base = 10);
|
|
|
|
|
|
2023-11-21 15:02:03 +00:00
|
|
|
|
template<typename T, std::enable_if_t<std::is_floating_point_v<T>, bool> = true>
|
2023-06-30 14:49:58 +00:00
|
|
|
|
[[nodiscard]] std::optional<T> tr_num_parse(std::string_view str, std::string_view* setme_remainder = nullptr);
|
2008-12-29 21:17:48 +00:00
|
|
|
|
|
2010-01-01 22:13:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief Given a string like "1-4" or "1-4,6,9,14-51", this returns a
|
|
|
|
|
* newly-allocated array of all the integers in the set.
|
2022-08-17 00:28:57 +00:00
|
|
|
|
* @return a vector of integers, which is empty if the string can't be parsed.
|
2010-01-01 22:13:27 +00:00
|
|
|
|
*
|
|
|
|
|
* For example, "5-8" will return [ 5, 6, 7, 8 ] and setmeCount will be 4.
|
|
|
|
|
*/
|
2023-06-30 14:49:58 +00:00
|
|
|
|
[[nodiscard]] std::vector<int> tr_num_parse_range(std::string_view str);
|
2008-01-04 19:13:30 +00:00
|
|
|
|
|
2010-01-06 00:18:33 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief truncate a double value at a given number of decimal places.
|
|
|
|
|
*
|
2023-01-23 16:26:11 +00:00
|
|
|
|
* this can be used to prevent a `printf()` call from rounding up:
|
|
|
|
|
* call with the `decimal_places` argument equal to the number of
|
|
|
|
|
* decimal places in the `printf()`'s precision:
|
2010-01-06 00:18:33 +00:00
|
|
|
|
*
|
2017-04-21 07:40:57 +00:00
|
|
|
|
* - printf("%.2f%%", 99.999) ==> "100.00%"
|
2010-01-06 00:18:33 +00:00
|
|
|
|
*
|
2017-04-21 07:40:57 +00:00
|
|
|
|
* - printf("%.2f%%", tr_truncd(99.999, 2)) ==> "99.99%"
|
2010-01-06 00:18:33 +00:00
|
|
|
|
* ^ ^
|
|
|
|
|
* | These should match |
|
|
|
|
|
* +------------------------+
|
|
|
|
|
*/
|
2022-04-05 03:51:56 +00:00
|
|
|
|
[[nodiscard]] double tr_truncd(double x, int decimal_places);
|
2009-07-14 20:09:46 +00:00
|
|
|
|
|
2010-06-22 22:30:58 +00:00
|
|
|
|
/* return a percent formatted string of either x.xx, xx.x or xxx */
|
2022-04-05 03:51:56 +00:00
|
|
|
|
[[nodiscard]] std::string tr_strpercent(double x);
|
2010-06-22 22:30:58 +00:00
|
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
|
/** @brief return `TR_RATIO_NA`, `TR_RATIO_INF`, or a number in [0..1]
|
|
|
|
|
@return `TR_RATIO_NA`, `TR_RATIO_INF`, or a number in [0..1] */
|
|
|
|
|
[[nodiscard]] double tr_getRatio(uint64_t numerator, uint64_t denominator);
|
2009-03-04 16:16:02 +00:00
|
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
|
/** @param ratio the ratio to convert to a string
|
|
|
|
|
@param infinity the string representation of "infinity" */
|
2024-08-17 19:04:49 +00:00
|
|
|
|
[[nodiscard]] std::string tr_strratio(double ratio, std::string_view infinity);
|
2009-05-13 15:54:04 +00:00
|
|
|
|
|
2023-01-22 19:21:30 +00:00
|
|
|
|
// ---
|
2009-11-26 18:47:08 +00:00
|
|
|
|
|
2022-11-07 17:48:26 +00:00
|
|
|
|
namespace libtransmission::detail::tr_time
|
|
|
|
|
{
|
|
|
|
|
extern time_t current_time;
|
|
|
|
|
}
|
2009-11-26 18:47:08 +00:00
|
|
|
|
|
2010-01-01 22:13:27 +00:00
|
|
|
|
/**
|
2021-10-06 16:32:17 +00:00
|
|
|
|
* @brief very inexpensive form of time(nullptr)
|
2010-01-01 22:13:27 +00:00
|
|
|
|
* @return the current epoch time in seconds
|
|
|
|
|
*
|
|
|
|
|
* This function returns a second counter that is updated once per second.
|
|
|
|
|
* If something blocks the libtransmission thread for more than a second,
|
|
|
|
|
* that counter may be thrown off, so this function is not guaranteed
|
2010-12-27 19:18:17 +00:00
|
|
|
|
* to always be accurate. However, it is *much* faster when 100% accuracy
|
2010-01-01 22:13:27 +00:00
|
|
|
|
* isn't needed
|
|
|
|
|
*/
|
2022-04-05 03:51:56 +00:00
|
|
|
|
[[nodiscard]] static inline time_t tr_time() noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
|
{
|
2022-11-07 17:48:26 +00:00
|
|
|
|
return libtransmission::detail::tr_time::current_time;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
}
|
2009-11-26 18:47:08 +00:00
|
|
|
|
|
2023-01-23 16:26:11 +00:00
|
|
|
|
/** @brief Private libtransmission function to update `tr_time()`'s counter */
|
2022-04-05 03:51:56 +00:00
|
|
|
|
constexpr void tr_timeUpdate(time_t now) noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
|
{
|
2022-11-07 17:48:26 +00:00
|
|
|
|
libtransmission::detail::tr_time::current_time = now;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
}
|
2009-11-26 18:47:08 +00:00
|
|
|
|
|
2023-01-23 16:26:11 +00:00
|
|
|
|
/** @brief Portability wrapper for `htonll()` that uses the system implementation if available */
|
2023-01-28 23:58:20 +00:00
|
|
|
|
[[nodiscard]] uint64_t tr_htonll(uint64_t hostlonglong);
|
2011-03-13 00:18:11 +00:00
|
|
|
|
|
2023-01-23 16:26:11 +00:00
|
|
|
|
/** @brief Portability wrapper for `ntohll()` that uses the system implementation if available */
|
2023-01-28 23:58:20 +00:00
|
|
|
|
[[nodiscard]] uint64_t tr_ntohll(uint64_t netlonglong);
|
2011-03-13 00:18:11 +00:00
|
|
|
|
|
2023-01-22 19:21:30 +00:00
|
|
|
|
// ---
|
2009-11-26 18:47:08 +00:00
|
|
|
|
|
2014-09-21 18:05:14 +00:00
|
|
|
|
/** @brief Check if environment variable exists. */
|
2022-08-19 02:31:53 +00:00
|
|
|
|
[[nodiscard]] bool tr_env_key_exists(char const* key);
|
2014-09-21 18:05:14 +00:00
|
|
|
|
|
2022-07-27 04:26:37 +00:00
|
|
|
|
/** @brief Get environment variable value as string. */
|
2022-08-19 02:31:53 +00:00
|
|
|
|
[[nodiscard]] std::string tr_env_get_string(std::string_view key, std::string_view default_value = {});
|
2014-09-21 18:05:14 +00:00
|
|
|
|
|
2023-01-22 19:21:30 +00:00
|
|
|
|
// ---
|
2014-09-21 18:05:14 +00:00
|
|
|
|
|
2023-07-06 03:05:03 +00:00
|
|
|
|
class tr_net_init_mgr
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
~tr_net_init_mgr();
|
|
|
|
|
static std::unique_ptr<tr_net_init_mgr> create();
|
|
|
|
|
|
|
|
|
|
private:
|
2023-12-24 17:02:54 +00:00
|
|
|
|
tr_net_init_mgr();
|
|
|
|
|
tr_net_init_mgr(tr_net_init_mgr&&) = delete;
|
|
|
|
|
tr_net_init_mgr(tr_net_init_mgr const&) = delete;
|
|
|
|
|
tr_net_init_mgr& operator=(tr_net_init_mgr&&) = delete;
|
|
|
|
|
tr_net_init_mgr& operator=(tr_net_init_mgr const&) = delete;
|
|
|
|
|
|
2023-07-06 03:05:03 +00:00
|
|
|
|
static bool initialised;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** @brief Initialise libtransmission for each app
|
|
|
|
|
* @return A manager object to be kept in scope of main() */
|
|
|
|
|
std::unique_ptr<tr_net_init_mgr> tr_lib_init();
|