forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_agent.cpp
More file actions
101 lines (70 loc) · 1.95 KB
/
user_agent.cpp
File metadata and controls
101 lines (70 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Aseprite
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string>
#include <sstream>
#if _WIN32 // Windows
#include <windows.h>
extern "C" BOOL IsWow64();
#elif __APPLE__ // Mac OS X
void getMacOSXVersion(int* major, int* minor, int* bugFix);
#else // Unix-like system
#include <sys/utsname.h>
#endif
namespace updater {
std::string getUserAgent()
{
std::stringstream userAgent;
// 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
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);
userAgent << utsn.sysname << " " << utsn.release;
#endif
userAgent << ")";
return userAgent.str();
}
} // namespace updater