]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/libraries/finder/windows/windows.factor
alien.c-types: not necessary to import `short` differently anymore
[factor.git] / basis / alien / libraries / finder / windows / windows.factor
1 ! Copyright (C) 2013 Björn Lindqvist, John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
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
8 windows.kernel32 ;
9 SPECIALIZED-ARRAY: ushort
10 IN: alien.libraries.finder.windows
11
12 <PRIVATE
13
14 : search-paths ( -- seq )
15     "resource:" normalize-path
16     system-directory
17     windows-directory 3array
18     "PATH" os-env [ ";" split ] [ f ] if* append ;
19
20 : candidate-paths ( name -- seq )
21     search-paths over ".dll" tail? [
22         [ prepend-path ] with map
23     ] [
24         [
25             [ prepend-path ]
26             [ [ ".dll" append ] [ prepend-path ] bi* ] 2bi
27             2array
28         ] with map concat
29     ] if ;
30
31 : find-library-paths ( name -- path/f )
32     candidate-paths [
33         { [ file-exists? ] [ file-info regular-file? ] } 1&&
34     ] find nip ;
35
36 : find-library-file ( name -- path/f )
37     f DONT_RESOLVE_DLL_REFERENCES LoadLibraryEx [
38         [
39             32768 ushort (c-array) [ 32768 GetModuleFileName drop ] keep
40             alien>native-string
41         ] [ FreeLibrary drop ] bi
42     ] [ f ] if* ;
43
44 PRIVATE>
45
46 M: windows find-library*
47     { [ find-library-paths ] [ find-library-file ] } 1|| ;