diff --git a/laf b/laf index b97886c18..1992817fa 160000 --- a/laf +++ b/laf @@ -1 +1 @@ -Subproject commit b97886c18e788e9a623747e8308ccaf29797a6d3 +Subproject commit 1992817fa854987e85c6071a27a6fc7c9a794391 diff --git a/src/README.md b/src/README.md index 8c1334162..493d1b79d 100644 --- a/src/README.md +++ b/src/README.md @@ -42,7 +42,7 @@ because they don't depend on any other component. * [filters](filters/) (base, doc, gfx): Effects for images. * [render](render/) (base, doc, gfx): Library to render documents. * [ui](ui/) (base, gfx, she): Portable UI library (buttons, windows, text fields, etc.) - * [updater](updater/) (base, net): Component to check for updates. + * [updater](updater/) (base, cfg, net): Component to check for updates. ## Level 4 diff --git a/src/updater/CMakeLists.txt b/src/updater/CMakeLists.txt index 6e198e785..8e704e1c0 100644 --- a/src/updater/CMakeLists.txt +++ b/src/updater/CMakeLists.txt @@ -1,5 +1,5 @@ # ASEPRITE -# Copyright (C) 2001-2015 David Capello +# Copyright (C) 2001-2017 David Capello set(UPDATER_LIB_SOURCES check_update.cpp @@ -15,4 +15,5 @@ add_library(updater-lib ${UPDATER_LIB_SOURCES}) target_link_libraries(updater-lib net-lib + cfg-lib ${TINYXML_LIBRARY}) diff --git a/src/updater/user_agent.cpp b/src/updater/user_agent.cpp index 6a9a2412d..010755e09 100644 --- a/src/updater/user_agent.cpp +++ b/src/updater/user_agent.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2016 David Capello +// Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -23,6 +23,9 @@ #else // Unix-like system + #include "base/trim_string.h" + #include "cfg/cfg.h" + #include #include #endif @@ -88,9 +91,58 @@ std::string getUserAgent() // ---------------------------------------------------------------------- // Unix like - struct utsname utsn; - uname(&utsn); - userAgent << utsn.sysname << " " << utsn.release; + cfg::CfgFile file; + + auto isQuote = [](int c) { + return + c == '"' || + c == '\'' || + std::isspace(c); + }; + + auto getValue = [&file, &isQuote](const char* varName) -> std::string { + std::string result; + const char* value = file.getValue("", varName, nullptr); + if (value && std::strlen(value) > 0) + base::trim_string(value, result, isQuote); + return result; + }; + + // Read information from /etc/os-release + file.load("/etc/os-release"); + std::string name = getValue("PRETTY_NAME"); + if (!name.empty()) { + userAgent << name; + } + else { + name = getValue("NAME"); + std::string version = getValue("VERSION"); + if (!name.empty() && !version.empty()) { + userAgent << name << " " << version; + } + else { + // Read information from /etc/lsb-release + file.load("/etc/lsb-release"); + name = getValue("DISTRIB_DESCRIPTION"); + if (!name.empty()) { + userAgent << name; + } + else { + name = getValue("DISTRIB_ID"); + version = getValue("DISTRIB_RELEASE"); + if (!name.empty() && + !version.empty()) { + userAgent << name << " " << version; + } + else { + // Last resource, use uname() function + struct utsname utsn; + uname(&utsn); + userAgent << utsn.sysname << " " << utsn.release; + } + } + } + } #endif