Show
Ignore:
Timestamp:
01/04/08 11:00:27 (4 years ago)
Author:
flithm
Message:

Fixes for Tango 0.99.4

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/scrapple/sys/win32/Registry.d

    r34 r39  
    6363private import tango.core.Exception; 
    6464private import tango.stdc.string : wcslen; 
    65 private import tango.text.convert.Utf : toUtf16, toUTF8 = toUtf8
     65private import tango.text.convert.Utf : toString16, toUTF8 = toString
    6666 
    6767// Grabbed from juno.base.native, use tango.sys.win32.UserGdi have some problem here 
     
    220220 
    221221// Grabbed from juno.base.string since Tango's stdc.stringz, text.convert.Utf lacks these: 
    222 public wchar* toUtf16z(string s, int start = 0, int count = -1) { 
     222public wchar* toString16z(string s, int start = 0, int count = -1) { 
    223223  if (s is null) 
    224224    return null; 
     
    229229  return s[start .. count].toUTF16z(); 
    230230} 
    231 public string toUtf8(wchar* s, int start = 0, int count = -1) { 
     231public string toString(wchar* s, int start = 0, int count = -1) { 
    232232  if (s == null) 
    233233    return null; 
     
    342342    { 
    343343        wchar[] ws; 
    344         ws = toUtf16(s); 
     344        ws = toString16(s); 
    345345        ws ~= '\0'; 
    346346        return ws.ptr; 
     
    356356    if (parts[i].length > 0) { 
    357357      string temp = "%" ~ parts[i] ~ "%"; 
    358       uint n = ExpandEnvironmentStrings(temp.toUtf16z(), buffer.ptr, c); 
     358      uint n = ExpandEnvironmentStrings(temp.toString16z(), buffer.ptr, c); 
    359359      while (n > c) { 
    360360        c = n; 
    361361        buffer.length = c; 
    362         n = ExpandEnvironmentStrings(temp.toUtf16z(), buffer.ptr, c); 
    363       } 
    364     } 
    365   } 
    366   int n = ExpandEnvironmentStrings(name.toUtf16z(), buffer.ptr, c); 
     362        n = ExpandEnvironmentStrings(temp.toString16z(), buffer.ptr, c); 
     363      } 
     364    } 
     365  } 
     366  int n = ExpandEnvironmentStrings(name.toString16z(), buffer.ptr, c); 
    367367  while (n > c) { 
    368368    c = n; 
    369369    buffer.length = c; 
    370     n = ExpandEnvironmentStrings(name.toUtf16z(), buffer.ptr, c); 
    371   } 
    372  
    373   return .toUtf8(buffer.ptr); 
     370    n = ExpandEnvironmentStrings(name.toString16z(), buffer.ptr, c); 
     371  } 
     372 
     373  return .toString(buffer.ptr); 
    374374} 
    375375 
     
    465465  public RegistryKey openSubKey(string name, bool writable = false) { 
    466466    Handle hkey; 
    467     int r = RegOpenKeyEx(hKey_, name.toUtf16z(), 0, (writable ? (KEY_READ | KEY_WRITE) : KEY_READ), hkey); 
     467    int r = RegOpenKeyEx(hKey_, name.toString16z(), 0, (writable ? (KEY_READ | KEY_WRITE) : KEY_READ), hkey); 
    468468    if (r == ERROR_SUCCESS && hkey != Handle.init && hkey != INVALID_HANDLE_VALUE) { 
    469469      auto key = new RegistryKey(hkey, writable, false, false, false); 
     
    479479    Handle hkey; 
    480480    uint disposition; 
    481     int r = RegCreateKeyEx(hKey_, name.toUtf16z(), 0, null, 0, KEY_READ | KEY_WRITE, null, hkey, disposition); 
     481    int r = RegCreateKeyEx(hKey_, name.toString16z(), 0, null, 0, KEY_READ | KEY_WRITE, null, hkey, disposition); 
    482482    if (r == ERROR_SUCCESS && hkey != Handle.init && hkey != INVALID_HANDLE_VALUE) { 
    483483      auto key = new RegistryKey(hkey, true, false, false, false); 
     
    498498   */ 
    499499  public void deleteSubKey(string name) { 
    500     RegDeleteKey(hKey_, name.toUtf16z()); 
     500    RegDeleteKey(hKey_, name.toString16z()); 
    501501  } 
    502502 
     
    511511      key.close(); 
    512512 
    513       int r = RegDeleteKey(hKey_, name.toUtf16z()); 
     513      int r = RegDeleteKey(hKey_, name.toString16z()); 
    514514      //if (r != ERROR_SUCCESS) 
    515515        //issueError(r, null); 
     
    524524   */ 
    525525  public void deleteValue(string name) { 
    526     RegDeleteValue(hKey_, name.toUtf16z()); 
     526    RegDeleteValue(hKey_, name.toString16z()); 
    527527  } 
    528528 
     
    534534  public RegistryValueKind getValueKind(string name) { 
    535535    uint cb, type; 
    536     RegQueryValueEx(hKey_, name.toUtf16z(), null, &type, null, &cb); 
     536    RegQueryValueEx(hKey_, name.toString16z(), null, &type, null, &cb); 
    537537    return cast(RegistryValueKind)type; 
    538538  } 
     
    548548  public T getValue(T)(string name, T defaultValue = T.init, bool doNotExpand = false) { 
    549549    uint cb, type; 
    550     if (RegQueryValueEx(hKey_, name.toUtf16z(), null, &type, null, &cb) == 0) { 
     550    if (RegQueryValueEx(hKey_, name.toString16z(), null, &type, null, &cb) == 0) { 
    551551      static if (is(T == int)) { 
    552552        if (type == REG_DWORD) { 
    553553          int b; 
    554           RegQueryValueEx(hKey_, name.toUtf16z(), null, &type, cast(ubyte*)&b, &cb); 
     554          RegQueryValueEx(hKey_, name.toString16z(), null, &type, cast(ubyte*)&b, &cb); 
    555555          return b; 
    556556        } 
     
    559559        if (type == REG_QWORD) { 
    560560          long b; 
    561           RegQueryValueEx(hKey_, name.toUtf16z(), null, &type, cast(ubyte*)&b, &cb); 
     561          RegQueryValueEx(hKey_, name.toString16z(), null, &type, cast(ubyte*)&b, &cb); 
    562562          return b; 
    563563        } 
     
    566566        if (type == REG_SZ || type == REG_EXPAND_SZ) { 
    567567          wchar[] b = new wchar[cb / 2]; 
    568           RegQueryValueEx(hKey_, name.toUtf16z(), null, &type, cast(ubyte*)b.ptr, &cb); 
    569           string result = .toUtf8(b.ptr); 
     568          RegQueryValueEx(hKey_, name.toString16z(), null, &type, cast(ubyte*)b.ptr, &cb); 
     569          string result = .toString(b.ptr); 
    570570 
    571571          if (!doNotExpand && type == REG_EXPAND_SZ) 
     
    580580 
    581581          wchar[] b = new wchar[cb / 2]; 
    582           RegQueryValueEx(hKey_, name.toUtf16z(), null, &type, cast(ubyte*)b.ptr, &cb); 
     582          RegQueryValueEx(hKey_, name.toString16z(), null, &type, cast(ubyte*)b.ptr, &cb); 
    583583 
    584584          uint index = 0; 
     
    589589 
    590590            if (pos < end) { 
    591               if (pos - index > 0) result ~= .toUtf8(b.ptr, index, pos); 
     591              if (pos - index > 0) result ~= .toString(b.ptr, index, pos); 
    592592              else if (pos != end - 1) result ~= ""; 
    593593            } 
    594             else result ~= .toUtf8(b.ptr, index, end); 
     594            else result ~= .toString(b.ptr, index, end); 
    595595 
    596596            index = pos + 1; 
     
    603603        if (type == REG_BINARY || type == REG_DWORD_BIG_ENDIAN) { 
    604604          ubyte[] b = new ubyte[cb]; 
    605           RegQueryValueEx(hKey_, name.toUtf16z(), null, &type, b.ptr, &cb); 
     605          RegQueryValueEx(hKey_, name.toString16z(), null, &type, b.ptr, &cb); 
    606606          return b; 
    607607        } 
     
    643643        else 
    644644          s = value; 
    645         r = RegSetValueEx(hKey_, name.toUtf16z(), 0, REG_SZ, cast(ubyte*)s.toUtf16z(), (s.length * 2) + 2); 
     645        r = RegSetValueEx(hKey_, name.toString16z(), 0, REG_SZ, cast(ubyte*)s.toString16z(), (s.length * 2) + 2); 
    646646        break; 
    647647      case RegistryValueKind.MultiString: 
    648648        break; 
    649649      case RegistryValueKind.Binary: 
    650         r = RegSetValueEx(hKey_, name.toUtf16z(), 0, REG_BINARY, cast(ubyte*)value.ptr, value.length); 
     650        r = RegSetValueEx(hKey_, name.toString16z(), 0, REG_BINARY, cast(ubyte*)value.ptr, value.length); 
    651651        break; 
    652652      case RegistryValueKind.DWord: 
    653         r = RegSetValueEx(hKey_, name.toUtf16z(), 0, REG_DWORD, cast(ubyte*)&value, int.sizeof); 
     653        r = RegSetValueEx(hKey_, name.toString16z(), 0, REG_DWORD, cast(ubyte*)&value, int.sizeof); 
    654654        break; 
    655655      case RegistryValueKind.QWord: 
    656         r = RegSetValueEx(hKey_, name.toUtf16z(), 0, REG_QWORD, cast(ubyte*)&value, long.sizeof); 
     656        r = RegSetValueEx(hKey_, name.toString16z(), 0, REG_QWORD, cast(ubyte*)&value, long.sizeof); 
    657657        break; 
    658658      default: 
     
    692692        uint cch = buffer.length; 
    693693        RegEnumKeyEx(hKey_, index, buffer.ptr, &cch, null, null, null, null); 
    694         result[index] = .toUtf8(buffer.ptr); 
     694        result[index] = .toString(buffer.ptr); 
    695695      } 
    696696    } 
     
    722722        uint cch = buffer.length; 
    723723        RegEnumValue(hKey_, index, buffer.ptr, &cch, null, null, null, null); 
    724         result[index] = .toUtf8(buffer.ptr); 
     724        result[index] = .toString(buffer.ptr); 
    725725      } 
    726726    } 
     
    749749      uint r = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_IGNORE_INSERTS, null, error, LOCALE_USER_DEFAULT, buffer.ptr, buffer.length + 1, null); 
    750750      if (r != 0) { 
    751         return toUtf8(buffer.ptr, 0, r); 
     751        return toString(buffer.ptr, 0, r); 
    752752      } 
    753753      return format("Unspecified error (0x{0:X8})", error);