Win32OperatingSystem.st
changeset 25235 5b21dbe1656b
parent 25225 37f7886845ca
child 25236 5710dec96cf9
--- a/Win32OperatingSystem.st	Tue Feb 04 12:29:20 2020 +0100
+++ b/Win32OperatingSystem.st	Tue Feb 04 12:29:30 2020 +0100
@@ -1723,6 +1723,28 @@
 
 !Win32OperatingSystem class methodsFor:'clipboard & console'!
 
+characterEncoderForConsoleOutput
+    "see what encoding is set in the console"
+
+    |cp outputEncoder|
+
+    ConsoleOutputEncoder isNil ifTrue:[
+        cp := self getConsoleOutputCP.
+        "/ should handle more codePages via GetConsoleOutputCP
+        outputEncoder := CharacterEncoder encoderNamed:('cp%1' bindWith:cp).
+        outputEncoder isNullEncoder ifTrue:[
+            "/ should we fallback here???
+            ^ nil
+        ].
+        ConsoleOutputEncoder := outputEncoder
+    ].
+    ^ outputEncoder
+
+    "
+     self characterEncoderForConsoleOutput
+    "
+!
+
 clipboardContainsBitmap
     "Answer whether the clipboard contains a bitmap."
 
@@ -11342,34 +11364,35 @@
 !Win32OperatingSystem class methodsFor:'regional settings'!
 
 country
-	"Answer the current system value for country."
-
-    ^self queryNationalProfileString: 'iCountry' default: 0
-
-    "
-	self country
+    "Answer the current system value for country."
+
+    ^ self queryNationalProfileString: 'iCountry' default: 0
+
+    "
+     self country
     "
 
     "Modified: / 22-12-2006 / 16:45:32 / User"
 !
 
 countryName
-	"Answer the current system value for country name."
-
-    ^self queryNationalProfileString: 'sCountry' default: 'Deutschland'
-
-    "
-	self countryName
+    "Answer the current system value for country name."
+
+    ^ self queryNationalProfileString: 'sCountry' default: 'Deutschland'
+
+    "
+     self countryName
     "
 
     "Modified: / 22-12-2006 / 16:45:32 / User"
 !
 
 dateFormat
-    "Answer the current system value for date format.
-     Answer DfMDY = Month-Day-Year
-	    DfDMY = Day-Month-Year
-	    DfYMD = Year-Month-Day."
+    "Answer the date format string to be used dep. on the OS system value for date format.
+     One of DfMDY = Month-Day-Year
+            DfDMY = Day-Month-Year
+            DfYMD = Year-Month-Day
+     is mapped to the ST/X dateFormatString %(mon)-%(day)-%(year)"
 
     |separatorString code|
 
@@ -11383,7 +11406,8 @@
     ^ '%(day)', separatorString, '%(mon)', separatorString, '%(year)'
 
     "
-     self dateFormat
+     self dateFormat 
+     Date today printStringFormat:(self dateFormat)
     "
 
     "Modified: / 22-12-2006 / 16:43:30 / User"
@@ -11391,156 +11415,169 @@
 !
 
 dateFormatCode
-	"Answer the current system value for date format.
-	 Answer DfMDY = Month-Day-Year = 0
-		DfDMY = Day-Month-Year = 1
-		DfYMD = Year-Month-Day = 2"
-
-    ^self queryNationalProfileInt: 'iDate' default: 0
-
-    "
-	self dateFormatCode
+    "Answer the current system value for date format.
+     Answer DfMDY = Month-Day-Year = 0
+            DfDMY = Day-Month-Year = 1
+            DfYMD = Year-Month-Day = 2
+    "
+
+    "/ this is somewhat outdated, but windows maps the initProfile query to
+    "/ a registry fetch (i.e. in HKEY_CURRENT_USER\Control Panel\International).
+    "/ Code should probably be changed to ask there...
+
+    ^ self queryNationalProfileInt: 'iDate' default: 0
+
+    "
+     self dateFormatCode
     "
 
     "Modified: / 22-12-2006 / 16:45:53 / User"
 !
 
 dateSeparator
-	"Answer the current system value for date separator."
-
-    ^self queryNationalProfileString: 'sDate' default: '/'
-
-    "
-	self dateSeparator
+    "Answer the current system value for date separator."
+
+    ^ self queryNationalProfileString:'sDate' default:'/'
+
+    "
+     self dateSeparator
     "
 
     "Modified: / 22-12-2006 / 16:45:32 / User"
 !
 
 decimalSeparator
-	"Answer the current system value for decimal separator."
-
-    ^self queryNationalProfileString: 'sDecimal' default: '.'
-
-    "
-	self decimalSeparator
+   "Answer the current system value for decimal separator."
+
+    ^ self queryNationalProfileString:'sDecimal' default:'.'
+
+    "
+     self decimalSeparator
     "
 
     "Created: / 22-12-2006 / 16:45:11 / User"
 !
 
 isDateFormatDMY
-	"Answer the current system value for date format.
-	 Answer DfMDY = Month-Day-Year
-		DfDMY = Day-Month-Year
-		DfYMD = Year-Month-Day."
-
-    ^self dateFormatCode = 1
+    "Answer true if the current system date format is DfDMY = Day-Month-Year"
+
+    ^ self dateFormatCode == 1
 
     "Created: / 18-01-2007 / 14:56:23 / User"
 !
 
 isDateFormatMDY
