1 ! Copyright (C) 2013 Björn Lindqvist, John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: alien.data alien.libraries.finder alien.strings arrays
5 byte-arrays combinators.short-circuit environment io.backend
6 io.files io.files.info io.pathnames kernel sequences
7 specialized-arrays splitting system system-info.windows
8 windows.kernel32 windows.types ;
9 FROM: alien.c-types => ushort ;
10 SPECIALIZED-ARRAY: ushort
12 IN: alien.libraries.finder.windows
16 : search-paths ( -- seq )
17 "resource:" normalize-path
19 windows-directory 3array
20 "PATH" os-env [ ";" split ] [ f ] if* append ;
22 : candidate-paths ( name -- seq )
23 search-paths over ".dll" tail? [
24 [ prepend-path ] with map
28 [ [ ".dll" append ] [ prepend-path ] bi* ] 2bi
33 : find-library-paths ( name -- path/f )
35 { [ exists? ] [ file-info regular-file? ] } 1&&
38 : find-library-file ( name -- path/f )
39 f DONT_RESOLVE_DLL_REFERENCES LoadLibraryEx [
41 32768 ushort (c-array) [ 32768 GetModuleFileName drop ] keep
43 ] [ FreeLibrary drop ] bi
48 M: windows find-library*
49 { [ find-library-paths ] [ find-library-file ] } 1|| ;