-
Notifications
You must be signed in to change notification settings - Fork 0
/
MachinePower.cpp
67 lines (57 loc) · 1.69 KB
/
MachinePower.cpp
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
#include <apollo/Utilities/MachinePower.h>
#ifdef __MACH__
#include <sys/types.h>
#include <sys/sysctl.h>
#include <string.h>
#include <stdlib.h>
#include <apollo/Utilities/ResourceManager.h>
#include <CoreFoundation/CoreFoundation.h>
extern "C" long NSRunAlertPanel(CFStringRef title, CFStringRef msg, CFStringRef defaultButton, CFStringRef alternateButton, CFStringRef otherButton, ...);
MachinePower GetMachinePower()
{
char nameBuf[64];
size_t nameLen = sizeof(nameBuf);
memset(nameBuf, 0, sizeof(nameBuf));
sysctlbyname("hw.model", &nameBuf, &nameLen, NULL, NULL);
if (nameLen == 0)
return MACHINE_POWER_CAPABLE; // assume capable
else
{
// check our list
SDL_RWops* ops = ResourceManager::OpenFile("Config/MacModels.txt");
if (!ops)
return MACHINE_POWER_CAPABLE;
size_t length;
void* ptr = ResourceManager::ReadFull(&length, ops, 1);
if (!ptr)
return MACHINE_POWER_CAPABLE;
bool found = strnstr((const char*)ptr, nameBuf, length);
free(ptr);
return found ? MACHINE_POWER_MIGHTY : MACHINE_POWER_WIMPY;
}
}
void CheckMachinePowerSanity()
{
MachinePower power = GetMachinePower();
if (power == MACHINE_POWER_WIMPY)
{
long result = NSRunAlertPanel(CFSTR("Underpowered Machine"),
CFSTR("Your machine does not have enough power to run the Apollo engine properly. If you choose to continue, you may experience performance difficulties."),
CFSTR("Quit"),
CFSTR("Continue"),
0);
if (result != 0)
exit(0);
}
}
#else
#warning GetMachinePower is not implemented on this architecture
MachinePower GetMachinePower()
{
// return an average guess
return MACHINE_POWER_CAPABLE;
}
void CheckMachinePowerSanity()
{
}
#endif