[ttssh2-commit] [9631] ディレクトリの変更ダイアログを Unicode に対応するよう修正

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2021年 12月 25日 (土) 19:36:00 JST


Revision: 9631
          https://osdn.net/projects/ttssh2/scm/svn/commits/9631
Author:   zmatsuo
Date:     2021-12-25 19:35:59 +0900 (Sat, 25 Dec 2021)
Log Message:
-----------
ディレクトリの変更ダイアログを Unicode に対応するよう修正

- ts.FileDir を FileDirW に置き換え
- FileDir(W) は環境変数への参照を含んでいてもよい
  - %APPDATA% など
  - 使用前に ExpandEnvironmentStringsW() で展開する
- iniファイル読み込み時に環境変数への参照を残すようにした
- r9618

Revision Links:
--------------
    https://osdn.net/projects/ttssh2/scm/svn/commits/9618

Modified Paths:
--------------
    trunk/teraterm/common/tttypes.h
    trunk/teraterm/teraterm/ttdialog.h
    trunk/teraterm/teraterm/vtwin.cpp
    trunk/teraterm/ttpdlg/ttdlg.c
    trunk/teraterm/ttpdlg/ttdlg.h
    trunk/teraterm/ttpset/ttset.c

-------------- next part --------------
Modified: trunk/teraterm/common/tttypes.h
===================================================================
--- trunk/teraterm/common/tttypes.h	2021-12-24 14:43:10 UTC (rev 9630)
+++ trunk/teraterm/common/tttypes.h	2021-12-25 10:35:59 UTC (rev 9631)
@@ -644,7 +644,7 @@
 	wchar_t *UILanguageFileW_ini;		// \x91\x8A\x91΃p\x83X,ini\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g
 	wchar_t *ExeDirW;					// ttermpro.exe \x82̂\xA0\x82\xE9\x83t\x83H\x83\x8B\x83_
 	wchar_t *LogDirW;					// log\x82\xE2\x83_\x83\x93\x83v\x82\xF0\x92u\x82\xAD\x83t\x83H\x83\x8B\x83_
-	wchar_t *FileDirW;					// \x83_\x83E\x83\x93\x83\x8D\x81[\x83h\x83p\x83X(\x83\x8D\x81[\x83h\x8E\x9E\x8A‹\xAB\x95ϐ\x94\x82\xAA\x93W\x8AJ\x82\xB3\x82\xEA\x82邪\x83Z\x81[\x83u\x8E\x9E\x8E\xB8\x82\xED\x82\xEA\x82\xE9)
+	wchar_t *FileDirW;					// \x83_\x83E\x83\x93\x83\x8D\x81[\x83h\x83p\x83X("%APPDATA%" \x93\x99\x82\xAA\x8A܂܂\xEA\x82\xE9,\x8Eg\x97p\x91O\x82Ɋ‹\xAB\x95ϐ\x94\x82\xF0\x93W\x8AJ\x82\xB7\x82邱\x82\xC6)
 };
 
 typedef struct tttset TTTSet, *PTTSet;

Modified: trunk/teraterm/teraterm/ttdialog.h
===================================================================
--- trunk/teraterm/teraterm/ttdialog.h	2021-12-24 14:43:10 UTC (rev 9630)
+++ trunk/teraterm/teraterm/ttdialog.h	2021-12-25 10:35:59 UTC (rev 9631)
@@ -45,7 +45,7 @@
 typedef BOOL (PASCAL *PGetHostName)
   (HWND WndParent, PGetHNRec GetHNRec);
 typedef BOOL (PASCAL *PChangeDirectory)
-  (HWND WndParent, PCHAR CurDir);
+  (HWND WndParent, PTTSet ts);
 typedef BOOL (PASCAL *PAboutDialog)
   (HWND WndParent);
 typedef BOOL (PASCAL *PChooseFontDlg)

Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2021-12-24 14:43:10 UTC (rev 9630)
+++ trunk/teraterm/teraterm/vtwin.cpp	2021-12-25 10:35:59 UTC (rev 9631)
@@ -4062,7 +4062,7 @@
 	}
 	SetDialogFont(ts.DialogFontName, ts.DialogFontPoint, ts.DialogFontCharSet,
 				  ts.UILanguageFile, "Tera Term", "DLG_SYSTEM_FONT");
