Ticket #23: gtkdPathTango.diff

File gtkdPathTango.diff, 3.1 kB (added by Mike Wey, 10 months ago)

Tango support for paths.d

  • gtkD-gen/wrap/paths.d

    old new  
    66 * Added:   John Reimer -- 2004-12-20 
    77 * Updated: 2005-02-21 changed names; added version(linux) 
    88 * Updated: 2005-05-05 updated Linux support 
     9 * Updated: 2008-02-16 Tango support 
    910 */ 
    1011 
    1112module gtkc.paths; 
     
    9394    ]; 
    9495} 
    9596 
    96 // dmd 1.005 still makes private char[] public?! 
    97 //private char[] libPath; 
    98 // Specify the default path for the gtkD dll's 
    99  
    10097version(Windows) 
    10198{ 
    102     import std.windows.registry; 
    103     import std.stdio; 
     99    //version(Phobos) 
     100    version(Tango){} else 
     101    { 
     102        import std.windows.registry; 
     103        import std.stdio; 
     104    } 
    104105 
    105     char[] libPath(
     106    extern (Windows
    106107    { 
    107 //      if ( libPath is null ) 
    108 //      { 
    109 //          libPath = "\\Program Files\\Common Files\\GTK\\2.0\\bin\\"; 
    110 //      } 
    111 //      return libPath; 
     108        private uint GetEnvironmentVariableA(char*, char*, uint); 
     109    } 
    112110 
    113         Key k = Registry.localMachine(); 
     111    //Based on tango.sys.Environment.Environment.get 
     112    static char[] GetEnvironmentVariable(char[] variable) 
     113    { 
     114        var = variable ~ 0; 
     115        uint size = GetEnvironmentVariableA(var.ptr, cast(char*)null, 0); 
     116     
     117        if (size == 0) return ""; 
    114118 
     119        char buf = new char[size]; 
     120        size = GetEnvironmentVariableA(var.ptr, buffer.ptr, size); 
     121 
     122        if (size == 0) return ""; 
     123 
     124        return buf[0 .. size]; 
     125    } 
     126 
     127    char[] libPath() 
     128    { 
    115129        char[] libPath; 
    116130 
    117         foreach ( Key key ; k.keys() ) 
    118         { 
    119             writefln("key = ", key.name()); 
    120         } 
     131        libPath = GetEnvironmentVariable("%GTK_BASEPATH%"); 
    121132 
    122         try 
    123         { 
    124             k = k.getKey("SOFTWARE"); 
    125             //writefln("key.value = %s", k.name()); 
    126             k = k.getKey("GTK"); 
    127             //writefln("key.value = %s", k.name()); 
    128             k = k.getKey("2.0"); 
    129             //writefln("key.value = %s", k.name()); 
    130             Value v = k.getValue("DllPath"); 
    131             libPath = v.value_SZ() ~ "\\"; 
    132         } 
    133         catch ( Exception e ) 
    134         { 
    135             libPath = "\\Program Files\\Common Files\\GTK\\2.0\\bin\\"; 
    136         } 
     133        if(libPath.length > 0) 
     134            return libPath ~ "\\bin\\"; 
    137135 
    138         if ( libPath is null ) 
     136        // version(Phobos) 
     137        version(Tango){} else 
    139138        { 
    140             libPath = "\\Program Files\\Common Files\\GTK\\2.0\\bin\\"; 
    141         } 
     139            // When using phobos Also try the Register 
    142140 
     141            Key k = Registry.localMachine(); 
     142 
     143            debug(register) foreach ( Key key ; k.keys() ) 
     144            { 
     145                writefln("key = ", key.name()); 
     146            } 
     147 
     148            try 
     149            { 
     150                k = k.getKey("SOFTWARE"); 
     151                //writefln("key.value = %s", k.name()); 
     152                k = k.getKey("GTK"); 
     153                //writefln("key.value = %s", k.name()); 
     154                k = k.getKey("2.0"); 
     155                //writefln("key.value = %s", k.name()); 
     156                Value v = k.getValue("DllPath"); 
     157                libPath = v.value_SZ() ~ "\\"; 
     158            } 
     159            catch ( Exception e ) 
     160            { 
     161                libPath = ""; 
     162            } 
     163        } 
    143164 
     165        // Returns the found location or an empty string 
     166        // to load the libraries from the path. 
     167        // see http://msdn2.microsoft.com/en-us/library/ms682586(VS.85).aspx 
    144168        return libPath; 
    145169    } 
    146170} 
    147171 
    148 //   empty for linux because default path is known by ld 
     172// empty for linux because default path is known by ld 
    149173 
    150174version(linux) 
    151175{ 
    152176    char[] libPath() 
    153177    { 
    154 //      if ( libPath is null ) 
    155 //      { 
    156 //          libPath = ""; 
    157 //      } 
    158 //      return libPath; 
    159178        return ""; 
    160179    } 
    161180}