1// Aseprite
2// Copyright (C) 2019-2021 Igara Studio S.A.
3// Copyright (C) 2001-2017 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifdef HAVE_CONFIG_H
9#include "config.h"
10#endif
11
12#include "updater/user_agent.h"
13
14#include "base/platform.h"
15#include "ver/info.h"
16
17#include <string>
18#include <sstream>
19
20namespace updater {
21
22std::string getUserAgent()
23{
24 base::Platform p = base::get_platform();
25 std::stringstream userAgent;
26
27 // App name and version
28 userAgent << get_app_name() << "/" << get_app_version() << " (";
29
30#if LAF_WINDOWS
31
32 // ----------------------------------------------------------------------
33 // Windows
34
35 userAgent << "Windows";
36 switch (p.windowsType) {
37 case base::Platform::WindowsType::Server:
38 userAgent << " Server";
39 break;
40 case base::Platform::WindowsType::NT:
41 userAgent << " NT";
42 break;
43 }
44 userAgent << " " << p.osVer.major() << "." << p.osVer.minor();
45
46 if (p.servicePack.major() > 0)
47 userAgent << " SP" << p.servicePack.major();
48
49 if (p.isWow64)
50 userAgent << "; WOW64";
51
52 if (p.wineVer)
53 userAgent << "; Wine " << p.wineVer;
54
55#elif LAF_MACOS
56
57 userAgent << "macOS "
58 << p.osVer.major() << "."
59 << p.osVer.minor() << "."
60 << p.osVer.patch();
61
62#else
63
64 // ----------------------------------------------------------------------
65 // Unix like
66
67 if (!p.distroName.empty()) {
68 userAgent << p.distroName;
69 if (!p.distroVer.empty())
70 userAgent << " " << p.distroVer;
71 }
72
73#endif
74
75 userAgent << ")";
76 return userAgent.str();
77}
78
79} // namespace updater
80