Tera Termの個人的な作業用リポジトリ
修订版 | 34bc3ec3c8dcdc47f52ced2a8119bf0496034bfa (tree) |
---|---|
时间 | 2020-05-15 00:10:58 |
作者 | zmatsuo <zmatsuo@user...> |
Commiter | zmatsuo |
layer_for_unicode 内で未実装だったAPIを実装
- _CopyFileW()
- _DeleteFileW()
- _MoveFileW()
- _CreateFileW()
- _FindFirstFileW()
- _FindNextFileW()
- _RemoveDirectoryW()
git-svn-id: svn+ssh://svn.osdn.net/svnroot/ttssh2/trunk@8772 f5f01b69-1e22-0410-acbf-894ab4bd6246
@@ -73,7 +73,7 @@ BOOL (WINAPI *pSetCurrentDirectoryW)(LPCWSTR lpPathName); | ||
73 | 73 | // user32 |
74 | 74 | int (WINAPI *pGetSystemMetricsForDpi)(int nIndex, UINT dpi); |
75 | 75 | |
76 | -// kernel32.dll | |
76 | +// kernel32 | |
77 | 77 | DWORD (WINAPI *pGetFileAttributesW)(LPCWSTR lpFileName); |
78 | 78 | void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString); |
79 | 79 | HWND (WINAPI *pGetConsoleWindow)(void); |
@@ -85,6 +85,15 @@ BOOL (WINAPI *pCreateProcessW)(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, | ||
85 | 85 | LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, |
86 | 86 | DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, |
87 | 87 | LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation); |
88 | +BOOL (WINAPI *pCopyFileW)(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName, BOOL bFailIfExists); | |
89 | +BOOL (WINAPI *pDeleteFileW)(LPCWSTR lpFileName); | |
90 | +BOOL (WINAPI *pMoveFileW)(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName); | |
91 | +HANDLE (WINAPI *pCreateFileW)(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, | |
92 | + LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, | |
93 | + DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); | |
94 | +HANDLE (WINAPI *pFindFirstFileW)(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData); | |
95 | +BOOL (WINAPI *pFindNextFileW)(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData); | |
96 | +BOOL(WINAPI *pRemoveDirectoryW)(LPCWSTR lpPathName); | |
88 | 97 | |
89 | 98 | // gdi32 |
90 | 99 | int (WINAPI *pAddFontResourceExW)(LPCWSTR name, DWORD fl, PVOID res); |
@@ -229,6 +238,13 @@ static const APIInfo Lists_kernel32[] = { | ||
229 | 238 | { "GetPrivateProfileStringW", (void **)&pGetPrivateProfileStringW }, |
230 | 239 | { "WritePrivateProfileStringW", (void **)&pWritePrivateProfileStringW }, |
231 | 240 | { "CreateProcessW", (void **)&pCreateProcessW }, |
241 | + { "CopyFileW", (void **)&pCopyFileW }, | |
242 | + { "DeleteFileW", (void **)&pDeleteFileW }, | |
243 | + { "MoveFileW", (void **)&pMoveFileW }, | |
244 | + { "CreateFileW", (void **)&pCreateFileW }, | |
245 | + { "FindFirstFileW", (void **)&pFindFirstFileW }, | |
246 | + { "FindNextFileW", (void **)&pFindNextFileW }, | |
247 | + { "RemoveDirectoryW", (void **)&pRemoveDirectoryW }, | |
232 | 248 | #endif |
233 | 249 | { "GetConsoleWindow", (void **)&pGetConsoleWindow }, |
234 | 250 | {}, |
@@ -317,6 +333,13 @@ void WinCompatInit() | ||
317 | 333 | pSHBrowseForFolderW = NULL; |
318 | 334 | pSHGetPathFromIDListW = NULL; |
319 | 335 | pCreateProcessW = NULL; |
336 | + pCopyFileW = NULL; | |
337 | + pDeleteFileW = NULL; | |
338 | + pMoveFileW = NULL; | |
339 | + pCreateFileW = NULL; | |
340 | + pFindFirstFileW = NULL; | |
341 | + pFindNextFileW = NULL; | |
342 | + pRemoveDirectoryW = NULL; | |
320 | 343 | } |
321 | 344 | |
322 | 345 | // GetConsoleWindow特別処理 |
@@ -82,7 +82,6 @@ extern BOOL(WINAPI *pSetWindowTextW)(HWND hWnd, LPCWSTR lpString); | ||
82 | 82 | extern DWORD(WINAPI *pGetPrivateProfileStringW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpDefault, |
83 | 83 | LPWSTR lpReturnedString, DWORD nSize, LPCWSTR lpFileName); |
84 | 84 | extern UINT(WINAPI *pDragQueryFileW)(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch); |
85 | -extern DWORD (WINAPI *pGetFileAttributesW)(LPCWSTR lpFileName); | |
86 | 85 | extern BOOL (WINAPI *pSetDlgItemTextW)(HWND hDlg, int nIDDlgItem, LPCWSTR lpString); |
87 | 86 | extern BOOL (WINAPI *pGetDlgItemTextW)(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int cchMax); |
88 | 87 | extern BOOL (WINAPI *pAlphaBlend)(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION); |
@@ -97,7 +96,6 @@ extern BOOL (WINAPI *pAdjustWindowRectExForDpi)(LPRECT lpRect, DWORD dwStyle, BO | ||
97 | 96 | extern BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags); |
98 | 97 | extern int (WINAPI *pAddFontResourceExW)(LPCWSTR name, DWORD fl, PVOID res); |
99 | 98 | extern BOOL (WINAPI *pRemoveFontResourceExW)(LPCWSTR name, DWORD fl, PVOID pdv); |
100 | -extern HWND (WINAPI *pGetConsoleWindow)(void); | |
101 | 99 | extern int (WINAPI *pMessageBoxW)(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType); |
102 | 100 | extern INT_PTR (WINAPI *pDialogBoxIndirectParamW)(HINSTANCE hInstance, LPCDLGTEMPLATEW hDialogTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam); |
103 | 101 | extern HWND (WINAPI *pCreateDialogIndirectParamW)(HINSTANCE hInstance, LPCDLGTEMPLATEW lpTemplate, |
@@ -121,7 +119,6 @@ extern LONG_PTR (WINAPI *pSetWindowLongPtrW)(HWND hWnd, int nIndex, LONG_PTR dwN | ||
121 | 119 | #endif |
122 | 120 | extern LRESULT (WINAPI *pCallWindowProcW)(WNDPROC lpPrevWndFunc, |
123 | 121 | HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); |
124 | -extern void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString); | |
125 | 122 | extern DWORD (WINAPI *pGetCurrentDirectoryW)(DWORD nBufferLength, LPWSTR lpBuffer); |
126 | 123 | extern BOOL (WINAPI *pSetCurrentDirectoryW)(LPCWSTR lpPathName); |
127 | 124 | extern BOOL (WINAPI *pGetOpenFileNameW)(LPOPENFILENAMEW ofnW); |
@@ -136,6 +133,28 @@ extern BOOL (WINAPI *pCreateProcessW)(LPCWSTR lpApplicationName, LPWSTR lpComman | ||
136 | 133 | LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation); |
137 | 134 | extern int (WINAPI *pGetSystemMetricsForDpi)(int nIndex, UINT dpi); |
138 | 135 | |
136 | +// kernel32 | |
137 | +extern DWORD (WINAPI *pGetFileAttributesW)(LPCWSTR lpFileName); | |
138 | +extern void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString); | |
139 | +extern HWND (WINAPI *pGetConsoleWindow)(void); | |
140 | +extern DWORD (WINAPI *pGetPrivateProfileStringW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpDefault, | |
141 | + LPWSTR lpReturnedString, DWORD nSize, LPCWSTR lpFileName); | |
142 | +extern BOOL (WINAPI *pWritePrivateProfileStringW)(LPCWSTR lpAppName,LPCWSTR lpKeyName,LPCWSTR lpString,LPCWSTR lpFileName); | |
143 | +extern BOOL (WINAPI *pCreateProcessW)(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, | |
144 | + LPSECURITY_ATTRIBUTES lpProcessAttributes, | |
145 | + LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, | |
146 | + DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, | |
147 | + LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation); | |
148 | +extern BOOL (WINAPI *pCopyFileW)(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName, BOOL bFailIfExists); | |
149 | +extern BOOL (WINAPI *pDeleteFileW)(LPCWSTR lpFileName); | |
150 | +extern BOOL (WINAPI *pMoveFileW)(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName); | |
151 | +extern HANDLE (WINAPI *pCreateFileW)(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, | |
152 | + LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, | |
153 | + DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); | |
154 | +extern HANDLE (WINAPI *pFindFirstFileW)(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData); | |
155 | +extern BOOL (WINAPI *pFindNextFileW)(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData); | |
156 | +extern BOOL(WINAPI *pRemoveDirectoryW)(LPCWSTR lpPathName); | |
157 | + | |
139 | 158 | // shlobj_core.h |
140 | 159 | extern LPITEMIDLIST (WINAPI *pSHBrowseForFolderW)(LPBROWSEINFOW lpbi); |
141 | 160 | extern BOOL (WINAPI *pSHGetPathFromIDListW)(LPITEMIDLIST pidl, LPWSTR pszPath); |
@@ -33,6 +33,12 @@ | ||
33 | 33 | */ |
34 | 34 | |
35 | 35 | #include <windows.h> |
36 | +#if !defined(_CRTDBG_MAP_ALLOC) | |
37 | +#define _CRTDBG_MAP_ALLOC | |
38 | +#endif | |
39 | +#include <stdlib.h> | |
40 | +#include <crtdbg.h> | |
41 | +#include <assert.h> | |
36 | 42 | |
37 | 43 | #include "codeconv.h" |
38 | 44 | #include "compat_win.h" |
@@ -693,38 +699,103 @@ BOOL _CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, | ||
693 | 699 | |
694 | 700 | BOOL _CopyFileW(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName, BOOL bFailIfExists) |
695 | 701 | { |
696 | - return CopyFileW(lpExistingFileName, lpNewFileName, bFailIfExists); | |
702 | + if (pCopyFileW != NULL) { | |
703 | + return pCopyFileW(lpExistingFileName, lpNewFileName, bFailIfExists); | |
704 | + } | |
705 | + char *lpExistingFileNameA = ToCharW(lpExistingFileName); | |
706 | + char *lpNewFileNameA = ToCharW(lpNewFileName); | |
707 | + BOOL r = CopyFileA(lpExistingFileNameA, lpNewFileNameA, bFailIfExists); | |
708 | + free(lpExistingFileNameA); | |
709 | + free(lpNewFileNameA); | |
710 | + return r; | |
697 | 711 | } |
698 | 712 | |
699 | 713 | BOOL _DeleteFileW(LPCWSTR lpFileName) |
700 | 714 | { |
701 | - return DeleteFileW(lpFileName); | |
715 | + if (pDeleteFileW != NULL) { | |
716 | + return pDeleteFileW(lpFileName); | |
717 | + } | |
718 | + char *lpFileNameA = ToCharW(lpFileName); | |
719 | + BOOL r = DeleteFileA(lpFileNameA); | |
720 | + free(lpFileNameA); | |
721 | + return r; | |
702 | 722 | } |
703 | 723 | |
704 | 724 | BOOL _MoveFileW(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName) |
705 | 725 | { |
706 | - return MoveFileW(lpExistingFileName, lpNewFileName); | |
726 | + if (pMoveFileW != NULL) { | |
727 | + return pMoveFileW(lpExistingFileName, lpNewFileName); | |
728 | + } | |
729 | + char *lpExistingFileNameA = ToCharW(lpExistingFileName); | |
730 | + char *lpNewFileNameA = ToCharW(lpNewFileName); | |
731 | + BOOL r = MoveFileA(lpExistingFileNameA, lpNewFileNameA); | |
732 | + free(lpExistingFileNameA); | |
733 | + free(lpNewFileNameA); | |
734 | + return r; | |
707 | 735 | } |
708 | 736 | |
709 | 737 | HANDLE _CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, |
710 | 738 | LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, |
711 | 739 | HANDLE hTemplateFile) |
712 | 740 | { |
713 | - return CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, | |
714 | - dwFlagsAndAttributes, hTemplateFile); | |
741 | + if (pCreateFileW != NULL) { | |
742 | + return pCreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, | |
743 | + dwFlagsAndAttributes, hTemplateFile); | |
744 | + } | |
745 | + | |
746 | + char *lpFileNameA = ToCharW(lpFileName); | |
747 | + HANDLE handle = CreateFileA(lpFileNameA, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, | |
748 | + dwFlagsAndAttributes, hTemplateFile); | |
749 | + free(lpFileNameA); | |
750 | + return handle; | |
751 | +} | |
752 | + | |
753 | +static void FindDataAW(const WIN32_FIND_DATAA *a, WIN32_FIND_DATAW *w) | |
754 | +{ | |
755 | + w->dwFileAttributes = a->dwFileAttributes; | |
756 | + w->ftCreationTime = a->ftCreationTime; | |
757 | + w->ftLastAccessTime = a->ftLastAccessTime; | |
758 | + w->ftLastWriteTime = a->ftLastWriteTime; | |
759 | + w->nFileSizeHigh = a->nFileSizeHigh; | |
760 | + w->nFileSizeLow = a->nFileSizeLow; | |
761 | + w->dwReserved0 = a->dwReserved0; | |
762 | + w->dwReserved1 = a->dwReserved1; | |
763 | + ::MultiByteToWideChar(CP_ACP, 0, a->cFileName, _countof(a->cFileName), w->cFileName, _countof(w->cFileName)); | |
764 | + ::MultiByteToWideChar(CP_ACP, 0, a->cAlternateFileName, _countof(a->cAlternateFileName), w->cAlternateFileName, _countof(w->cAlternateFileName)); | |
715 | 765 | } |
716 | 766 | |
717 | 767 | HANDLE _FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData) |
718 | 768 | { |
719 | - return FindFirstFileW(lpFileName, lpFindFileData); | |
769 | + if (pFindFirstFileW != NULL) { | |
770 | + return pFindFirstFileW(lpFileName, lpFindFileData); | |
771 | + } | |
772 | + | |
773 | + WIN32_FIND_DATAA find_file_data; | |
774 | + char *lpFileNameA = ToCharW(lpFileName); | |
775 | + HANDLE handle = FindFirstFileA(lpFileNameA, &find_file_data); | |
776 | + free(lpFileNameA); | |
777 | + FindDataAW(&find_file_data, lpFindFileData); | |
778 | + return handle; | |
720 | 779 | } |
721 | 780 | |
722 | 781 | BOOL _FindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData) |
723 | 782 | { |
724 | - return FindNextFileW(hFindFile, lpFindFileData); | |
783 | + if (pFindNextFileW != NULL) { | |
784 | + return pFindNextFileW(hFindFile, lpFindFileData); | |
785 | + } | |
786 | + WIN32_FIND_DATAA find_file_data; | |
787 | + BOOL r = FindNextFileA(hFindFile, &find_file_data); | |
788 | + FindDataAW(&find_file_data, lpFindFileData); | |
789 | + return r; | |
725 | 790 | } |
726 | 791 | |
727 | 792 | BOOL _RemoveDirectoryW(LPCWSTR lpPathName) |
728 | 793 | { |
729 | - return RemoveDirectoryW(lpPathName); | |
794 | + if (pRemoveDirectoryW != NULL) { | |
795 | + return pRemoveDirectoryW(lpPathName); | |
796 | + } | |
797 | + char *lpPathNameA = ToCharW(lpPathName); | |
798 | + BOOL r = RemoveDirectoryA(lpPathNameA); | |
799 | + free(lpPathNameA); | |
800 | + return r; | |
730 | 801 | } |