-	"Answer the current system value for date format.
-	 Answer DfMDY = Month-Day-Year
-		DfDMY = Day-Month-Year
-		DfYMD = Year-Month-Day."
-
-    ^self dateFormatCode = 0
+    "Answer true if the current system date format is DfMDY = Month-Day-Year"
+
+    ^ self dateFormatCode == 0
 
     "Created: / 18-01-2007 / 14:56:07 / User"
 !
 
 isDateFormatYMD
-	"Answer the current system value for date format.
-	 Answer DfMDY = Month-Day-Year
-		DfDMY = Day-Month-Year
-		DfYMD = Year-Month-Day."
-
-    ^self dateFormatCode = 2
+    "Answer true if the current system date format is DfYMD = Year-Month-Day"
+
+    ^ self dateFormatCode == 2
 
     "Created: / 18-01-2007 / 14:56:30 / User"
 !
 
 isTimeFormat12Hour
-	"Answer whether the current system time format is 12-hour."
-
-    ^self timeFormat = 0
+    "Answer whether the current system time format is 12-hour."
+
+    ^ self timeFormat = 0
 
     "Created: / 22-12-2006 / 16:48:17 / User"
 !
 
-primGetProfileInt: appName keyName: keyName default: anInt
-
+language
+    "Answer the current system value for country name.
+     Notice that windows uses a different format (iso 639-2/b ???), 
+     where the first two chars correspond to the standard iso language, 
+     and the 3 third char represents the territory (somehow).
+     US-english which is 'en-us', is in windows ENU,
+     GB-english which is 'en-gb', is in windows ENG,
+     German de-de, de-au, de-ch are DEU, DEA, DES respectively.
+     See ISO-3166 Country Codes / ISO-639 Language Codes"
+
+    ^ self queryNationalProfileString: 'sLanguage' default: 'ENG'
+
+    "
+     self language
+    "
+!
+
+primGetProfileInt:appName keyName:keyName default:anInt
     <apicall: uint32 "GetProfileIntA" ( lpstr lpstr uint32) module: "kernel32.dll" >
+
     ^self primitiveFailed
 
     "Created: / 22-12-2006 / 16:17:18 / User"
 !
 
 primGetProfileString: appName keyName: keyName default: defaultStr returnedString: retStr size: anInt
-
     <apicall: uint32 "GetProfileStringA" ( lpstr lpstr lpstr lpstr uint32) module: "kernel32.dll" >
+
     ^self primitiveFailed
 
     "Created: / 22-12-2006 / 16:20:23 / User"
 !
 
 queryNationalProfileInt: aKeyName default: defaultValue
-
     | answer |
-    answer := self primGetProfileInt: 'Intl'
-	keyName: aKeyName
-	default: -1 asUnsigned32.
-    ^answer = -1 asUnsigned32
-	ifTrue: [ defaultValue ]
-	ifFalse: [ answer ]
-
-"
-    self queryNationalProfileInt: 'iDate' default: 0
-"
+
+    answer := self primGetProfileInt: 'Intl' keyName: aKeyName default:(-1 asUnsigned32).
+    ^ answer = -1 asUnsigned32
+        ifTrue: [ defaultValue ]
+        ifFalse: [ answer ]
+
+    "
+     self queryNationalProfileInt: 'iDate' default: 0
+    "
 
     "Modified: / 22-12-2006 / 16:23:05 / User"
 !
 
 queryNationalProfileString: aKeyName default: defaultValue
-	"Answer the string value of key aKeyName in
-	the [Intl] application section of the WIN.INI profile file.
-	Answer defaultValue if aKeyName cannot be found."
+    "Answer the string value of key aKeyName in
+     the [Intl] application section of the WIN.INI profile file.
+     Answer defaultValue if aKeyName cannot be found."
+
     | extString result |
+
     extString := String new: 80.
-    result := self primGetProfileString: 'Intl'
-	keyName: aKeyName
-	default: ''
-	returnedString: extString
-	size: extString size.
-    ^result > 0
-	ifTrue: [extString copyFrom: 1 to: result]
-	ifFalse: [ defaultValue ]
+    result := self 
+                primGetProfileString:'Intl' keyName:aKeyName default:''
+                returnedString:extString
+                size:(extString size).
+    result > 0 ifTrue: [
+        ^ extString copyFrom: 1 to: result
+    ].
+    ^ defaultValue
 
     "Created: / 22-12-2006 / 16:13:01 / User"
 !
 
 thousandsSeparator
-	"Answer the current system value
-	for the thousands separator."
-
-    ^self queryNationalProfileString: 'sThousand' default: ','
-
-    "
-	self thousandsSeparator
+    "Answer the current system value
+     for the thousands separator."
+
+    ^ self queryNationalProfileString: 'sThousand' default: ','
+
+    "
+     self thousandsSeparator
     "
 
     "Created: / 22-12-2006 / 16:46:50 / User"
 !
 
 timeFormat
-	"Answer the current system value for time format."
-
-    ^self queryNationalProfileInt: 'iTime' default: 0
-
-    "
-	self timeFormat
+    "Answer the current system value for time format."
+
+    ^ self queryNationalProfileInt:'iTime' default: 0
+
+    "
+     self timeFormat
     "
 
     "Created: / 22-12-2006 / 16:48:27 / User"