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
| ;@windows
;@author Progi1984
;@linux
;@author Progi1984
;@@macos
;@author jack
;@link http://www.purebasic.fr/english/viewtopic.php?p=282943#282943
ProcedureDLL.s System_GetCPUInfo()
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux ;{
Protected lProgram.l
Protected sOutput.s
lProgram = RunProgram("grep", Chr(34)+"model name"+Chr(34)+" /proc/cpuinfo", "", #PB_Program_Open|#PB_Program_Read)
If lProgram
sOutput = ReadProgramString(lProgram)
sOutput = ReplaceString(sOutput, "model name", "")
sOutput = ReplaceString(sOutput, ":", "")
sOutput = Trim(sOutput)
ProcedureReturn sOutput
Else
ProcedureReturn ""
EndIf
;}
CompilerCase #PB_OS_MacOS ;{
ImportC "/usr/lib/libc.dylib"
sysctlbyname.l(s.s,*buffer,*length,*null,*null2)
EndImport
Protected *MemBuffer
Protected lMemLength.l = 128
*MemBuffer = AllocateMemory(lMemLength)
sysctlbyname("machdep.cpu.brand_string", *MemBuffer, @lMemLength, 0, 0)
ProcedureReturn PeekS(*MemBuffer)
;}
CompilerCase #PB_OS_Windows ;{
Protected sSubKey.s, sKeyValue.s, sResult.s
Protected lKey.l, lResultLen.l
sSubKey = "HARDWARE\DESCRIPTION\System\CentralProcessor\0"
sKeyValue = "ProcessorNameString"
sResult = Space(255)
lResultLen = 255
If RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, sSubKey, #Null, #KEY_ALL_ACCESS, @lKey) = #ERROR_SUCCESS
If lKey
If RegQueryValueEx_(lKey, sKeyValue, 0, 0, @sResult, @lResultLen) = #ERROR_SUCCESS
ProcedureReturn sResult
EndIf
RegCloseKey_(lKey)
EndIf
EndIf
;}
CompilerEndSelect
EndProcedure
Debug System_GetCPUInfo()
|