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:
yann64andClaude Opus 5.5 committed 2026-11-28 19:54:04 +01:00
1 parent 6a7a2f1ee9
commit 384aaf78c6
62 files changed
+3029 -20

No files matched your search

+24 -1
View File
@@ -1,10 +1,13 @@
// SPDX-License-Identifier: MIT
// openpu-cli — command-line front-end of libopenpu.
#include "openpu/api_client.hpp"
#include "openpu/app_update.hpp"
#include "openpu/archive.hpp"
#include "openpu/download.hpp"
#include "openpu/storage.hpp"
#include "openpu/usb.hpp"
#include "openpu/version.hpp"
#include "openpu/vin.hpp"
#include <algorithm>
@@ -30,6 +33,7 @@ extern "C" void onSignal(int /*sig*/)
void usage()
{
std::cerr << "usage: openpu-cli [--verbose] <command> [args]\n"
" openpu-cli --version\n"
"\n"
"commands:\n"
" check <VIN> identify the head unit and list available updates\n"
@@ -43,6 +47,7 @@ void usage()
" ERASE <device>, format FAT32 and write the update\n"
" write-dir <dir> [--license F] <archive.tar>...\n"
" write the update into an existing directory\n"
" app-update check for a newer OpenPU (exit status 10 if any)\n"
" raw-devices <VIN> print the raw devices/{VIN} response\n"
" raw-updates <VIN> print the raw getAvailableUpdate response\n"
"\n"
@@ -361,6 +366,22 @@ int run(std::vector<std::string> args)
curlOptions.verbose = true;
args.erase(args.begin());
}
if (args.size() == 1 && (args[0] == "--version" || args[0] == "version")) {
std::cout << "openpu-cli " << openpu::versionDescription() << '\n';
return 0;
}
if (args.size() == 1 && args[0] == "app-update") {
auto transport = openpu::makeCurlTransport(curlOptions);
const auto release = openpu::checkForNewerRelease(*transport, openpu::AppUpdateConfig::fromEnvironment(),
openpu::version());
if (!release) {
std::cout << "OpenPU " << openpu::version() << " is up to date\n";
return 0;
}
std::cout << "OpenPU " << release->version.toString() << " is available (this is " << openpu::version()
<< "): " << release->pageUrl << '\n';
return 10;
}
if (args.size() == 1 && args[0] == "usb-list")
return cmdUsbList();
if (args.size() < 2) {
@@ -418,7 +439,9 @@ int main(int argc, char** argv)
<< "): " << e.what() << '\n';
} catch (const openpu::UsbError& e) {
std::cerr << "\nUSB error: " << e.what() << '\n';
} catch (const openpu::StorageError& e) {
} catch (const openpu::NetworkError& e) {
std::cerr << "network error: " << e.what() << '\n';
} catch (const std::runtime_error& e) { // StorageError, ParseError, app-update errors...
std::cerr << "error: " << e.what() << '\n';
}
return 1;
+17 -1
View File
@@ -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
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#include "openpu/api_client.hpp"
#include "openpu/vin.hpp"
+125
View File
@@ -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
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#include "openpu/archive.hpp"
#include <archive.h>
+4 -4
View File
@@ -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
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#include "openpu/download.hpp"
#include <cerrno>
+1
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#include "openpu/http.hpp"
#include <algorithm>
+1
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#pragma once
#include "openpu/http.hpp"
+63
View File
@@ -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
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#pragma once
#include "openpu/cancel.hpp"
+1
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#pragma once
#include <atomic>
+1
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#pragma once
#include "openpu/cancel.hpp"
+38
View File
@@ -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
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#pragma once
#include <chrono>
+59
View File
@@ -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
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#pragma once
#include <cstdint>
+2
View File
@@ -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
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#pragma once
#include "openpu/cancel.hpp"
+12
View File
@@ -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
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#pragma once
#include <string>
+130
View File
@@ -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
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#include "openpu/models.hpp"
#include <algorithm>
+5 -1
View File
@@ -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
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#include "openpu/usb.hpp"
#include "openpu/archive.hpp"
+1
View File
@@ -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
View File
@@ -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
View File
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#include "openpu/vin.hpp"
#include <cctype>
+17
View File
@@ -0,0 +1,17 @@
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTKMM REQUIRED IMPORTED_TARGET gtkmm-4.0>=4.10)
include(GNUInstallDirs)
add_executable(openpu
main.cpp
main_window.cpp
)
target_link_libraries(openpu PRIVATE openpu_core PkgConfig::GTKMM openpu_warnings)
target_compile_definitions(openpu PRIVATE
GETTEXT_PACKAGE="openpu"
OPENPU_LOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}")
# gtkmm headers trigger -Wshadow/-Wconversion noise we cannot fix.
target_compile_options(openpu PRIVATE -Wno-shadow -Wno-conversion)
install(TARGETS openpu RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES io.github.openpu.OpenPU.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
@@ -0,0 +1,12 @@
[Desktop Entry]
Type=Application
Name=OpenPU
GenericName=Head unit updates
GenericName[fr]=Mises à jour de l'autoradio
Comment=Download firmware and map updates for Peugeot head units and prepare the USB stick
Comment[fr]=Télécharger les mises à jour système et cartographie des autoradios Peugeot et préparer la clé USB
Exec=openpu
Icon=io.github.openpu.OpenPU
Terminal=false
Categories=Utility;GTK;
Keywords=Peugeot;NAC;RCC;GPS;map;firmware;USB;
+30
View File
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
#include "main_window.hpp"
#include "openpu/storage.hpp"
#include <clocale>
#include <cstdlib>
#include <glibmm/i18n.h>
#include <gtkmm/application.h>
int main(int argc, char* argv[])
{
// A language chosen in the settings overrides the session language (gettext reads LANGUAGE).
try {
const auto settings = openpu::Settings::load(openpu::paths::configDir() / "config.json");
if (!settings.language.empty())
(void)setenv("LANGUAGE", settings.language.c_str(), 1); // NOLINT(concurrency-mt-unsafe): no thread yet
} catch (const openpu::StorageError&) {
// dismissed: the window reports unreadable settings itself
}
(void)std::setlocale(LC_ALL, ""); // NOLINT(concurrency-mt-unsafe): no thread yet
// OPENPU_LOCALEDIR lets a build-tree binary find its translations.
const char* localeDir = std::getenv("OPENPU_LOCALEDIR"); // NOLINT(concurrency-mt-unsafe)
bindtextdomain(GETTEXT_PACKAGE, localeDir != nullptr ? localeDir : OPENPU_LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
auto app = Gtk::Application::create("io.github.openpu.OpenPU");
return app->make_window_and_run<openpu::gtk::MainWindow>(argc, argv);
}
File diff suppressed because it is too large. Load diff
+141
View File
@@ -0,0 +1,141 @@
// SPDX-License-Identifier: MIT
#pragma once
#include "ui_queue.hpp"
#include "openpu/api_client.hpp"
#include "openpu/app_update.hpp"
#include "openpu/job.hpp"
#include "openpu/storage.hpp"
#include "openpu/usb.hpp"
#include <gtkmm.h>
#include <memory>
#include <optional>
#include <thread>
namespace openpu::gtk {
class MainWindow : public Gtk::ApplicationWindow {
public:
MainWindow();
~MainWindow() override;
MainWindow(const MainWindow&) = delete;
MainWindow& operator=(const MainWindow&) = delete;
private:
// pages
void buildVehiclesPage();
void buildAddPage();
void buildUpdatesPage();
void buildDownloadPage();
void buildUsbPage();
void buildWritePage();
void buildDonePage();
void show(const char* page);
// vehicles
void refreshVehicles();
std::optional<Vehicle> selectedVehicle() const;
void onAddVehicle();
void onRemoveVehicle();
void onCheckUpdates();
// updates / download
void showUpdates(const AvailableUpdates& updates);
void onChooseFolder();
void onStartDownload();
void startDownload(const DownloadPlan& plan);
void onDownloadProgress(const JobProgress& p);
void onDownloaded(const DownloadedFiles& files);
// usb
void enterUsbPage();
void refreshDrives();
void onPrepareUsb();
void startWrite(const UsbDrive& drive);
void onWriteProgress(const UsbProgress& p);
void onWritten();
// helpers
template <typename F>
void runAsync(F&& work);
void joinWorker();
void showError(const Glib::ustring& title, const Glib::ustring& detail);
void showAbout();
void showPreferences();
void checkAppUpdate(bool manual);
void offerAppUpdate(const AppRelease& release);
void saveVehicles();
void updateDownloadDirLabel();
std::string language() const;
UiQueue ui_;
std::unique_ptr<Transport> transport_;
std::unique_ptr<ApiClient> api_;
std::unique_ptr<UsbBackend> usb_;
VehicleStore store_;
Settings settings_;
std::filesystem::path settingsFile_;
std::thread worker_;
std::thread updateThread_; // OpenPU new-version check, independent of the main flow
bool updateCheckRunning_ = false;
CancelToken cancel_;
// flow state
std::optional<Vehicle> current_;
AvailableUpdates updates_;
DownloadedFiles files_;
std::vector<UsbDrive> drives_;
std::uint64_t payload_ = 0;
// widgets
Gtk::HeaderBar header_;
Gtk::Button back_;
Gtk::MenuButton menu_;
Gtk::Label* prefsDirLabel_ = nullptr; // download folder shown in the open preferences window
Gtk::Stack stack_;
Gtk::Box vehiclesPage_{Gtk::Orientation::VERTICAL, 12};
Gtk::ListBox vehicleList_;
Gtk::Label vehiclesEmpty_;
Gtk::Button addButton_, removeButton_, checkButton_;
Gtk::Box addPage_{Gtk::Orientation::VERTICAL, 12};
Gtk::Entry vinEntry_, nameEntry_;
Gtk::Label addStatus_;
Gtk::Spinner addSpinner_;
Gtk::Button addConfirm_;
Gtk::Box updatesPage_{Gtk::Orientation::VERTICAL, 12};
Gtk::Label updatesTitle_, updatesStatus_;
Gtk::Spinner updatesSpinner_;
Gtk::CheckButton firmwareCheck_, mapCheck_;
Gtk::Label downloadDirLabel_;
Gtk::Button chooseDir_, downloadButton_, guideButton_;
Gtk::Box downloadPage_{Gtk::Orientation::VERTICAL, 12};
Gtk::Label downloadTitle_;
Gtk::Label licenseLabel_, firmwareLabel_, mapLabel_;
Gtk::ProgressBar firmwareBar_, mapBar_;
Gtk::Label etaLabel_;
Gtk::Button cancelDownload_;
Gtk::Box usbPage_{Gtk::Orientation::VERTICAL, 12};
Gtk::Label usbInfo_;
Gtk::DropDown driveDrop_;
Glib::RefPtr<Gtk::StringList> driveModel_;
Gtk::Button refreshDrives_, prepareButton_;
Gtk::Label usbStatus_;
Gtk::Box writePage_{Gtk::Orientation::VERTICAL, 12};
Gtk::Label writeStep_, writeDetail_;
Gtk::ProgressBar writeBar_;
Gtk::Button cancelWrite_;
Gtk::Box donePage_{Gtk::Orientation::VERTICAL, 12};
Gtk::Label doneText_;
Gtk::Button doneGuide_, doneButton_;
};
} // namespace openpu::gtk
+43
View File
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT
#pragma once
#include <deque>
#include <functional>
#include <glibmm/dispatcher.h>
#include <mutex>
namespace openpu::gtk {
/// Runs closures posted from worker threads on the GTK main loop.
/// Must be constructed on the main thread (Glib::Dispatcher requirement).
class UiQueue {
public:
UiQueue() { dispatcher_.connect([this] { drain(); }); }
void post(std::function<void()> fn)
{
{
std::scoped_lock lock(mutex_);
queue_.push_back(std::move(fn));
}
dispatcher_.emit();
}
private:
void drain()
{
std::deque<std::function<void()>> local;
{
std::scoped_lock lock(mutex_);
local.swap(queue_);
}
for (auto& fn : local)
fn();
}
Glib::Dispatcher dispatcher_;
std::mutex mutex_;
std::deque<std::function<void()>> queue_;
};
} // namespace openpu::gtk