-	(*ChangeDirectory)(HVTWin,ts.FileDir);
+	(*ChangeDirectory)(HVTWin, &ts);
 }
 
 void CVTWindow::OnFilePrint()

Modified: trunk/teraterm/ttpdlg/ttdlg.c
===================================================================
--- trunk/teraterm/ttpdlg/ttdlg.c	2021-12-24 14:43:10 UTC (rev 9630)
+++ trunk/teraterm/ttpdlg/ttdlg.c	2021-12-25 10:35:59 UTC (rev 9631)
@@ -2007,29 +2007,24 @@
 		{ IDCANCEL, "BTN_CANCEL" },
 		{ IDC_DIRHELP, "BTN_HELP" },
 	};
-	PCHAR CurDir;
-	char HomeDir[MAXPATHLEN];
-	char TmpDir[MAXPATHLEN];
-	RECT R;
-	HDC TmpDC;
-	SIZE s;
-	HWND HDir, HSel, HOk, HCancel, HHelp;
-	POINT D, B, S;
-	int WX, WY, WW, WH, CW, DW, DH, BW, BH, SW, SH;
-	char uimsg[MAX_UIMSG], uimsg2[MAX_UIMSG];
 
 	switch (Message) {
-		case WM_INITDIALOG:
+		case WM_INITDIALOG: {
+			PTTSet ts;
+			wchar_t *CurDir;
+			RECT R;
+			HDC TmpDC;
+			SIZE s;
+			HWND HDir, HSel, HOk, HCancel, HHelp;
+			POINT D, B, S;
+			int WX, WY, WW, WH, CW, DW, DH, BW, BH, SW, SH;
 
+			ts = (PTTSet)lParam;
+			CurDir = ts->FileDirW;
+			SetWindowLongPtr(Dialog, DWLP_USER, lParam);
 			SetDlgTexts(Dialog, TextInfos, _countof(TextInfos), UILanguageFile);
+			SetDlgItemTextW(Dialog, IDC_DIRCURRENT, CurDir);
 
-			CurDir = (PCHAR)(lParam);
-			SetWindowLongPtr(Dialog, DWLP_USER, lParam);
-
-			SetDlgItemText(Dialog, IDC_DIRCURRENT, CurDir);
-			SendDlgItemMessage(Dialog, IDC_DIRNEW, EM_LIMITTEXT,
-			                   MAXPATHLEN-1, 0);
-
 // adjust dialog size
 			// get size of current dir text
 			HDir = GetDlgItem(Dialog, IDC_DIRCURRENT);
@@ -2039,7 +2034,7 @@
 			ScreenToClient(Dialog,&D);
 			DH = R.bottom-R.top;
 			TmpDC = GetDC(Dialog);
-			GetTextExtentPoint32(TmpDC,CurDir,strlen(CurDir),&s);
+			GetTextExtentPoint32W(TmpDC,CurDir,(int)wcslen(CurDir),&s);
 			ReleaseDC(Dialog,TmpDC);
 			DW = s.cx + s.cx/10;
 
@@ -2101,32 +2096,47 @@
 			CenterWindow(Dialog, GetParent(Dialog));
 
 			return TRUE;
+		}
 
 		case WM_COMMAND:
 			switch (LOWORD(wParam)) {
-				case IDOK:
-					CurDir = (PCHAR)GetWindowLongPtr(Dialog,DWLP_USER);
-					if ( CurDir!=NULL ) {
-						char FileDirExpanded[MAX_PATH];
-						_getcwd(HomeDir,sizeof(HomeDir));
-						ExpandEnvironmentStrings(CurDir, FileDirExpanded, sizeof(FileDirExpanded));
-						_chdir(FileDirExpanded);
-						GetDlgItemText(Dialog, IDC_DIRNEW, TmpDir, sizeof(TmpDir));
-						if ( strlen(TmpDir)>0 ) {
-							ExpandEnvironmentStrings(TmpDir, FileDirExpanded, sizeof(FileDirExpanded));
-							if (_chdir(FileDirExpanded) != 0) {
-								get_lang_msg("MSG_TT_ERROR", uimsg2, sizeof(uimsg2), "Tera Term: Error", UILanguageFile);
-								get_lang_msg("MSG_FIND_DIR_ERROR", uimsg, sizeof(uimsg), "Cannot find directory", UILanguageFile);
-								MessageBox(Dialog,uimsg,uimsg2,MB_ICONEXCLAMATION);
-								_chdir(HomeDir);
-								return TRUE;
-							}
-							strncpy_s(CurDir, MAXPATHLEN, TmpDir, _TRUNCATE);
+				case IDOK: {
+					PTTSet ts = (PTTSet)GetWindowLongPtr(Dialog,DWLP_USER);
+					BOOL OK = FALSE;
+					wchar_t *current_dir;
+					wchar_t *new_dir;
+					hGetCurrentDirectoryW(&current_dir);
+					hGetDlgItemTextW(Dialog, IDC_DIRNEW, &new_dir);
+					if (wcslen(new_dir) > 0) {
+						wchar_t *FileDirExpanded;
+						hExpandEnvironmentStringsW(new_dir, &FileDirExpanded);
+						if (DoesFolderExistW(FileDirExpanded)) {
+							free(ts->FileDirW);
+							ts->FileDirW = new_dir;
+							WideCharToACP_t(ts->FileDirW, ts->FileDir, sizeof(ts->FileDir));
+							OK = TRUE;
 						}
-						_chdir(HomeDir);
+						else {
+							free(new_dir);
+						}
+						free(FileDirExpanded);
 					}
-					EndDialog(Dialog, 1);
+					SetCurrentDirectoryW(current_dir);
+					free(current_dir);
+					if (OK) {
+						EndDialog(Dialog, 1);
+					}
+					else {
+						static const TTMessageBoxInfoW info = {
+							"Tera Term",
+							"MSG_TT_ERROR", L"Tera Term: Error",
+							"MSG_FIND_DIR_ERROR", L"Cannot find directory",
+							MB_ICONEXCLAMATION
+						};
+						TTMessageBoxW(Dialog, &info, ts->UILanguageFileW);
+					}
 					return TRUE;
+				}
 
 				case IDCANCEL:
 					EndDialog(Dialog, 0);
@@ -2133,20 +2143,24 @@
 					return TRUE;
 
 				case IDC_SELECT_DIR: {
-					wchar_t uimsgW[MAX_UIMSG];
-					wchar_t *buf, *buf2;
-					get_lang_msgW("DLG_SELECT_DIR_TITLE", uimsgW, _countof(uimsgW),
-								  L"Select new directory", UILanguageFile);
-					{
-						wchar_t FileDirExpanded[MAX_PATH];
-						hGetDlgItemTextW(Dialog, IDC_DIRNEW, &buf);
-						ExpandEnvironmentStringsW(buf, FileDirExpanded, _countof(FileDirExpanded));
-						if (doSelectFolderW(Dialog, FileDirExpanded, uimsgW, &buf2)) {
-							SetDlgItemTextW(Dialog, IDC_DIRNEW, buf2);
-							free(buf2);
-						}
+					PTTSet ts = (PTTSet)GetWindowLongPtr(Dialog,DWLP_USER);
+					wchar_t *uimsgW;
+					wchar_t *buf;
+					wchar_t *FileDirExpanded;
+					GetI18nStrWW("Tera Term", "DLG_SELECT_DIR_TITLE", L"Select new directory", ts->UILanguageFileW, &uimsgW);
+					hGetDlgItemTextW(Dialog, IDC_DIRNEW, &buf);
+					if (buf[0] == 0) {
 						free(buf);
+						hGetDlgItemTextW(Dialog, IDC_DIRCURRENT, &buf);
 					}
+					hExpandEnvironmentStringsW(buf, &FileDirExpanded);
+					free(buf);
+					if (doSelectFolderW(Dialog, FileDirExpanded, uimsgW, &buf)) {
+						SetDlgItemTextW(Dialog, IDC_DIRNEW, buf);
+						free(buf);
+					}
+					free(FileDirExpanded);
+					free(uimsgW);
 					return TRUE;
 				}
 
@@ -3153,12 +3167,12 @@
 		                     WndParent, HostDlg, (LPARAM)GetHNRec);
 }
 
-BOOL WINAPI _ChangeDirectory(HWND WndParent, PCHAR CurDir)
+BOOL WINAPI _ChangeDirectory(HWND WndParent, PTTSet ts)
 {
 	return
 		(BOOL)DialogBoxParam(hInst,
 		                     MAKEINTRESOURCE(IDD_DIRDLG),
-		                     WndParent, DirDlg, (LPARAM)CurDir);
+		                     WndParent, DirDlg, (LPARAM)ts);
 }
 
 BOOL WINAPI _AboutDialog(HWND WndParent)

Modified: trunk/teraterm/ttpdlg/ttdlg.h
===================================================================
--- trunk/teraterm/ttpdlg/ttdlg.h	2021-12-24 14:43:10 UTC (rev 9630)
+++ trunk/teraterm/ttpdlg/ttdlg.h	2021-12-25 10:35:59 UTC (rev 9631)
@@ -35,7 +35,7 @@
 BOOL WINAPI _SetupSerialPort(HWND WndParent, PTTSet ts);
 BOOL WINAPI _SetupTCPIP(HWND WndParent, PTTSet ts);
 BOOL WINAPI _GetHostName(HWND WndParent, PGetHNRec GetHNRec);
-BOOL WINAPI _ChangeDirectory(HWND WndParent, PCHAR CurDir);
+BOOL WINAPI _ChangeDirectory(HWND WndParent, PTTSet ts);
 BOOL WINAPI _AboutDialog(HWND WndParent);
 BOOL WINAPI _ChooseFontDlg(HWND WndParent, LPLOGFONTA LogFont, PTTSet ts);
 BOOL WINAPI _SetupGeneral(HWND WndParent, PTTSet ts);

Modified: trunk/teraterm/ttpset/ttset.c
===================================================================
--- trunk/teraterm/ttpset/ttset.c	2021-12-24 14:43:10 UTC (rev 9630)
+++ trunk/teraterm/ttpset/ttset.c	2021-12-25 10:35:59 UTC (rev 9631)
@@ -1301,16 +1301,14 @@
 	if (ts->FileDirW != NULL && ts->FileDirW[0] != 0) {
 		wchar_t *FileDirExpanded;
 		hExpandEnvironmentStringsW(ts->FileDirW, &FileDirExpanded);
-		free(ts->FileDirW);
-		ts->FileDirW = NULL;
-		if (DoesFolderExistW(FileDirExpanded)) {
-			ts->FileDirW = FileDirExpanded;
+		if (!DoesFolderExistW(FileDirExpanded)) {
+			free(ts->FileDirW);
+			ts->FileDirW = NULL;
 		}
-		else {
-			free(FileDirExpanded);
-		}
+		free(FileDirExpanded);
 	}
 	if (ts->FileDirW == NULL || ts->FileDirW[0] == 0) {
+		// \x83f\x83t\x83H\x83\x8B\x83g\x83t\x83H\x83\x8B\x83_\x82\xF0\x83Z\x83b\x83g\x82\xB7\x82\xE9
 		free(ts->FileDirW);
 		ts->FileDirW = GetDownloadFolderW();
 	}


ttssh2-commit メーリングリストの案内
Back to archive index