Revision: 8811 https://osdn.net/projects/ttssh2/scm/svn/commits/8811 Author: zmatsuo Date: 2020-06-25 00:26:13 +0900 (Thu, 25 Jun 2020) Log Message: ----------- _GetFullPathNameW() を追加 Modified Paths: -------------- trunk/teraterm/common/compat_win.cpp trunk/teraterm/common/compat_win.h trunk/teraterm/common/layer_for_unicode.cpp trunk/teraterm/common/layer_for_unicode.h -------------- next part -------------- Modified: trunk/teraterm/common/compat_win.cpp =================================================================== --- trunk/teraterm/common/compat_win.cpp 2020-06-23 14:55:45 UTC (rev 8810) +++ trunk/teraterm/common/compat_win.cpp 2020-06-24 15:26:13 UTC (rev 8811) @@ -93,7 +93,8 @@ DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); HANDLE (WINAPI *pFindFirstFileW)(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData); BOOL (WINAPI *pFindNextFileW)(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData); -BOOL(WINAPI *pRemoveDirectoryW)(LPCWSTR lpPathName); +BOOL (WINAPI *pRemoveDirectoryW)(LPCWSTR lpPathName); +DWORD (WINAPI *pGetFullPathNameW)(LPCWSTR lpFileName, DWORD nBufferLength, LPWSTR lpBuffer, LPWSTR *lpFilePart); // gdi32 int (WINAPI *pAddFontResourceExW)(LPCWSTR name, DWORD fl, PVOID res); @@ -245,6 +246,7 @@ { "FindFirstFileW", (void **)&pFindFirstFileW }, { "FindNextFileW", (void **)&pFindNextFileW }, { "RemoveDirectoryW", (void **)&pRemoveDirectoryW }, + { "GetFullPathNameW", (void **)&pGetFullPathNameW }, #endif { "GetConsoleWindow", (void **)&pGetConsoleWindow }, {}, Modified: trunk/teraterm/common/compat_win.h =================================================================== --- trunk/teraterm/common/compat_win.h 2020-06-23 14:55:45 UTC (rev 8810) +++ trunk/teraterm/common/compat_win.h 2020-06-24 15:26:13 UTC (rev 8811) @@ -153,7 +153,8 @@ DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); extern HANDLE (WINAPI *pFindFirstFileW)(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData); extern BOOL (WINAPI *pFindNextFileW)(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData); -extern BOOL(WINAPI *pRemoveDirectoryW)(LPCWSTR lpPathName); +extern BOOL (WINAPI *pRemoveDirectoryW)(LPCWSTR lpPathName); +extern DWORD (WINAPI *pGetFullPathNameW)(LPCWSTR lpFileName, DWORD nBufferLength, LPWSTR lpBuffer, LPWSTR *lpFilePart); // shlobj_core.h extern LPITEMIDLIST (WINAPI *pSHBrowseForFolderW)(LPBROWSEINFOW lpbi); Modified: trunk/teraterm/common/layer_for_unicode.cpp =================================================================== --- trunk/teraterm/common/layer_for_unicode.cpp 2020-06-23 14:55:45 UTC (rev 8810) +++ trunk/teraterm/common/layer_for_unicode.cpp 2020-06-24 15:26:13 UTC (rev 8811) @@ -799,3 +799,31 @@ free(lpPathNameA); return r; } + +DWORD _GetFullPathNameW(LPCWSTR lpFileName, DWORD nBufferLength, LPWSTR lpBuffer, LPWSTR *lpFilePart) +{ + if (pGetFullPathNameW != NULL) { + return pGetFullPathNameW(lpFileName, nBufferLength, lpBuffer, lpFilePart); + } + + char *filenameA = ToCharW(lpFileName); + char bufA[MAX_PATH]; + char *filepartA; + DWORD r = GetFullPathNameA(filenameA, sizeof(bufA), bufA, &filepartA); + if (r == 0) { + // error + free(filenameA); + return 0; + } + wchar_t *bufW = ToWcharA(bufA); + r = wcslen(bufW); // \x95K\x97v\x82ȃo\x83b\x83t\x83@\x83T\x83C\x83Y\x82\xF0\x95Ԃ\xB7('\0'\x8A܂܂Ȃ\xA2) + wcsncpy_s(lpBuffer, nBufferLength, bufW, _TRUNCATE); + if (lpFilePart != NULL) { + *lpFilePart = lpBuffer + (filepartA - filenameA) * sizeof(wchar_t); + } + free(filenameA); + free(bufW); + + return r; +} + Modified: trunk/teraterm/common/layer_for_unicode.h =================================================================== --- trunk/teraterm/common/layer_for_unicode.h 2020-06-23 14:55:45 UTC (rev 8810) +++ trunk/teraterm/common/layer_for_unicode.h 2020-06-24 15:26:13 UTC (rev 8811) @@ -134,6 +134,7 @@ HANDLE _FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData); BOOL _FindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData); BOOL _RemoveDirectoryW(LPCWSTR lpPathName); +DWORD _GetFullPathNameW(LPCWSTR lpFileName, DWORD nBufferLength, LPWSTR lpBuffer, LPWSTR *lpFilePart); // gdi32.lib int _AddFontResourceW(LPCWSTR lpFileName);