File: SystemInfo.cs

package info (click to toggle)
sysinfo 0.7-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 1,832 kB
  • ctags: 1,140
  • sloc: cs: 2,933; sh: 701; makefile: 115; xml: 98
file content (408 lines) | stat: -rw-r--r-- 9,946 bytes parent folder | download | duplicates (2)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
// Filename: SystemInfo.cs
// Contains functions to extract information displayed in System category

using System;
using System.IO;
using System.Diagnostics;

namespace Sysinfo {
	
	public class SystemInfo {
		
		//global variables
		public String system_release = "unknown";
		
		public String system_gnomev = "unknown";
		public String system_gnomeo = "unknown";
		
		public String system_kernelv = "unknown";
		public String system_kernelb = "unknown";
		
		public String system_uptime = "unknown";
		
		public String system_ostype = "unknown";
		public String system_gcc = "unknown";
		public String system_xorg = "unknown";
		
		public String system_hostname = "unknown";
		
		public String distro = "";
		
		//read release info
		public void Release() {

		    String temp;
			
			try {
				
				if (File.Exists("/etc/redhat-release")) {
					using (TextReader textread = File.OpenText("/etc/redhat-release")) {
						
						distro = "RedHat";
						system_release = textread.ReadLine();
					}
				}
				
				if (File.Exists("/etc/fedora-release")) {
					using (TextReader textread = File.OpenText("/etc/fedora-release")) {
						
						distro = "Fedora Core";
						system_release = textread.ReadLine();
					}
				}
				
				if (File.Exists("/etc/SuSE-release")) {
					using (TextReader textread = File.OpenText("/etc/SuSE-release")) {
						
						distro = "SuSE";
						system_release = textread.ReadLine();
					}
				}
				
				if (File.Exists("/etc/slackware-version")) {
					using (TextReader textread = File.OpenText("/etc/slackware-version")) {
						
						distro = "Slackware";
						system_release = textread.ReadLine();
					}
				}
				
				if (File.Exists("/etc/debian_version")) {
					using (TextReader textread = File.OpenText("/etc/debian_version")) {
						
						if (Directory.Exists("/usr/share/ubuntu-docs") || File.Exists("/usr/share/pixmaps/splash/ubuntu-splash.png"))
							distro = "Ubuntu";
						else
							distro = "Debian";
						
						system_release = textread.ReadLine();
					}
				}
				
				if (File.Exists("/etc/mandrake-release")) {
					using (TextReader textread = File.OpenText("/etc/mandrake-release")) {
						
						distro = "Mandrake";
						system_release = textread.ReadLine();
					}
				}
				
				if (File.Exists("/etc/mandrive-release")) {
					using (TextReader textread = File.OpenText("/etc/mandrive-release")) {
						
						distro = "Mandriva";
						system_release = textread.ReadLine();
					}
				}
				
				if (File.Exists("/etc/yellowdog-release")) {
					using (TextReader textread = File.OpenText("/etc/yellowdog-release")) {
						
						distro = "Yellowdog";
						system_release = textread.ReadLine();
					}
				}
				
				if (File.Exists("/etc/sun-release")) {
					using (TextReader textread = File.OpenText("/etc/sun-release")) {
						
						distro = "Sun";
						system_release = textread.ReadLine();
					}
				}
				
				if (File.Exists("/etc/gentoo-release")) {
					using (TextReader textread = File.OpenText("/etc/gentoo-release")) {
						
						distro = "Gentoo";
						system_release = textread.ReadLine();
					}
				}
				
				if (File.Exists("/etc/release")) {
					using (TextReader textread = File.OpenText("/etc/release")) {
						
						distro = "Generic";
						system_release = textread.ReadLine();
					}
				}
				
				if (File.Exists("/etc/lsb-release")) {
					using (TextReader textread = File.OpenText("/etc/lsb-release")) {

					    while ( (temp = textread.ReadLine()) != null ) {

					    	// get distro
					    	if ( temp.StartsWith("DISTRIB_ID=") ) {
					    		distro = temp.Substring(11);
					    	}

					    	// get release
					    	if ( temp.StartsWith("DISTRIB_RELEASE=") ) {
					    		system_release = temp.Substring(16);
					    	}

					    	// get codename
 					    	if ( temp.StartsWith("DISTRIB_CODENAME=") ) {
					    		system_release = String.Concat(system_release, " (", temp.Substring(17), ")");
					    	}

                        }
                        system_release = String.Concat(distro, " ", system_release);
					}
				}

			} catch (FileNotFoundException ex) {  Console.WriteLine( ex );  }
		}
		
