Win32OperatingSystem.st
changeset 14514 e45969ab90ac
parent 14449 f49e77252f99
child 14519 14ebce6fccae
--- a/Win32OperatingSystem.st	Fri Nov 09 10:08:52 2012 +0100
+++ b/Win32OperatingSystem.st	Tue Nov 13 14:43:04 2012 +0100
@@ -13543,139 +13543,176 @@
 examples
 "
     retrieve an existing entry by key:
-									[exBegin]
-	|k|
-
-	k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X'
-									[exEnd]
+                                                                        [exBegin]
+        |k|
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X'
+                                                                        [exEnd]
 
 
     retrieve a non-existing entry by key:
-									[exBegin]
-	|k|
-
-	k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\xxx'
-									[exEnd]
+                                                                        [exBegin]
+        |k|
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\xxx'
+                                                                        [exEnd]
 
 
     ask a keys value:
-									[exBegin]
-	|k|
-
-	k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion'.
-	Transcript show:'Windows serial NR:'; showCR:(k valueNamed:'ProductId').
-
-	k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X'.
-	Transcript showCR:(k valueNamed:'CurrentVersion').
-									[exEnd]
+                                                                        [exBegin]
+        |k|
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion'.
+        Transcript show:'Windows serial NR:'; showCR:(k valueNamed:'ProductId').
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X'.
+        Transcript showCR:(k valueNamed:'CurrentVersion').
+                                                                        [exEnd]
 
 
     create a sub-key (if not already present):
-									[exBegin]
-	|k subKey|
-
-	k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X'.
-	subKey := k createSubKeyNamed:'RegistryDemo'
-									[exEnd]
+                                                                        [exBegin]
+        |k subKey|
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X'.
+        subKey := k createSubKeyNamed:'RegistryDemo'
+                                                                        [exEnd]
 
 
     change a keys value:
-									[exBegin]
-	|k|
-
-	k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X\RegistryDemo'.
-	k valueNamed:'FooBarBaz' put:'a foo bar baz string'.
-									[exEnd]
+                                                                        [exBegin]
+        |k|
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X\RegistryDemo'.
+        k valueNamed:'FooBarBaz' put:'a foo bar baz string'.
+                                                                        [exEnd]
 
     delete a value:
-									[exBegin]
-	|k|
-
-	k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X\RegistryDemo'.
-	k deleteValueNamed:'FooBarBaz'.
-									[exEnd]
+                                                                        [exBegin]
+        |k|
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X\RegistryDemo'.
+        k deleteValueNamed:'FooBarBaz'.
+                                                                        [exEnd]
 
     delete a key:
-									[exBegin]
-	|k|
-
-	k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X'.
-	k deleteSubKeyNamed:'RegistryDemo'.
-									[exEnd]
+                                                                        [exBegin]
+        |k|
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X'.
+        k deleteSubKeyNamed:'RegistryDemo'.
+                                                                        [exEnd]
 
     enumerate keys:
-									[exBegin]
-	|k|
-
-	k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software'.
-	k subKeysDo:[:subKey |
-	    Transcript showCR:subKey path
-	]
-									[exEnd]
+                                                                        [exBegin]
+        |k|
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software'.
+        k subKeysDo:[:subKey |
+            Transcript showCR:subKey path
+        ]
+                                                                        [exEnd]
 
     enumerate all keys (recursive):
-									[exBegin]
-	|k|
-
-	k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software'.
-	k allSubKeysDo:[:subKey |
-	    Transcript showCR:subKey path
-	]
-									[exEnd]
+                                                                        [exBegin]
+        |k|
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\Software'.
+        k allSubKeysDo:[:subKey |
+            Transcript showCR:subKey path
+        ]
+                                                                        [exEnd]
 
     fetch value by index:
-									[exBegin]
-	|k|
-
-	k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\SOFTWARE\eXept\Smalltalk/X'.
-	Transcript showCR:(k valueNameAtIndex:0)
-									[exEnd]
+                                                                        [exBegin]
+        |k|
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\SOFTWARE\eXept\Smalltalk/X'.
+        Transcript showCR:(k valueNameAtIndex:0)
+                                                                        [exEnd]
 
 
     enumerate value names:
-									[exBegin]
-	|k|
-
-	k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\SOFTWARE\eXept\Smalltalk/X'.
-	k valueNamesDo:[:nm  |
-	   Transcript showCR:nm.
-	]
-									[exEnd]
+                                                                        [exBegin]
+        |k|
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\SOFTWARE\eXept\Smalltalk/X'.
+        k valueNamesDo:[:nm  |
+           Transcript showCR:nm.
+        ]
+                                                                        [exEnd]
 
     enumerate values:
-									[exBegin]
-	|k|
-
-	k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\SOFTWARE\eXept\Smalltalk/X'.
-	k valueNamesAndValuesDo:[:nm :val |
-	    Transcript showCR:(nm , ' -> ' , val storeString).
-	]
-									[exEnd]
+                                                                        [exBegin]
+        |k|
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\SOFTWARE\eXept\Smalltalk/X'.
+        k valueNamesAndValuesDo:[:nm :val |
+            Transcript showCR:(nm , ' -> ' , val storeString).
+        ]
+                                                                        [exEnd]
 
     search for a value (where does NT store the domain ?):
