ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/OSVersion/OSVersion.cpp
Revision: 368
Committed: 2008-08-23T02:44:00-07:00 (14 years, 3 months ago) by douglas
File size: 2360 byte(s)
Log Message:
Rearranged everything else.

File Contents

# Content
1 // OS Version
2 //
3 // Douglas Thrift
4 //
5 // OSVersion.cpp
6
7 #include <iostream>
8 #include <string>
9 #include <cstdlib>
10 #include <cstdio>
11 #include <cstring>
12
13 #ifndef _WIN32
14 #include <sys/utsname.h>
15 #else
16 #include <windows.h>
17 #endif // _WIN32
18
19 using namespace std;
20
21 int main(int argc, char* argv[])
22 {
23 string os;
24 string version;
25 string architecture;
26 string marketing;
27
28 #ifdef _WIN32
29 OSVERSIONINFO* computer = new OSVERSIONINFO;
30 computer->dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
31 GetVersionEx(computer);
32
33 os = computer->dwPlatformId == VER_PLATFORM_WIN32_NT ? "Windows NT" :
34 "Windows";
35 unsigned major = computer->dwMajorVersion;
36 unsigned minor = computer->dwMinorVersion;
37
38 delete computer;
39
40 SYSTEM_INFO* system = new SYSTEM_INFO;
41 GetSystemInfo(system);
42
43 switch (system->wProcessorArchitecture)
44 {
45 case PROCESSOR_ARCHITECTURE_INTEL:
46 architecture = "ix86";
47 break;
48 case PROCESSOR_ARCHITECTURE_MIPS:
49 architecture = "mips";
50 break;
51 case PROCESSOR_ARCHITECTURE_ALPHA:
52 architecture = "alpha";
53 break;
54 case PROCESSOR_ARCHITECTURE_PPC:
55 architecture = "ppc";
56 break;
57 case PROCESSOR_ARCHITECTURE_IA64:
58 architecture = "ia64";
59 break;
60 case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
61 architecture = "ix86_on_win64";
62 break;
63 case PROCESSOR_ARCHITECTURE_AMD64:
64 architecture = "amd64";
65 break;
66 default:
67 architecture = "unknown";
68 break;
69 }
70
71 char* cversion = new char[1024];
72 sprintf(cversion, "%u.%u", major, minor);
73 version = cversion;
74
75 delete [] cversion;
76
77 if (major == 4 && minor <= 3 && os != "Windows NT")
78 {
79 marketing = " [Windows 95]";
80 }
81 else if (major == 4 && minor == 10 && os != "Windows NT")
82 {
83 marketing = " [Windows 98]";
84 }
85 else if (major == 5 && minor == 0 && os == "Windows NT")
86 {
87 marketing = " [Windows 2000]";
88 }
89 else if (major == 4 && minor == 90 && os != "Windows NT")
90 {
91 marketing = " [Windows ME]";
92 }
93 else if (major == 5 && minor == 1 && os == "Windows NT")
94 {
95 marketing = " [Windows XP]";
96 }
97 else if (major == 5 && minor == 2 && os == "Windows NT")
98 {
99 marketing = " [Windows .NET Server]";
100 }
101 #else // _WIN32
102 struct utsname* computer = new struct utsname;
103 uname(computer);
104
105 os = computer->sysname;
106 version = computer->release;
107 architecture = computer->machine;
108
109 delete computer;
110 #endif // _WIN32
111 cout << os << " " << version << marketing << " " << architecture << "\n";
112
113 return 0;
114 }