mirror of https://github.com/vitalif/openscad
Include basic sysinfo to app updater
parent
252a870059
commit
12abe07da4
|
@ -39,7 +39,7 @@ unsigned long PlatformUtils::stackLimit()
|
|||
return STACK_LIMIT_DEFAULT;
|
||||
}
|
||||
|
||||
std::string PlatformUtils::sysinfo()
|
||||
std::string PlatformUtils::sysinfo(bool extended)
|
||||
{
|
||||
std::string result;
|
||||
|
||||
|
@ -54,15 +54,27 @@ std::string PlatformUtils::sysinfo()
|
|||
sysctlbyname("hw.memsize", &physical_memory, &length64, NULL, 0);
|
||||
sysctlbyname("hw.physicalcpu", &numcpu, &length32, NULL, 0);
|
||||
|
||||
result += " ";
|
||||
result += boost::lexical_cast<std::string>(numcpu);
|
||||
result += " CPU";
|
||||
if (numcpu > 1) result += "s";
|
||||
|
||||
result += " ";
|
||||
result += PlatformUtils::toMemorySizeString(physical_memory, 2);
|
||||
result += " RAM";
|
||||
size_t modellen = 0;
|
||||
sysctlbyname("hw.model", NULL, &modellen, NULL, 0);
|
||||
if (modellen) {
|
||||
char *model = (char *)malloc(modellen*sizeof(char));
|
||||
sysctlbyname("hw.model", model, &modellen, NULL, 0);
|
||||
result += " ";
|
||||
result += model;
|
||||
free(model);
|
||||
}
|
||||
|
||||
if (extended) {
|
||||
result += " ";
|
||||
result += boost::lexical_cast<std::string>(numcpu);
|
||||
result += " CPU";
|
||||
if (numcpu > 1) result += "s";
|
||||
|
||||
result += " ";
|
||||
result += PlatformUtils::toMemorySizeString(physical_memory, 2);
|
||||
result += " RAM ";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -129,47 +129,49 @@ static std::string detectDistribution()
|
|||
return "";
|
||||
}
|
||||
|
||||
std::string PlatformUtils::sysinfo()
|
||||
std::string PlatformUtils::sysinfo(bool extended)
|
||||
{
|
||||
std::string result;
|
||||
|
||||
struct utsname osinfo;
|
||||
if (uname(&osinfo) == 0) {
|
||||
result += osinfo.sysname;
|
||||
result += " ";
|
||||
result += osinfo.release;
|
||||
result += " ";
|
||||
result += osinfo.version;
|
||||
result += " ";
|
||||
result += osinfo.machine;
|
||||
result += osinfo.sysname;
|
||||
result += " ";
|
||||
result += osinfo.release;
|
||||
result += " ";
|
||||
result += osinfo.version;
|
||||
result += " ";
|
||||
result += osinfo.machine;
|
||||
} else {
|
||||
result += "Unknown Linux";
|
||||
result += "Unknown Linux";
|
||||
}
|
||||
|
||||
long numcpu = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
if (numcpu > 0) {
|
||||
result += " ";
|
||||
result += boost::lexical_cast<std::string>(numcpu);
|
||||
result += " CPU";
|
||||
if (numcpu > 1) {
|
||||
result += "s";
|
||||
}
|
||||
}
|
||||
|
||||
long pages = sysconf(_SC_PHYS_PAGES);
|
||||
long pagesize = sysconf(_SC_PAGE_SIZE);
|
||||
if ((pages > 0) && (pagesize > 0)) {
|
||||
result += " ";
|
||||
result += PlatformUtils::toMemorySizeString(pages * pagesize, 2);
|
||||
result += " RAM";
|
||||
}
|
||||
|
||||
std::string distribution = detectDistribution();
|
||||
if (!distribution.empty()) {
|
||||
result += " ";
|
||||
result += distribution;
|
||||
result += " ";
|
||||
result += distribution;
|
||||
}
|
||||
|
||||
if (extended) {
|
||||
long numcpu = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
if (numcpu > 0) {
|
||||
result += " ";
|
||||
result += boost::lexical_cast<std::string>(numcpu);
|
||||
result += " CPU";
|
||||
if (numcpu > 1) {
|
||||
result += "s";
|
||||
}
|
||||
}
|
||||
|
||||
long pages = sysconf(_SC_PHYS_PAGES);
|
||||
long pagesize = sysconf(_SC_PAGE_SIZE);
|
||||
if ((pages > 0) && (pagesize > 0)) {
|
||||
result += " ";
|
||||
result += PlatformUtils::toMemorySizeString(pages * pagesize, 2);
|
||||
result += " RAM";
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -121,90 +121,92 @@ static BOOL IsWow64()
|
|||
return bIsWow64;
|
||||
}
|
||||
|
||||
std::string PlatformUtils::sysinfo()
|
||||
std::string PlatformUtils::sysinfo(bool extended)
|
||||
{
|
||||
std::string result;
|
||||
|
||||
OSVERSIONINFOEX osinfo;
|
||||
osinfo.dwOSVersionInfoSize = sizeof(osinfo);
|
||||
|
||||
if (GetVersionExEx(&osinfo) == 0) {
|
||||
result += "Unknown Windows";
|
||||
} else {
|
||||
unsigned int version = osinfo.dwMajorVersion * 1000 + osinfo.dwMinorVersion;
|
||||
if (osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||
switch (version) {
|
||||
case 5000:
|
||||
result += "Windows 2000";
|
||||
break;
|
||||
case 5001:
|
||||
result += "Windows XP";
|
||||
break;
|
||||
case 5002:
|
||||
result += "Windows Server 2003";
|
||||
break;
|
||||
case 6000:
|
||||
result += (osinfo.wProductType == VER_NT_WORKSTATION ? "Windows Vista" : "Windows Server 2008");
|
||||
break;
|
||||
case 6001:
|
||||
result += (osinfo.wProductType == VER_NT_WORKSTATION ? "Windows 7" : "Windows Server 2008 R2");
|
||||
break;
|
||||
case 6002:
|
||||
result += (osinfo.wProductType == VER_NT_WORKSTATION ? "Windows 8" : "Windows Server 2012");
|
||||
break;
|
||||
case 6003:
|
||||
// For applications that have been manifested for Windows 8.1.
|
||||
result += (osinfo.wProductType == VER_NT_WORKSTATION ? "Windows 8.1" : "Windows Server 2012 R2");
|
||||
break;
|
||||
default:
|
||||
result += "Unknown Windows";
|
||||
break;
|
||||
}
|
||||
|
||||
if (osinfo.wServicePackMajor > 0) {
|
||||
boost::format fmtServicePack;
|
||||
if (osinfo.wServicePackMinor == 0) {
|
||||
fmtServicePack = boost::format(" SP%d");
|
||||
fmtServicePack % osinfo.wServicePackMajor;
|
||||
} else {
|
||||
fmtServicePack = boost::format(" SP%d.%d");
|
||||
fmtServicePack % osinfo.wServicePackMajor % osinfo.wServicePackMinor;
|
||||
}
|
||||
result += fmtServicePack.str();
|
||||
}
|
||||
|
||||
boost::format fmt(" (v%d.%d.%d.%d)");
|
||||
fmt % osinfo.dwMajorVersion % osinfo.dwMinorVersion % osinfo.wServicePackMajor % osinfo.wServicePackMinor;
|
||||
result += fmt.str();
|
||||
std::string result;
|
||||
|
||||
OSVERSIONINFOEX osinfo;
|
||||
osinfo.dwOSVersionInfoSize = sizeof(osinfo);
|
||||
|
||||
if (GetVersionExEx(&osinfo) == 0) {
|
||||
result += "Unknown Windows";
|
||||
} else {
|
||||
boost::format fmt("Unknown Windows (dwPlatformId = %d, dwMajorVersion = %d, dwMinorVersion = %d");
|
||||
fmt % osinfo.dwPlatformId % osinfo.dwMajorVersion % osinfo.dwMinorVersion;
|
||||
result += fmt.str();
|
||||
unsigned int version = osinfo.dwMajorVersion * 1000 + osinfo.dwMinorVersion;
|
||||
if (osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||
switch (version) {
|
||||
case 5000:
|
||||
result += "Windows 2000";
|
||||
break;
|
||||
case 5001:
|
||||
result += "Windows XP";
|
||||
break;
|
||||
case 5002:
|
||||
result += "Windows Server 2003";
|
||||
break;
|
||||
case 6000:
|
||||
result += (osinfo.wProductType == VER_NT_WORKSTATION ? "Windows Vista" : "Windows Server 2008");
|
||||
break;
|
||||
case 6001:
|
||||
result += (osinfo.wProductType == VER_NT_WORKSTATION ? "Windows 7" : "Windows Server 2008 R2");
|
||||
break;
|
||||
case 6002:
|
||||
result += (osinfo.wProductType == VER_NT_WORKSTATION ? "Windows 8" : "Windows Server 2012");
|
||||
break;
|
||||
case 6003:
|
||||
// For applications that have been manifested for Windows 8.1.
|
||||
result += (osinfo.wProductType == VER_NT_WORKSTATION ? "Windows 8.1" : "Windows Server 2012 R2");
|
||||
break;
|
||||
default:
|
||||
result += "Unknown Windows";
|
||||
break;
|
||||
}
|
||||
|
||||
if (osinfo.wServicePackMajor > 0) {
|
||||
boost::format fmtServicePack;
|
||||
if (osinfo.wServicePackMinor == 0) {
|
||||
fmtServicePack = boost::format(" SP%d");
|
||||
fmtServicePack % osinfo.wServicePackMajor;
|
||||
} else {
|
||||
fmtServicePack = boost::format(" SP%d.%d");
|
||||
fmtServicePack % osinfo.wServicePackMajor % osinfo.wServicePackMinor;
|
||||
}
|
||||
result += fmtServicePack.str();
|
||||
}
|
||||
|
||||
boost::format fmt(" (v%d.%d.%d.%d)");
|
||||
fmt % osinfo.dwMajorVersion % osinfo.dwMinorVersion % osinfo.wServicePackMajor % osinfo.wServicePackMinor;
|
||||
result += fmt.str();
|
||||
} else {
|
||||
boost::format fmt("Unknown Windows (dwPlatformId = %d, dwMajorVersion = %d, dwMinorVersion = %d");
|
||||
fmt % osinfo.dwPlatformId % osinfo.dwMajorVersion % osinfo.dwMinorVersion;
|
||||
result += fmt.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SYSTEM_INFO systeminfo;
|
||||
bool isWow64 = IsWow64();
|
||||
if (isWow64) {
|
||||
GetNativeSystemInfo(&systeminfo);
|
||||
} else {
|
||||
GetSystemInfo(&systeminfo);
|
||||
}
|
||||
|
||||
if (extended) {
|
||||
int numcpu = systeminfo.dwNumberOfProcessors;
|
||||
boost::format fmt(" %d CPU%s%s");
|
||||
fmt % numcpu % (numcpu > 1 ? "s" : "") % (isWow64 ? " WOW64" : "");
|
||||
result += fmt.str();
|
||||
|
||||
MEMORYSTATUSEX memoryinfo;
|
||||
memoryinfo.dwLength = sizeof(memoryinfo);
|
||||
if (GlobalMemoryStatusEx(&memoryinfo) != 0) {
|
||||
result += " ";
|
||||
result += PlatformUtils::toMemorySizeString(memoryinfo.ullTotalPhys, 2);
|
||||
result += " RAM";
|
||||
}
|
||||
}
|
||||
|
||||
SYSTEM_INFO systeminfo;
|
||||
bool isWow64 = IsWow64();
|
||||
if (isWow64) {
|
||||
GetNativeSystemInfo(&systeminfo);
|
||||
} else {
|
||||
GetSystemInfo(&systeminfo);
|
||||
}
|
||||
|
||||
int numcpu = systeminfo.dwNumberOfProcessors;
|
||||
boost::format fmt(" %d CPU%s%s");
|
||||
fmt % numcpu % (numcpu > 1 ? "s" : "") % (isWow64 ? " WOW64" : "");
|
||||
result += fmt.str();
|
||||
|
||||
MEMORYSTATUSEX memoryinfo;
|
||||
memoryinfo.dwLength = sizeof(memoryinfo);
|
||||
if (GlobalMemoryStatusEx(&memoryinfo) != 0) {
|
||||
result += " ";
|
||||
result += PlatformUtils::toMemorySizeString(memoryinfo.ullTotalPhys, 2);
|
||||
result += " RAM";
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
#include <io.h>
|
||||
|
|
|
@ -44,9 +44,11 @@ namespace PlatformUtils {
|
|||
* OS type is reported based on what platform the application was
|
||||
* built for.
|
||||
*
|
||||
* Extended sysinfo will return more info, like CPUs and RAM
|
||||
*
|
||||
* @return system information.
|
||||
*/
|
||||
std::string sysinfo();
|
||||
std::string sysinfo(bool extended = true);
|
||||
|
||||
/**
|
||||
* Platform abstraction to set environment variables. Windows/MinGW
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
#include "SparkleAutoUpdater.h"
|
||||
#include "PlatformUtils.h"
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <Sparkle/Sparkle.h>
|
||||
|
@ -65,8 +66,13 @@ QString SparkleAutoUpdater::lastUpdateCheckDate()
|
|||
return QString::fromUtf8([datestring UTF8String]);
|
||||
}
|
||||
|
||||
#define STRINGIFY(x) #x
|
||||
#define TOSTRING(x) STRINGIFY(x)
|
||||
|
||||
void SparkleAutoUpdater::updateFeed()
|
||||
{
|
||||
NSString *urlstring = [NSString stringWithFormat:@"http://openscad.org/appcast%@.xml", enableSnapshots() ? @"-snapshots" : @""];
|
||||
NSString *urlstring = [NSString stringWithFormat:@"http://files.openscad.org/appcast%@.xml", enableSnapshots() ? @"-snapshots" : @""];
|
||||
[d->updater setFeedURL:[NSURL URLWithString:urlstring]];
|
||||
NSString *userAgent = [NSString stringWithFormat:@"OpenSCAD %s %s", TOSTRING(OPENSCAD_VERSION), PlatformUtils::sysinfo(false).c_str()];
|
||||
[d->updater setUserAgentString: userAgent];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue