Win32OperatingSystem.st
changeset 23502 4826a1e286e2
parent 23491 113096ef5a36
child 23510 a51aaf76fd25
--- a/Win32OperatingSystem.st	Thu Nov 01 20:27:40 2018 +0100
+++ b/Win32OperatingSystem.st	Fri Nov 02 09:55:31 2018 +0100
@@ -1020,7 +1020,6 @@
     "Modified: 7.1.1997 / 19:36:11 / stefan"
 ! !
 
-
 !Win32OperatingSystem class methodsFor:'OS signal constants'!
 
 sigABRT
@@ -17154,40 +17153,48 @@
 
 valueNamed:aValueName put:datum
     "store a value; the value type depends upon the stored value:
-	ByteArray       -> REG_BINARY
-	String          -> REG_SZ
-	Array of string -> REG_MULTI_SZ
-	Integer         -> REG_DWORD
-	nil             -> REG_NONE
+        ByteArray       -> REG_BINARY
+        String          -> REG_SZ
+        Array of string -> REG_MULTI_SZ
+        Integer         -> REG_DWORD
+        nil             -> REG_NONE
      aValueName name may be a string or unicode16string.
     "
 
     |nameA nameW dataA dataW stringArray errorNumber badArg |
 
-    nameA := aValueName asSingleByteStringIfPossible.
-    nameA isSingleByteString ifFalse:[
-	nameW := aValueName asUnicode16StringZ.
-	nameA := nil
-    ].
-
     "/ when value is a unicode string, we'll need a unicode name as well.
     "/ when name is a unicode name, we'll need a unicode string as well