		//read GNOME version
		public void Gnome() {
			
			String temp;
			Boolean gnomeB = false;
			
			//Fedora,RedHat,Debian,Ubuntu,...
			String gnome_about = "/usr/share/gnome-about/gnome-version.xml";
			//SuSE
			if (File.Exists("/opt/gnome/share/gnome-about/gnome-version.xml"))
				gnome_about = "/opt/gnome/share/gnome-about/gnome-version.xml";
			
			try {
				
				using (TextReader textread = File.OpenText(gnome_about)) {
					
					while ( gnomeB == false ) {
						
						temp = textread.ReadLine();
						
						//get version from xml
						if ( temp.EndsWith("platform>")) {

							temp = temp.Remove(0, 12);
							temp = temp.Remove(temp.IndexOf("</platform>"), 11);
							system_gnomev = temp;
						}
						
						if ( temp.EndsWith("minor>")) {

							temp = temp.Remove(0, 9);
							temp = temp.Remove(temp.IndexOf("</minor>"), 8);
							system_gnomev = system_gnomev + "." + temp;
						}
						
						if ( temp.EndsWith("micro>")) {

							temp = temp.Remove(0, 9);
							temp = temp.Remove(temp.IndexOf("</micro>"), 8);
							system_gnomev = system_gnomev + "." + temp;
						}
						
						//get distributor
						if ( temp.EndsWith("distributor>")) {

							temp = temp.Remove(0, 15);
							temp = temp.Remove(temp.IndexOf("</distributor>"), 14);
							system_gnomeo = temp;
						}
						
						//get build date
						if ( temp.EndsWith("date>")) {

							temp = temp.Remove(0, 8);
							temp = temp.Remove(temp.IndexOf("</date>"), 7);
							system_gnomeo = system_gnomeo + " " + temp;
							
							gnomeB = true;
						}

					}

				}

			}
			catch (FileNotFoundException ex) {  Console.WriteLine( ex );  }
			catch (DirectoryNotFoundException ex) {  Console.WriteLine( ex );  }
		}
		
		//read kernel version
		public void Kernel() {
			
			try {
				
				//get kernel version
				using (TextReader textread = File.OpenText("/proc/sys/kernel/osrelease")) {
					
					system_kernelv = textread.ReadLine();
				}
				
				//get kernel build date
				using (TextReader textread = File.OpenText("/proc/sys/kernel/version")) {
					
					system_kernelb = textread.ReadLine();
				}
			}catch (FileNotFoundException ex) {  Console.WriteLine( ex );  }
		}
		
		//read uptime
		public void Uptime() {

			Int32 days, hours, minutes;
			String temp = "";
					
			try {
			
				//get uptime
				using (TextReader textread = File.OpenText("/proc/uptime")) {
					
					temp = textread.ReadLine();
				}
			}catch (Exception ex) {  Console.WriteLine( ex );  }
			
			//I need just the first number from uptime
			temp = temp.Remove(temp.IndexOf("."), temp.Length - temp.IndexOf(".") );
			
			//string to int conversion - days
			days = Int32.Parse(temp);
			days = days / 86400;
			
			//hours
			hours = Int32.Parse(temp);
			hours = (hours / 3600) - (days * 24);
			
			//minutes
			minutes = Int32.Parse(temp);
			minutes = (minutes / 60) - ((days * 1440) + (hours * 60));
			
			system_uptime = days + " days " + hours + " h " + minutes + " min";
		}
		
		//read ostype
		public void Ostype() {
			
			try {
				
				//get ostype
				using (TextReader textread = File.OpenText("/proc/sys/kernel/ostype")) {
					
					system_ostype = textread.ReadLine();
				}
			}catch (FileNotFoundException ex) {  Console.WriteLine( ex );  }
		}
		
		//read gcc version
		public void Gccv() {
			
			try {
				
				//run command and read output
				//gcc version
				Process proc1 = new Process();
				proc1.StartInfo.FileName = "gcc";
				proc1.StartInfo.Arguments = "-dumpversion";
				proc1.StartInfo.UseShellExecute = false;
				proc1.StartInfo.RedirectStandardOutput = true;
				proc1.Start();
				proc1.WaitForExit(); 
				
				system_gcc = proc1.StandardOutput.ReadToEnd();
				system_gcc = system_gcc.Remove(system_gcc.Length - 1, 1);
				proc1.Close();
				
				//gcc distibutor machine
				Process proc2 = new Process();
				proc2.StartInfo.FileName = "gcc";
				proc2.StartInfo.Arguments = "-dumpmachine";
				proc2.StartInfo.UseShellExecute = false;
				proc2.StartInfo.RedirectStandardOutput = true;
				proc2.Start();
				proc2.WaitForExit();
				
				system_gcc = system_gcc + " (" + proc2.StandardOutput.ReadToEnd();
				system_gcc = system_gcc.Remove(system_gcc.Length - 1, 1) + ")";
				proc2.Close();
				
			}
			catch (System.ComponentModel.Win32Exception ex) {
				
				system_gcc = "no gcc detected";
				
				Console.WriteLine( ex );  
			}

		}
		
		//read xorg version
		public void Xorg() {
			
			String temp;
			Boolean xorgB = false;
			int index;
			
			try {
				
				//get xorg version
				using (TextReader textread = File.OpenText("/var/log/Xorg.0.log")) {
					
					while ( xorgB == false ) {
						
						temp = textread.ReadLine();

						// EOF
						if (temp == null) {

							break;
						}

						// Blank line
						if (temp.Trim().Length == 0) {

							continue;
						}
						
						//version
						index = temp.IndexOf("X Window System Version");

						if (index >= 0 && system_xorg == "unknown") {

							system_xorg = temp.Substring(index + 24);
						}

						index = temp.IndexOf("X.Org X Server");

						if (index >= 0 && system_xorg == "unknown") {

							system_xorg = temp.Substring(index + 15);
						}
						
						//build date
						index = temp.IndexOf("Build Date");

						if (index >= 0) {
							
							system_xorg = system_xorg + " (" + temp.Substring(index + 12) + ")";
							xorgB = true;
						}

					}
				}
			}catch (FileNotFoundException ex) {  Console.WriteLine( ex );  }
		}
		
		//read hostname
		public void Hostname() {
			
			try {
				
				//get hostname
				using (TextReader textread = File.OpenText("/proc/sys/kernel/hostname")) {
					
					system_hostname = textread.ReadLine();
				}
			}catch (FileNotFoundException ex) {  Console.WriteLine( ex );  }
		}

		
	}
}

//ghaefb