Revision: 8772 https://osdn.net/projects/ttssh2/scm/svn/commits/8772 Author: zmatsuo Date: 2020-05-15 00:10:58 +0900 (Fri, 15 May 2020) Log Message: ----------- layer_for_unicode 内で未実装だったAPIを実装 - _CopyFileW() - _DeleteFileW() - _MoveFileW() - _CreateFileW() - _FindFirstFileW() - _FindNextFileW() - _RemoveDirectoryW() Modified Paths: -------------- trunk/teraterm/common/compat_win.cpp trunk/teraterm/common/compat_win.h trunk/teraterm/common/layer_for_unicode.cpp -------------- next part -------------- Modified: trunk/teraterm/common/compat_win.cpp =================================================================== --- trunk/teraterm/common/compat_win.cpp 2020-05-12 14:32:44 UTC (rev 8771) +++ trunk/teraterm/common/compat_win.cpp 2020-05-14 15:10:58 UTC (rev 8772) @@ -73,7 +73,7 @@ // user32 int (WINAPI *pGetSystemMetricsForDpi)(int nIndex, UINT dpi); -// kernel32.dll +// kernel32 DWORD (WINAPI *pGetFileAttributesW)(LPCWSTR lpFileName); void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString); HWND (WINAPI *pGetConsoleWindow)(void); @@ -85,6 +85,15 @@ LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation); +BOOL (WINAPI *pCopyFileW)(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName, BOOL bFailIfExists); +BOOL (WINAPI *pDeleteFileW)(LPCWSTR lpFileName); +BOOL (WINAPI *pMoveFileW)(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName); +HANDLE (WINAPI *pCreateFileW)(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, + 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); // gdi32 int (WINAPI *pAddFontResourceExW)(LPCWSTR name, DWORD fl, PVOID res); @@ -229,6 +238,13 @@ { "GetPrivateProfileStringW", (void **)&pGetPrivateProfileStringW }, { "WritePrivateProfileStringW", (void **)&pWritePrivateProfileStringW }, { "CreateProcessW", (void **)&pCreateProcessW }, + { "CopyFileW", (void **)&pCopyFileW }, + { "DeleteFileW", (void **)&pDeleteFileW }, + { "MoveFileW", (void **)&pMoveFileW }, + { "CreateFileW", (void **)&pCreateFileW }, + { "FindFirstFileW", (void **)&pFindFirstFileW }, + { "FindNextFileW", (void **)&pFindNextFileW }, + { "RemoveDirectoryW", (void **)&pRemoveDirectoryW }, #endif { "GetConsoleWindow", (void **)&pGetConsoleWindow }, {}, @@ -317,6 +333,13 @@ pSHBrowseForFolderW = NULL; pSHGetPathFromIDListW = NULL; pCreateProcessW = NULL; + pCopyFileW = NULL; + pDeleteFileW = NULL; + pMoveFileW = NULL; + pCreateFileW = NULL; + pFindFirstFileW = NULL; + pFindNextFileW = NULL; + pRemoveDirectoryW = NULL; } // GetConsoleWindow\x93\xC1\x95ʏ\x88\x97\x9D Modified: trunk/teraterm/common/compat_win.h =================================================================== --- trunk/teraterm/common/compat_win.h 2020-05-12 14:32:44 UTC (rev 8771) +++ trunk/teraterm/common/compat_win.h 2020-05-14 15:10:58 UTC (rev 8772) @@ -82,7 +82,6 @@ extern DWORD(WINAPI *pGetPrivateProfileStringW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpDefault, LPWSTR lpReturnedString, DWORD nSize, LPCWSTR lpFileName); extern UINT(WINAPI *pDragQueryFileW)(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch); -extern DWORD (WINAPI *pGetFileAttributesW)(LPCWSTR lpFileName); extern BOOL (WINAPI *pSetDlgItemTextW)(HWND hDlg, int nIDDlgItem, LPCWSTR lpString); extern BOOL (WINAPI *pGetDlgItemTextW)(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int cchMax); extern BOOL (WINAPI *pAlphaBlend)(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION); @@ -97,7 +96,6 @@ extern BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags); extern int (WINAPI *pAddFontResourceExW)(LPCWSTR name, DWORD fl, PVOID res); extern BOOL (WINAPI *pRemoveFontResourceExW)(LPCWSTR name, DWORD fl, PVOID pdv); -extern HWND (WINAPI *pGetConsoleWindow)(void); extern int (WINAPI *pMessageBoxW)(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType); extern INT_PTR (WINAPI *pDialogBoxIndirectParamW)(HINSTANCE hInstance, LPCDLGTEMPLATEW hDialogTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam); extern HWND (WINAPI *pCreateDialogIndirectParamW)(HINSTANCE hInstance, LPCDLGTEMPLATEW lpTemplate, @@ -121,7 +119,6 @@ #endif extern LRESULT (WINAPI *pCallWindowProcW)(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); -extern void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString); extern DWORD (WINAPI *pGetCurrentDirectoryW)(DWORD nBufferLength, LPWSTR lpBuffer); extern BOOL (WINAPI *pSetCurrentDirectoryW)(LPCWSTR lpPathName); extern BOOL (WINAPI *pGetOpenFileNameW)(LPOPENFILENAMEW ofnW); @@ -136,6 +133,28 @@ LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation); extern int (WINAPI *pGetSystemMetricsForDpi)(int nIndex, UINT dpi); +// kernel32 +extern DWORD (WINAPI *pGetFileAttributesW)(LPCWSTR lpFileName); +extern void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString); +extern HWND (WINAPI *pGetConsoleWindow)(void); +extern DWORD (WINAPI *pGetPrivateProfileStringW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpDefault, + LPWSTR lpReturnedString, DWORD nSize, LPCWSTR lpFileName); +extern BOOL (WINAPI *pWritePrivateProfileStringW)(LPCWSTR lpAppName,LPCWSTR lpKeyName,LPCWSTR lpString,LPCWSTR lpFileName); +extern BOOL (WINAPI *pCreateProcessW)(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, + DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, + LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation); +extern BOOL (WINAPI *pCopyFileW)(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName, BOOL bFailIfExists); +extern BOOL (WINAPI *pDeleteFileW)(LPCWSTR lpFileName); +extern BOOL (WINAPI *pMoveFileW)(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName); +extern HANDLE (WINAPI *pCreateFileW)(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, + 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); + // shlobj_core.h extern LPITEMIDLIST (WINAPI *pSHBrowseForFolderW)(LPBROWSEINFOW lpbi); extern BOOL (WINAPI *pSHGetPathFromIDListW)(LPITEMIDLIST pidl, LPWSTR pszPath); Modified: trunk/teraterm/common/layer_for_unicode.cpp =================================================================== --- trunk/teraterm/common/layer_for_unicode.cpp 2020-05-12 14:32:44 UTC (rev 8771) +++ trunk/teraterm/common/layer_for_unicode.cpp 2020-05-14 15:10:58 UTC (rev 8772) @@ -33,6 +33,12 @@ */ #include <windows.h> +#if !defined(_CRTDBG_MAP_ALLOC) +#define _CRTDBG_MAP_ALLOC +#endif +#include <stdlib.h> +#include <crtdbg.h> +#include <assert.h> #include "codeconv.h" #include "compat_win.h" @@ -693,17 +699,39 @@ BOOL _CopyFileW(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName, BOOL bFailIfExists) { - return CopyFileW(lpExistingFileName, lpNewFileName, bFailIfExists); + if (pCopyFileW != NULL) { + return pCopyFileW(lpExistingFileName, lpNewFileName, bFailIfExists); + } + char *lpExistingFileNameA = ToCharW(lpExistingFileName); + char *lpNewFileNameA = ToCharW(lpNewFileName); + BOOL r = CopyFileA(lpExistingFileNameA, lpNewFileNameA, bFailIfExists); + free(lpExistingFileNameA); + free(lpNewFileNameA); + return r; } BOOL _DeleteFileW(LPCWSTR lpFileName) { - return DeleteFileW(lpFileName); + if (pDeleteFileW != NULL) { + return pDeleteFileW(lpFileName); + } + char *lpFileNameA = ToCharW(lpFileName); + BOOL r = DeleteFileA(lpFileNameA); + free(lpFileNameA); + return r; } BOOL _MoveFileW(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName) { - return MoveFileW(lpExistingFileName, lpNewFileName); + if (pMoveFileW != NULL) { + return pMoveFileW(lpExistingFileName, lpNewFileName); + } + char *lpExistingFileNameA = ToCharW(lpExistingFileName); + char *lpNewFileNameA = ToCharW(lpNewFileName); + BOOL r = MoveFileA(lpExistingFileNameA, lpNewFileNameA); + free(lpExistingFileNameA); + free(lpNewFileNameA); + return r; } HANDLE _CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, @@ -710,21 +738,64 @@ LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) { - return CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, - dwFlagsAndAttributes, hTemplateFile); + if (pCreateFileW != NULL) { + return pCreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, + dwFlagsAndAttributes, hTemplateFile); + } + + char *lpFileNameA = ToCharW(lpFileName); + HANDLE handle = CreateFileA(lpFileNameA, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, + dwFlagsAndAttributes, hTemplateFile); + free(lpFileNameA); + return handle; } +static void FindDataAW(const WIN32_FIND_DATAA *a, WIN32_FIND_DATAW *w) +{ + w->dwFileAttributes = a->dwFileAttributes; + w->ftCreationTime = a->ftCreationTime; + w->ftLastAccessTime = a->ftLastAccessTime; + w->ftLastWriteTime = a->ftLastWriteTime; + w->nFileSizeHigh = a->nFileSizeHigh; + w->nFileSizeLow = a->nFileSizeLow; + w->dwReserved0 = a->dwReserved0; + w->dwReserved1 = a->dwReserved1; + ::MultiByteToWideChar(CP_ACP, 0, a->cFileName, _countof(a->cFileName), w->cFileName, _countof(w->cFileName)); + ::MultiByteToWideChar(CP_ACP, 0, a->cAlternateFileName, _countof(a->cAlternateFileName), w->cAlternateFileName, _countof(w->cAlternateFileName)); +} + HANDLE _FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData) { - return FindFirstFileW(lpFileName, lpFindFileData); + if (pFindFirstFileW != NULL) { + return pFindFirstFileW(lpFileName, lpFindFileData); + } + + WIN32_FIND_DATAA find_file_data; + char *lpFileNameA = ToCharW(lpFileName); + HANDLE handle = FindFirstFileA(lpFileNameA, &find_file_data); + free(lpFileNameA); + FindDataAW(&find_file_data, lpFindFileData); + return handle; } BOOL _FindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData) { - return FindNextFileW(hFindFile, lpFindFileData); + if (pFindNextFileW != NULL) { + return pFindNextFileW(hFindFile, lpFindFileData); + } + WIN32_FIND_DATAA find_file_data; + BOOL r = FindNextFileA(hFindFile, &find_file_data); + FindDataAW(&find_file_data, lpFindFileData); + return r; } BOOL _RemoveDirectoryW(LPCWSTR lpPathName) { - return RemoveDirectoryW(lpPathName); + if (pRemoveDirectoryW != NULL) { + return pRemoveDirectoryW(lpPathName); + } + char *lpPathNameA = ToCharW(lpPathName); + BOOL r = RemoveDirectoryA(lpPathNameA); + free(lpPathNameA); + return r; }