root/trunk/libs/xinfinity-support/api/xinf/support/DLLLoader.hx

Revision 1039 (checked in by dan, 6 months ago)

some OSX compatibility

Line 
1 /*  Copyright (c) the Xinf contributors.
2         see http://xinf.org/copyright for license. */
3
4 package xinf.support;
5
6 class DLLLoader {
7         public static var loaded:Hash<Bool>;
8
9         public static function getHaxelibPath() :String {
10                 switch( neko.Sys.systemName() ) {
11                         case "Windows":
12                                 var haxepath = neko.Sys.getEnv("HAXEPATH");
13                                 if( haxepath==null ) {
14                                         throw "HAXEPATH environment variable not defined, please install haXe";
15                                 }
16                                 return haxepath+"\\lib\\";
17                                
18                         default:
19                                 var config = neko.Sys.getEnv("HOME")+"/.haxelib";
20                                 try {
21                                         return neko.io.File.getContent(config);
22                                 } catch( e : Dynamic ) {
23                                         try {
24                                                 return neko.io.File.getContent("/etc/.haxelib");
25                                         } catch( e : Dynamic )
26                                                 throw "haxelib seems not to be correctly installed. run 'haxelib setup'";
27                                 }
28                 }
29                 return null;
30         }
31
32         public static function getXinfLibPath() :String {
33                 var pathSep = "/";
34                 if( neko.Sys.systemName()=="Windows" ) pathSep = "\\";
35                 var libPath = getHaxelibPath()+pathSep+"xinfinity-support";
36                 var version = neko.io.File.getContent( libPath+pathSep+".current" );
37                 version = version.split(".").join(",");
38                 libPath += pathSep+version+pathSep+"ndll"+pathSep+neko.Sys.systemName();
39                 return libPath;
40         }
41
42         public static function addToEnvironment( name:String, separator:String, value:String ) {
43                 var cur = neko.Sys.getEnv(name);
44                 if( cur==null || cur.length==0 )
45                         cur = value;
46                 else
47                         cur = value+separator+cur;
48                        
49                 neko.Sys.putEnv( name, cur );
50         }
51
52         public static function checkEnvironment( name:String, separator:String, value:String ) {
53                 var value = StringTools.replace( StringTools.replace( value, "//", "/" ), "\\\\", "\\" );
54        
55                 var cur = neko.Sys.getEnv(name);
56                 if( cur!=null ) {
57                         var a = cur.split(separator);
58                         for( i in a ) {
59                                 if( i==value ) return;
60                         }
61                 }
62                
63                 addToEnvironment(name,separator,value);
64         }
65
66         public static function addLibToPath( lib:String ) :Void {
67                 if( loaded==null ) loaded = new Hash<Bool>();
68                 if( loaded.get(lib) ) return;
69
70                 var libPath = getXinfLibPath();
71
72                 switch( neko.Sys.systemName() ) {
73                         case "Windows":
74                                 checkEnvironment("PATH",";",libPath);
75                         case "Mac":
76                                 checkEnvironment("DYLD_LIBRARY_PATH",":",libPath);
77                         default:
78                 }
79                
80                 loaded.set( lib, true );
81         }
82 }
Note: See TracBrowser for help on using the browser.