Fix User-Agent on Linux to include the distribution name/version

This commit is contained in:
David Capello 2017-06-29 13:03:28 -03:00
parent 55637693dd
commit cc8337fa84
4 changed files with 60 additions and 7 deletions

2
laf

@ -1 +1 @@
Subproject commit b97886c18e788e9a623747e8308ccaf29797a6d3 Subproject commit 1992817fa854987e85c6071a27a6fc7c9a794391

View File

@ -42,7 +42,7 @@ because they don't depend on any other component.
* [filters](filters/) (base, doc, gfx): Effects for images. * [filters](filters/) (base, doc, gfx): Effects for images.
* [render](render/) (base, doc, gfx): Library to render documents. * [render](render/) (base, doc, gfx): Library to render documents.
* [ui](ui/) (base, gfx, she): Portable UI library (buttons, windows, text fields, etc.) * [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 ## Level 4

View File

@ -1,5 +1,5 @@
# ASEPRITE # ASEPRITE
# Copyright (C) 2001-2015 David Capello # Copyright (C) 2001-2017 David Capello
set(UPDATER_LIB_SOURCES set(UPDATER_LIB_SOURCES
check_update.cpp check_update.cpp
@ -15,4 +15,5 @@ add_library(updater-lib ${UPDATER_LIB_SOURCES})
target_link_libraries(updater-lib target_link_libraries(updater-lib
net-lib net-lib
cfg-lib
${TINYXML_LIBRARY}) ${TINYXML_LIBRARY})

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2016 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -23,6 +23,9 @@
#else // Unix-like system #else // Unix-like system
#include "base/trim_string.h"
#include "cfg/cfg.h"
#include <cstring>
#include <sys/utsname.h> #include <sys/utsname.h>
#endif #endif
@ -88,9 +91,58 @@ std::string getUserAgent()
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Unix like // Unix like
struct utsname utsn; cfg::CfgFile file;
uname(&utsn);
userAgent << utsn.sysname << " " << utsn.release; 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 #endif