Changeset 39 for trunk/tango/scrapple/sys/win32/Registry.d
- Timestamp:
- 01/04/08 11:00:27 (4 years ago)
- Files:
-
- trunk/tango/scrapple/sys/win32/Registry.d (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tango/scrapple/sys/win32/Registry.d
r34 r39 63 63 private import tango.core.Exception; 64 64 private import tango.stdc.string : wcslen; 65 private import tango.text.convert.Utf : to Utf16, toUTF8 = toUtf8;65 private import tango.text.convert.Utf : toString16, toUTF8 = toString; 66 66 67 67 // Grabbed from juno.base.native, use tango.sys.win32.UserGdi have some problem here … … 220 220 221 221 // Grabbed from juno.base.string since Tango's stdc.stringz, text.convert.Utf lacks these: 222 public wchar* to Utf16z(string s, int start = 0, int count = -1) {222 public wchar* toString16z(string s, int start = 0, int count = -1) { 223 223 if (s is null) 224 224 return null; … … 229 229 return s[start .. count].toUTF16z(); 230 230 } 231 public string to Utf8(wchar* s, int start = 0, int count = -1) {231 public string toString(wchar* s, int start = 0, int count = -1) { 232 232 if (s == null) 233 233 return null; … … 342 342 { 343 343 wchar[] ws; 344 ws = to Utf16(s);344 ws = toString16(s); 345 345 ws ~= '\0'; 346 346 return ws.ptr; … … 356 356 if (parts[i].length > 0) { 357 357 string temp = "%" ~ parts[i] ~ "%"; 358 uint n = ExpandEnvironmentStrings(temp.to Utf16z(), buffer.ptr, c);358 uint n = ExpandEnvironmentStrings(temp.toString16z(), buffer.ptr, c); 359 359 while (n > c) { 360 360 c = n; 361 361 buffer.length = c; 362 n = ExpandEnvironmentStrings(temp.to Utf16z(), buffer.ptr, c);363 } 364 } 365 } 366 int n = ExpandEnvironmentStrings(name.to Utf16z(), buffer.ptr, c);362 n = ExpandEnvironmentStrings(temp.toString16z(), buffer.ptr, c); 363 } 364 } 365 } 366 int n = ExpandEnvironmentStrings(name.toString16z(), buffer.ptr, c); 367 367 while (n > c) { 368 368 c = n; 369 369 buffer.length = c; 370 n = ExpandEnvironmentStrings(name.to Utf16z(), buffer.ptr, c);371 } 372 373 return .to Utf8(buffer.ptr);370 n = ExpandEnvironmentStrings(name.toString16z(), buffer.ptr, c); 371 } 372 373 return .toString(buffer.ptr); 374 374 } 375 375 … … 465 465 public RegistryKey openSubKey(string name, bool writable = false) { 466 466 Handle hkey; 467 int r = RegOpenKeyEx(hKey_, name.to Utf16z(), 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); 468 468 if (r == ERROR_SUCCESS && hkey != Handle.init && hkey != INVALID_HANDLE_VALUE) { 469 469 auto key = new RegistryKey(hkey, writable, false, false, false); … … 479 479 Handle hkey; 480 480 uint disposition; 481 int r = RegCreateKeyEx(hKey_, name.to Utf16z(), 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); 482 482 if (r == ERROR_SUCCESS && hkey != Handle.init && hkey != INVALID_HANDLE_VALUE) { 483 483 auto key = new RegistryKey(hkey, true, false, false, false); … … 498 498 */ 499 499 public void deleteSubKey(string name) { 500 RegDeleteKey(hKey_, name.to Utf16z());500 RegDeleteKey(hKey_, name.toString16z()); 501 501 } 502 502 … … 511 511 key.close(); 512 512 513 int r = RegDeleteKey(hKey_, name.to Utf16z());513 int r = RegDeleteKey(hKey_, name.toString16z()); 514 514 //if (r != ERROR_SUCCESS) 515 515 //issueError(r, null); … … 524 524 */ 525 525 public void deleteValue(string name) { 526 RegDeleteValue(hKey_, name.to Utf16z());526 RegDeleteValue(hKey_, name.toString16z()); 527 527 } 528 528 … … 534 534 public RegistryValueKind getValueKind(string name) { 535 535 uint cb, type; 536 RegQueryValueEx(hKey_, name.to Utf16z(), null, &type, null, &cb);536 RegQueryValueEx(hKey_, name.toString16z(), null, &type, null, &cb); 537 537 return cast(RegistryValueKind)type; 538 538 } … … 548 548 public T getValue(T)(string name, T defaultValue = T.init, bool doNotExpand = false) { 549 549 uint cb, type; 550 if (RegQueryValueEx(hKey_, name.to Utf16z(), null, &type, null, &cb) == 0) {550 if (RegQueryValueEx(hKey_, name.toString16z(), null, &type, null, &cb) == 0) { 551 551 static if (is(T == int)) { 552 552 if (type == REG_DWORD) { 553 553 int b; 554 RegQueryValueEx(hKey_, name.to Utf16z(), null, &type, cast(ubyte*)&b, &cb);554 RegQueryValueEx(hKey_, name.toString16z(), null, &type, cast(ubyte*)&b, &cb); 555 555 return b; 556 556 } … … 559 559 if (type == REG_QWORD) { 560 560 long b; 561 RegQueryValueEx(hKey_, name.to Utf16z(), null, &type, cast(ubyte*)&b, &cb);561 RegQueryValueEx(hKey_, name.toString16z(), null, &type, cast(ubyte*)&b, &cb); 562 562 return b; 563 563 } … … 566 566 if (type == REG_SZ || type == REG_EXPAND_SZ) { 567 567 wchar[] b = new wchar[cb / 2]; 568 RegQueryValueEx(hKey_, name.to Utf16z(), null, &type, cast(ubyte*)b.ptr, &cb);569 string result = .to Utf8(b.ptr);568 RegQueryValueEx(hKey_, name.toString16z(), null, &type, cast(ubyte*)b.ptr, &cb); 569 string result = .toString(b.ptr); 570 570 571 571 if (!doNotExpand && type == REG_EXPAND_SZ) … … 580 580 581 581 wchar[] b = new wchar[cb / 2]; 582 RegQueryValueEx(hKey_, name.to Utf16z(), null, &type, cast(ubyte*)b.ptr, &cb);582 RegQueryValueEx(hKey_, name.toString16z(), null, &type, cast(ubyte*)b.ptr, &cb); 583 583 584 584 uint index = 0; … … 589 589 590 590 if (pos < end) { 591 if (pos - index > 0) result ~= .to Utf8(b.ptr, index, pos);591 if (pos - index > 0) result ~= .toString(b.ptr, index, pos); 592 592 else if (pos != end - 1) result ~= ""; 593 593 } 594 else result ~= .to Utf8(b.ptr, index, end);594 else result ~= .toString(b.ptr, index, end); 595 595 596 596 index = pos + 1; … … 603 603 if (type == REG_BINARY || type == REG_DWORD_BIG_ENDIAN) { 604 604 ubyte[] b = new ubyte[cb]; 605 RegQueryValueEx(hKey_, name.to Utf16z(), null, &type, b.ptr, &cb);605 RegQueryValueEx(hKey_, name.toString16z(), null, &type, b.ptr, &cb); 606 606 return b; 607 607 } … … 643 643 else 644 644 s = value; 645 r = RegSetValueEx(hKey_, name.to Utf16z(), 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); 646 646 break; 647 647 case RegistryValueKind.MultiString: 648 648 break; 649 649 case RegistryValueKind.Binary: 650 r = RegSetValueEx(hKey_, name.to Utf16z(), 0, REG_BINARY, cast(ubyte*)value.ptr, value.length);650 r = RegSetValueEx(hKey_, name.toString16z(), 0, REG_BINARY, cast(ubyte*)value.ptr, value.length); 651 651 break; 652 652 case RegistryValueKind.DWord: 653 r = RegSetValueEx(hKey_, name.to Utf16z(), 0, REG_DWORD, cast(ubyte*)&value, int.sizeof);653 r = RegSetValueEx(hKey_, name.toString16z(), 0, REG_DWORD, cast(ubyte*)&value, int.sizeof); 654 654 break; 655 655 case RegistryValueKind.QWord: 656 r = RegSetValueEx(hKey_, name.to Utf16z(), 0, REG_QWORD, cast(ubyte*)&value, long.sizeof);656 r = RegSetValueEx(hKey_, name.toString16z(), 0, REG_QWORD, cast(ubyte*)&value, long.sizeof); 657 657 break; 658 658 default: … … 692 692 uint cch = buffer.length; 693 693 RegEnumKeyEx(hKey_, index, buffer.ptr, &cch, null, null, null, null); 694 result[index] = .to Utf8(buffer.ptr);694 result[index] = .toString(buffer.ptr); 695 695 } 696 696 } … … 722 722 uint cch = buffer.length; 723 723 RegEnumValue(hKey_, index, buffer.ptr, &cch, null, null, null, null); 724 result[index] = .to Utf8(buffer.ptr);724 result[index] = .toString(buffer.ptr); 725 725 } 726 726 } … … 749 749 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); 750 750 if (r != 0) { 751 return to Utf8(buffer.ptr, 0, r);751 return toString(buffer.ptr, 0, r); 752 752 } 753 753 return format("Unspecified error (0x{0:X8})", error);
