• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Tera Termの個人的な作業用リポジトリ


Commit MetaInfo

修订版34bc3ec3c8dcdc47f52ced2a8119bf0496034bfa (tree)
时间2020-05-15 00:10:58
作者zmatsuo <zmatsuo@user...>
Commiterzmatsuo

Log Message

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

更改概述

差异

--- a/teraterm/common/compat_win.cpp
+++ b/teraterm/common/compat_win.cpp
@@ -73,7 +73,7 @@ BOOL (WINAPI *pSetCurrentDirectoryW)(LPCWSTR lpPathName);
7373 // user32
7474 int (WINAPI *pGetSystemMetricsForDpi)(int nIndex, UINT dpi);
7575
76-// kernel32.dll
76+// kernel32
7777 DWORD (WINAPI *pGetFileAttributesW)(LPCWSTR lpFileName);
7878 void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString);
7979 HWND (WINAPI *pGetConsoleWindow)(void);
@@ -85,6 +85,15 @@ BOOL (WINAPI *pCreateProcessW)(LPCWSTR lpApplicationName, LPWSTR lpCommandLine,
8585 LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles,
8686 DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory,
8787 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);
8897
8998 // gdi32
9099 int (WINAPI *pAddFontResourceExW)(LPCWSTR name, DWORD fl, PVOID res);
@@ -229,6 +238,13 @@ static const APIInfo Lists_kernel32[] = {
229238 { "GetPrivateProfileStringW", (void **)&pGetPrivateProfileStringW },
230239 { "WritePrivateProfileStringW", (void **)&pWritePrivateProfileStringW },
231240 { "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 },
232248 #endif
233249 { "GetConsoleWindow", (void **)&pGetConsoleWindow },
234250 {},
@@ -317,6 +333,13 @@ void WinCompatInit()
317333 pSHBrowseForFolderW = NULL;
318334 pSHGetPathFromIDListW = NULL;
319335 pCreateProcessW = NULL;
336+ pCopyFileW = NULL;
337+ pDeleteFileW = NULL;
338+ pMoveFileW = NULL;
339+ pCreateFileW = NULL;
340+ pFindFirstFileW = NULL;
341+ pFindNextFileW = NULL;
342+ pRemoveDirectoryW = NULL;
320343 }
321344
322345 // GetConsoleWindow特別処理
--- a/teraterm/common/compat_win.h
+++ b/teraterm/common/compat_win.h
@@ -82,7 +82,6 @@ extern BOOL(WINAPI *pSetWindowTextW)(HWND hWnd, LPCWSTR lpString);
8282 extern DWORD(WINAPI *pGetPrivateProfileStringW)(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpDefault,
8383 LPWSTR lpReturnedString, DWORD nSize, LPCWSTR lpFileName);
8484 extern UINT(WINAPI *pDragQueryFileW)(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch);
85-extern DWORD (WINAPI *pGetFileAttributesW)(LPCWSTR lpFileName);
8685 extern BOOL (WINAPI *pSetDlgItemTextW)(HWND hDlg, int nIDDlgItem, LPCWSTR lpString);
8786 extern BOOL (WINAPI *pGetDlgItemTextW)(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int cchMax);
8887 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
9796 extern BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
9897 extern int (WINAPI *pAddFontResourceExW)(LPCWSTR name, DWORD fl, PVOID res);
9998 extern BOOL (WINAPI *pRemoveFontResourceExW)(LPCWSTR name, DWORD fl, PVOID pdv);
100-extern HWND (WINAPI *pGetConsoleWindow)(void);
10199 extern int (WINAPI *pMessageBoxW)(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);
102100 extern INT_PTR (WINAPI *pDialogBoxIndirectParamW)(HINSTANCE hInstance, LPCDLGTEMPLATEW hDialogTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam);
103101 extern HWND (WINAPI *pCreateDialogIndirectParamW)(HINSTANCE hInstance, LPCDLGTEMPLATEW lpTemplate,
@@ -121,7 +119,6 @@ extern LONG_PTR (WINAPI *pSetWindowLongPtrW)(HWND hWnd, int nIndex, LONG_PTR dwN
121119 #endif
122120 extern LRESULT (WINAPI *pCallWindowProcW)(WNDPROC lpPrevWndFunc,
123121 HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
124-extern void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString);
125122 extern DWORD (WINAPI *pGetCurrentDirectoryW)(DWORD nBufferLength, LPWSTR lpBuffer);
126123 extern BOOL (WINAPI *pSetCurrentDirectoryW)(LPCWSTR lpPathName);
127124 extern BOOL (WINAPI *pGetOpenFileNameW)(LPOPENFILENAMEW ofnW);
@@ -136,6 +133,28 @@ extern BOOL (WINAPI *pCreateProcessW)(LPCWSTR lpApplicationName, LPWSTR lpComman
136133 LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation);
137134 extern int (WINAPI *pGetSystemMetricsForDpi)(int nIndex, UINT dpi);
138135
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+
139158 // shlobj_core.h
140159 extern LPITEMIDLIST (WINAPI *pSHBrowseForFolderW)(LPBROWSEINFOW lpbi);
141160 extern BOOL (WINAPI *pSHGetPathFromIDListW)(LPITEMIDLIST pidl, LPWSTR pszPath);
--- a/teraterm/common/layer_for_unicode.cpp
+++ b/teraterm/common/layer_for_unicode.cpp
@@ -33,6 +33,12 @@
3333 */
3434
3535 #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>
3642
3743 #include "codeconv.h"
3844 #include "compat_win.h"
@@ -693,38 +699,103 @@ BOOL _CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine,
693699
694700 BOOL _CopyFileW(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName, BOOL bFailIfExists)
695701 {
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;
697711 }
698712
699713 BOOL _DeleteFileW(LPCWSTR lpFileName)
700714 {
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;
702722 }
703723
704724 BOOL _MoveFileW(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName)
705725 {
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;
707735 }
708736
709737 HANDLE _CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
710738 LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
711739 HANDLE hTemplateFile)
712740 {
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));
715765 }
716766
717767 HANDLE _FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData)
718768 {
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;
720779 }
721780
722781 BOOL _FindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData)
723782 {
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;
725790 }
726791
727792 BOOL _RemoveDirectoryW(LPCWSTR lpPathName)
728793 {
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;
730801 }