[Arakhnę-Dev] [145] C++ -> C |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
Revision: 145
Author: galland
Date: 2010-05-18 08:42:57 +0200 (Tue, 18 May 2010)
Log Message:
-----------
C++ -> C
Modified Paths:
--------------
trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.h
trunk/arakhneVmutils/native/josuuid/src/main/native/osmacro.h
trunk/arakhneVmutils/native/josuuid/src/main/native/winos.h
Added Paths:
-----------
trunk/arakhneVmutils/native/josuuid/src/main/native/OperatingSystemJNI.c
trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.c
trunk/arakhneVmutils/native/josuuid/src/main/native/winos.c
Removed Paths:
-------------
trunk/arakhneVmutils/native/josuuid/src/main/native/OperatingSystemJNI.cpp
trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.cpp
trunk/arakhneVmutils/native/josuuid/src/main/native/winos.cpp
Copied: trunk/arakhneVmutils/native/josuuid/src/main/native/OperatingSystemJNI.c (from rev 140, trunk/arakhneVmutils/native/josuuid/src/main/native/OperatingSystemJNI.cpp)
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/OperatingSystemJNI.c (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/OperatingSystemJNI.c 2010-05-18 06:42:57 UTC (rev 145)
@@ -0,0 +1,65 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2005-2010 Stéphane GALLAND
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+
+#ifdef DEBUG
+# warning THE LIBRARY IS COMPILED WITH DEBUG INFORMATION
+#endif
+
+#include <jni.h>
+#include <stdlib.h>
+
+#include "org_arakhne_vmutil_OperatingSystem.h"
+#include "josuuid.h"
+
+/*
+ * Class: org_arakhne_vmutil_OperatingSystem
+ * Method: getOSSerialNumber
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL
+Java_org_arakhne_vmutil_OperatingSystem_getOSSerialNumber
+(JNIEnv * env, jclass clazz) {
+ jstring jSerial = NULL;
+ char* cSerial = getOSSerial();
+ if (cSerial!=NULL) {
+ jSerial = (*env)->NewStringUTF (env, cSerial);
+ free(cSerial);
+ }
+ return jSerial;
+}
+
+
+/*
+ * Class: org_arakhne_vmutil_OperatingSystem
+ * Method: getOSUUID
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL
+Java_org_arakhne_vmutil_OperatingSystem_getOSUUID
+(JNIEnv *env, jclass clazz) {
+ jstring jUUID = NULL;
+ char* cUUID = getOSUUID();
+ if (cUUID!=NULL) {
+ jUUID = (*env)->NewStringUTF (env, cUUID);
+ free(cUUID);
+ }
+ return jUUID;
+}
Deleted: trunk/arakhneVmutils/native/josuuid/src/main/native/OperatingSystemJNI.cpp
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/OperatingSystemJNI.cpp 2010-05-18 06:42:48 UTC (rev 144)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/OperatingSystemJNI.cpp 2010-05-18 06:42:57 UTC (rev 145)
@@ -1,65 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2005-2008 Stéphane GALLAND
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- * This program is free software; you can redistribute it and/or modify
- */
-
-#ifdef DEBUG
-# warning THE LIBRARY IS COMPILED WITH DEBUG INFORMATION
-#endif
-
-#include <jni.h>
-#include <stdlib.h>
-
-#include "org_arakhne_vmutil_OperatingSystem.h"
-#include "josuuid.h"
-
-/*
- * Class: org_arakhne_vmutil_OperatingSystem
- * Method: getOSSerialNumber
- * Signature: ()Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL
-Java_org_arakhne_vmutil_OperatingSystem_getOSSerialNumber
-(JNIEnv * env, jclass clazz) {
- jstring jSerial = NULL;
- char* cSerial = getOSSerial();
- if (cSerial!=NULL) {
- jSerial = env->NewStringUTF (cSerial);
- free(cSerial);
- }
- return jSerial;
-}
-
-
-/*
- * Class: org_arakhne_vmutil_OperatingSystem
- * Method: getOSUUID
- * Signature: ()Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL
-Java_org_arakhne_vmutil_OperatingSystem_getOSUUID
-(JNIEnv *env, jclass clazz) {
- jstring jUUID = NULL;
- char* cUUID = getOSUUID();
- if (cUUID!=NULL) {
- jUUID = env->NewStringUTF (cUUID);
- free(cUUID);
- }
- return jUUID;
-}
Copied: trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.c (from rev 140, trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.cpp)
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.c (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.c 2010-05-18 06:42:57 UTC (rev 145)
@@ -0,0 +1,194 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2005-2010 Stéphane GALLAND
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+
+#ifdef DEBUG
+# warning THE LIBRARY IS COMPILED WITH DEBUG INFORMATION
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "osmacro.h"
+
+#ifdef __WINDOWS__
+# include <windows.h>
+# include "winos.h"
+# define WINUUID_PART_COUNT 4
+static char hexCharacters[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+#else
+# include <unistd.h>
+# define DWORD unsigned long int
+#endif
+
+#include "josuuid.h"
+
+/* Remove white spaces at the begining and at the end of a string */
+static void trim(char** text) {
+ char* t;
+ unsigned long startIdx, endIdx;
+ unsigned long len, i;
+ if ((text==NULL)||(*text==NULL)) return;
+ len = strlen(*text);
+ // Search starting character
+ for(startIdx=0; startIdx<len; startIdx++) {
+ if (!isspace((*text)[startIdx])) break;
+ }
+ if (startIdx>=len) {
+ free(*text);
+ *text = strdup("");
+ return;
+ }
+ // Search ending character
+ for(endIdx=len-1; endIdx>=0; endIdx--) {
+ if (!isspace((*text)[endIdx])) break;
+ }
+ if (endIdx<0) {
+ free(*text);
+ *text = strdup("");
+ return;
+ }
+ // Create the new string
+ t = (char*)malloc(sizeof(char)*(endIdx-startIdx+2));
+ for(i=0; startIdx<=endIdx; i++, startIdx++) {
+ t[i] = (*text)[startIdx];
+ }
+ t[i] = '\0';
+ free(*text);
+ *text = t;
+}
+
+#ifndef __WINDOWS__
+/* Run the specified shell command and replies its standard output */
+static char* runCommand(const char* cmd) {
+ FILE* cmdOutput;
+ char* result = NULL;
+
+ cmdOutput = popen(cmd, "r");
+
+ if (cmdOutput!=NULL) {
+ char buffer[128];
+ unsigned long i,j, count = 0;
+ unsigned long charCount;
+
+ charCount = fread(buffer, sizeof(char), 128, cmdOutput);
+ while (charCount>0) {
+ result = (char*)realloc(result,sizeof(char)*(count+charCount+1));
+ for(i=0, j=count; i<charCount; i++, j++) {
+ result[j] = buffer[i];
+ }
+ count += charCount;
+ result[count] = '\0';
+ charCount = fread(buffer, sizeof(char), 128, cmdOutput);
+ }
+
+ pclose(cmdOutput);
+ }
+
+ return result;
+}
+#endif
+
+/* Replies the serial number of the system */
+char* getOSSerial() {
+#ifdef __WINDOWS__
+ DWORD size = 0;
+ BYTE* data = NULL;
+ if (getWindowsSerial(&data, &size)) {
+ unsigned long i;
+ char* serial = (char*)malloc(sizeof(char)*size);
+ for(i=0; i<size; i++) {
+ serial[i] = data[i];
+ }
+ free(data);
+ trim(&serial);
+ return serial;
+ }
+ return NULL;
+#else
+ char* result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.serial");
+ if (result!=NULL) {
+ trim(&result);
+ }
+ else {
+ result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key smbios.system.serial");
+ if (result!=NULL) {
+ trim(&result);
+ }
+ }
+ return result;
+#endif
+}
+
+/* Replies the UUID of the system */
+char* getOSUUID() {
+#ifdef __WINDOWS__
+ DWORD size;
+ BYTE* data;
+ if (getWindowsSerial(&data, &size)) {
+ unsigned long i, j, k, totalSize = 2*(size-1);
+ char* serial = (char*)malloc(sizeof(char)*(totalSize+(totalSize/WINUUID_PART_COUNT)+2));
+ char characterToTreat;
+ short b0, b1;
+ BOOL lastIsSeparator = FALSE;
+
+ for(i=0, j=0, k=WINUUID_PART_COUNT; i<size; i++) {
+ characterToTreat = data[i];
+ if (isalnum(characterToTreat)) {
+ b0 = (characterToTreat & 0x0F) ^ 0x0F;
+ b1 = ((characterToTreat & 0xF0) >> 4) ^ 0x0F;
+ serial[j++] = hexCharacters[b0];
+ serial[j++] = hexCharacters[b1];
+ k --;
+ if (k<=0) {
+ serial[j++] = '-';
+ k = WINUUID_PART_COUNT;
+ lastIsSeparator = TRUE;
+ }
+ else {
+ lastIsSeparator = FALSE;
+ }
+ }
+ }
+ if (lastIsSeparator) j--;
+ serial[j] = '\0';
+ free(data);
+
+ trim(&serial);
+
+ return serial;
+ }
+ return NULL;
+#else
+ char* result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.uuid");
+ if (result!=NULL) {
+ trim(&result);
+ }
+ else {
+ result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key smbios.system.uuid");
+ if (result!=NULL) {
+ trim(&result);
+ }
+ }
+ return result;
+#endif
+}
Deleted: trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.cpp
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.cpp 2010-05-18 06:42:48 UTC (rev 144)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.cpp 2010-05-18 06:42:57 UTC (rev 145)
@@ -1,193 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2005-2008 Stéphane GALLAND
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- * This program is free software; you can redistribute it and/or modify
- */
-
-#ifdef DEBUG
-# warning THE LIBRARY IS COMPILED WITH DEBUG INFORMATION
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "osmacro.h"
-
-#ifdef __WINDOWS__
-# include <windows.h>
-# include "winos.h"
-# define WINUUID_PART_COUNT 4
-static char hexCharacters[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
-#else
-# include <unistd.h>
-# define DWORD unsigned long int
-#endif
-
-#include "josuuid.h"
-
-/* Remove white spaces at the begining and at the end of a string */
-static void trim(char** text) {
- char* t;
- unsigned long startIdx, endIdx;
- unsigned long len, i;
- if ((text==NULL)||(*text==NULL)) return;
- len = strlen(*text);
- // Search starting character
- for(startIdx=0; startIdx<len; startIdx++) {
- if (!isspace((*text)[startIdx])) break;
- }
- if (startIdx>=len) {
- free(*text);
- *text = strdup("");
- return;
- }
- // Search ending character
- for(endIdx=len-1; endIdx>=0; endIdx--) {
- if (!isspace((*text)[endIdx])) break;
- }
- if (endIdx<0) {
- free(*text);
- *text = strdup("");
- return;
- }
- // Create the new string
- t = (char*)malloc(sizeof(char)*(endIdx-startIdx+2));
- for(i=0; startIdx<=endIdx; i++, startIdx++) {
- t[i] = (*text)[startIdx];
- }
- t[i] = '\0';
- free(*text);
- *text = t;
-}
-
-#ifndef __WINDOWS__
-/* Run the specified shell command and replies its standard output */
-static char* runCommand(const char* cmd) {
- FILE* cmdOutput;
- char* result = NULL;
-
- cmdOutput = popen(cmd, "r");
-
- if (cmdOutput!=NULL) {
- char buffer[128];
- unsigned long i,j, count = 0;
- unsigned long charCount;
-
- charCount = fread(buffer, sizeof(char), 128, cmdOutput);
- while (charCount>0) {
- result = (char*)realloc(result,sizeof(char)*(count+charCount+1));
- for(i=0, j=count; i<charCount; i++, j++) {
- result[j] = buffer[i];
- }
- count += charCount;
- result[count] = '\0';
- charCount = fread(buffer, sizeof(char), 128, cmdOutput);
- }
-
- pclose(cmdOutput);
- }
-
- return result;
-}
-#endif
-
-/* Replies the serial number of the system */
-char* getOSSerial() {
-#ifdef __WINDOWS__
- DWORD size = 0;
- BYTE* data = NULL;
- if (getWindowsSerial(&data, &size)) {
- char* serial = new char[size];
- for(unsigned long i=0; i<size; i++) {
- serial[i] = data[i];
- }
- free(data);
- trim(&serial);
- return serial;
- }
- return NULL;
-#else
- char* result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.serial");
- if (result!=NULL) {
- trim(&result);
- }
- else {
- result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key smbios.system.serial");
- if (result!=NULL) {
- trim(&result);
- }
- }
- return result;
-#endif
-}
-
-/* Replies the UUID of the system */
-char* getOSUUID() {
-#ifdef __WINDOWS__
- DWORD size;
- BYTE* data;
- if (getWindowsSerial(&data, &size)) {
- unsigned long i, j, k, totalSize = 2*(size-1);
- char* serial = (char*)malloc(sizeof(char)*(totalSize+(totalSize/WINUUID_PART_COUNT)+2));
- char characterToTreat;
- short b0, b1;
- bool lastIsSeparator = false;
-
- for(i=0, j=0, k=WINUUID_PART_COUNT; i<size; i++) {
- characterToTreat = data[i];
- if (isalnum(characterToTreat)) {
- b0 = (characterToTreat & 0x0F) ^ 0x0F;
- b1 = ((characterToTreat & 0xF0) >> 4) ^ 0x0F;
- serial[j++] = hexCharacters[b0];
- serial[j++] = hexCharacters[b1];
- k --;
- if (k<=0) {
- serial[j++] = '-';
- k = WINUUID_PART_COUNT;
- lastIsSeparator = true;
- }
- else {
- lastIsSeparator = false;
- }
- }
- }
- if (lastIsSeparator) j--;
- serial[j] = '\0';
- free(data);
-
- trim(&serial);
-
- return serial;
- }
- return NULL;
-#else
- char* result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.uuid");
- if (result!=NULL) {
- trim(&result);
- }
- else {
- result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key smbios.system.uuid");
- if (result!=NULL) {
- trim(&result);
- }
- }
- return result;
-#endif
-}
Modified: trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.h
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.h 2010-05-18 06:42:48 UTC (rev 144)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.h 2010-05-18 06:42:57 UTC (rev 145)
@@ -1,7 +1,7 @@
/*
* $Id$
*
- * Copyright (C) 2005-2009 Stéphane GALLAND
+ * Copyright (C) 2005-2010 Stéphane GALLAND
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Modified: trunk/arakhneVmutils/native/josuuid/src/main/native/osmacro.h
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/osmacro.h 2010-05-18 06:42:48 UTC (rev 144)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/osmacro.h 2010-05-18 06:42:57 UTC (rev 145)
@@ -1,7 +1,7 @@
/*
* $Id$
*
- * Copyright (C) 2009 Stéphane GALLAND
+ * Copyright (C) 2009-10 Stéphane GALLAND
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Copied: trunk/arakhneVmutils/native/josuuid/src/main/native/winos.c (from rev 140, trunk/arakhneVmutils/native/josuuid/src/main/native/winos.cpp)
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/winos.c (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/winos.c 2010-05-18 06:42:57 UTC (rev 145)
@@ -0,0 +1,178 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2005-2010 Stéphane GALLAND
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+
+#include "osmacro.h"
+
+#ifdef DEBUG
+# warning THE LIBRARY IS COMPILED WITH DEBUG INFORMATION
+#endif
+
+#ifndef __WINDOWS__
+# error You may use Windows compiler
+#endif
+
+#include <windows.h>
+#include <winreg.h>
+#include "winos.h"
+
+#include <stdio.h>
+
+/* Replies the windows version */
+BOOL getWindowsVersion(DWORD *version) {
+ OSVERSIONINFO osinfo;
+ osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ if (!GetVersionEx(&osinfo))
+ return FALSE;
+
+ DWORD platform_id = osinfo.dwPlatformId;
+ DWORD minor_version = osinfo.dwMinorVersion;
+ DWORD major_version = osinfo.dwMajorVersion;
+ DWORD build_number = osinfo.dwBuildNumber & 0xFFFF; // Win 95 needs this
+
+ if ((platform_id == VER_PLATFORM_WIN32_WINDOWS) && (major_version == 4)) {
+ if ((minor_version < 10) && (build_number == 950))
+ *version = W95;
+ else if ((minor_version < 10) &&
+ ((build_number > 950) && (build_number <= 1080)))
+ *version = W95SP1;
+ else if ((minor_version < 10) && (build_number > 1080))
+ *version = W95OSR2;
+ else if ((minor_version == 10) && (build_number == 1998))
+ *version = W98;
+ else if ((minor_version == 10) &&
+ ((build_number > 1998) && (build_number < 2183)))
+ *version = W98SP1;
+ else if ((minor_version == 10) && (build_number >= 2183))
+ *version = W98SE;
+ else if (minor_version == 90)
+ *version = WME;
+ }
+ else if (platform_id == VER_PLATFORM_WIN32_NT) {
+ if ((major_version == 3) && (minor_version == 51))
+ *version = WNT351;
+ else if ((major_version == 4) && (minor_version == 0))
+ *version = WNT4;
+ else if ((major_version == 5) && (minor_version == 0))
+ *version = W2K;
+ else if ((major_version == 5) && (minor_version == 1))
+ *version = WXP;
+ }
+ else if (platform_id == VER_PLATFORM_WIN32_CE) {
+ *version = WCE;
+ }
+
+ return TRUE;
+}
+
+/* Read the value of a registrery value */
+BOOL readRegistry(const CHAR* key, const CHAR* valueName, BYTE** data, DWORD* size) {
+ return readRegistryI(key,valueName,data,size,1);
+}
+
+/* Read the value of a registrery value */
+BOOL readRegistryI(const CHAR* key, const CHAR* valueName, BYTE** data, DWORD* size, BYTE allocationFactor) {
+ HKEY hKey = NULL; // registry handle, kept open between calls
+ LONG ret;
+
+ ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_ALL_ACCESS /*KEY_QUERY_VALUE*/, &hKey);
+ if (ret != ERROR_SUCCESS) return FALSE;
+
+ // Get the size of the value
+ DWORD valueSize=0;
+ ret = RegQueryValueEx(
+ hKey,
+ valueName,
+ NULL, //reserved
+ NULL, //type
+ NULL, //data
+ &valueSize);
+ if (ret != ERROR_SUCCESS) return FALSE;
+ if (size!=NULL) {
+ *size = valueSize;
+ }
+ // Read the value data
+ BYTE* valueData;
+
+ if (data!=NULL) {
+ DWORD valueType;
+ valueData = (BYTE*)malloc(sizeof(BYTE)*valueSize*allocationFactor);
+ ret = RegQueryValueEx(
+ hKey,
+ valueName,
+ NULL, //reserved
+ &valueType, //type
+ valueData,
+ &valueSize);
+ RegCloseKey(hKey);
+ if (ret != ERROR_SUCCESS) {
+ free(valueData);
+ return FALSE;
+ }
+ *data = valueData;
+ }
+ else {
+ RegCloseKey(hKey);
+ }
+
+ return TRUE;
+}
+
+/* Replies the serial number of the system */
+BOOL getWindowsSerial(BYTE** serial, DWORD* serialSize) {
+ return getWindowsSerialI(serial, serialSize, 1);
+}
+
+/* Replies the serial number of the system */
+BOOL getWindowsSerialI(BYTE** serial, DWORD* serialSize, BYTE allocationFactor) {
+ DWORD version;
+ getWindowsVersion(&version);
+
+ CHAR* reg_path;
+ if ((version >=WNT_FIRST) && (version <= WNT_LAST))
+ reg_path = (CHAR*)("Software\\Microsoft\\Windows NT\\CurrentVersion");
+ else
+ reg_path = (CHAR*)("Software\\Microsoft\\Windows\\CurrentVersion");
+
+ DWORD size = 0;
+ BYTE* data = NULL;
+ if (!readRegistryI(reg_path, "ProductId", &data, &size, allocationFactor)) {
+ if ((version >=WNT_FIRST) && (version <= WNT_LAST)) {
+ reg_path = (CHAR*)("Software\\Microsoft\\Windows\\CurrentVersion");
+ if (!readRegistryI(reg_path, "ProductId", &data, &size, allocationFactor))
+ return FALSE;
+ }
+ else return FALSE;
+ }
+
+ if (serial!=NULL) {
+ *serial = data;
+ }
+ else {
+ free(data);
+ }
+
+ if (serialSize!=NULL) {
+ *serialSize = size;
+ }
+
+ return TRUE;
+}
Deleted: trunk/arakhneVmutils/native/josuuid/src/main/native/winos.cpp
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/winos.cpp 2010-05-18 06:42:48 UTC (rev 144)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/winos.cpp 2010-05-18 06:42:57 UTC (rev 145)
@@ -1,178 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2005-2009 Stéphane GALLAND
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- * This program is free software; you can redistribute it and/or modify
- */
-
-#include "osmacro.h"
-
-#ifdef DEBUG
-# warning THE LIBRARY IS COMPILED WITH DEBUG INFORMATION
-#endif
-
-#ifndef __WINDOWS__
-# error You may use Windows compiler
-#endif
-
-#include <windows.h>
-#include <winreg.h>
-#include "winos.h"
-
-#include <stdio.h>
-
-/* Replies the windows version */
-BOOL getWindowsVersion(DWORD *version) {
- OSVERSIONINFO osinfo;
- osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-
- if (!GetVersionEx(&osinfo))
- return false;
-
- DWORD platform_id = osinfo.dwPlatformId;
- DWORD minor_version = osinfo.dwMinorVersion;
- DWORD major_version = osinfo.dwMajorVersion;
- DWORD build_number = osinfo.dwBuildNumber & 0xFFFF; // Win 95 needs this
-
- if ((platform_id == VER_PLATFORM_WIN32_WINDOWS) && (major_version == 4)) {
- if ((minor_version < 10) && (build_number == 950))
- *version = W95;
- else if ((minor_version < 10) &&
- ((build_number > 950) && (build_number <= 1080)))
- *version = W95SP1;
- else if ((minor_version < 10) && (build_number > 1080))
- *version = W95OSR2;
- else if ((minor_version == 10) && (build_number == 1998))
- *version = W98;
- else if ((minor_version == 10) &&
- ((build_number > 1998) && (build_number < 2183)))
- *version = W98SP1;
- else if ((minor_version == 10) && (build_number >= 2183))
- *version = W98SE;
- else if (minor_version == 90)
- *version = WME;
- }
- else if (platform_id == VER_PLATFORM_WIN32_NT) {
- if ((major_version == 3) && (minor_version == 51))
- *version = WNT351;
- else if ((major_version == 4) && (minor_version == 0))
- *version = WNT4;
- else if ((major_version == 5) && (minor_version == 0))
- *version = W2K;
- else if ((major_version == 5) && (minor_version == 1))
- *version = WXP;
- }
- else if (platform_id == VER_PLATFORM_WIN32_CE) {
- *version = WCE;
- }
-
- return true;
-}
-
-/* Read the value of a registrery value */
-BOOL readRegistry(const CHAR* key, const CHAR* valueName, BYTE** data, DWORD* size) {
- return readRegistryI(key,valueName,data,size,1);
-}
-
-/* Read the value of a registrery value */
-BOOL readRegistryI(const CHAR* key, const CHAR* valueName, BYTE** data, DWORD* size, BYTE allocationFactor) {
- HKEY hKey = NULL; // registry handle, kept open between calls
- LONG ret;
-
- ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_ALL_ACCESS /*KEY_QUERY_VALUE*/, &hKey);
- if (ret != ERROR_SUCCESS) return false;
-
- // Get the size of the value
- DWORD valueSize=0;
- ret = RegQueryValueEx(
- hKey,
- valueName,
- NULL, //reserved
- NULL, //type
- NULL, //data
- &valueSize);
- if (ret != ERROR_SUCCESS) return false;
- if (size!=NULL) {
- *size = valueSize;
- }
- // Read the value data
- BYTE* valueData;
-
- if (data!=NULL) {
- DWORD valueType;
- valueData = (BYTE*)malloc(sizeof(BYTE)*valueSize*allocationFactor);
- ret = RegQueryValueEx(
- hKey,
- valueName,
- NULL, //reserved
- &valueType, //type
- valueData,
- &valueSize);
- RegCloseKey(hKey);
- if (ret != ERROR_SUCCESS) {
- free(valueData);
- return false;
- }
- *data = valueData;
- }
- else {
- RegCloseKey(hKey);
- }
-
- return true;
-}
-
-/* Replies the serial number of the system */
-BOOL getWindowsSerial(BYTE** serial, DWORD* serialSize) {
- return getWindowsSerialI(serial, serialSize, 1);
-}
-
-/* Replies the serial number of the system */
-BOOL getWindowsSerialI(BYTE** serial, DWORD* serialSize, BYTE allocationFactor) {
- DWORD version;
- getWindowsVersion(&version);
-
- CHAR* reg_path;
- if ((version >=WNT_FIRST) && (version <= WNT_LAST))
- reg_path = (CHAR*)("Software\\Microsoft\\Windows NT\\CurrentVersion");
- else
- reg_path = (CHAR*)("Software\\Microsoft\\Windows\\CurrentVersion");
-
- DWORD size = 0;
- BYTE* data = NULL;
- if (!readRegistryI(reg_path, "ProductId", &data, &size, allocationFactor)) {
- if ((version >=WNT_FIRST) && (version <= WNT_LAST)) {
- reg_path = (CHAR*)("Software\\Microsoft\\Windows\\CurrentVersion");
- if (!readRegistryI(reg_path, "ProductId", &data, &size, allocationFactor))
- return false;
- }
- else return false;
- }
-
- if (serial!=NULL) {
- *serial = data;
- }
- else {
- free(data);
- }
-
- if (serialSize!=NULL) {
- *serialSize = size;
- }
-
- return true;
-}
Modified: trunk/arakhneVmutils/native/josuuid/src/main/native/winos.h
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/winos.h 2010-05-18 06:42:48 UTC (rev 144)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/winos.h 2010-05-18 06:42:57 UTC (rev 145)
@@ -1,7 +1,7 @@
/*
* $Id$
*
- * Copyright (C) 2005-2009 Stéphane GALLAND
+ * Copyright (C) 2005-2010 Stéphane GALLAND
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public