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