2015-02-12 12:16:25 -03:00
|
|
|
// Aseprite
|
2019-06-06 12:15:31 -03:00
|
|
|
// Copyright (C) 2019 Igara Studio S.A.
|
2017-06-29 13:03:28 -03:00
|
|
|
// Copyright (C) 2001-2017 David Capello
|
2015-02-12 12:16:25 -03:00
|
|
|
//
|
2016-08-26 17:02:58 -03:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2011-07-26 23:25:02 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2011-07-26 23:25:02 -03:00
|
|
|
#include "config.h"
|
2013-08-05 21:20:19 -03:00
|
|
|
#endif
|
2011-07-26 23:25:02 -03:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#if _WIN32 // Windows
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
extern "C" BOOL IsWow64();
|
2019-06-06 12:15:31 -03:00
|
|
|
extern "C" const char* WineVersion();
|
2011-07-26 23:25:02 -03:00
|
|
|
|
|
|
|
#elif __APPLE__ // Mac OS X
|
|
|
|
|
2017-09-22 16:51:56 -03:00
|
|
|
void getMacOSXVersion(int& major, int& minor, int& patch);
|
2011-07-26 23:25:02 -03:00
|
|
|
|
|
|
|
#else // Unix-like system
|
|
|
|
|
2017-06-29 13:03:28 -03:00
|
|
|
#include "base/trim_string.h"
|
|
|
|
#include "cfg/cfg.h"
|
|
|
|
#include <cstring>
|
2011-07-26 23:25:02 -03:00
|
|
|
#include <sys/utsname.h>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace updater {
|
|
|
|
|
|
|
|
std::string getUserAgent()
|
|
|
|
{
|
|
|
|
std::stringstream userAgent;
|
|
|
|
|
2016-03-03 19:26:46 -03:00
|
|
|
// App name and version
|
|
|
|
|
|
|
|
#ifndef PACKAGE
|
|
|
|
#define PACKAGE ""
|
|
|
|
#pragma message("warning: Define PACKAGE macro")
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef VERSION
|
|
|
|
#define VERSION ""
|
|
|
|
#pragma message("warning: Define VERSION macro")
|
|
|
|
#endif
|
2011-07-26 23:25:02 -03:00
|
|
|
|
|
|
|
userAgent << PACKAGE << "/" << VERSION << " (";
|
|
|
|
|
|
|
|
#if _WIN32
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Windows
|
|
|
|
|
|
|
|
OSVERSIONINFOEX osv;
|
|
|
|
osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
|
|
|
::GetVersionEx((OSVERSIONINFO*)&osv);
|
|
|
|
|
|
|
|
userAgent << "Windows";
|
|
|
|
switch (osv.wProductType) {
|
|
|
|
case VER_NT_DOMAIN_CONTROLLER:
|
|
|
|
case VER_NT_SERVER:
|
|
|
|
userAgent << " Server";
|
|
|
|
break;
|
|
|
|
case VER_NT_WORKSTATION:
|
|
|
|
userAgent << " NT";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
userAgent << " " << osv.dwMajorVersion << "." << osv.dwMinorVersion;
|
|
|
|
|
|
|
|
if (osv.wServicePackMajor > 0)
|
|
|
|
userAgent << " SP" << osv.wServicePackMajor;
|
|
|
|
|
|
|
|
if (IsWow64())
|
|
|
|
userAgent << "; WOW64";
|
|
|
|
|
2019-06-06 12:15:31 -03:00
|
|
|
if (const char* wineVer = WineVersion())
|
|
|
|
userAgent << "; Wine " << wineVer;
|
|
|
|
|
2011-07-26 23:25:02 -03:00
|
|
|
#elif __APPLE__
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Mac OS X
|
|
|
|
|
2017-09-22 16:51:56 -03:00
|
|
|
int major, minor, patch;
|
|
|
|
getMacOSXVersion(major, minor, patch);
|
|
|
|
userAgent << "Mac OS X " << major << "." << minor << "." << patch;
|
2011-07-26 23:25:02 -03:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Unix like
|
|
|
|
|
2017-06-29 13:03:28 -03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-26 23:25:02 -03:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
userAgent << ")";
|
|
|
|
return userAgent.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace updater
|