Fix deprecations on Windows

This commit is contained in:
Sebastian Wilzbach 2017-07-05 19:56:37 +02:00
parent 5b456a10a9
commit d8959320e0
4 changed files with 16 additions and 22 deletions

View file

@ -2991,8 +2991,6 @@ else version(Windows)
static immutable(WindowsTimeZone) getTimeZone(string name) @trusted static immutable(WindowsTimeZone) getTimeZone(string name) @trusted
{ {
import std.utf : toUTF16;
scope baseKey = Registry.localMachine.getKey(`Software\Microsoft\Windows NT\CurrentVersion\Time Zones`); scope baseKey = Registry.localMachine.getKey(`Software\Microsoft\Windows NT\CurrentVersion\Time Zones`);
foreach (tzKeyName; baseKey.keyNames) foreach (tzKeyName; baseKey.keyNames)
@ -3015,8 +3013,8 @@ else version(Windows)
TIME_ZONE_INFORMATION tzInfo; TIME_ZONE_INFORMATION tzInfo;
auto wstdName = toUTF16(stdName); auto wstdName = stdName.to!wstring;
auto wdstName = toUTF16(dstName); auto wdstName = dstName.to!wstring;
auto wstdNameLen = wstdName.length > 32 ? 32 : wstdName.length; auto wstdNameLen = wstdName.length > 32 ? 32 : wstdName.length;
auto wdstNameLen = wdstName.length > 32 ? 32 : wdstName.length; auto wdstNameLen = wdstName.length > 32 ? 32 : wdstName.length;

View file

@ -2644,7 +2644,6 @@ version(Posix) @system unittest // input range of dchars
version(Windows) string getcwd() version(Windows) string getcwd()
{ {
import std.conv : to; import std.conv : to;
import std.utf : toUTF8;
/* GetCurrentDirectory's return value: /* GetCurrentDirectory's return value:
1. function succeeds: the number of characters that are written to 1. function succeeds: the number of characters that are written to
the buffer, not including the terminating null character. the buffer, not including the terminating null character.
@ -2658,7 +2657,7 @@ version(Windows) string getcwd()
// we can do it because toUTFX always produces a fresh string // we can do it because toUTFX always produces a fresh string
if (n < buffW.length) if (n < buffW.length)
{ {
return toUTF8(buffW[0 .. n]); return buffW[0 .. n].to!string;
} }
else //staticBuff isn't enough else //staticBuff isn't enough
{ {
@ -2666,7 +2665,7 @@ version(Windows) string getcwd()
scope(exit) free(ptr); scope(exit) free(ptr);
immutable n2 = GetCurrentDirectoryW(n, ptr); immutable n2 = GetCurrentDirectoryW(n, ptr);
cenforce(n2 && n2 < n, "getcwd"); cenforce(n2 && n2 < n, "getcwd");
return toUTF8(ptr[0 .. n2]); return ptr[0 .. n2].to!string;
} }
} }
else version (Solaris) string getcwd() else version (Solaris) string getcwd()
@ -2968,7 +2967,6 @@ else version(Windows)
{ {
struct DirEntry struct DirEntry
{ {
import std.utf : toUTF8;
public: public:
alias name this; alias name this;
@ -2994,12 +2992,12 @@ else version(Windows)
private this(string path, in WIN32_FIND_DATAW *fd) private this(string path, in WIN32_FIND_DATAW *fd)
{ {
import core.stdc.wchar_ : wcslen; import core.stdc.wchar_ : wcslen;
import std.conv : to;
import std.datetime.systime : FILETIMEToSysTime; import std.datetime.systime : FILETIMEToSysTime;
import std.path : buildPath; import std.path : buildPath;
size_t clength = wcslen(fd.cFileName.ptr); size_t clength = wcslen(fd.cFileName.ptr);
_name = toUTF8(fd.cFileName[0 .. clength]); _name = buildPath(path, fd.cFileName[0 .. clength].to!string);
_name = buildPath(path, toUTF8(fd.cFileName[0 .. clength]));
_size = (cast(ulong) fd.nFileSizeHigh << 32) | fd.nFileSizeLow; _size = (cast(ulong) fd.nFileSizeHigh << 32) | fd.nFileSizeLow;
_timeCreated = FILETIMEToSysTime(&fd.ftCreationTime); _timeCreated = FILETIMEToSysTime(&fd.ftCreationTime);
_timeLastAccessed = FILETIMEToSysTime(&fd.ftLastAccessTime); _timeLastAccessed = FILETIMEToSysTime(&fd.ftLastAccessTime);
@ -3431,7 +3429,7 @@ private void copyImpl(const(char)[] f, const(char)[] t, const(FSChar)* fromz, co
{ {
version(Windows) version(Windows)
{ {
assert(preserve == Yes.preserve); assert(preserve == Yes.preserveAttributes);
immutable result = CopyFileW(fromz, toz, false); immutable result = CopyFileW(fromz, toz, false);
if (!result) if (!result)
{ {
@ -4287,11 +4285,11 @@ string tempDir() @trusted
{ {
version(Windows) version(Windows)
{ {
import std.utf : toUTF8; import std.conv : to;
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa364992(v=vs.85).aspx // http://msdn.microsoft.com/en-us/library/windows/desktop/aa364992(v=vs.85).aspx
wchar[MAX_PATH + 2] buf; wchar[MAX_PATH + 2] buf;
DWORD len = GetTempPathW(buf.length, buf.ptr); DWORD len = GetTempPathW(buf.length, buf.ptr);
if (len) cache = toUTF8(buf[0 .. len]); if (len) cache = buf[0 .. len].to!string;
} }
else version(Android) else version(Android)
{ {

View file

@ -53,7 +53,6 @@ version (Windows):
private import core.sys.windows.windows; private import core.sys.windows.windows;
private import std.conv; private import std.conv;
private import std.string; private import std.string;
private import std.utf;
private import std.windows.syserror; private import std.windows.syserror;
import std.internal.cstring; import std.internal.cstring;
@ -114,7 +113,7 @@ string fromMBSz(immutable(char)* s, int codePage = 0)
sysErrorString(GetLastError())); sysErrorString(GetLastError()));
} }
return std.utf.toUTF8(result[0 .. result.length-1]); // omit trailing null return result[0 .. result.length-1].to!string; // omit trailing null
} }
} }
return s[0 .. c-s]; // string is ASCII, no conversion necessary return s[0 .. c-s]; // string is ASCII, no conversion necessary

View file

@ -45,7 +45,6 @@ import std.exception;
import std.internal.cstring; import std.internal.cstring;
private import std.internal.windows.advapi32; private import std.internal.windows.advapi32;
import std.system : Endian, endian; import std.system : Endian, endian;
import std.utf : toUTF8, toUTF16;
import std.windows.syserror; import std.windows.syserror;
//debug = winreg; //debug = winreg;
@ -557,7 +556,7 @@ body
if (wstr.length && wstr[$-1] == '\0') if (wstr.length && wstr[$-1] == '\0')
wstr.length = wstr.length - 1; wstr.length = wstr.length - 1;
assert(wstr.length == 0 || wstr[$-1] != '\0'); assert(wstr.length == 0 || wstr[$-1] != '\0');
value = toUTF8(wstr); value = wstr.to!string;
break; break;
case REG_VALUE_TYPE.REG_DWORD_LITTLE_ENDIAN: case REG_VALUE_TYPE.REG_DWORD_LITTLE_ENDIAN:
@ -623,7 +622,7 @@ body
value.length = list.length; value.length = list.length;
foreach (i, ref v; value) foreach (i, ref v; value)
{ {
v = toUTF8(list[i]); v = list[i].to!string;
} }
} }
@ -752,7 +751,7 @@ private void regProcessNthKey(HKEY hkey, scope void delegate(scope LONG delegate
immutable res = regEnumKeyName(hkey, index, sName, cchName); immutable res = regEnumKeyName(hkey, index, sName, cchName);
if (res == ERROR_SUCCESS) if (res == ERROR_SUCCESS)
{ {
name = toUTF8(sName[0 .. cchName]); name = sName[0 .. cchName].to!string;
} }
return res; return res;
}); });
@ -774,7 +773,7 @@ private void regProcessNthValue(HKEY hkey, scope void delegate(scope LONG delega
immutable res = regEnumValueName(hkey, index, sName, cchName); immutable res = regEnumValueName(hkey, index, sName, cchName);
if (res == ERROR_SUCCESS) if (res == ERROR_SUCCESS)
{ {
name = toUTF8(sName[0 .. cchName]); name = sName[0 .. cchName].to!string;
} }
return res; return res;
}); });
@ -1098,7 +1097,7 @@ public:
wstring[] data = new wstring[value.length+1]; wstring[] data = new wstring[value.length+1];
foreach (i, ref s; data[0..$-1]) foreach (i, ref s; data[0..$-1])
{ {
s = toUTF16(value[i]); s = value[i].to!wstring;
} }
data[$-1] = "\0"; data[$-1] = "\0";
auto ws = std.array.join(data, "\0"w); auto ws = std.array.join(data, "\0"w);
@ -1235,7 +1234,7 @@ public:
ExpandEnvironmentStringsW(srcTmp, newValue.ptr, to!DWORD(newValue.length)), ExpandEnvironmentStringsW(srcTmp, newValue.ptr, to!DWORD(newValue.length)),
"Failed to expand environment variables"); "Failed to expand environment variables");
return toUTF8(newValue[0 .. count-1]); // remove trailing 0 return newValue[0 .. count-1].to!string; // remove trailing 0
} }
/** /**