gtk: interface GTK4, préférences, versions, traductions, licence MIT
- interface gtkmm-4 : véhicules, ajout par VIN, mises à jour, dossier, téléchargement avec reprise et arrêt, choix de la clé, confirmation, écriture avec progression, fin avec guide d'installation ; travail dans un thread, résultats renvoyés via Glib::Dispatcher - préférences : dossier de téléchargement, langue (système par défaut), recherche automatique de nouvelle version d'OpenPU - recherche de nouvelle version (releases GitHub, format tags Gitea accepté) avec ouverture de la page dans le navigateur ; openpu-cli app-update - versions : project(VERSION) + git describe régénéré à chaque build, openpu-cli --version, À propos, User-Agent, CHANGELOG, tools/release.sh (étiquette annotée, push vers tous les remotes, release GitHub) - traductions gettext : textes anglais, fr.po complet (96 chaînes), extracteur de secours sans xgettext - core : module job (téléchargement licence/fw/carte), liens des guides PDF, ordre des véhicules conservé (ordered_json) - licence MIT (LICENSE, en-têtes SPDX) ; dépôt principal sur GitHub - validé dans WSLg : parcours complet jusqu'à l'écriture d'une clé loop (FAT32 propre, fichiers téléchargés supprimés) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WDASLCiN764v685boRVYar
This commit is contained in:
1 parent
6a7a2f1ee9
commit
384aaf78c6
62 files changed
+3029
-20
No files matched your search
+17
-1
@@ -13,12 +13,13 @@ add_library(openpu_core STATIC
|
||||
archive.cpp
|
||||
storage.cpp
|
||||
usb.cpp
|
||||
job.cpp
|
||||
app_update.cpp
|
||||
)
|
||||
target_include_directories(openpu_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
target_link_libraries(openpu_core
|
||||
PUBLIC CURL::libcurl Threads::Threads
|
||||
PRIVATE nlohmann_json::nlohmann_json LibArchive::LibArchive openpu_warnings)
|
||||
target_compile_definitions(openpu_core PRIVATE OPENPU_VERSION="${PROJECT_VERSION}")
|
||||
|
||||
# USB backend
|
||||
if(HAIKU)
|
||||
@@ -32,3 +33,18 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
else()
|
||||
target_sources(openpu_core PRIVATE usb_none.cpp)
|
||||
endif()
|
||||
|
||||
# Version (regenerated at every build from `git describe`, rewritten only when it changes)
|
||||
find_package(Git QUIET)
|
||||
set(OPENPU_VERSION_CPP ${CMAKE_CURRENT_BINARY_DIR}/generated/version.cpp)
|
||||
add_custom_target(openpu_version
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DSOURCE_DIR=${PROJECT_SOURCE_DIR}
|
||||
-DOUTPUT=${OPENPU_VERSION_CPP}
|
||||
-DVERSION=${PROJECT_VERSION}
|
||||
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
|
||||
-P ${PROJECT_SOURCE_DIR}/cmake/GitVersion.cmake
|
||||
BYPRODUCTS ${OPENPU_VERSION_CPP}
|
||||
COMMENT "Computing the build version")
|
||||
target_sources(openpu_core PRIVATE ${OPENPU_VERSION_CPP})
|
||||
add_dependencies(openpu_core openpu_version)
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "openpu/api_client.hpp"
|
||||
|
||||
#include "openpu/vin.hpp"
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "openpu/app_update.hpp"
|
||||
|
||||
#include "openpu/models.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace openpu {
|
||||
|
||||
namespace {
|
||||
|
||||
std::optional<unsigned> number(std::string_view s)
|
||||
{
|
||||
if (s.empty() || s.size() > 6)
|
||||
return std::nullopt;
|
||||
unsigned v = 0;
|
||||
for (char c : s) {
|
||||
if (c < '0' || c > '9')
|
||||
return std::nullopt;
|
||||
v = v * 10 + static_cast<unsigned>(c - '0');
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
void overrideFromEnv(std::string& field, const char* name)
|
||||
{
|
||||
const char* value = std::getenv(name); // NOLINT(concurrency-mt-unsafe): read once at startup
|
||||
if (value != nullptr && *value != '\0')
|
||||
field = value;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::optional<SemVer> SemVer::parse(std::string_view text)
|
||||
{
|
||||
if (!text.empty() && (text.front() == 'v' || text.front() == 'V'))
|
||||
text.remove_prefix(1);
|
||||
text = text.substr(0, text.find('+'));
|
||||
const auto dot1 = text.find('.');
|
||||
const auto dot2 = dot1 == std::string_view::npos ? dot1 : text.find('.', dot1 + 1);
|
||||
if (dot2 == std::string_view::npos)
|
||||
return std::nullopt;
|
||||
const auto major = number(text.substr(0, dot1));
|
||||
const auto minor = number(text.substr(dot1 + 1, dot2 - dot1 - 1));
|
||||
const auto patch = number(text.substr(dot2 + 1)); // "1.2.3-rc1" fails here: no pre-releases
|
||||
if (!major || !minor || !patch)
|
||||
return std::nullopt;
|
||||
return SemVer{*major, *minor, *patch};
|
||||
}
|
||||
|
||||
std::string SemVer::toString() const
|
||||
{
|
||||
return std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch);
|
||||
}
|
||||
|
||||
AppUpdateConfig AppUpdateConfig::fromEnvironment()
|
||||
{
|
||||
AppUpdateConfig c;
|
||||
overrideFromEnv(c.releasesUrl, "OPENPU_RELEASES_URL");
|
||||
overrideFromEnv(c.pageUrl, "OPENPU_RELEASE_PAGE_URL");
|
||||
return c;
|
||||
}
|
||||
|
||||
std::optional<AppRelease> latestRelease(std::string_view json, const AppUpdateConfig& config)
|
||||
{
|
||||
const auto doc = nlohmann::json::parse(json, nullptr, false);
|
||||
if (doc.is_discarded() || !doc.is_array())
|
||||
throw ParseError("unexpected release list");
|
||||
const auto text = [](const nlohmann::json& o, const char* key) {
|
||||
auto it = o.find(key);
|
||||
return it != o.end() && it->is_string() ? it->get<std::string>() : std::string();
|
||||
};
|
||||
const auto flag = [](const nlohmann::json& o, const char* key) {
|
||||
auto it = o.find(key);
|
||||
return it != o.end() && it->is_boolean() && it->get<bool>();
|
||||
};
|
||||
std::optional<AppRelease> best;
|
||||
for (const auto& item : doc) {
|
||||
if (!item.is_object() || flag(item, "draft") || flag(item, "prerelease"))
|
||||
continue;
|
||||
// Releases carry "tag_name"; plain tags carry "name".
|
||||
const bool isRelease = item.contains("tag_name");
|
||||
const std::string tag = text(item, isRelease ? "tag_name" : "name");
|
||||
if (tag.empty() || tag.front() != 'v')
|
||||
continue;
|
||||
const auto v = SemVer::parse(tag);
|
||||
if (!v || (best && !(best->version < *v)))
|
||||
continue;
|
||||
AppRelease r;
|
||||
r.version = *v;
|
||||
r.tag = tag;
|
||||
r.pageUrl = text(item, "html_url");
|
||||
if (r.pageUrl.empty()) {
|
||||
r.pageUrl = config.pageUrl;
|
||||
const auto pos = r.pageUrl.find("{tag}");
|
||||
if (pos != std::string::npos)
|
||||
r.pageUrl.replace(pos, 5, tag);
|
||||
}
|
||||
r.notes = text(item, isRelease ? "body" : "message");
|
||||
best = std::move(r);
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
std::optional<AppRelease> checkForNewerRelease(Transport& transport, const AppUpdateConfig& config,
|
||||
std::string_view currentVersion)
|
||||
{
|
||||
const auto current = SemVer::parse(currentVersion);
|
||||
if (!current)
|
||||
throw std::runtime_error("invalid current version");
|
||||
HttpRequest req;
|
||||
req.url = config.releasesUrl;
|
||||
req.headers.emplace_back("Accept", "application/vnd.github+json, application/json");
|
||||
req.stallTimeout = std::chrono::seconds(20);
|
||||
const HttpResponse r = transport.perform(req);
|
||||
if (r.status != 200)
|
||||
throw std::runtime_error("release server answered HTTP " + std::to_string(r.status));
|
||||
auto latest = latestRelease(r.body, config);
|
||||
if (latest && *current < latest->version)
|
||||
return latest;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace openpu
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "openpu/archive.hpp"
|
||||
|
||||
#include <archive.h>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "openpu/http.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -5,9 +6,8 @@
|
||||
#include <curl/curl.h>
|
||||
#include <mutex>
|
||||
|
||||
#ifndef OPENPU_VERSION
|
||||
#define OPENPU_VERSION "dev"
|
||||
#endif
|
||||
#include "openpu/version.hpp"
|
||||
|
||||
|
||||
namespace openpu {
|
||||
|
||||
@@ -123,7 +123,7 @@ public:
|
||||
{
|
||||
globalInit();
|
||||
if (options_.userAgent.empty())
|
||||
options_.userAgent = std::string("OpenPU/") + OPENPU_VERSION;
|
||||
options_.userAgent = std::string("OpenPU/") + version();
|
||||
}
|
||||
|
||||
HttpResponse perform(const HttpRequest& request) override
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "openpu/download.hpp"
|
||||
|
||||
#include <cerrno>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "openpu/http.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include "openpu/http.hpp"
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include "openpu/http.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace openpu {
|
||||
|
||||
/// MAJOR.MINOR.PATCH, ordered numerically.
|
||||
struct SemVer {
|
||||
unsigned major = 0;
|
||||
unsigned minor = 0;
|
||||
unsigned patch = 0;
|
||||
|
||||
/// Accepts "1.2.3" and "v1.2.3"; build metadata ("+3.gabc") is ignored. Pre-releases are rejected.
|
||||
static std::optional<SemVer> parse(std::string_view text);
|
||||
std::string toString() const;
|
||||
|
||||
friend bool operator<(const SemVer& a, const SemVer& b)
|
||||
{
|
||||
if (a.major != b.major)
|
||||
return a.major < b.major;
|
||||
if (a.minor != b.minor)
|
||||
return a.minor < b.minor;
|
||||
return a.patch < b.patch;
|
||||
}
|
||||
friend bool operator==(const SemVer& a, const SemVer& b)
|
||||
{
|
||||
return a.major == b.major && a.minor == b.minor && a.patch == b.patch;
|
||||
}
|
||||
};
|
||||
|
||||
/// Where new OpenPU versions are published: the GitHub releases of the project.
|
||||
/// A Gitea/GitHub `/tags` list is understood too (OPENPU_RELEASES_URL may point to one).
|
||||
struct AppUpdateConfig {
|
||||
std::string releasesUrl = "https://api.github.com/repos/yann64/openpu/releases";
|
||||
/// Page opened in the browser when the answer gives none; "{tag}" is replaced by the tag name.
|
||||
std::string pageUrl = "https://github.com/yann64/openpu/releases/tag/{tag}";
|
||||
|
||||
/// Defaults overridden by OPENPU_RELEASES_URL and OPENPU_RELEASE_PAGE_URL when set.
|
||||
static AppUpdateConfig fromEnvironment();
|
||||
};
|
||||
|
||||
struct AppRelease {
|
||||
SemVer version;
|
||||
std::string tag;
|
||||
std::string pageUrl;
|
||||
std::string notes; ///< release notes (or annotated tag message)
|
||||
};
|
||||
|
||||
/// Highest vX.Y.Z release of a GitHub/Gitea `/releases` list (drafts and pre-releases skipped) or
|
||||
/// of a `/tags` list (nullopt if none). Throws ParseError.
|
||||
std::optional<AppRelease> latestRelease(std::string_view json, const AppUpdateConfig& config);
|
||||
|
||||
/// Newest published release if it is newer than `currentVersion`, nullopt when up to date.
|
||||
/// Throws NetworkError, or std::runtime_error for an unexpected answer.
|
||||
std::optional<AppRelease> checkForNewerRelease(Transport& transport, const AppUpdateConfig& config,
|
||||
std::string_view currentVersion);
|
||||
|
||||
} // namespace openpu
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include "openpu/cancel.hpp"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include "openpu/cancel.hpp"
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
namespace openpu {
|
||||
|
||||
/// "8.39 GB" (decimal units, as storage vendors and the official app use).
|
||||
inline std::string formatSize(std::uint64_t bytes)
|
||||
{
|
||||
const char* units[] = {"B", "KB", "MB", "GB", "TB"};
|
||||
auto value = static_cast<double>(bytes);
|
||||
std::size_t unit = 0;
|
||||
while (value >= 1000.0 && unit + 1 < sizeof units / sizeof units[0]) {
|
||||
value /= 1000.0;
|
||||
++unit;
|
||||
}
|
||||
char buf[32];
|
||||
(void)std::snprintf(buf, sizeof buf, unit == 0 ? "%.0f %s" : "%.2f %s", value, units[unit]);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/// "1:02:03" or "02:03".
|
||||
inline std::string formatDuration(std::chrono::seconds s)
|
||||
{
|
||||
const auto total = static_cast<long long>(s.count());
|
||||
char buf[32];
|
||||
if (total >= 3600)
|
||||
(void)std::snprintf(buf, sizeof buf, "%lld:%02lld:%02lld", total / 3600, (total / 60) % 60, total % 60);
|
||||
else
|
||||
(void)std::snprintf(buf, sizeof buf, "%02lld:%02lld", total / 60, total % 60);
|
||||
return buf;
|
||||
}
|
||||
|
||||
} // namespace openpu
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include "openpu/download.hpp"
|
||||
#include "openpu/models.hpp"
|
||||
#include "openpu/usb.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace openpu {
|
||||
|
||||
/// URL of the installation guide (PDF) for a guide key such as "path_guide_rcc".
|
||||
/// `language` is an ISO 639-1 code; French and English are known, anything else gives English.
|
||||
std::string guideUrl(std::string_view guideKey, std::string_view language);
|
||||
|
||||
/// Two-letter language of the user session (LANGUAGE / LC_ALL / LC_MESSAGES / LANG), "en" by default.
|
||||
std::string systemLanguage();
|
||||
|
||||
/// What to download for one vehicle.
|
||||
struct DownloadPlan {
|
||||
std::optional<UpdateInfo> firmware;
|
||||
std::optional<UpdateInfo> map;
|
||||
std::filesystem::path dir;
|
||||
|
||||
/// Bytes still to download (announced sizes minus partial files already in `dir`), +10 %.
|
||||
/// Partial files are matched by name, so this needs the names (see resolveNames()).
|
||||
std::uint64_t requiredSpace() const;
|
||||
/// Total announced size.
|
||||
std::uint64_t totalSize() const;
|
||||
};
|
||||
|
||||
struct DownloadedFiles {
|
||||
std::optional<std::filesystem::path> license;
|
||||
std::optional<std::filesystem::path> firmware;
|
||||
std::optional<std::filesystem::path> map;
|
||||
|
||||
/// Write plan for the stick: license (with firmware only), firmware archive, then map archive.
|
||||
UsbWritePlan writePlan() const;
|
||||
/// Removes every file of the set (after a successful copy, or when the user gives up).
|
||||
void remove() const;
|
||||
};
|
||||
|
||||
enum class DownloadItem { License, Firmware, Map };
|
||||
|
||||
struct JobProgress {
|
||||
DownloadItem item = DownloadItem::Firmware;
|
||||
DownloadProgress progress;
|
||||
};
|
||||
using JobProgressCallback = std::function<void(const JobProgress&)>;
|
||||
|
||||
/// Official order: license (firmware only), firmware, map. Partial files are resumed.
|
||||
DownloadedFiles downloadUpdates(Downloader& downloader, const DownloadPlan& plan, const JobProgressCallback& onProgress = {},
|
||||
const CancelToken* cancel = nullptr);
|
||||
|
||||
} // namespace openpu
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include "openpu/models.hpp"
|
||||
@@ -74,6 +75,7 @@ struct PendingDownload {
|
||||
struct Settings {
|
||||
std::string language; ///< empty: follow the system locale
|
||||
std::filesystem::path downloadDir; ///< empty: paths::defaultDownloadDir()
|
||||
bool checkAppUpdates = true; ///< look for a newer OpenPU at startup
|
||||
std::optional<PendingDownload> pending;
|
||||
|
||||
std::filesystem::path effectiveDownloadDir() const;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include "openpu/cancel.hpp"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
namespace openpu {
|
||||
|
||||
/// Release version, "MAJOR.MINOR.PATCH" (CMake project version, tagged vMAJOR.MINOR.PATCH in git).
|
||||
const char* version() noexcept;
|
||||
|
||||
/// Build description: the version, plus "+<commits>.g<hash>[.dirty]" when not built from the tag.
|
||||
const char* versionDescription() noexcept;
|
||||
|
||||
} // namespace openpu
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "openpu/job.hpp"
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <system_error>
|
||||
|
||||
namespace openpu {
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace {
|
||||
|
||||
struct GuideLinks {
|
||||
const char* nac;
|
||||
const char* rcc;
|
||||
const char* aio;
|
||||
};
|
||||
|
||||
// From the official application's translations (dist/ovip-ui/assets/i18n/{fr,en}.json).
|
||||
constexpr GuideLinks kFrench{
|
||||
"https://www.peugeot.fr/content/dam/peugeot/master/media/manual/1/fr/map-software-nac-fr.632350.pdf",
|
||||
"https://www.peugeot.fr/content/dam/peugeot/master/media/manual/1/fr/map-software-rcc-fr.632352.pdf",
|
||||
"https://www.peugeot.fr/content/dam/peugeot/master/media/manual/1/fr/map-software-iao-fr.793298.pdf",
|
||||
};
|
||||
constexpr GuideLinks kEnglish{
|
||||
"https://www.peugeot.co.uk/content/dam/peugeot/master/media/manual/1/en/map-software-nac-en.632380.pdf",
|
||||
"https://www.peugeot.co.uk/content/dam/peugeot/master/media/manual/1/en/map-software-rcc-en.632382.pdf",
|
||||
"https://www.peugeot.co.uk/content/dam/peugeot/master/media/manual/1/en/map-software-iao-es.793301.pdf",
|
||||
};
|
||||
constexpr const char* kCronyGuide = "https://www.stellantis.com/";
|
||||
|
||||
std::uint64_t sizeOf(const fs::path& p)
|
||||
{
|
||||
std::error_code ec;
|
||||
const auto s = fs::file_size(p, ec);
|
||||
return ec ? 0 : static_cast<std::uint64_t>(s);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string guideUrl(std::string_view key, std::string_view language)
|
||||
{
|
||||
const GuideLinks& links = language == "fr" ? kFrench : kEnglish;
|
||||
if (key == "path_guide_rcc")
|
||||
return links.rcc;
|
||||
if (key == "path_guide_aio")
|
||||
return links.aio;
|
||||
if (key.substr(0, 16) == "path_guide_wave_")
|
||||
return links.nac;
|
||||
if (key.substr(0, 17) == "path_guide_crony_")
|
||||
return kCronyGuide;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string systemLanguage()
|
||||
{
|
||||
for (const char* var : {"LANGUAGE", "LC_ALL", "LC_MESSAGES", "LANG"}) {
|
||||
const char* v = std::getenv(var); // NOLINT(concurrency-mt-unsafe)
|
||||
if (v == nullptr || *v == '\0')
|
||||
continue;
|
||||
std::string s(v);
|
||||
if (s == "C" || s == "POSIX" || s.size() < 2)
|
||||
continue;
|
||||
std::string lang;
|
||||
for (char c : s.substr(0, 2))
|
||||
lang.push_back(static_cast<char>(std::tolower(static_cast<unsigned char>(c))));
|
||||
return lang;
|
||||
}
|
||||
return "en";
|
||||
}
|
||||
|
||||
std::uint64_t DownloadPlan::totalSize() const
|
||||
{
|
||||
return (firmware ? firmware->size : 0) + (map ? map->size : 0);
|
||||
}
|
||||
|
||||
std::uint64_t DownloadPlan::requiredSpace() const
|
||||
{
|
||||
return withMargin(totalSize());
|
||||
}
|
||||
|
||||
UsbWritePlan DownloadedFiles::writePlan() const
|
||||
{
|
||||
UsbWritePlan plan;
|
||||
if (firmware) {
|
||||
plan.license = license;
|
||||
plan.archives.push_back(*firmware);
|
||||
}
|
||||
if (map)
|
||||
plan.archives.push_back(*map);
|
||||
return plan;
|
||||
}
|
||||
|
||||
void DownloadedFiles::remove() const
|
||||
{
|
||||
std::error_code ec;
|
||||
for (const auto& f : {license, firmware, map})
|
||||
if (f)
|
||||
fs::remove(*f, ec);
|
||||
}
|
||||
|
||||
DownloadedFiles downloadUpdates(Downloader& downloader, const DownloadPlan& plan, const JobProgressCallback& onProgress,
|
||||
const CancelToken* cancel)
|
||||
{
|
||||
DownloadedFiles files;
|
||||
auto forward = [&](DownloadItem item) {
|
||||
return [&onProgress, item](const DownloadProgress& p) {
|
||||
if (onProgress)
|
||||
onProgress(JobProgress{item, p});
|
||||
};
|
||||
};
|
||||
if (plan.firmware) {
|
||||
if (!plan.firmware->licenseUrl.empty()) {
|
||||
const auto lic = downloader.downloadSmall(plan.firmware->licenseUrl, plan.dir, std::nullopt, cancel);
|
||||
files.license = lic.file;
|
||||
if (onProgress) {
|
||||
DownloadProgress p;
|
||||
p.total = p.done = sizeOf(lic.file);
|
||||
onProgress(JobProgress{DownloadItem::License, p});
|
||||
}
|
||||
}
|
||||
files.firmware = downloader.downloadResumable(plan.firmware->url, plan.dir, forward(DownloadItem::Firmware), cancel).file;
|
||||
}
|
||||
if (plan.map)
|
||||
files.map = downloader.downloadResumable(plan.map->url, plan.dir, forward(DownloadItem::Map), cancel).file;
|
||||
return files;
|
||||
}
|
||||
|
||||
} // namespace openpu
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "openpu/models.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "openpu/storage.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -15,7 +16,7 @@
|
||||
namespace openpu {
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
using json = nlohmann::json;
|
||||
using json = nlohmann::ordered_json; // keep the user's vehicle order
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -244,6 +245,8 @@ Settings Settings::load(const fs::path& file)
|
||||
const json doc = parseJson(readFile(file), file.string());
|
||||
s.language = str(doc, "language");
|
||||
s.downloadDir = str(doc, "downloadPath");
|
||||
if (auto it = doc.find("checkAppUpdates"); it != doc.end() && it->is_boolean())
|
||||
s.checkAppUpdates = it->get<bool>();
|
||||
auto p = doc.find("pendingDownload");
|
||||
if (p != doc.end() && p->is_object() && !str(*p, "vin").empty()) {
|
||||
PendingDownload d;
|
||||
@@ -267,6 +270,7 @@ void Settings::save(const fs::path& file) const
|
||||
doc["language"] = language;
|
||||
if (!downloadDir.empty())
|
||||
doc["downloadPath"] = downloadDir.string();
|
||||
doc["checkAppUpdates"] = checkAppUpdates;
|
||||
if (pending) {
|
||||
doc["pendingDownload"] = {
|
||||
{"vin", pending->vin},
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "openpu/usb.hpp"
|
||||
|
||||
#include "openpu/archive.hpp"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Fallback for platforms without a USB backend: listing and formatting are unavailable,
|
||||
// but writePayload() still works on an already prepared stick.
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// UDisks2 backend (Linux): enumeration, FAT32 formatting, mounting and ejecting over D-Bus.
|
||||
// Authorisation is delegated to polkit, so no root privileges are needed in a desktop session.
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "openpu/vin.hpp"
|
||||
|
||||
#include <cctype>
|
||||
|
||||
Reference in new issue
Block a user