|
15 | 15 | #include <ctime> |
16 | 16 | #include <algorithm> |
17 | 17 |
|
| 18 | +#if defined(__APPLE__) |
| 19 | + #include <sys/sysctl.h> |
| 20 | +#elif defined(_WIN32) |
| 21 | + #include <windows.h> |
| 22 | +#elif defined(__linux__) |
| 23 | + #include <sys/utsname.h> |
| 24 | + #include <fstream> |
| 25 | +#endif |
| 26 | + |
18 | 27 | namespace MiniScript { |
19 | 28 |
|
20 | 29 | String hostName = ""; |
@@ -849,6 +858,53 @@ namespace MiniScript { |
849 | 858 | d.SetValue("host", hostVersion); |
850 | 859 | d.SetValue("hostName", hostName); |
851 | 860 | d.SetValue("hostInfo", hostInfo); |
| 861 | + |
| 862 | + // Platform detection |
| 863 | + String platform; |
| 864 | +#if defined(__APPLE__) |
| 865 | + platform = "macOS"; |
| 866 | + char osversion[32]; |
| 867 | + size_t osversion_len = sizeof(osversion); |
| 868 | + if (sysctlbyname("kern.osproductversion", osversion, &osversion_len, NULL, 0) == 0) { |
| 869 | + platform = String("macOS ") + osversion; |
| 870 | + } |
| 871 | +#elif defined(_WIN32) |
| 872 | + platform = "Windows"; |
| 873 | + typedef LONG(WINAPI* RtlGetVersionPtr)(OSVERSIONINFOW*); |
| 874 | + HMODULE ntdll = GetModuleHandleW(L"ntdll.dll"); |
| 875 | + if (ntdll) { |
| 876 | + RtlGetVersionPtr fn = (RtlGetVersionPtr)GetProcAddress(ntdll, "RtlGetVersion"); |
| 877 | + if (fn) { |
| 878 | + OSVERSIONINFOW osvi = {}; |
| 879 | + osvi.dwOSVersionInfoSize = sizeof(osvi); |
| 880 | + if (fn(&osvi) == 0) { |
| 881 | + platform = String("Windows ") + String::Format((int)osvi.dwMajorVersion) |
| 882 | + + "." + String::Format((int)osvi.dwMinorVersion); |
| 883 | + } |
| 884 | + } |
| 885 | + } |
| 886 | +#elif defined(__linux__) |
| 887 | + platform = "Linux"; |
| 888 | + { |
| 889 | + std::ifstream osrelease("/etc/os-release"); |
| 890 | + std::string line; |
| 891 | + while (std::getline(osrelease, line)) { |
| 892 | + if (line.compare(0, 12, "PRETTY_NAME=") == 0) { |
| 893 | + std::string val = line.substr(12); |
| 894 | + // Strip surrounding quotes |
| 895 | + if (val.size() >= 2 && val.front() == '"' && val.back() == '"') { |
| 896 | + val = val.substr(1, val.size() - 2); |
| 897 | + } |
| 898 | + platform = platform + " " + String(val.c_str()); |
| 899 | + break; |
| 900 | + } |
| 901 | + } |
| 902 | + } |
| 903 | +#else |
| 904 | + platform = "Unknown"; |
| 905 | +#endif |
| 906 | + d.SetValue("platform", platform); |
| 907 | + |
852 | 908 | context->vm->versionMap = Value(d); |
853 | 909 | } |
854 | 910 | return IntrinsicResult(context->vm->versionMap); |
|
0 commit comments