X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=win32%2Fvdir.h;h=db7ec8417fef425597e9c36e18dc88b288beeb09;hb=0100440d3c83cbbd0295cecf65f71318c7bebf25;hp=37cb4a580e6293bdbe652c675e750f4ec0661586;hpb=22d4bb9ccb8701e68f9243547d7e3a3c55f70908;p=p5sagit%2Fp5-mst-13.2.git diff --git a/win32/vdir.h b/win32/vdir.h index 37cb4a5..db7ec84 100644 --- a/win32/vdir.h +++ b/win32/vdir.h @@ -34,47 +34,48 @@ public: inline char* GetCurrentDirectoryA(int dwBufSize, char *lpBuffer) { char* ptr = dirTableA[nDefault]; - while (dwBufSize--) + while (--dwBufSize) { if ((*lpBuffer++ = *ptr++) == '\0') break; } - return lpBuffer; + *lpBuffer = '\0'; + return /* unused */ NULL; }; inline WCHAR* GetCurrentDirectoryW(int dwBufSize, WCHAR *lpBuffer) { WCHAR* ptr = dirTableW[nDefault]; - while (dwBufSize--) + while (--dwBufSize) { if ((*lpBuffer++ = *ptr++) == '\0') break; } - return lpBuffer; + *lpBuffer = '\0'; + return /* unused */ NULL; }; - DWORD CalculateEnvironmentSpace(void); LPSTR BuildEnvironmentSpace(LPSTR lpStr); protected: int SetDirA(char const *pPath, int index); + int SetDirW(WCHAR const *pPath, int index); void FromEnvA(char *pEnv, int index); + void FromEnvW(WCHAR *pEnv, int index); + inline const char *GetDefaultDirA(void) { return dirTableA[nDefault]; }; - inline void SetDefaultDirA(char const *pPath, int index) { SetDirA(pPath, index); nDefault = index; }; - int SetDirW(WCHAR const *pPath, int index); inline const WCHAR *GetDefaultDirW(void) { return dirTableW[nDefault]; }; - inline void SetDefaultDirW(WCHAR const *pPath, int index) { SetDirW(pPath, index); @@ -134,9 +135,6 @@ VDir::VDir(int bManageDir /* = 1 */) void VDir::Init(VDir* pDir, VMem *p) { int index; - DWORD driveBits; - int nSave; - char szBuffer[MAX_PATH*driveCount]; pMem = p; if (pDir) { @@ -146,23 +144,47 @@ void VDir::Init(VDir* pDir, VMem *p) nDefault = pDir->GetDefault(); } else { - nSave = bManageDirectory; + int bSave = bManageDirectory; + DWORD driveBits = GetLogicalDrives(); + OSVERSIONINFO osver; + + memset(&osver, 0, sizeof(osver)); + osver.dwOSVersionInfoSize = sizeof(osver); + GetVersionEx(&osver); + bManageDirectory = 0; - driveBits = GetLogicalDrives(); - if (GetLogicalDriveStrings(sizeof(szBuffer), szBuffer)) { - char* pEnv = GetEnvironmentStrings(); - char* ptr = szBuffer; - for (index = 0; index < driveCount; ++index) { - if (driveBits & (1<Free(dirTableA[index]); dirTableA[index] = (char*)pMem->Malloc(length+1); if (dirTableA[index] != NULL) { - strcpy(dirTableA[index], szBuffer); + strcpy(dirTableA[index], ansi); } + win32_free(ansi); } } @@ -281,7 +316,7 @@ inline void DoGetFullPathNameA(char* lpBuffer, DWORD dwSize, char* Dest) /* * On WinNT GetFullPathName does not fail, (or at least always - * succeeds when the drive is valid) WinNT does set *Dest to Nullch + * succeeds when the drive is valid) WinNT does set *Dest to NULL * On Win98 GetFullPathName will set last error if it fails, but * does not touch *Dest */ @@ -393,7 +428,7 @@ char *VDir::MapPathA(const char *pInName) /* has drive letter */ if (IsPathSep(pInName[2])) { /* absolute with drive letter */ - strcpy(szLocalBufferA, pInName); + DoGetFullPathNameA((char*)pInName, sizeof(szLocalBufferA), szLocalBufferA); } else { /* relative path with drive letter */ @@ -409,15 +444,14 @@ char *VDir::MapPathA(const char *pInName) /* no drive letter */ if (IsPathSep(pInName[1]) && IsPathSep(pInName[0])) { /* UNC name */ - strcpy(szLocalBufferA, pInName); + DoGetFullPathNameA((char*)pInName, sizeof(szLocalBufferA), szLocalBufferA); } else { strcpy(szBuffer, GetDefaultDirA()); if (IsPathSep(pInName[0])) { /* absolute path */ - szLocalBufferA[0] = szBuffer[0]; - szLocalBufferA[1] = szBuffer[1]; - strcpy(&szLocalBufferA[2], pInName); + strcpy(&szBuffer[2], pInName); + DoGetFullPathNameA(szBuffer, sizeof(szLocalBufferA), szLocalBufferA); } else { /* relative path */ @@ -453,7 +487,9 @@ int VDir::SetCurrentDirectoryA(char *lpBuffer) DWORD r = GetFileAttributesA(pPtr); if ((r != 0xffffffff) && (r & FILE_ATTRIBUTE_DIRECTORY)) { - SetDefaultDirA(pPtr, DriveIndex(pPtr[0])); + char szBuffer[(MAX_PATH+1)*2]; + DoGetFullPathNameA(pPtr, sizeof(szBuffer), szBuffer); + SetDefaultDirA(szBuffer, DriveIndex(szBuffer[0])); nRet = 0; } @@ -508,7 +544,7 @@ inline void DoGetFullPathNameW(WCHAR* lpBuffer, DWORD dwSize, WCHAR* Dest) /* * On WinNT GetFullPathName does not fail, (or at least always - * succeeds when the drive is valid) WinNT does set *Dest to Nullch + * succeeds when the drive is valid) WinNT does set *Dest to NULL * On Win98 GetFullPathName will set last error if it fails, but * does not touch *Dest */ @@ -620,7 +656,7 @@ WCHAR* VDir::MapPathW(const WCHAR *pInName) /* has drive letter */ if (IsPathSep(pInName[2])) { /* absolute with drive letter */ - wcscpy(szLocalBufferW, pInName); + DoGetFullPathNameW((WCHAR*)pInName, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW); } else { /* relative path with drive letter */ @@ -636,15 +672,14 @@ WCHAR* VDir::MapPathW(const WCHAR *pInName) /* no drive letter */ if (IsPathSep(pInName[1]) && IsPathSep(pInName[0])) { /* UNC name */ - wcscpy(szLocalBufferW, pInName); + DoGetFullPathNameW((WCHAR*)pInName, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW); } else { wcscpy(szBuffer, GetDefaultDirW()); if (IsPathSep(pInName[0])) { /* absolute path */ - szLocalBufferW[0] = szBuffer[0]; - szLocalBufferW[1] = szBuffer[1]; - wcscpy(&szLocalBufferW[2], pInName); + wcscpy(&szBuffer[2], pInName); + DoGetFullPathNameW(szBuffer, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW); } else { /* relative path */ @@ -679,7 +714,9 @@ int VDir::SetCurrentDirectoryW(WCHAR *lpBuffer) DWORD r = GetFileAttributesW(pPtr); if ((r != 0xffffffff) && (r & FILE_ATTRIBUTE_DIRECTORY)) { - SetDefaultDirW(pPtr, DriveIndex((char)pPtr[0])); + WCHAR wBuffer[(MAX_PATH+1)*2]; + DoGetFullPathNameW(pPtr, (sizeof(wBuffer)/sizeof(WCHAR)), wBuffer); + SetDefaultDirW(wBuffer, DriveIndex((char)wBuffer[0])); nRet = 0; }