• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Révision9543 (tree)
l'heure2021-11-23 23:05:04
Auteurzmatsuo

Message de Log

設定フォルダダイアログで設定ファイルのパスをexplorerで開くとき、失敗することがあった

- 設定ファイルが存在するとき、ファイルを選択した状態でexplorerで開くようにした(r9340)
- 設定ファイルが存在しないとき、ファイルがないエラーが出て開かない
- ファイルがないとき、(ファイルは選択しないで)フォルダを開くようにした

- 従来と同じ動作

Change Summary

Modification

--- trunk/teraterm/teraterm/setupdirdlg.cpp (revision 9542)
+++ trunk/teraterm/teraterm/setupdirdlg.cpp (revision 9543)
@@ -55,6 +55,7 @@
5555 #include "codeconv.h"
5656 #include "asprintf.h"
5757 #include "helpid.h"
58+#include "win32helper.h"
5859
5960 #include "setupdirdlg.h"
6061
@@ -94,15 +95,14 @@
9495 // UACが有効かどうか。
9596 // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\SystemのEnableLUA(DWORD値)が0かどうかで判断できます(0はUAC無効、1はUAC有効)。
9697 flag = 0;
97- lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
98- TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"),
99- NULL, KEY_QUERY_VALUE, &hKey
100- );
98+ lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
99+ "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",
100+ 0, KEY_QUERY_VALUE, &hKey);
101101 if (lRet == ERROR_SUCCESS) {
102102 dwDataSize = sizeof(lpData) / sizeof(lpData[0]);
103- lRet = RegQueryValueEx(
103+ lRet = RegQueryValueExA(
104104 hKey,
105- TEXT("EnableLUA"),
105+ "EnableLUA",
106106 0,
107107 &dwType,
108108 (LPBYTE)lpData,
@@ -146,7 +146,7 @@
146146 // return TRUE: success
147147 // FALSE: failure
148148 //
149-static BOOL openFileWithApplication(const wchar_t *filename, const char *editor, const char *UILanguageFile)
149+static BOOL openFileWithApplication(const wchar_t *filename, const char *editor, const wchar_t *UILanguageFile)
150150 {
151151 wchar_t *commandW = NULL;
152152 BOOL ret = FALSE;
@@ -160,7 +160,7 @@
160160 "DLG_SETUPDIR_NOFILE_ERROR", L"File does not exist.(%d)",
161161 MB_OK | MB_ICONWARNING
162162 };
163- TTMessageBoxA(NULL, &info, UILanguageFile, no);
163+ TTMessageBoxW(NULL, &info, UILanguageFile, no);
164164
165165 goto error;
166166 }
@@ -182,7 +182,7 @@
182182 "DLG_SETUPDIR_OPENFILE_ERROR", L"Cannot open file.(%d)",
183183 MB_OK | MB_ICONWARNING
184184 };
185- TTMessageBoxA(NULL, &info, UILanguageFile, no);
185+ TTMessageBoxW(NULL, &info, UILanguageFile, no);
186186
187187 goto error;
188188 }
@@ -199,36 +199,50 @@
199199 return (ret);
200200 }
201201
202-//
203-// エクスプローラでパスを開く。
204-//
205-// return TRUE: success
206-// FALSE: failure
207-//
208-static BOOL openDirectoryWithExplorer(const wchar_t *path, const char *UILanguageFile)
202+/**
203+ * エクスプローラで指定ファイルのフォルダを開く
204+ * ファイルが存在する場合はファイルを選択した状態で開く
205+ * ファイルが存在しない場合はフォルダを開く
206+ *
207+ * @param file ファイル
208+ * @retval TRUE: success
209+ * @retval FALSE: failure
210+ */
211+static BOOL openDirectoryWithExplorer(const wchar_t *file, const wchar_t *UILanguageFile)
209212 {
210213 BOOL ret;
211214
212- const DWORD attr = GetFileAttributesW(path);
215+ DWORD attr = GetFileAttributesW(file);
213216 if (attr == INVALID_FILE_ATTRIBUTES) {
214- // ファイルが存在しない
215- DWORD no = GetLastError();
216- static const TTMessageBoxInfoW info = {
217- "Tera Term",
218- "MSG_ERROR", L"ERROR",
219- "DLG_SETUPDIR_NOFILE_ERROR", L"File does not exist.(%d)",
220- MB_OK | MB_ICONWARNING
221- };
222- TTMessageBoxA(NULL, &info, UILanguageFile, no);
223- ret = FALSE;
217+ // ファイルが存在しない, ディレクトリをオープンする
218+ wchar_t *dir = ExtractDirNameW(file);
219+ attr = GetFileAttributesW(dir);
220+ if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
221+ // フォルダを開く
222+ INT_PTR h = (INT_PTR)ShellExecuteW(NULL, L"open", L"explorer.exe", dir, NULL, SW_NORMAL);
223+ ret = h > 32 ? TRUE : FALSE;
224+ }
225+ else {
226+ // ファイルもフォルダも存在しない
227+ DWORD no = GetLastError();
228+ static const TTMessageBoxInfoW info = {
229+ "Tera Term",
230+ "MSG_ERROR", L"ERROR",
231+ "DLG_SETUPDIR_NOFILE_ERROR", L"File does not exist.(%d)",
232+ MB_OK | MB_ICONWARNING
233+ };
234+ TTMessageBoxW(NULL, &info, UILanguageFile, no);
235+ ret = FALSE;
236+ }
237+ free(dir);
224238 } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
225- // フォルダを開く
226- INT_PTR h = (INT_PTR)ShellExecuteW(NULL, L"open", L"explorer.exe", path, NULL, SW_NORMAL);
239+ // 指定されたのがフォルダだった、フォルダを開く
240+ INT_PTR h = (INT_PTR)ShellExecuteW(NULL, L"open", L"explorer.exe", file, NULL, SW_NORMAL);
227241 ret = h > 32 ? TRUE : FALSE;
228242 } else {
229243 // フォルダを開く + ファイル選択
230244 wchar_t *param;
231- aswprintf(&param, L"/select,%s", path);
245+ aswprintf(&param, L"/select,%s", file);
232246 INT_PTR h = (INT_PTR)ShellExecuteW(NULL, L"open", L"explorer.exe", param, NULL, SW_NORMAL);
233247 free(param);
234248 ret = h > 32 ? TRUE : FALSE;
@@ -310,15 +324,6 @@
310324 return ret;
311325 }
312326
313-static wchar_t *GetWindowTextAlloc(HWND hWnd)
314-{
315- size_t length = GetWindowTextLengthW(hWnd);
316- length++;
317- wchar_t *buf = (wchar_t *)malloc(sizeof(wchar_t) * length);
318- GetWindowTextW(hWnd, buf, (int)length);
319- return buf;
320-}
321-
322327 static INT_PTR CALLBACK OnSetupDirectoryDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
323328 {
324329 static const DlgTextInfo TextInfos[] = {
@@ -530,31 +535,24 @@
530535 }
531536
532537 if (button_pressed) {
533- wchar_t *filename_p;
538+ wchar_t *filename;
534539 if (!IsWindowEnabled(GetDlgItem(hDlgWnd, edit_vstore))) {
535- filename_p = GetWindowTextAlloc(GetDlgItem(hDlgWnd, edit));
540+ hGetWindowTextW(GetDlgItem(hDlgWnd, edit), &filename);
536541 } else {
537- filename_p = GetWindowTextAlloc(GetDlgItem(hDlgWnd, edit_vstore));
542+ hGetWindowTextW(GetDlgItem(hDlgWnd, edit_vstore), &filename);
538543 }
539544
540- const char *UILanguageFile = pts->UILanguageFile;
545+ const wchar_t *UILanguageFile = pts->UILanguageFileW;
541546 if (open_dir) {
542-#if 0
543- // フォルダを開く
544- wchar_t *path_p = ExtractDirNameW(filename_p);
545- openDirectoryWithExplorer(path_p, UILanguageFile);
546- free(path_p);
547-#else
548547 // フォルダを開いて、ファイルを選択する
549- openDirectoryWithExplorer(filename_p, UILanguageFile);
550-#endif
548+ openDirectoryWithExplorer(filename, UILanguageFile);
551549 }
552550 else {
553- char *editor = pts->ViewlogEditor;
554- openFileWithApplication(filename_p, editor, UILanguageFile);
551+ const char *editor = pts->ViewlogEditor;
552+ openFileWithApplication(filename, editor, UILanguageFile);
555553 }
556554
557- free(filename_p);
555+ free(filename);
558556 return TRUE;
559557 }
560558 return FALSE;
Afficher sur ancien navigateur de dépôt.