Win32OperatingSystem.st
changeset 15076 f4c814ed8258
parent 15039 aad511684e79
child 15169 0cf7770d6e58
child 18045 c0c600e0d3b3
equal deleted inserted replaced
15075:57e8939d96cc 15076:f4c814ed8258
     8  inclusion of the above copyright notice.   This software may not
     8  inclusion of the above copyright notice.   This software may not
     9  be provided or otherwise made available to, or used by, any
     9  be provided or otherwise made available to, or used by, any
    10  other person.  No title to or ownership of the software is
    10  other person.  No title to or ownership of the software is
    11  hereby transferred.
    11  hereby transferred.
    12 "
    12 "
       
    13 'From Smalltalk/X, Version:6.2.3.0 on 10-04-2013 at 09:59:01'                   !
       
    14 
    13 "{ Package: 'stx:libbasic' }"
    15 "{ Package: 'stx:libbasic' }"
    14 
    16 
    15 AbstractOperatingSystem subclass:#Win32OperatingSystem
    17 AbstractOperatingSystem subclass:#Win32OperatingSystem
    16 	instanceVariableNames:''
    18 	instanceVariableNames:''
    17 	classVariableNames:'Initialized HostName DomainName CurrentDirectory'
    19 	classVariableNames:'Initialized HostName DomainName CurrentDirectory'
   131 OSHandle subclass:#Win32IOHandle
   133 OSHandle subclass:#Win32IOHandle
   132 	instanceVariableNames:''
   134 	instanceVariableNames:''
   133 	classVariableNames:'Lobby'
   135 	classVariableNames:'Lobby'
   134 	poolDictionaries:''
   136 	poolDictionaries:''
   135 	privateIn:Win32OperatingSystem
   137 	privateIn:Win32OperatingSystem
       
   138 !
       
   139 
       
   140 Win32Handle subclass:#Win32NetworkResourceHandle
       
   141 	instanceVariableNames:''
       
   142 	classVariableNames:'ScopeMappingTable TypeMappingTable DisplayTypeMappingTable
       
   143 		UsageMappingTable'
       
   144 	poolDictionaries:''
       
   145 	privateIn:Win32OperatingSystem
       
   146 !
       
   147 
       
   148 Object subclass:#NetworkResource
       
   149 	instanceVariableNames:'scope type usage displayType remoteName localName provider
       
   150 		comment'
       
   151 	classVariableNames:''
       
   152 	poolDictionaries:''
       
   153 	privateIn:Win32OperatingSystem::Win32NetworkResourceHandle
   136 !
   154 !
   137 
   155 
   138 Win32Handle subclass:#Win32PrinterHandle
   156 Win32Handle subclass:#Win32PrinterHandle
   139 	instanceVariableNames:''
   157 	instanceVariableNames:''
   140 	classVariableNames:''
   158 	classVariableNames:''
   826     "Modified: 22.4.1996 / 13:10:43 / cg"
   844     "Modified: 22.4.1996 / 13:10:43 / cg"
   827     "Created: 15.6.1996 / 15:22:37 / cg"
   845     "Created: 15.6.1996 / 15:22:37 / cg"
   828     "Modified: 7.1.1997 / 19:36:11 / stefan"
   846     "Modified: 7.1.1997 / 19:36:11 / stefan"
   829 ! !
   847 ! !
   830 
   848 
   831 
       
   832 !Win32OperatingSystem class methodsFor:'OS signal constants'!
   849 !Win32OperatingSystem class methodsFor:'OS signal constants'!
   833 
   850 
   834 sigABRT
   851 sigABRT
   835     "return the signal number for SIGABRT - 0 if not supported by OS
   852     "return the signal number for SIGABRT - 0 if not supported by OS
   836      (the numeric value is not the same across unix-systems)"
   853      (the numeric value is not the same across unix-systems)"
  7372 
  7389 
  7373     result := self primWaitForSingleObject: handle milliseconds: 500.
  7390     result := self primWaitForSingleObject: handle milliseconds: 500.
  7374     ^ result
  7391     ^ result
  7375 
  7392 
  7376     "Modified: / 03-08-2010 / 17:00:10 / cg"
  7393     "Modified: / 03-08-2010 / 17:00:10 / cg"
       
  7394 ! !
       
  7395 
       
  7396 !Win32OperatingSystem class methodsFor:'network resources'!
       
  7397 
       
  7398 networkResourceAccessor
       
  7399     "answer the Win32NetworkResourceHandle or nil if not supported"
       
  7400 
       
  7401     ^ Win32NetworkResourceHandle
  7377 ! !
  7402 ! !
  7378 
  7403 
  7379 !Win32OperatingSystem class methodsFor:'os queries'!
  7404 !Win32OperatingSystem class methodsFor:'os queries'!
  7380 
  7405 
  7381 executableFileExtensions
  7406 executableFileExtensions
 15445 	CloseHandle(h);
 15470 	CloseHandle(h);
 15446     }
 15471     }
 15447 %}.
 15472 %}.
 15448 ! !
 15473 ! !
 15449 
 15474 
       
 15475 !Win32OperatingSystem::Win32NetworkResourceHandle class methodsFor:'accessing - types'!
       
 15476 
       
 15477 displayTypeMappingTable
       
 15478     "answer a Dictionary containing displayTypes symbols to integer mapping and vice versa"
       
 15479     | symbTable |
       
 15480 
       
 15481     DisplayTypeMappingTable notNil ifTrue:[ ^ DisplayTypeMappingTable ].
       
 15482 
       
 15483     symbTable := Dictionary new.
       
 15484 %{
       
 15485     __AT_PUT_(symbTable , @symbol(GENERIC),      __MKUINT( RESOURCEDISPLAYTYPE_GENERIC ) );
       
 15486     __AT_PUT_(symbTable , @symbol(DOMAIN),       __MKUINT( RESOURCEDISPLAYTYPE_DOMAIN ) );
       
 15487     __AT_PUT_(symbTable , @symbol(SERVER),       __MKUINT( RESOURCEDISPLAYTYPE_SERVER ) );
       
 15488     __AT_PUT_(symbTable , @symbol(SHARE),        __MKUINT( RESOURCEDISPLAYTYPE_SHARE ) );
       
 15489     __AT_PUT_(symbTable , @symbol(FILE),         __MKUINT( RESOURCEDISPLAYTYPE_FILE ) );
       
 15490     __AT_PUT_(symbTable , @symbol(GROUP),        __MKUINT( RESOURCEDISPLAYTYPE_GROUP ) );
       
 15491     __AT_PUT_(symbTable , @symbol(NETWORK),      __MKUINT( RESOURCEDISPLAYTYPE_NETWORK ) );
       
 15492     __AT_PUT_(symbTable , @symbol(ROOT),         __MKUINT( RESOURCEDISPLAYTYPE_ROOT ) );
       
 15493     __AT_PUT_(symbTable , @symbol(SHAREADMIN),   __MKUINT( RESOURCEDISPLAYTYPE_SHAREADMIN ) );
       
 15494     __AT_PUT_(symbTable , @symbol(DIRECTORY),    __MKUINT( RESOURCEDISPLAYTYPE_DIRECTORY ) );
       
 15495     __AT_PUT_(symbTable , @symbol(TREE),         __MKUINT( RESOURCEDISPLAYTYPE_TREE ) );
       
 15496     __AT_PUT_(symbTable , @symbol(NDSCONTAINER), __MKUINT( RESOURCEDISPLAYTYPE_NDSCONTAINER ) );
       
 15497 %}.
       
 15498     DisplayTypeMappingTable := Dictionary new.
       
 15499 
       
 15500     symbTable keysAndValuesDo:[:aSYMB :anINT |
       
 15501 	DisplayTypeMappingTable at: aSYMB put: anINT.
       
 15502 	DisplayTypeMappingTable at: anINT put: aSYMB. "/ vice versa
       
 15503     ].
       
 15504     ^ DisplayTypeMappingTable
       
 15505 !
       
 15506 
       
 15507 scopeMappingTable
       
 15508     "answer a Dictionary with scopes mapping symbol to integer and vice verca"
       
 15509     | symbTable |
       
 15510 
       
 15511     ScopeMappingTable notNil ifTrue:[ ^ ScopeMappingTable].
       
 15512 
       
 15513     symbTable := Dictionary new.
       
 15514 %{
       
 15515     __AT_PUT_(symbTable, @symbol(CONNECTED),  __MKUINT( RESOURCE_CONNECTED ) );
       
 15516     __AT_PUT_(symbTable, @symbol(CONTEXT),    __MKUINT( RESOURCE_CONTEXT ) );
       
 15517     __AT_PUT_(symbTable, @symbol(GLOBALNET),  __MKUINT( RESOURCE_GLOBALNET ) );
       
 15518     __AT_PUT_(symbTable, @symbol(REMEMBERED), __MKUINT( RESOURCE_REMEMBERED ) );
       
 15519     __AT_PUT_(symbTable, @symbol(RECENT),     __MKUINT( RESOURCE_RECENT ) );
       
 15520 %}.
       
 15521     ScopeMappingTable := Dictionary new.
       
 15522 
       
 15523     symbTable keysAndValuesDo:[:aSYMB :anINT |
       
 15524 	ScopeMappingTable at: aSYMB put: anINT.
       
 15525 	ScopeMappingTable at: anINT put: aSYMB. "/ vice versa
       
 15526     ].
       
 15527     ^ ScopeMappingTable
       
 15528 !
       
 15529 
       
 15530 typeMappingTable
       
 15531     "answer a Dictionary containing types symbols to integer mapping and vice versa"
       
 15532     | symbTable |
       
 15533 
       
 15534     TypeMappingTable notNil ifTrue:[ ^ TypeMappingTable].
       
 15535 
       
 15536     symbTable := Dictionary new.
       
 15537 %{
       
 15538     __AT_PUT_(symbTable , @symbol(ANY),      __MKUINT( RESOURCETYPE_ANY ) );
       
 15539     __AT_PUT_(symbTable , @symbol(DISK),     __MKUINT( RESOURCETYPE_DISK ) );
       
 15540     __AT_PUT_(symbTable , @symbol(PRINT),    __MKUINT( RESOURCETYPE_PRINT ) );
       
 15541     __AT_PUT_(symbTable , @symbol(UNKNOWN),  __MKUINT( RESOURCETYPE_UNKNOWN ) );
       
 15542     __AT_PUT_(symbTable , @symbol(RESERVED), __MKUINT( RESOURCETYPE_RESERVED ) );
       
 15543 %}.
       
 15544     TypeMappingTable := Dictionary new.
       
 15545 
       
 15546     symbTable keysAndValuesDo:[:aSYMB :anINT |
       
 15547 	TypeMappingTable at: aSYMB put: anINT.
       
 15548 	TypeMappingTable at: anINT put: aSYMB. "/ vice versa
       
 15549     ].
       
 15550     ^ TypeMappingTable
       
 15551 !
       
 15552 
       
 15553 usageMappingTable
       
 15554     "answer a Dictionary containing usages symbols to integer mapping and vice versa"
       
 15555     | symbTable |
       
 15556 
       
 15557     UsageMappingTable notNil ifTrue:[ ^ UsageMappingTable].
       
 15558 
       
 15559     symbTable := Dictionary new.
       
 15560 %{
       
 15561     __AT_PUT_(symbTable , @symbol(NULL),          __MKUINT( 0 ) );
       
 15562     __AT_PUT_(symbTable , @symbol(CONNECTABLE),   __MKUINT( RESOURCEUSAGE_CONNECTABLE ) );
       
 15563     __AT_PUT_(symbTable , @symbol(CONTAINER),     __MKUINT( RESOURCEUSAGE_CONTAINER ) );
       
 15564     __AT_PUT_(symbTable , @symbol(ATTACHED),      __MKUINT( RESOURCEUSAGE_ATTACHED ) );
       
 15565     __AT_PUT_(symbTable , @symbol(ALL),           __MKUINT( RESOURCEUSAGE_ALL ) );
       
 15566     __AT_PUT_(symbTable , @symbol(NOLOCALDEVICE), __MKUINT( RESOURCEUSAGE_NOLOCALDEVICE ) );
       
 15567     __AT_PUT_(symbTable , @symbol(SIBLING),       __MKUINT( RESOURCEUSAGE_SIBLING ) );
       
 15568     __AT_PUT_(symbTable , @symbol(RESERVED),      __MKUINT( RESOURCEUSAGE_RESERVED ) );
       
 15569 %}.
       
 15570     UsageMappingTable := Dictionary new.
       
 15571 
       
 15572     symbTable keysAndValuesDo:[:aSYMB :anINT |
       
 15573 	UsageMappingTable at: aSYMB put: anINT.
       
 15574 	UsageMappingTable at: anINT put: aSYMB. "/ vice versa
       
 15575     ].
       
 15576     ^ UsageMappingTable
       
 15577 ! !
       
 15578 
       
 15579 !Win32OperatingSystem::Win32NetworkResourceHandle class methodsFor:'fetch resources'!
       
 15580 
       
 15581 fetchResourcesStartingAt: aNetworkResourceOrNil
       
 15582     withScope: aScope type: aType usage: aUsage onError: aBlock
       
 15583 
       
 15584     "Fetch all resources from the given network resource or if nil the root system.
       
 15585      On success a collection of al network resources is returned.
       
 15586      If the open fails, the error block if notNil will be evaluated with the error number
       
 15587      and nil is returned.
       
 15588 
       
 15589     self fetchResourcesStartingAt: nil withScope: #GLOBALNET type: #ANY usage: 0
       
 15590         onError: [:err| Transcript showCR: err ].
       
 15591     "
       
 15592     | stream networkResources |
       
 15593 
       
 15594     [
       
 15595         stream := self openAt: aNetworkResourceOrNil
       
 15596             withScope: aScope type: aType usage: aUsage onError: aBlock.
       
 15597 
       
 15598         stream notNil ifTrue:[
       
 15599             |next|
       
 15600 
       
 15601             networkResources := OrderedCollection new.
       
 15602 
       
 15603             [ (next := stream nextOrNil) notNil ] whileTrue:[
       
 15604                 networkResources add:next.
       
 15605             ].
       
 15606         ]
       
 15607     ] ensure:[
       
 15608         stream notNil ifTrue:[ stream close ].
       
 15609     ].
       
 15610     ^ networkResources.
       
 15611 !
       
 15612 
       
 15613 fetchSystemResourcesWithScope: aScope type: aType usage: aUsage onError: aBlock
       
 15614 
       
 15615     "Fetch all system resources.
       
 15616      On success a collection of al network resources is returned.
       
 15617      If the open fails, the error block if notNil will be evaluated with the error number
       
 15618      and nil is returned.
       
 15619 
       
 15620     self fetchSystemResourcesWithScope: #GLOBALNET type: #ANY usage: 0
       
 15621         onError: [:err| Transcript showCR: err ].
       
 15622 
       
 15623     self fetchSystemResourcesWithScope: #REMEMBERED type: #DISK usage: 0
       
 15624         onError: [:err| Transcript showCR: err ].
       
 15625 
       
 15626     self fetchSystemResourcesWithScope: #REMEMBERED type: #ANY usage: 0
       
 15627         onError: [:err| Transcript showCR: err ].
       
 15628     "
       
 15629 
       
 15630     ^ self fetchResourcesStartingAt: nil
       
 15631             withScope: aScope type: aType usage: aUsage onError: aBlock
       
 15632 !
       
 15633 
       
 15634 fetchVirtualDrives
       
 15635     "answer a collection of virtual drive resources
       
 15636 
       
 15637      self fetchVirtualDrives
       
 15638     "
       
 15639     ^ self fetchSystemResourcesWithScope: #REMEMBERED type: #DISK usage: 0 onError: nil.
       
 15640 ! !
       
 15641 
       
 15642 !Win32OperatingSystem::Win32NetworkResourceHandle class methodsFor:'opening'!
       
 15643 
       
 15644 openAt: aResourceOrNil withScope: aScope type: aType usage: aUsage onError: aBlock
       
 15645     "Open a handle for network resource enumeratation starting at the given NetworkResource
       
 15646      or if nil on the system root. On success the handle will is returned.
       
 15647      If the open fails, the error block if notNil will be evaluated with the error number
       
 15648      and nil is returned.
       
 15649 
       
 15650     OperatingSystem networkResourceAccessor openOn:nil withScope:#GLOBALNET  type:#ANY  usage:0 onError:nil.
       
 15651     OperatingSystem networkResourceAccessor openOn:nil withScope:#REMEMBERED type:#DISK usage:0 onError:nil.
       
 15652     "
       
 15653     | resourceHandle errorNumber enumScope enumUsage enumType
       
 15654       resScope resType resUsage resDisplayType resComment resLocalName resRemoteName resProvider |
       
 15655 
       
 15656     "/ map symbols to integer values.. on error an exception is raised
       
 15657     aScope isInteger ifTrue:[ enumScope := aScope ]
       
 15658 		    ifFalse:[ enumScope := self scopeMappingTable at:aScope ].
       
 15659 
       
 15660     aUsage isInteger ifTrue:[ enumUsage := aUsage ]
       
 15661 		    ifFalse:[ enumUsage := self usageMappingTable at:aUsage ].
       
 15662 
       
 15663     aType isInteger ifTrue:[ enumType := aType ]
       
 15664 		   ifFalse:[ enumType := self typeMappingTable at:aType ].
       
 15665 
       
 15666     aResourceOrNil notNil ifTrue:[ | checkAndGetString |
       
 15667 	resScope := aResourceOrNil scope.
       
 15668 	resScope isInteger ifFalse:[ resScope := self scopeMappingTable at:resScope ].
       
 15669 
       
 15670 	resType := aResourceOrNil type.
       
 15671 	resType isInteger ifFalse:[ resType := self typeMappingTable at: resType ].
       
 15672 
       
 15673 	resUsage := aResourceOrNil usage.
       
 15674 	resUsage isInteger ifFalse:[ resUsage := self usageMappingTable at: resUsage ].
       
 15675 
       
 15676 	resDisplayType := aResourceOrNil displayType.
       
 15677 	resDisplayType isInteger ifFalse:[ resDisplayType := self displayTypeMappingTable at:resDisplayType ].
       
 15678 
       
 15679 	checkAndGetString := [: aString| |string|
       
 15680 	    aString notNil ifTrue:[
       
 15681 		self isUsingUnicode
       
 15682 		    ifTrue: [ string := aString asUnicode16String  ]
       
 15683 		    ifFalse:[ string := aString asSingleByteString ].
       
 15684 	    ].
       
 15685 	    string
       
 15686 	].
       
 15687 	resRemoteName  := checkAndGetString value:( aResourceOrNil remoteName ).
       
 15688 	resLocalName   := checkAndGetString value:( aResourceOrNil localName ).
       
 15689 	resComment     := checkAndGetString value:( aResourceOrNil comment ).
       
 15690 	resProvider    := checkAndGetString value:( aResourceOrNil provider ).
       
 15691     ].
       
 15692     resourceHandle := self new.
       
 15693 
       
 15694 %{
       
 15695     HANDLE __hEnum;
       
 15696     int    __errno;
       
 15697     DWORD  __scope = __unsignedLongIntVal( enumScope );
       
 15698     DWORD  __usage = __unsignedLongIntVal( enumUsage );
       
 15699     DWORD  __type  = __unsignedLongIntVal( enumType );
       
 15700 
       
 15701 #ifdef USE_ANSI_NETWORKRESOURCES
       
 15702     char           __buffer[ 8192 ];
       
 15703     LPNETRESOURCE  __lpnetRes = (LPNETRESOURCE) __buffer;
       
 15704     char *         __cp = __buffer + sizeof(NETRESOURCE);
       
 15705     char *         __sp;
       
 15706 #else
       
 15707     wchar_t        __buffer[ 8192 ];
       
 15708     LPNETRESOURCEW __lpnetRes = (LPNETRESOURCEW) __buffer;
       
 15709     wchar_t *      __cp = __buffer + sizeof(NETRESOURCEW);
       
 15710     wchar_t *      __sp;
       
 15711 #endif
       
 15712 
       
 15713     if( resScope == nil ) {
       
 15714 	__lpnetRes = 0;
       
 15715     } else {
       
 15716 	int __sz;
       
 15717 
       
 15718 	ZeroMemory( __buffer, (__cp - __buffer) );
       
 15719 
       
 15720 	__lpnetRes->dwScope       = __unsignedLongIntVal( resScope );
       
 15721 	__lpnetRes->dwType        = __unsignedLongIntVal( resType  );
       
 15722 	__lpnetRes->dwUsage       = __unsignedLongIntVal( resUsage );
       
 15723 	__lpnetRes->dwDisplayType = __unsignedLongIntVal( resDisplayType );
       
 15724 
       
 15725 	if( resRemoteName != nil ) {
       
 15726 #ifdef USE_ANSI_NETWORKRESOURCES
       
 15727 	    __sp = __stringVal(resRemoteName);
       
 15728 	    __sz = strlen(__sp);
       
 15729 #else
       
 15730 	    __sp = __unicode16StringVal(resRemoteName);
       
 15731 	    __sz = __unicode16StringSize(resRemoteName);
       
 15732 #endif
       
 15733 	    for( __lpnetRes->lpRemoteName = __cp; __sz > 0; --__sz ) { * __cp++ = * __sp++; }
       
 15734 	    *__cp++ = 0;
       
 15735 	}
       
 15736 
       
 15737 	if( resLocalName != nil ) {
       
 15738 #ifdef USE_ANSI_NETWORKRESOURCES
       
 15739 	    __sp = __stringVal(resLocalName);
       
 15740 	    __sz = strlen(__sp);
       
 15741 #else
       
 15742 	    __sp = __unicode16StringVal(resLocalName);
       
 15743 	    __sz = __unicode16StringSize(resLocalName);
       
 15744 #endif
       
 15745 	    for( __lpnetRes->lpLocalName = __cp; __sz > 0; --__sz ) { * __cp++ = * __sp++; }
       
 15746 	    *__cp++ = 0;
       
 15747 	}
       
 15748 
       
 15749 	if( resComment != nil ) {
       
 15750 #ifdef USE_ANSI_NETWORKRESOURCES
       
 15751 	    __sp = __stringVal(resComment);
       
 15752 	    __sz = strlen(__sp);
       
 15753 #else
       
 15754 	    __sp = __unicode16StringVal(resComment);
       
 15755 	    __sz = __unicode16StringSize(resComment);
       
 15756 #endif
       
 15757 	    for( __lpnetRes->lpComment = __cp; __sz > 0; --__sz ) { * __cp++ = * __sp++; }
       
 15758 	    *__cp++ = 0;
       
 15759 	}
       
 15760 
       
 15761 	if( resProvider != nil ) {
       
 15762 #ifdef USE_ANSI_NETWORKRESOURCES
       
 15763 	    __sp = __stringVal(resProvider);
       
 15764 	    __sz = strlen(__sp);
       
 15765 #else
       
 15766 	    __sp = __unicode16StringVal(resProvider);
       
 15767 	    __sz = __unicode16StringSize(resProvider);
       
 15768 #endif
       
 15769 	    for( __lpnetRes->lpProvider = __cp; __sz > 0; --__sz ) { * __cp++ = * __sp++; }
       
 15770 	    *__cp++ = 0;
       
 15771 	}
       
 15772     }
       
 15773 
       
 15774 #ifdef DO_WRAP_CALLS
       
 15775     do {
       
 15776 	__threadErrno = 0;
       
 15777 #ifdef USE_ANSI_NETWORKRESOURCES
       
 15778 	__errno = STX_API_NOINT_CALL5( "WNetOpenEnum",  WNetOpenEnum,  __scope, __type, __usage, __lpnetRes, & __hEnum );
       
 15779 #else
       
 15780 	__errno = STX_API_NOINT_CALL5( "WNetOpenEnumW", WNetOpenEnumW, __scope, __type, __usage, __lpnetRes, & __hEnum );
       
 15781 #endif
       
 15782     } while ((__errno < 0) && (__threadErrno == EINTR));
       
 15783 #else
       
 15784 
       
 15785 #ifdef USE_ANSI_NETWORKRESOURCES
       
 15786     __errno = WNetOpenEnum ( __scope, __type, __usage, __lpnetRes, & __hEnum );
       
 15787 #else
       
 15788     __errno = WNetOpenEnumW( __scope, __type, __usage, __lpnetRes, & __hEnum );
       
 15789 #endif
       
 15790 
       
 15791 #endif
       
 15792 
       
 15793     if( __errno == NO_ERROR ) {
       
 15794 	__externalAddressVal(resourceHandle) = (void *) __hEnum;
       
 15795     } else {
       
 15796 	resourceHandle = nil;
       
 15797 	errorNumber    = __mkSmallInteger( __errno );
       
 15798     }
       
 15799 
       
 15800 %}.
       
 15801     resourceHandle isNil ifTrue:[
       
 15802 	aBlock notNil ifTrue:[ aBlock value: errorNumber ].
       
 15803 	^ nil
       
 15804     ].
       
 15805     resourceHandle registerForFinalization.
       
 15806     ^ resourceHandle
       
 15807 ! !
       
 15808 
       
 15809 !Win32OperatingSystem::Win32NetworkResourceHandle class methodsFor:'testing'!
       
 15810 
       
 15811 isUsingUnicode
       
 15812     "answer true if we are using unicode; has effect to the open and next operation"
       
 15813 
       
 15814 %{
       
 15815 #ifdef USE_ANSI_NETWORKRESOURCES
       
 15816     RETURN( false );
       
 15817 #endif
       
 15818 %}.
       
 15819     ^ true
       
 15820 ! !
       
 15821 
       
 15822 !Win32OperatingSystem::Win32NetworkResourceHandle methodsFor:'queries'!
       
 15823 
       
 15824 atEnd
       
 15825     "answer true if the stream is at the end (no longer valid)"
       
 15826     ^ (self address == 0)
       
 15827 ! !
       
 15828 
       
 15829 !Win32OperatingSystem::Win32NetworkResourceHandle methodsFor:'reading'!
       
 15830 
       
 15831 nextOrNil
       
 15832     "answer the next NetworkResource or nil (no more resource available);
       
 15833      if no more resource is available the stream is closed"
       
 15834 
       
 15835     | scope type usage displayType comment localName remoteName provider |
       
 15836 
       
 15837     self atEnd ifTrue:[ ^ nil ].
       
 15838 
       
 15839 %{
       
 15840     HANDLE __hEnum = (HANDLE)(__externalAddressVal(self));
       
 15841 
       
 15842     if ((__hEnum == 0) || (__hEnum == INVALID_HANDLE_VALUE)) {
       
 15843 	__externalAddressVal(self) = (HANDLE)0;
       
 15844     } else {
       
 15845 	DWORD           __entries = 1;
       
 15846 	DWORD           __bufSize = 8192;
       
 15847 	int             __errno;
       
 15848 
       
 15849 #ifdef USE_ANSI_NETWORKRESOURCES
       
 15850 	char            __buffer[ 8192 ];
       
 15851 	LPNETRESOURCE   __lpNetRes  = (LPNETRESOURCE)  __buffer;
       
 15852 
       
 15853 	ZeroMemory( __buffer, sizeof(NETRESOURCE) );
       
 15854 	__errno = WNetEnumResource ( __hEnum , & __entries , __lpNetRes, & __bufSize );
       
 15855 #else
       
 15856 	wchar_t         __buffer[ 8192 ];
       
 15857 	LPNETRESOURCEW  __lpNetRes  = (LPNETRESOURCEW) __buffer;
       
 15858 
       
 15859 	ZeroMemory( __buffer, sizeof(NETRESOURCEW) );
       
 15860 	__errno = WNetEnumResourceW ( __hEnum , & __entries , __lpNetRes, & __bufSize );
       
 15861 #endif
       
 15862 
       
 15863 	if( (__errno  == NO_ERROR) && (__entries == 1) ) {
       
 15864 	    scope       = __MKUINT( __lpNetRes->dwScope );
       
 15865 	    type        = __MKUINT( __lpNetRes->dwType );
       
 15866 	    usage       = __MKUINT( __lpNetRes->dwUsage );
       
 15867 	    displayType = __MKUINT( __lpNetRes->dwDisplayType );
       
 15868 
       
 15869 #ifdef USE_ANSI_NETWORKRESOURCES
       
 15870 	    if( __lpNetRes->lpRemoteName != 0 ) { remoteName =  __MKSTRING( __lpNetRes->lpRemoteName ); }
       
 15871 	    if( __lpNetRes->lpLocalName  != 0 ) { localName  =  __MKSTRING( __lpNetRes->lpLocalName ); }
       
 15872 	    if( __lpNetRes->lpComment    != 0 ) { comment    =  __MKSTRING( __lpNetRes->lpComment ); }
       
 15873 	    if( __lpNetRes->lpProvider   != 0 ) { provider   =  __MKSTRING( __lpNetRes->lpProvider ); }
       
 15874 #else
       
 15875 	    if( __lpNetRes->lpRemoteName != 0 ) { remoteName =  __MKU16STRING( __lpNetRes->lpRemoteName ); }
       
 15876 	    if( __lpNetRes->lpLocalName  != 0 ) { localName  =  __MKU16STRING( __lpNetRes->lpLocalName ); }
       
 15877 	    if( __lpNetRes->lpComment    != 0 ) { comment    =  __MKU16STRING( __lpNetRes->lpComment ); }
       
 15878 	    if( __lpNetRes->lpProvider   != 0 ) { provider   =  __MKU16STRING( __lpNetRes->lpProvider ); }
       
 15879 #endif
       
 15880 	}
       
 15881     }
       
 15882 %}.
       
 15883     scope notNil ifTrue:[ |netResource|
       
 15884 	netResource := NetworkResource new.
       
 15885 
       
 15886 	"map integer values to symbol excluding the usage..."
       
 15887 	netResource scope: (self class scopeMappingTable at:scope ifAbsent:[scope]).
       
 15888 	netResource type:  (self class typeMappingTable  at:type ifAbsent:[type]).
       
 15889 	netResource displayType: (self class displayTypeMappingTable at:displayType ifAbsent:[displayType]).
       
 15890 	netResource usage: usage.
       
 15891 
       
 15892 	netResource remoteName: remoteName.
       
 15893 	netResource localName: localName.
       
 15894 	netResource comment: comment.
       
 15895 	netResource provider: provider.
       
 15896 
       
 15897 	^ netResource
       
 15898     ].
       
 15899     self close.
       
 15900     ^ nil
       
 15901 ! !
       
 15902 
       
 15903 !Win32OperatingSystem::Win32NetworkResourceHandle methodsFor:'release'!
       
 15904 
       
 15905 closeHandle
       
 15906     "close the handle"
       
 15907 
       
 15908     self address == 0 ifTrue:[ ^ self ].
       
 15909 %{
       
 15910     HANDLE __hEnum = (HANDLE)(__externalAddressVal(self));
       
 15911 
       
 15912     if (__hEnum) {
       
 15913 	__externalAddressVal(self) = (HANDLE)0;
       
 15914 	WNetCloseEnum(__hEnum);
       
 15915     }
       
 15916 %}.
       
 15917 ! !
       
 15918 
       
 15919 !Win32OperatingSystem::Win32NetworkResourceHandle::NetworkResource methodsFor:'accessing'!
       
 15920 
       
 15921 comment
       
 15922     "comment supplied by the network provider or nil"
       
 15923 
       
 15924     ^ comment
       
 15925 !
       
 15926 
       
 15927 comment: aStringOrNil
       
 15928     "comment supplied by the network provider or nil"
       
 15929 
       
 15930     comment := aStringOrNil.
       
 15931 !
       
 15932 
       
 15933 displayType
       
 15934     "The display options for the network object in a network browsing user interface"
       
 15935 
       
 15936     ^ displayType
       
 15937 !
       
 15938 
       
 15939 displayType: theDisplayType
       
 15940     "The display options for the network object in a network browsing user interface"
       
 15941 
       
 15942     displayType := theDisplayType.
       
 15943 !
       
 15944 
       
 15945 localName
       
 15946     "if the scope member is equal to RESOURCE_CONNECTED or RESOURCE_REMEMBERED,
       
 15947      this specifies the name of a local device. This member is NULL if the connection
       
 15948      does not use a device."
       
 15949 
       
 15950     ^ localName
       
 15951 !
       
 15952 
       
 15953 localName: aStringOrNil
       
 15954     "if the scope member is equal to RESOURCE_CONNECTED or RESOURCE_REMEMBERED,
       
 15955      this specifies the name of a local device. This member is NULL if the connection
       
 15956      does not use a device."
       
 15957 
       
 15958     localName := aStringOrNil.
       
 15959 !
       
 15960 
       
 15961 provider
       
 15962     "the name of the provider that owns the resource or nil"
       
 15963 
       
 15964     ^ provider
       
 15965 !
       
 15966 
       
 15967 provider: aStringOrNil
       
 15968     "the name of the provider that owns the resource or nil"
       
 15969 
       
 15970     provider := aStringOrNil.
       
 15971 !
       
 15972 
       
 15973 remoteName
       
 15974     "If the resource is a network resource, this specifies the remote network name.
       
 15975      If the resource is a current or persistent connection, this specifies the network
       
 15976      name associated with the name pointed to by the localName"
       
 15977 
       
 15978     ^ remoteName
       
 15979 !
       
 15980 
       
 15981 remoteName: aStringOrNil
       
 15982     "If the resource is a network resource, this specifies the remote network name.
       
 15983      If the resource is a current or persistent connection, this specifies the network
       
 15984      name associated with the name pointed to by the localName"
       
 15985 
       
 15986     remoteName := aStringOrNil.
       
 15987 !
       
 15988 
       
 15989 scope
       
 15990     "The scope of the enumeration
       
 15991 	RESOURCE_CONNECTED RESOURCE_GLOBALNET RESOURCE_REMEMBERED
       
 15992     "
       
 15993     ^ scope
       
 15994 !
       
 15995 
       
 15996 scope: theScope
       
 15997     "The scope of the enumeration
       
 15998 	RESOURCE_CONNECTED RESOURCE_GLOBALNET RESOURCE_REMEMBERED
       
 15999     "
       
 16000     scope := theScope.
       
 16001 !
       
 16002 
       
 16003 type
       
 16004     "describes the type of the resource
       
 16005 	RESOURCETYPE_ANY  RESOURCETYPE_DISK  RESOURCETYPE_PRINT
       
 16006     "
       
 16007     ^ type
       
 16008 !
       
 16009 
       
 16010 type: theType
       
 16011     "describes the type of the resource
       
 16012 	RESOURCETYPE_ANY  RESOURCETYPE_DISK  RESOURCETYPE_PRINT
       
 16013     "
       
 16014     type := theType.
       
 16015 !
       
 16016 
       
 16017 usage
       
 16018     "a set of bit flags (INTEGER) describing how the resource can be used"
       
 16019 
       
 16020     ^ usage
       
 16021 !
       
 16022 
       
 16023 usage: anInteger
       
 16024     "a set of bit flags (INTEGER) describing how the resource can be used"
       
 16025 
       
 16026     usage := anInteger.
       
 16027 ! !
       
 16028 
       
 16029 !Win32OperatingSystem::Win32NetworkResourceHandle::NetworkResource methodsFor:'printing'!
       
 16030 
       
 16031 printOn: aStream
       
 16032     "print self on a stream"
       
 16033 
       
 16034     | paction |
       
 16035 
       
 16036     paction := [: anIdentifier :theValue |
       
 16037 	anIdentifier printOn: aStream.
       
 16038 
       
 16039 	theValue notNil ifTrue:[
       
 16040 	    theValue isInteger ifTrue:[
       
 16041 		theValue printOn:aStream base:2 showRadix:true.
       
 16042 	    ] ifFalse:[
       
 16043 		theValue isSymbol ifTrue:[
       
 16044 		    theValue printOn: aStream.
       
 16045 		] ifFalse:[
       
 16046 		    aStream nextPut: $". theValue printOn: aStream. aStream nextPut: $"
       
 16047 		]
       
 16048 	    ]
       
 16049 	].
       
 16050 	aStream cr.
       
 16051     ].
       
 16052 
       
 16053     aStream nextPutAll: 'NetworkResource {'; cr.
       
 16054 
       
 16055     paction value: '  Scope:        ' value:scope.
       
 16056     paction value: '  Type:         ' value:type.
       
 16057     paction value: '  DisplayType:  ' value:displayType.
       
 16058     paction value: '  Usage(mask):  ' value:usage.
       
 16059 
       
 16060     aStream cr.
       
 16061 
       
 16062     paction value: '  RemoteName:   ' value:remoteName.
       
 16063     paction value: '  LocalName:    ' value:localName.
       
 16064     paction value: '  Comment       ' value:comment.
       
 16065     paction value: '  Provider      ' value:provider.
       
 16066 
       
 16067     aStream nextPut: $}; cr.
       
 16068 ! !
       
 16069 
       
 16070 !Win32OperatingSystem::Win32NetworkResourceHandle::NetworkResource methodsFor:'queries'!
       
 16071 
       
 16072 isResourceContainer
       
 16073     "answer true if the resource is a resource container"
       
 16074 
       
 16075     | flag |
       
 16076 
       
 16077     usage isInteger ifFalse:[ ^ usage = #CONTAINER ].
       
 16078     flag := usage.
       
 16079 %{
       
 16080     DWORD __usage = __unsignedLongIntVal( flag );
       
 16081 
       
 16082     if( __usage & RESOURCEUSAGE_CONTAINER ) {
       
 16083 	RETURN( true );
       
 16084     }
       
 16085 %}.
       
 16086     ^ false
       
 16087 ! !
       
 16088 
 15450 !Win32OperatingSystem::Win32PrinterHandle methodsFor:'release'!
 16089 !Win32OperatingSystem::Win32PrinterHandle methodsFor:'release'!
 15451 
 16090 
 15452 closeHandle
 16091 closeHandle
 15453     self address ~~ 0 ifTrue:[
 16092     self address ~~ 0 ifTrue:[
 15454 	OperatingSystem primClosePrinter:self.
 16093 	OperatingSystem primClosePrinter:self.
 16525 ! !
 17164 ! !
 16526 
 17165 
 16527 !Win32OperatingSystem class methodsFor:'documentation'!
 17166 !Win32OperatingSystem class methodsFor:'documentation'!
 16528 
 17167 
 16529 version
 17168 version
 16530     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.458 2013-04-03 11:46:25 cg Exp $'
 17169     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.459 2013-04-10 08:04:37 ca Exp $'
 16531 !
 17170 !
 16532 
 17171 
 16533 version_CVS
 17172 version_CVS
 16534     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.458 2013-04-03 11:46:25 cg Exp $'
 17173     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.459 2013-04-10 08:04:37 ca Exp $'
 16535 !
 17174 !
 16536 
 17175 
 16537 version_SVN
 17176 version_SVN
 16538     ^ '§Id§'
 17177     ^ '§Id§'
 16539 
 17178