1 ! Copyright (C) 2013 Björn Lindqvist, John Benediktsson
2 ! See https://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 SPECIALIZED-ARRAY: ushort
10 IN: alien.libraries.finder.windows
14 : search-paths ( -- seq )
15 "resource:" normalize-path
17 windows-directory 3array
18 "PATH" os-env [ ";" split ] [ f ] if* append ;
20 : candidate-paths ( name -- seq )
21 search-paths over ".dll" tail? [
22 [ prepend-path ] with map
26 [ [ ".dll" append ] [ prepend-path ] bi* ] 2bi
31 : find-library-paths ( name -- path/f )
33 { [ file-exists? ] [ file-info regular-file? ] } 1&&
36 : find-library-file ( name -- path/f )
37 f DONT_RESOLVE_DLL_REFERENCES LoadLibraryEx [
39 32768 ushort (c-array) [ 32768 GetModuleFileName drop ] keep
41 ] [ FreeLibrary drop ] bi
46 M: windows find-library*
47 { [ find-library-paths ] [ find-library-file ] } 1|| ;