X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7d33179be4d36ceb6cccb3fe3718e7d2cddcc200..f0c5ebdc0d881e5478f166bab335265460409ec9:/src/msw/utils.cpp diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index 634668dd77..2a9d0a99a4 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -436,14 +436,29 @@ wxChar *wxGetUserHome(const wxString& user) bool wxDirExists(const wxString& dir) { #if defined(__WIN32__) - DWORD attribs = GetFileAttributes(dir); - return ((attribs != -1) && (attribs & FILE_ATTRIBUTE_DIRECTORY)); + WIN32_FIND_DATA fileInfo; #else // Win16 #ifdef __BORLANDC__ struct ffblk fileInfo; #else struct find_t fileInfo; #endif +#endif // Win32/16 + +#if defined(__WIN32__) + HANDLE h = ::FindFirstFile(dir, &fileInfo); + + if ( h == INVALID_HANDLE_VALUE ) + { + wxLogLastError(wxT("FindFirstFile")); + + return FALSE; + } + + ::FindClose(h); + + return (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; +#else // Win16 // In Borland findfirst has a different argument // ordering from _dos_findfirst. But _dos_findfirst // _should_ be ok in both MS and Borland... why not? @@ -457,6 +472,47 @@ bool wxDirExists(const wxString& dir) #endif // Win32/16 } +// ---------------------------------------------------------------------------- +// env vars +// ---------------------------------------------------------------------------- + +bool wxGetEnv(const wxString& var, wxString *value) +{ + // first get the size of the buffer + DWORD dwRet = ::GetEnvironmentVariable(var, NULL, 0); + if ( !dwRet ) + { + // this means that there is no such variable + return FALSE; + } + + if ( value ) + { + (void)::GetEnvironmentVariable(var, value->GetWriteBuf(dwRet), dwRet); + value->UngetWriteBuf(); + } + + return TRUE; +} + +bool wxSetEnv(const wxString& var, const wxChar *value) +{ + // some compilers have putenv() or _putenv() or _wputenv() but it's better + // to always use Win32 function directly instead of dealing with them +#if defined(__WIN32__) + if ( !::SetEnvironmentVariable(var, value) ) + { + wxLogLastError(_T("SetEnvironmentVariable")); + + return FALSE; + } + + return TRUE; +#else // no way to set env vars + return FALSE; +#endif +} + // ---------------------------------------------------------------------------- // process management // ---------------------------------------------------------------------------- @@ -532,7 +588,7 @@ wxString wxGetOsDescription() case VER_PLATFORM_WIN32_WINDOWS: str.Printf(_("Windows 9%c"), - info.dwMinorVersion == 0 ? _T('5') : _T('9')); + info.dwMinorVersion == 0 ? _T('5') : _T('8')); if ( !wxIsEmpty(info.szCSDVersion) ) { str << _T(" (") << info.szCSDVersion << _T(')');