ProcessUtils.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../Precompiled.h"
  23. #include "../Core/ProcessUtils.h"
  24. #include "../Core/StringUtils.h"
  25. #include "../IO/FileSystem.h"
  26. #include <cstdio>
  27. #include <fcntl.h>
  28. #ifdef __APPLE__
  29. #include "TargetConditionals.h"
  30. #endif
  31. #if defined(IOS)
  32. #include "../Math/MathDefs.h"
  33. #include <mach/mach_host.h>
  34. #elif !defined(__linux__) && !defined(__EMSCRIPTEN__)
  35. #include <LibCpuId/libcpuid.h>
  36. #endif
  37. #if defined(_WIN32)
  38. #include <windows.h>
  39. #include <io.h>
  40. #if defined(_MSC_VER)
  41. #include <float.h>
  42. #include <Lmcons.h> // For UNLEN.
  43. #elif defined(__MINGW32__)
  44. #include <lmcons.h> // For UNLEN. Apparently MSVC defines "<Lmcons.h>" (with an upperscore 'L' but MinGW uses an underscore 'l').
  45. #include <ntdef.h>
  46. #endif
  47. #elif defined(__linux__) && !defined(__ANDROID__)
  48. #include <pwd.h>
  49. #include <sys/sysinfo.h>
  50. #include <sys/utsname.h>
  51. #elif defined(__APPLE__)
  52. #include <sys/sysctl.h>
  53. #include <SystemConfiguration/SystemConfiguration.h> // For the detection functions inside GetLoginName().
  54. #endif
  55. #ifndef _WIN32
  56. #include <unistd.h>
  57. #endif
  58. #if defined(__EMSCRIPTEN__) && defined(__EMSCRIPTEN_PTHREADS__)
  59. #include <emscripten/threading.h>
  60. #endif
  61. #if defined(__i386__)
  62. // From http://stereopsis.com/FPU.html
  63. #define FPU_CW_PREC_MASK 0x0300
  64. #define FPU_CW_PREC_SINGLE 0x0000
  65. #define FPU_CW_PREC_DOUBLE 0x0200
  66. #define FPU_CW_PREC_EXTENDED 0x0300
  67. #define FPU_CW_ROUND_MASK 0x0c00
  68. #define FPU_CW_ROUND_NEAR 0x0000
  69. #define FPU_CW_ROUND_DOWN 0x0400
  70. #define FPU_CW_ROUND_UP 0x0800
  71. #define FPU_CW_ROUND_CHOP 0x0c00
  72. inline unsigned GetFPUState()
  73. {
  74. unsigned control = 0;
  75. __asm__ __volatile__ ("fnstcw %0" : "=m" (control));
  76. return control;
  77. }
  78. inline void SetFPUState(unsigned control)
  79. {
  80. __asm__ __volatile__ ("fldcw %0" : : "m" (control));
  81. }
  82. #endif
  83. #ifndef MINI_URHO
  84. #include <SDL/SDL.h>
  85. #endif
  86. #include "../DebugNew.h"
  87. namespace Urho3D
  88. {
  89. #ifdef _WIN32
  90. static bool consoleOpened = false;
  91. #endif
  92. static String currentLine;
  93. static Vector<String> arguments;
  94. static String miniDumpDir;
  95. #if defined(IOS)
  96. static void GetCPUData(host_basic_info_data_t* data)
  97. {
  98. mach_msg_type_number_t infoCount;
  99. infoCount = HOST_BASIC_INFO_COUNT;
  100. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)data, &infoCount);
  101. }
  102. #elif defined(__linux__)
  103. struct CpuCoreCount
  104. {
  105. unsigned numPhysicalCores_;
  106. unsigned numLogicalCores_;
  107. };
  108. // This function is used by all the target triplets with Linux as the OS, such as Android, RPI, desktop Linux, etc
  109. static void GetCPUData(struct CpuCoreCount* data)
  110. {
  111. // Sanity check
  112. assert(data);
  113. // At least return 1 core
  114. data->numPhysicalCores_ = data->numLogicalCores_ = 1;
  115. FILE* fp;
  116. int res;
  117. unsigned i, j;
  118. fp = fopen("/sys/devices/system/cpu/present", "r");
  119. if (fp)
  120. {
  121. res = fscanf(fp, "%d-%d", &i, &j);
  122. fclose(fp);
  123. if (res == 2 && i == 0)
  124. {
  125. data->numPhysicalCores_ = data->numLogicalCores_ = j + 1;
  126. fp = fopen("/sys/devices/system/cpu/cpu0/topology/thread_siblings_list", "r");
  127. if (fp)
  128. {
  129. res = fscanf(fp, "%d,%d,%d,%d", &i, &j, &i, &j);
  130. fclose(fp);
  131. // Having sibling thread(s) indicates the CPU is using HT/SMT technology
  132. if (res > 1)
  133. data->numPhysicalCores_ /= res;
  134. }
  135. }
  136. }
  137. }
  138. #elif !defined(__EMSCRIPTEN__)
  139. static void GetCPUData(struct cpu_id_t* data)
  140. {
  141. if (cpu_identify(0, data) < 0)
  142. {
  143. data->num_logical_cpus = 1;
  144. data->num_cores = 1;
  145. }
  146. }
  147. #endif
  148. void InitFPU()
  149. {
  150. // Make sure FPU is in round-to-nearest, single precision mode
  151. // This ensures Direct3D and OpenGL behave similarly, and all threads behave similarly
  152. #if defined(_MSC_VER) && defined(_M_IX86)
  153. _controlfp(_RC_NEAR | _PC_24, _MCW_RC | _MCW_PC);
  154. #elif defined(__i386__)
  155. unsigned control = GetFPUState();
  156. control &= ~(FPU_CW_PREC_MASK | FPU_CW_ROUND_MASK);
  157. control |= (FPU_CW_PREC_SINGLE | FPU_CW_ROUND_NEAR);
  158. SetFPUState(control);
  159. #endif
  160. }
  161. void ErrorDialog(const String& title, const String& message)
  162. {
  163. #ifndef MINI_URHO
  164. SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title.CString(), message.CString(), 0);
  165. #endif
  166. }
  167. void ErrorExit(const String& message, int exitCode)
  168. {
  169. if (!message.Empty())
  170. PrintLine(message, true);
  171. exit(exitCode);
  172. }
  173. void OpenConsoleWindow()
  174. {
  175. #ifdef _WIN32
  176. if (consoleOpened)
  177. return;
  178. AllocConsole();
  179. freopen("CONIN$", "r", stdin);
  180. freopen("CONOUT$", "w", stdout);
  181. consoleOpened = true;
  182. #endif
  183. }
  184. void PrintUnicode(const String& str, bool error)
  185. {
  186. #if !defined(__ANDROID__) && !defined(IOS)
  187. #ifdef _WIN32
  188. // If the output stream has been redirected, use fprintf instead of WriteConsoleW,
  189. // though it means that proper Unicode output will not work
  190. FILE* out = error ? stderr : stdout;
  191. if (!_isatty(_fileno(out)))
  192. fprintf(out, "%s", str.CString());
  193. else
  194. {
  195. HANDLE stream = GetStdHandle(error ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE);
  196. if (stream == INVALID_HANDLE_VALUE)
  197. return;
  198. WString strW(str);
  199. DWORD charsWritten;
  200. WriteConsoleW(stream, strW.CString(), strW.Length(), &charsWritten, 0);
  201. }
  202. #else
  203. fprintf(error ? stderr : stdout, "%s", str.CString());
  204. #endif
  205. #endif
  206. }
  207. void PrintUnicodeLine(const String& str, bool error)
  208. {
  209. PrintUnicode(str + "\n", error);
  210. }
  211. void PrintLine(const String& str, bool error)
  212. {
  213. #if !defined(__ANDROID__) && !defined(IOS)
  214. fprintf(error ? stderr : stdout, "%s\n", str.CString());
  215. #endif
  216. }
  217. const Vector<String>& ParseArguments(const String& cmdLine, bool skipFirstArgument)
  218. {
  219. arguments.Clear();
  220. unsigned cmdStart = 0, cmdEnd = 0;
  221. bool inCmd = false;
  222. bool inQuote = false;
  223. for (unsigned i = 0; i < cmdLine.Length(); ++i)
  224. {
  225. if (cmdLine[i] == '\"')
  226. inQuote = !inQuote;
  227. if (cmdLine[i] == ' ' && !inQuote)
  228. {
  229. if (inCmd)
  230. {
  231. inCmd = false;
  232. cmdEnd = i;
  233. // Do not store the first argument (executable name)
  234. if (!skipFirstArgument)
  235. arguments.Push(cmdLine.Substring(cmdStart, cmdEnd - cmdStart));
  236. skipFirstArgument = false;
  237. }
  238. }
  239. else
  240. {
  241. if (!inCmd)
  242. {
  243. inCmd = true;
  244. cmdStart = i;
  245. }
  246. }
  247. }
  248. if (inCmd)
  249. {
  250. cmdEnd = cmdLine.Length();
  251. if (!skipFirstArgument)
  252. arguments.Push(cmdLine.Substring(cmdStart, cmdEnd - cmdStart));
  253. }
  254. // Strip double quotes from the arguments
  255. for (unsigned i = 0; i < arguments.Size(); ++i)
  256. arguments[i].Replace("\"", "");
  257. return arguments;
  258. }
  259. const Vector<String>& ParseArguments(const char* cmdLine)
  260. {
  261. return ParseArguments(String(cmdLine));
  262. }
  263. const Vector<String>& ParseArguments(const WString& cmdLine)
  264. {
  265. return ParseArguments(String(cmdLine));
  266. }
  267. const Vector<String>& ParseArguments(const wchar_t* cmdLine)
  268. {
  269. return ParseArguments(String(cmdLine));
  270. }
  271. const Vector<String>& ParseArguments(int argc, char** argv)
  272. {
  273. String cmdLine;
  274. for (int i = 0; i < argc; ++i)
  275. cmdLine.AppendWithFormat("\"%s\" ", (const char*)argv[i]);
  276. return ParseArguments(cmdLine);
  277. }
  278. const Vector<String>& GetArguments()
  279. {
  280. return arguments;
  281. }
  282. String GetConsoleInput()
  283. {
  284. String ret;
  285. #ifdef URHO3D_TESTING
  286. // When we are running automated tests, reading the console may block. Just return empty in that case
  287. return ret;
  288. #else
  289. #ifdef _WIN32
  290. HANDLE input = GetStdHandle(STD_INPUT_HANDLE);
  291. HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
  292. if (input == INVALID_HANDLE_VALUE || output == INVALID_HANDLE_VALUE)
  293. return ret;
  294. // Use char-based input
  295. SetConsoleMode(input, ENABLE_PROCESSED_INPUT);
  296. INPUT_RECORD record;
  297. DWORD events = 0;
  298. DWORD readEvents = 0;
  299. if (!GetNumberOfConsoleInputEvents(input, &events))
  300. return ret;
  301. while (events--)
  302. {
  303. ReadConsoleInputW(input, &record, 1, &readEvents);
  304. if (record.EventType == KEY_EVENT && record.Event.KeyEvent.bKeyDown)
  305. {
  306. unsigned c = record.Event.KeyEvent.uChar.UnicodeChar;
  307. if (c)
  308. {
  309. if (c == '\b')
  310. {
  311. PrintUnicode("\b \b");
  312. int length = currentLine.LengthUTF8();
  313. if (length)
  314. currentLine = currentLine.SubstringUTF8(0, length - 1);
  315. }
  316. else if (c == '\r')
  317. {
  318. PrintUnicode("\n");
  319. ret = currentLine;
  320. currentLine.Clear();
  321. return ret;
  322. }
  323. else
  324. {
  325. // We have disabled echo, so echo manually
  326. wchar_t out = c;
  327. DWORD charsWritten;
  328. WriteConsoleW(output, &out, 1, &charsWritten, 0);
  329. currentLine.AppendUTF8(c);
  330. }
  331. }
  332. }
  333. }
  334. #elif !defined(__ANDROID__) && !defined(IOS)
  335. int flags = fcntl(STDIN_FILENO, F_GETFL);
  336. fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
  337. for (;;)
  338. {
  339. int ch = fgetc(stdin);
  340. if (ch >= 0 && ch != '\n')
  341. ret += (char)ch;
  342. else
  343. break;
  344. }
  345. #endif
  346. return ret;
  347. #endif
  348. }
  349. String GetPlatform()
  350. {
  351. #if defined(__ANDROID__)
  352. return "Android";
  353. #elif defined(IOS)
  354. return "iOS";
  355. #elif defined(_WIN32)
  356. return "Windows";
  357. #elif defined(__APPLE__)
  358. return "Mac OS X";
  359. #elif defined(RPI)
  360. return "Raspberry Pi";
  361. #elif defined(__EMSCRIPTEN__)
  362. return "Web";
  363. #elif defined(__linux__)
  364. return "Linux";
  365. #else
  366. return String::EMPTY;
  367. #endif
  368. }
  369. unsigned GetNumPhysicalCPUs()
  370. {
  371. #if defined(IOS)
  372. host_basic_info_data_t data;
  373. GetCPUData(&data);
  374. #if defined(TARGET_IPHONE_SIMULATOR)
  375. // Hardcoded to dual-core on simulator mode even if the host has more
  376. return Min(2, data.physical_cpu);
  377. #else
  378. return data.physical_cpu;
  379. #endif
  380. #elif defined(__linux__)
  381. struct CpuCoreCount data;
  382. GetCPUData(&data);
  383. return data.numPhysicalCores_;
  384. #elif defined(__EMSCRIPTEN__)
  385. #ifdef __EMSCRIPTEN_PTHREADS__
  386. return emscripten_num_logical_cores();
  387. #else
  388. return 1; // Targeting a single-threaded Emscripten build.
  389. #endif
  390. #else
  391. struct cpu_id_t data;
  392. GetCPUData(&data);
  393. return (unsigned)data.num_cores;
  394. #endif
  395. }
  396. unsigned GetNumLogicalCPUs()
  397. {
  398. #if defined(IOS)
  399. host_basic_info_data_t data;
  400. GetCPUData(&data);
  401. #if defined(TARGET_IPHONE_SIMULATOR)
  402. return Min(2, data.logical_cpu);
  403. #else
  404. return data.logical_cpu;
  405. #endif
  406. #elif defined(__linux__)
  407. struct CpuCoreCount data;
  408. GetCPUData(&data);
  409. return data.numLogicalCores_;
  410. #elif defined(__EMSCRIPTEN__)
  411. #ifdef __EMSCRIPTEN_PTHREADS__
  412. return emscripten_num_logical_cores();
  413. #else
  414. return 1; // Targeting a single-threaded Emscripten build.
  415. #endif
  416. #else
  417. struct cpu_id_t data;
  418. GetCPUData(&data);
  419. return (unsigned)data.num_logical_cpus;
  420. #endif
  421. }
  422. void SetMiniDumpDir(const String& pathName)
  423. {
  424. miniDumpDir = AddTrailingSlash(pathName);
  425. }
  426. String GetMiniDumpDir()
  427. {
  428. #ifndef MINI_URHO
  429. if (miniDumpDir.Empty())
  430. {
  431. char* pathName = SDL_GetPrefPath("urho3d", "crashdumps");
  432. if (pathName)
  433. {
  434. String ret(pathName);
  435. SDL_free(pathName);
  436. return ret;
  437. }
  438. }
  439. #endif
  440. return miniDumpDir;
  441. }
  442. unsigned long long GetTotalMemory()
  443. {
  444. #if defined(__linux__) && !defined(__ANDROID__)
  445. struct sysinfo s;
  446. if (sysinfo(&s) != -1)
  447. return s.totalram;
  448. #elif defined(_WIN32)
  449. MEMORYSTATUSEX state;
  450. state.dwLength = sizeof(state);
  451. if (GlobalMemoryStatusEx(&state))
  452. return state.ullTotalPhys;
  453. #elif defined(__APPLE__)
  454. unsigned long long memSize;
  455. size_t len = sizeof(memSize);
  456. int mib[2];
  457. mib[0] = CTL_HW;
  458. mib[1] = HW_MEMSIZE;
  459. sysctl(mib, 2, &memSize, &len, NULL, 0);
  460. return memSize;
  461. #endif
  462. return 0ull;
  463. }
  464. String GetLoginName()
  465. {
  466. #if defined(__linux__) && !defined(__ANDROID__)
  467. struct passwd *p = getpwuid(getuid());
  468. if (p)
  469. return p->pw_name;
  470. #elif defined(_WIN32)
  471. char name[UNLEN + 1];
  472. DWORD len = UNLEN + 1;
  473. if (GetUserName(name, &len))
  474. return name;
  475. #elif defined(__APPLE__) && !defined(IOS)
  476. SCDynamicStoreRef s = SCDynamicStoreCreate(NULL, CFSTR("GetConsoleUser"), NULL, NULL);
  477. if (s != NULL)
  478. {
  479. uid_t u;
  480. CFStringRef n = SCDynamicStoreCopyConsoleUser(s, &u, NULL);
  481. CFRelease(s);
  482. if (n != NULL)
  483. {
  484. char name[256];
  485. Boolean b = CFStringGetCString(n, name, 256, kCFStringEncodingUTF8);
  486. CFRelease(n);
  487. if (b == true)
  488. return name;
  489. }
  490. }
  491. #endif
  492. return "(?)";
  493. }
  494. String GetHostName()
  495. {
  496. #if (defined(__linux__) || defined(__APPLE__)) && !defined(__ANDROID__)
  497. char buffer[256];
  498. if (gethostname(buffer, 256) == 0)
  499. return buffer;
  500. #elif defined(_WIN32)
  501. char buffer[MAX_COMPUTERNAME_LENGTH + 1];
  502. DWORD len = MAX_COMPUTERNAME_LENGTH + 1;
  503. if (GetComputerName(buffer, &len))
  504. return buffer;
  505. #endif
  506. return String::EMPTY;
  507. }
  508. #if defined(_WIN32)
  509. typedef NTSTATUS (WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
  510. static void GetOS(RTL_OSVERSIONINFOW *r)
  511. {
  512. HMODULE m = GetModuleHandle("ntdll.dll");
  513. if (m)
  514. {
  515. RtlGetVersionPtr fPtr = (RtlGetVersionPtr) GetProcAddress(m, "RtlGetVersion");
  516. if (r && fPtr && fPtr(r) == 0)
  517. r->dwOSVersionInfoSize = sizeof *r;
  518. }
  519. }
  520. #endif
  521. String GetOSVersion()
  522. {
  523. #if defined(__linux__) && !defined(__ANDROID__)
  524. struct utsname u;
  525. if (uname(&u) == 0)
  526. return String(u.sysname) + " " + u.release;
  527. #elif defined(_WIN32)
  528. RTL_OSVERSIONINFOW r;
  529. GetOS(&r);
  530. // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx
  531. if (r.dwMajorVersion == 5 && r.dwMinorVersion == 0)
  532. return "Windows 2000";
  533. else if (r.dwMajorVersion == 5 && r.dwMinorVersion == 1)
  534. return "Windows XP";
  535. else if (r.dwMajorVersion == 5 && r.dwMinorVersion == 2)
  536. return "Windows XP 64-Bit Edition/Windows Server 2003/Windows Server 2003 R2";
  537. else if (r.dwMajorVersion == 6 && r.dwMinorVersion == 0)
  538. return "Windows Vista/Windows Server 2008";
  539. else if (r.dwMajorVersion == 6 && r.dwMinorVersion == 1)
  540. return "Windows 7/Windows Server 2008 R2";
  541. else if (r.dwMajorVersion == 6 && r.dwMinorVersion == 2)
  542. return "Windows 8/Windows Server 2012";
  543. else if (r.dwMajorVersion == 6 && r.dwMinorVersion == 3)
  544. return "Windows 8.1/Windows Server 2012 R2";
  545. else if (r.dwMajorVersion == 10 && r.dwMinorVersion == 0)
  546. return "Windows 10/Windows Server 2016";
  547. else
  548. return "Windows Unidentified";
  549. #elif defined(__APPLE__)
  550. char kernel_r[256];
  551. size_t size = sizeof(kernel_r);
  552. if (sysctlbyname("kern.osrelease", &kernel_r, &size, NULL, 0) != -1)
  553. {
  554. Vector<String> kernel_version = String(kernel_r).Split('.');
  555. String version = "macOS/Mac OS X ";
  556. int major = ToInt(kernel_version[0]);
  557. int minor = ToInt(kernel_version[1]);
  558. // https://en.wikipedia.org/wiki/Darwin_(operating_system)
  559. if (major == 16) // macOS Sierra
  560. {
  561. version += "Sierra ";
  562. switch(minor)
  563. {
  564. case 0: version += "10.12.0 "; break;
  565. case 1: version += "10.12.1 "; break;
  566. case 3: version += "10.12.2 "; break;
  567. }
  568. }
  569. else if (major == 15) // OS X El Capitan
  570. {
  571. version += "El Capitan ";
  572. switch(minor)
  573. {
  574. case 0: version += "10.11.0 "; break;
  575. case 6: version += "10.11.6 "; break;
  576. }
  577. }
  578. else if (major == 14) // OS X Yosemite
  579. {
  580. version += "Yosemite ";
  581. switch(minor)
  582. {
  583. case 0: version += "10.10.0 "; break;
  584. case 5: version += "10.10.5 "; break;
  585. }
  586. }
  587. else if (major == 13) // OS X Mavericks
  588. {
  589. version += "Mavericks ";
  590. switch(minor)
  591. {
  592. case 0: version += "10.9.0 "; break;
  593. case 4: version += "10.9.5 "; break;
  594. }
  595. }
  596. else if (major == 12) // OS X Mountain Lion
  597. {
  598. version += "Mountain Lion ";
  599. switch(minor)
  600. {
  601. case 0: version += "10.8.0 "; break;
  602. case 6: version += "10.8.5 "; break;
  603. }
  604. }
  605. else if (major == 11) // Mac OS X Lion
  606. {
  607. version += "Lion ";
  608. switch(minor)
  609. {
  610. case 0: version += "10.7.0 "; break;
  611. case 4: version += "10.7.5 "; break;
  612. }
  613. }
  614. else
  615. {
  616. version += "Unknown ";
  617. }
  618. return version + " (Darwin kernel " + kernel_version[0] + "." + kernel_version[1] + "." + kernel_version[2] + ")";
  619. }
  620. #endif
  621. return String::EMPTY;
  622. }
  623. }