-    dataA := datum.
-    dataA isString ifTrue:[
-	dataA := datum asSingleByteStringIfPossible.
-	dataA isSingleByteString ifFalse:[
-	    nameW isNil ifTrue:[
-		nameW := aValueName asUnicode16StringZ.
-		nameA := nil.
-	    ].
-	    dataW := datum asUnicode16StringZ.
-	    dataA := nil.
-	] ifTrue:[
-	    nameA isNil ifTrue:[
-		dataW := datum asUnicode16StringZ.
-		dataA := nil.
-	    ].
-	].
+    "sr: the unicode case must have priority,
+     to be able to set/force REG_EXPAND_SZ"
+    (datum isString 
+    and:[datum isUnicode16String]) ifTrue:[
+        nameW := aValueName asUnicode16StringZ.
+        dataW := datum asUnicode16StringZ.
+    ] ifFalse:[
+        nameA := aValueName asSingleByteStringIfPossible.
+        nameA isSingleByteString ifFalse:[
+            nameW := aValueName asUnicode16StringZ.
+            nameA := nil
+        ].
+
+        dataA := datum.
+        dataA isString ifTrue:[
+            dataA := datum asSingleByteStringIfPossible.
+            dataA isSingleByteString ifFalse:[
+                nameW isNil ifTrue:[
+                    nameW := aValueName asUnicode16StringZ.
+                    nameA := nil.
+                ].
+                dataW := datum asUnicode16StringZ.
+                dataA := nil.
+            ] ifTrue:[
+                nameA isNil ifTrue:[
+                    dataW := datum asUnicode16StringZ.
+                    dataA := nil.
+                ].
+            ].
+        ].
     ].
 
 %{
@@ -17203,133 +17210,131 @@
     char *_nameA = NULL;
 
     badArg = true;
-
     if (__isExternalAddressLike(__INST(handle))) {
-	myKey = (HKEY)__externalAddressVal(__INST(handle));
-
-	if (__isStringLike(nameA)) {
-	    _nameA = __unicode16StringVal(aValueName);
-	}
-	if (__isUnicode16String(nameW)) {
-	    _nameW = __unicode16StringVal(nameW);
-	}
-	if ((_nameA == NULL) && (_nameW == NULL)) {
-	    errorNumber = __MKSMALLINT(-1);
-	    goto getOutOfHere;
-	}
-
-	badArg = false;
-
-	if (datum == nil) {
-	    valueType = REG_NONE;
-	    dataSize = 0;
-	} else if (__isSmallInteger(datum)) {
-	    valueType = REG_DWORD;
-	    val = __intVal(datum);
-	    dataPointer = (unsigned char *)(&val);
-	    dataSize = sizeof(val);
-	} else if (__isStringLike(dataA)) {
-	    valueType = REG_SZ;
-	    dataPointer = __stringVal(dataA);
-	    dataSize = __stringSize(dataA) + 1;
-	} else if (__isUnicode16String(dataW)) {
-	    valueType = REG_SZ;
-	    dataPointer = __unicode16StringVal(dataW);
-	    dataSize = (__unicode16StringSize(dataW) + 1)*2;
-	    nameA = NULL; // must use WideChar-interface
-	} else if (__Class(datum) == ByteArray) {
-	    valueType = REG_BINARY;
-	    dataPointer = __ByteArrayInstPtr(datum)->ba_element;
-	    dataSize = __byteArraySize(datum);
-	} else if (__Class(datum) == LargeInteger) {
-	    valueType = REG_DWORD;
-	    val = __longIntVal(datum);
-	    if (val) {
-		dataPointer = (unsigned char *)(&val);
-		dataSize = sizeof(val);
-	    } else {
-		datumOk = 0;
-	    }
-	} else if (__Class(datum) == Array) {
-	    int i = 0, ns = 0, totalSize = 0;
-
-	    nameW = NULL; // must use Ascii-interface (for now)
-
-	    valueType = REG_MULTI_SZ;
-
-	    /*
-	     * must allocate a local buffer
-	     * find size ...
-	     */
-	    for (i=0; i<__arraySize(datum); i++) {
-		OBJ s = __ArrayInstPtr(datum)->a_element[i];
-
-		if (__isStringLike(s)) {
-		    totalSize += __stringSize(s) + 1;
-		} else {
-		    datumOk = 0;
-		    break;
-		}
-		ns++;
-	    }
-	    if (datumOk) {
-		char *cp;
-
-		/*
-		 * allocate and fill...
-		 */
-		totalSize ++;
-		dataPointer = (char *)(malloc(totalSize));
-		mustFreeData = 1;
-		cp = dataPointer;
-		for (i=0; i<__arraySize(datum); i++) {
-		    OBJ s = __ArrayInstPtr(datum)->a_element[i];
-
-		    strcpy(cp, __stringVal(s));
-		    cp += __stringSize(s);
-		    *cp++ = '\0';
-		}
-		*cp++ = '\0';
-		dataSize = totalSize;
-	    }
-	} else {
-	    datumOk = 0;
-	    badArg = true;
-	}
-
-	if (datumOk) {
-	    if (_nameA != NULL) {
-		ret = RegSetValueExA(myKey, _nameA,
-				    0, valueType,
-				    dataPointer, dataSize);
-	    } else {
-		ret = RegSetValueExW(myKey, _nameW,
-				    0, valueType,
-				    dataPointer, dataSize);
-	    }
-
-	    if (mustFreeData) {
-		free(dataPointer);
-	    }
-	    if (ret == ERROR_SUCCESS) {
-		RETURN (true);
-	    }
-	    if ((ret != ERROR_PATH_NOT_FOUND)
-	     && (ret != ERROR_FILE_NOT_FOUND)) {
-		errorNumber = __MKSMALLINT(ret);
-	    }
-	}
+        myKey = (HKEY)__externalAddressVal(__INST(handle));
+
+        if (__isStringLike(nameA)) {
+            _nameA = __unicode16StringVal(aValueName);
+        }
+        if (__isUnicode16String(nameW)) {
+            _nameW = __unicode16StringVal(nameW);
+        }
+        if ((_nameA == NULL) && (_nameW == NULL)) {
+            errorNumber = __MKSMALLINT(-1);
+            goto getOutOfHere;
+        }
+
+        badArg = false;
+        if (datum == nil) {
+            valueType = REG_NONE;
+            dataSize = 0;
+        } else if (__isSmallInteger(datum)) {
+            valueType = REG_DWORD;
+            val = __intVal(datum);
+            dataPointer = (unsigned char *)(&val);
+            dataSize = sizeof(val);
+        } else if (__isStringLike(dataA)) {
+            valueType = REG_SZ;
+            dataPointer = __stringVal(dataA);
+            dataSize = __stringSize(dataA) + 1;
+        } else if (__isUnicode16String(dataW)) {
+            valueType = REG_EXPAND_SZ;
+            dataPointer = __unicode16StringVal(dataW);
+            dataSize = (__unicode16StringSize(dataW) + 1)*2;
+            nameA = NULL; // must use WideChar-interface
+        } else if (__Class(datum) == ByteArray) {
+            valueType = REG_BINARY;
+            dataPointer = __ByteArrayInstPtr(datum)->ba_element;
+            dataSize = __byteArraySize(datum);
+        } else if (__Class(datum) == LargeInteger) {
+            valueType = REG_DWORD;
+            val = __longIntVal(datum);
+            if (val) {
+                dataPointer = (unsigned char *)(&val);
+                dataSize = sizeof(val);
+            } else {
+                datumOk = 0;
+            }
+        } else if (__Class(datum) == Array) {
+            int i = 0, ns = 0, totalSize = 0;
+
+            nameW = NULL; // must use Ascii-interface (for now)
+
+            valueType = REG_MULTI_SZ;
+
+            /*
+             * must allocate a local buffer
+             * find size ...
+             */
+            for (i=0; i<__arraySize(datum); i++) {
+                OBJ s = __ArrayInstPtr(datum)->a_element[i];
+
+                if (__isStringLike(s)) {
+                    totalSize += __stringSize(s) + 1;
+                } else {
+                    datumOk = 0;
+                    break;
+                }
+                ns++;
+            }
+            if (datumOk) {
+                char *cp;
+
+                /*
+                 * allocate and fill...
+                 */
+                totalSize ++;
+                dataPointer = (char *)(malloc(totalSize));
+                mustFreeData = 1;
+                cp = dataPointer;
+                for (i=0; i<__arraySize(datum); i++) {
+                    OBJ s = __ArrayInstPtr(datum)->a_element[i];
+
+                    strcpy(cp, __stringVal(s));
+                    cp += __stringSize(s);
+                    *cp++ = '\0';
+                }
+                *cp++ = '\0';
+                dataSize = totalSize;
+            }
+        } else {
+            datumOk = 0;
+            badArg = true;
+        }
+
+        if (datumOk) {
+            if (_nameA != NULL) {
+                ret = RegSetValueExA(myKey, _nameA,
+                                    0, valueType,
+                                    dataPointer, dataSize);
+            } else {
+                ret = RegSetValueExW(myKey, _nameW,
+                                    0, valueType,
+                                    dataPointer, dataSize);
+            }
+
+            if (mustFreeData) {
+                free(dataPointer);
+            }
+            if (ret == ERROR_SUCCESS) {
+                RETURN (true);
+            }
+            if ((ret != ERROR_PATH_NOT_FOUND)
+             && (ret != ERROR_FILE_NOT_FOUND)) {
+                errorNumber = __MKSMALLINT(ret);
+            }
+        }
     }
   getOutOfHere:
     /* intentional null statement to make recent gcc happy */
     ;
 %}.
     errorNumber notNil ifTrue:[
-	badArg ifTrue:[
-	    self primitiveFailed:'bad argument'
-	] ifFalse:[
-	    (OperatingSystem errorHolderForNumber:errorNumber) reportError.
-	]
+        badArg ifTrue:[
+            self primitiveFailed:'bad argument'
+        ] ifFalse:[
+            (OperatingSystem errorHolderForNumber:errorNumber) reportError.
+        ]
     ].
     ^ false
 
@@ -17354,6 +17359,8 @@
      key := self key:'HKEY_CURRENT_USER\Software\ExeptTest\Foo'.
      key valueNamed:'BLA10αβ' put:'αβγ123αβγ'
     "
+
+    "Modified: / 31-10-2018 / 14:32:59 / sr"
 ! !
 
 !Win32OperatingSystem::RegistryEntry methodsFor:'enumeration'!