-									[exBegin]
-	|k|
-
-	k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\System'.
-	k subKeysDo:[:subKey |
-	    subKey subKeysDo:[:subSubKey |
-		|tcp params|
-
-		(subSubKey path asLowercase endsWith:'services') ifTrue:[
-		    tcp := subSubKey subKeyNamed:'tcpip'.
-		    tcp notNil ifTrue:[
-			params := tcp subKeyNamed:'parameters'.
-			params notNil ifTrue:[
-			    Transcript showCR:'Domain is found in ' , params path ,
-					' value: ' , (params valueNamed:'Domain').
-			    params close.
-			].
-			tcp close.
-		    ]
-		]
-	    ]
-	]
-									[exEnd]
+                                                                        [exBegin]
+        |k|
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\System'.
+        k subKeysDo:[:subKey |
+            subKey subKeysDo:[:subSubKey |
+                |tcp params|
+
+                (subSubKey path asLowercase endsWith:'services') ifTrue:[
+                    tcp := subSubKey subKeyNamed:'tcpip'.
+                    tcp notNil ifTrue:[
+                        params := tcp subKeyNamed:'parameters'.
+                        params notNil ifTrue:[
+                            Transcript showCR:'Domain is found in ' , params path ,
+                                        ' value: ' , (params valueNamed:'Domain').
+                            params close.
+                        ].
+                        tcp close.
+                    ]
+                ]
+            ]
+        ]
+                                                                        [exEnd]
+    register an exe for shell-open:
+                                                                        [exBegin]
+        |k stx shell open cmd st_af edit st owl list id|
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_CURRENT_USER\Software\Classes\Applications'.
+        stx := k createSubKeyNamed:'SmalltalkX.exe'.
+        shell := stx createSubKeyNamed:'shell'.
+        open := shell createSubKeyNamed:'open'.
+        cmd := open createSubKeyNamed:'command'.
+        cmd defaultValue:(Character doubleQuote asString,OperatingSystem nameOfSTXExecutable,Character doubleQuote,
+                         ' ',Character doubleQuote,'%1',Character doubleQuote).
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_CURRENT_USER\Software\Classes'.
+        st_af := k createSubKeyNamed:'st_auto_file'.
+        shell := st_af createSubKeyNamed:'shell'.
+        open := shell createSubKeyNamed:'open'.
+        cmd := open createSubKeyNamed:'command'.
+        cmd defaultValue:(Character doubleQuote asString,OperatingSystem nameOfSTXExecutable,Character doubleQuote,
+                         ' --open ',Character doubleQuote,'%1',Character doubleQuote).
+        edit := shell createSubKeyNamed:'edit'.
+        cmd := edit createSubKeyNamed:'command'.
+        cmd defaultValue:(Character doubleQuote asString,OperatingSystem nameOfSTXExecutable,Character doubleQuote,
+                         ' --edit ',Character doubleQuote,'%1',Character doubleQuote).
+
+        k := Win32OperatingSystem registryEntry key:'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts'.
+        st := k createSubKeyNamed:'.st'.
+        owl := st createSubKeyNamed:'OpenWithList'.
+        list := owl valueNames.
+        (list contains:[:k | (owl valueNamed:k) = 'SmalltalkX.exe']) ifTrue:[
+            Transcript showCR:'already registered.'.
+        ] ifFalse:[
+            id := ($a to:$z) detect:[:k | (list includes:(k asString)) not] ifNone:nil.
+            owl valueNamed:id asString put:'SmalltalkX.exe'.
+        ]
+                                                                        [exEnd]
+
+
 
 
 "
@@ -14390,24 +14427,25 @@
 
     if (__isExternalAddressLike(__INST(handle))
      && __isSmallInteger(valueIndex)) {
-	myKey = (HKEY)__externalAddressVal(__INST(handle));
-	if ((_retVal = RegEnumValueA(myKey, __intVal(valueIndex),
-			 nameBuffer, &nameSize,
-			 NULL,
-			 &valueType,
-			 NULL, NULL)) == ERROR_SUCCESS) {
-	    nameBuffer[nameSize] = '\0';
-	    valueName = __MKSTRING(nameBuffer);
-	} else {
-	    if ((_retVal != ERROR_PATH_NOT_FOUND)
-	     && (_retVal != ERROR_FILE_NOT_FOUND)) {
-		errorNumber = __MKSMALLINT(_retVal);
-	    }
-	}
+        myKey = (HKEY)__externalAddressVal(__INST(handle));
+        if ((_retVal = RegEnumValueA(myKey, __intVal(valueIndex),
+                         nameBuffer, &nameSize,
+                         NULL,
+                         &valueType,
+                         NULL, NULL)) == ERROR_SUCCESS) {
+            nameBuffer[nameSize] = '\0';
+            valueName = __MKSTRING(nameBuffer);
+        } else {
+            if ((_retVal != ERROR_PATH_NOT_FOUND)
+             && (_retVal != ERROR_FILE_NOT_FOUND)
+             && (_retVal != ERROR_NO_MORE_ITEMS)) {
+                errorNumber = __MKSMALLINT(_retVal);
+            }
+        }
     }
 %}.
     errorNumber notNil ifTrue:[
-	(OperatingSystem errorHolderForNumber:errorNumber) reportError.
+        (OperatingSystem errorHolderForNumber:errorNumber) reportError.
     ].
     ^ valueName
 
@@ -14857,12 +14895,12 @@
 
     idx := 0.
     [true] whileTrue:[
-	valueName := self valueNameAtIndex:idx.
-	valueName isNil ifTrue:[
-	    ^self
-	].
-	aBlock value:valueName.
-	idx := idx + 1.
+        valueName := self valueNameAtIndex:idx.
+        valueName isNil ifTrue:[
+            ^self
+        ].
+        aBlock value:valueName.
+        idx := idx + 1.
     ]
 ! !
 
@@ -16459,11 +16497,11 @@
 !Win32OperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.439 2012-10-29 11:40:57 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.440 2012-11-13 13:43:04 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.439 2012-10-29 11:40:57 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.440 2012-11-13 13:43:04 cg Exp $'
 !
 
 version_SVN