]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/libraries/finder/windows/windows.factor
io.files: exists? -> file-exists? and rename primitive.
[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.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
11
12 IN: alien.libraries.finder.windows
13
14 <PRIVATE
15
16 : search-paths ( -- seq )
17     "resource:" normalize-path
18     system-directory
19     windows-directory 3array
20     "PATH" os-env [ ";" split ] [ f ] if* append ;
21
22 : candidate-paths ( name -- seq )
23     search-paths over ".dll" tail? [
24         [ prepend-path ] with map
25     ] [
26         [
27             [ prepend-path ]
28             [ [ ".dll" append ] [ prepend-path ] bi* ] 2bi
29             2array
30         ] with map concat
31     ] if ;
32
33 : find-library-paths ( name -- path/f )
34     candidate-paths [
35         { [ file-exists? ] [ file-info regular-file? ] } 1&&
36     ] find nip ;
37
38 : find-library-file ( name -- path/f )
39     f DONT_RESOLVE_DLL_REFERENCES LoadLibraryEx [
40         [
41             32768 ushort (c-array) [ 32768 GetModuleFileName drop ] keep
42             alien>native-string
43         ] [ FreeLibrary drop ] bi
44     ] [ f ] if* ;
45
46 PRIVATE>
47
48 M: windows find-library*
49     { [ find-library-paths ] [ find-library-file ] } 1|| ;