2015-02-12 12:16:25 -03:00
|
|
|
// Aseprite
|
|
|
|
// Copyright (C) 2001-2015 David Capello
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2 as
|
|
|
|
// published by the Free Software Foundation.
|
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();
|
|
|
|
|
|
|
|
#elif __APPLE__ // Mac OS X
|
|
|
|
|
2014-08-15 00:59:29 -03:00
|
|
|
void getMacOSXVersion(int* major, int* minor, int* bugFix);
|
2011-07-26 23:25:02 -03:00
|
|
|
|
|
|
|
#else // Unix-like system
|
|
|
|
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace updater {
|
|
|
|
|
|
|
|
std::string getUserAgent()
|
|
|
|
{
|
|
|
|
std::stringstream userAgent;
|
|
|
|
|
|
|
|
// ASEPRITE name and version
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
|
|
|
#elif __APPLE__
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Mac OS X
|
|
|
|
|
|
|
|
int major, minor, bugFix;
|
|
|
|
getMacOSXVersion(&major, &minor, &bugFix);
|
|
|
|
userAgent << "Mac OS X " << major << "." << minor << "." << bugFix;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Unix like
|
|
|
|
|
|
|
|
struct utsname utsn;
|
|
|
|
uname(&utsn);
|
2011-07-27 23:08:54 -03:00
|
|
|
userAgent << utsn.sysname << " " << utsn.release;
|
2011-07-26 23:25:02 -03:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
userAgent << ")";
|
|
|
|
return userAgent.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace updater
|