[Mono-list] [PATCH] Hard coded System.Environment.OSVersion...
Sebastien Pouliot
spouliot@videotron.ca
Fri, 23 Apr 2004 16:40:22 -0400
This is a multi-part message in MIME format.
--Boundary_(ID_Jw6ius2t0DS40/mOqn2pBg)
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7BIT
Here's the patches. There may be a better way on Linux to get a version...
The following code...
static void Main(string[] args)
{
Console.WriteLine (Environment.OSVersion.ToString ());
Console.WriteLine (Environment.OSVersion.Platform);
Console.WriteLine (Environment.OSVersion.Version);
}
Should display on Linux...
[poupou@rh9 poupou]$ mono version.exe
Unix 2.4.20.8
128
2.4.20.8
[poupou@rh9 poupou]$ uname -r
2.4.20-8smp
and on Windows XP SP1...
spouliot@farscape ~/cvs/mcs/class/corlib
$ mono version.exe
Microsoft Windows NT 5.1.2600.0
Win32NT
5.1.2600.0
spouliot@farscape ~/cvs/mcs/class/corlib
$ version.exe
Microsoft Windows NT 5.1.2600.0
Win32NT
5.1.2600.0
Sebastien Pouliot
http://pages.infinit.net/ctech/poupou.html
-----Original Message-----
From: mono-list-admin@lists.ximian.com
[mailto:mono-list-admin@lists.ximian.com]On Behalf Of Sebastien Pouliot
Sent: 22 avril 2004 07:33
To: jonathan.cooper@syntegra.com; mark.easton@blinksoftware.co.uk
Cc: mono-list@lists.ximian.com
Subject: RE: [Mono-list] Hard coded System.Environment.OSVersion...
I have a (local) patch that returns the true version number on Windows and
the value of "uname -r" on Linux.
I'll clean it up and sent it for review.
Sebastien Pouliot
http://pages.infinit.net/ctech/poupou.html
-----Original Message-----
From: mono-list-admin@lists.ximian.com
[mailto:mono-list-admin@lists.ximian.com]On Behalf Of
jonathan.cooper@syntegra.com
Sent: 22 avril 2004 04:54
To: mark.easton@blinksoftware.co.uk
Cc: mono-list@lists.ximian.com
Subject: RE: [Mono-list] Hard coded System.Environment.OSVersion...
5.1.2600.0 was the original build number of Windows XP, and I suspect is a
placeholder until the required functionality is completed (very much like
the
class which returns the system drives is currently hard coded to "c:" and
"a:" for windows for now)
Jon
-----Original Message-----
From: mono-list-admin@lists.ximian.com
[mailto:mono-list-admin@lists.ximian.com] On Behalf Of Mark Easton
Sent: Wednesday, April 21, 2004 11:45 AM
To: mono-list@lists.ximian.com
Subject: [Mono-list] Hard coded System.Environment.OSVersion...
Okay, it's been a bit of a while since I pestered the list, so here I am
with
another pesky question.
I know the System.Environment.OSVersion property is hard coded to 5.1.2600.0
(which PNET have copied) but I don't have a complete understanding of why
this is.
I was thinking that some OSes like GNU/Linux don't have definitive version
numbers (although I guess the kernel build gets close), but since a number
of
OSes do have definitive version numbers, and I right in assuming the value
might be retrieved from an internal call in due course?
Cheers,
Mark
_______________________________________________
Mono-list maillist - Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list
********************************************************************
This email may contain information which is privileged or confidential. If
you are not the intended recipient of this email, please notify the sender
immediately and delete it without reading, copying, storing, forwarding or
disclosing its contents to any other person
Thank you
Check us out at http://www.btsyntegra.com
********************************************************************
_______________________________________________
Mono-list maillist - Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list
_______________________________________________
Mono-list maillist - Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list
--Boundary_(ID_Jw6ius2t0DS40/mOqn2pBg)
Content-type: application/octet-stream; name=version.diff
Content-transfer-encoding: 7bit
Content-disposition: attachment; filename=version.diff
? Environment.diff
? version.diff
Index: ChangeLog
===================================================================
RCS file: /cvs/public/mcs/class/corlib/System/ChangeLog,v
retrieving revision 1.758
diff -u -r1.758 ChangeLog
--- ChangeLog 23 Apr 2004 15:02:26 -0000 1.758
+++ ChangeLog 23 Apr 2004 19:58:43 -0000
@@ -1,3 +1,9 @@
+2004-04-xx Sebastien Pouliot <sebastien@ximian.com>
+
+ * Environment.cs: Completed OSVersion property.
+ * Version.cs: Added internal CreateFromString() to "try" to build the
+ best version number form the specified string.
+
2004-04-23 Sebastien Pouliot <sebastien@ximian.com>
* Environment.cs: Better support for GetFolderPath (same results as MS
Index: Environment.cs
===================================================================
RCS file: /cvs/public/mcs/class/corlib/System/Environment.cs,v
retrieving revision 1.63
diff -u -r1.63 Environment.cs
--- Environment.cs 23 Apr 2004 15:02:26 -0000 1.63
+++ Environment.cs 23 Apr 2004 19:58:43 -0000
@@ -151,15 +151,18 @@
get;
}
+ [MethodImplAttribute (MethodImplOptions.InternalCall)]
+ internal static extern string GetOSVersionString ();
+
/// <summary>
/// Gets the current OS version information
/// </summary>
- [MonoTODO("Correct version")]
public static OperatingSystem OSVersion {
get {
- if (os == null)
- os = new OperatingSystem (Platform, new Version (5,1,2600,0));
-
+ if (os == null) {
+ Version v = Version.CreateFromString (GetOSVersionString ());
+ os = new OperatingSystem (Platform, v);
+ }
return os;
}
}
Index: Version.cs
===================================================================
RCS file: /cvs/public/mcs/class/corlib/System/Version.cs,v
retrieving revision 1.13
diff -u -r1.13 Version.cs
--- Version.cs 8 Mar 2004 19:42:28 -0000 1.13
+++ Version.cs 23 Apr 2004 19:58:43 -0000
@@ -267,5 +267,52 @@
{
return v1.CompareTo (v2) <= 0;
}
+
+ // a very gentle way to construct a Version object which takes
+ // the first four numbers in a string as the version
+ internal static Version CreateFromString (string info)
+ {
+ int major = 0;
+ int minor = 0;
+ int build = 0;
+ int revision = 0;
+ int state = 1;
+ int number = UNDEFINED; // string may not begin with a digit
+
+ for (int i=0; i < info.Length; i++) {
+ char c = info [i];
+ if (Char.IsDigit (c)) {
+ if (number < 0) {
+ number = (c - '0');
+ }
+ else {
+ number = (number * 10) + (c - '0');
+ }
+ }
+ else if (number >= 0) {
+ // assign
+ switch (state) {
+ case 1:
+ major = number;
+ break;
+ case 2:
+ minor = number;
+ break;
+ case 3:
+ build = number;
+ break;
+ case 4:
+ revision = number;
+ break;
+ }
+ number = -1;
+ state ++;
+ }
+ // ignore end of string
+ if (state == 5)
+ break;
+ }
+ return new Version (major, minor, build, revision);
+ }
}
}
--Boundary_(ID_Jw6ius2t0DS40/mOqn2pBg)
Content-type: application/octet-stream; name=runtime.diff
Content-transfer-encoding: quoted-printable
Content-disposition: attachment; filename=runtime.diff
Index: mono/metadata/environment.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/mono/mono/metadata/environment.c,v
retrieving revision 1.1
diff -u -r1.1 environment.c
--- mono/metadata/environment.c 23 Jan 2003 17:46:25 -0000 1.1
+++ mono/metadata/environment.c 23 Apr 2004 20:00:01 -0000
@@ -1,16 +1,24 @@
/*
* environment.c: System.Environment support internal calls
*
- * Author:
+ * Authors:
* Dick Porter (dick@ximian.com)
+ * Sebastien Pouliot (sebastien@ximian.com)
*
* (C) 2002 Ximian, Inc.
+ * (C) 2004 Novell (http://www.novell.com)
*/
=20
#include <config.h>
#include <glib.h>
=20
+#include <mono/metadata/appdomain.h>
#include <mono/metadata/environment.h>
+#include <mono/metadata/exception.h>
+
+#ifndef PLATFORM_WIN32
+#include <sys/utsname.h>
+#endif
=20
static gint32 exitcode=3D0;
=20
@@ -22,4 +30,36 @@
void mono_environment_exitcode_set (gint32 value)
{
exitcode=3Dvalue;
+}
+
+/* note: we better manipulate the string in managed code (easier and =
safer) */
+MonoString*
+ves_icall_System_Environment_GetOSVersionString (void)
+{
+#ifdef PLATFORM_WIN32
+ OSVERSIONINFO verinfo;
+
+ MONO_ARCH_SAVE_REGS;
+
+ verinfo.dwOSVersionInfoSize =3D sizeof (OSVERSIONINFO);
+ if (GetVersionEx (&verinfo)) {
+ char version [64];
+ // maximum string length is 35 bytes
+ // 3 x 10 bytes per number, 1 byte for 0, 3 x 1 byte for dots, 1 for =
NULL
+ sprintf (version, "%ld.%ld.%ld.0",=20
+ verinfo.dwMajorVersion,
+ verinfo.dwMinorVersion,
+ verinfo.dwBuildNumber);
+ return mono_string_new (mono_domain_get (), version);
+ }
+#else
+ struct utsname name;
+
+ MONO_ARCH_SAVE_REGS;
+
+ if (uname (&name) =3D=3D 0) {
+ return mono_string_new (mono_domain_get (), name.release);
+ }
+#endif
+ return mono_string_new (mono_domain_get (), "0.0.0.0");
}
Index: mono/metadata/environment.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/mono/mono/metadata/environment.h,v
retrieving revision 1.1
diff -u -r1.1 environment.h
--- mono/metadata/environment.h 23 Jan 2003 17:46:25 -0000 1.1
+++ mono/metadata/environment.h 23 Apr 2004 20:00:01 -0000
@@ -13,4 +13,6 @@
extern gint32 mono_environment_exitcode_get (void);
extern void mono_environment_exitcode_set (gint32 value);
=20
+extern MonoString* ves_icall_System_Environment_GetOSVersionString =
(void);
+
#endif /* _MONO_METADATA_ENVIRONMENT_H_ */
Index: mono/metadata/icall.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/mono/mono/metadata/icall.c,v
retrieving revision 1.466
diff -u -r1.466 icall.c
--- mono/metadata/icall.c 23 Apr 2004 14:58:44 -0000 1.466
+++ mono/metadata/icall.c 23 Apr 2004 20:00:02 -0000
@@ -4959,7 +4959,8 @@
{"GetCommandLineArgs", mono_runtime_get_main_args},
{"GetEnvironmentVariable", =
ves_icall_System_Environment_GetEnvironmentVariable},
{"GetEnvironmentVariableNames", =
ves_icall_System_Environment_GetEnvironmentVariableNames},
- {"GetMachineConfigPath", =
ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
+ {"GetMachineConfigPath", =
ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
+ {"GetOSVersionString", =
ves_icall_System_Environment_GetOSVersionString},
{"GetWindowsFolderPath", =
ves_icall_System_Environment_GetWindowsFolderPath},
{"get_ExitCode", mono_environment_exitcode_get},
{"get_HasShutdownStarted", =
ves_icall_System_Environment_get_HasShutdownStarted},
--Boundary_(ID_Jw6ius2t0DS40/mOqn2pBg)--