[Ttssh2-commit] [9158] 設定ファイル選択ダイアログをUnicode化

アーカイブの一覧に戻る
scmno****@osdn***** scmno****@osdn*****
2021年 2月 16日 (火) 00:02:58 JST


Revision: 9158
          https://osdn.net/projects/ttssh2/scm/svn/commits/9158
Author:   zmatsuo
Date:     2021-02-16 00:02:58 +0900 (Tue, 16 Feb 2021)
Log Message:
-----------
設定ファイル選択ダイアログをUnicode化

- つぎの3種
  - 設定の保存
  - 設定の読み込み
  - キーマップ読み込み
- GetOpenFileNameA() -> _GetOpenFileNameW()
- GetSaveFileNameA() -> _GetSaveFileNameW()

Modified Paths:
--------------
    trunk/teraterm/common/ttlib.h
    trunk/teraterm/common/ttlib_static_cpp.cpp
    trunk/teraterm/teraterm/vtwin.cpp
    trunk/teraterm/ttpset/ttset.c

-------------- next part --------------
Modified: trunk/teraterm/common/ttlib.h
===================================================================
--- trunk/teraterm/common/ttlib.h	2021-02-15 15:02:50 UTC (rev 9157)
+++ trunk/teraterm/common/ttlib.h	2021-02-15 15:02:58 UTC (rev 9158)
@@ -43,6 +43,7 @@
 
 BOOL GetFileNamePos(const char *PathName, int *DirLen, int *FNPos);
 BOOL GetFileNamePosU8(const char *PathName, int *DirLen, int *FNPos);
+BOOL GetFileNamePosW(const wchar_t *PathName, size_t *DirLen, size_t *FNPos);
 DllExport BOOL ExtractFileName(PCHAR PathName, PCHAR FileName, int destlen);
 DllExport BOOL ExtractDirName(PCHAR PathName, PCHAR DirName);
 void FitFileName(PCHAR FileName, int destlen, const char *DefExt);

Modified: trunk/teraterm/common/ttlib_static_cpp.cpp
===================================================================
--- trunk/teraterm/common/ttlib_static_cpp.cpp	2021-02-15 15:02:50 UTC (rev 9157)
+++ trunk/teraterm/common/ttlib_static_cpp.cpp	2021-02-15 15:02:58 UTC (rev 9158)
@@ -679,3 +679,56 @@
 	if (FNPos != NULL) *FNPos = FNPtr-PathName;
 	return TRUE;
 }
+
+/**
+ *	\x83t\x83@\x83C\x83\x8B\x96\xBC(\x83p\x83X\x96\xBC)\x82\xF0\x89\xF0\x90͂\xB7\x82\xE9
+ *	GetFileNamePos() \x82\xCC wchar_t\x94\xC5
+ *
+ *	@param[in]	PathName	\x83t\x83@\x83C\x83\x8B\x96\xBC\x81A\x83t\x83\x8B\x83p\x83X
+ *	@param[out]	DirLen		\x96\x96\x94\xF6\x82̃X\x83\x89\x83b\x83V\x83\x85\x82\xF0\x8A܂ރf\x83B\x83\x8C\x83N\x83g\x83\x8A\x83p\x83X\x92\xB7
+ *							NULL\x82̂Ƃ\xAB\x92l\x82\xF0\x95Ԃ\xB3\x82Ȃ\xA2
+ *	@param[out]	FNPos		\x83t\x83@\x83C\x83\x8B\x96\xBC\x82ւ\xCCindex
+ *							&PathName[FNPos] \x82\xAA\x83t\x83@\x83C\x83\x8B\x96\xBC
+ *							NULL\x82̂Ƃ\xAB\x92l\x82\xF0\x95Ԃ\xB3\x82Ȃ\xA2
+ *	@retval		FALSE		PathName\x82\xAA\x95s\x90\xB3
+ */
+BOOL GetFileNamePosW(const wchar_t *PathName, size_t *DirLen, size_t *FNPos)
+{
+	const wchar_t *Ptr;
+	const wchar_t *DirPtr;
+	const wchar_t *FNPtr;
+	const wchar_t *PtrOld;
+
+	if (DirLen != NULL) *DirLen = 0;
+	if (FNPos != NULL) *FNPos = 0;
+
+	if (PathName==NULL)
+		return FALSE;
+
+	if ((wcslen(PathName)>=2) && (PathName[1]==L':'))
+		Ptr = &PathName[2];
+	else
+		Ptr = PathName;
+	if (Ptr[0]=='\\' || Ptr[0]=='/')
+		Ptr++;
+
+	DirPtr = Ptr;
+	FNPtr = Ptr;
+	while (Ptr[0]!=0) {
+		wchar_t b = Ptr[0];
+		PtrOld = Ptr;
+		Ptr++;
+		switch (b) {
+			case L':':
+				return FALSE;
+			case L'/':	/* FALLTHROUGH */
+			case L'\\':
+				DirPtr = PtrOld;
+				FNPtr = Ptr;
+				break;
+		}
+	}
+	if (DirLen != NULL) *DirLen = DirPtr-PathName;
+	if (FNPos != NULL) *FNPos = FNPtr-PathName;
+	return TRUE;
+}

Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2021-02-15 15:02:50 UTC (rev 9157)
+++ trunk/teraterm/teraterm/vtwin.cpp	2021-02-15 15:02:58 UTC (rev 9158)
@@ -4623,23 +4623,24 @@
 	FreeTTDLG();
 }
 
+static wchar_t *_get_lang_msg(const char *key, const wchar_t *def, const char *iniFile)
+{
+	return TTGetLangStrW("Tera Term", key, def, iniFile);
+}
+
 /* GetSetupFname function id */
-#define GSF_SAVE	0 // Save setup
-#define GSF_RESTORE	1 // Restore setup
-#define GSF_LOADKEY	2 // Load key map
+typedef enum {
+	GSF_SAVE,		// Save setup
+	GSF_RESTORE,	// Restore setup
+	GSF_LOADKEY,	// Load key map
+} GetSetupFnameFuncId;
 
-static BOOL _GetSetupFname(HWND HWin, WORD FuncId, PTTSet ts)
+static BOOL _GetSetupFname(HWND HWin, GetSetupFnameFuncId FuncId, PTTSet ts)
 {
-	int i, j;
-	OPENFILENAME ofn;
-	char uimsg[MAX_UIMSG];
-
-	//  char FNameFilter[HostNameMaxLength + 1]; // 81(yutaka)
-	char FNameFilter[81]; // 81(yutaka)
-	wchar_t TempDir[MAXPATHLEN];
-	char Dir[MAXPATHLEN];
-	char Name[MAX_PATH];
-	BOOL Ok;
+	wchar_t *FNameFilter;
+	wchar_t TempDir[MAX_PATH];
+	wchar_t DirW[MAX_PATH];
+	wchar_t NameW[MAX_PATH];
 	const char *UILanguageFile = ts->UILanguageFile;
 
 	/* save current dir */
@@ -4646,55 +4647,60 @@
 	_GetCurrentDirectoryW(_countof(TempDir), TempDir);
 
 	/* File name filter */
-	memset(FNameFilter, 0, sizeof(FNameFilter));
 	if (FuncId==GSF_LOADKEY) {
-		get_lang_msg("FILEDLG_KEYBOARD_FILTER", uimsg, sizeof(uimsg), "keyboard setup files (*.cnf)\\0*.cnf\\0\\0", UILanguageFile);
-		memcpy(FNameFilter, uimsg, sizeof(FNameFilter));
+		FNameFilter = _get_lang_msg("FILEDLG_KEYBOARD_FILTER", L"keyboard setup files (*.cnf)\\0*.cnf\\0\\0", UILanguageFile);
 	}
 	else {
-		get_lang_msg("FILEDLG_SETUP_FILTER", uimsg, sizeof(uimsg), "setup files (*.ini)\\0*.ini\\0\\0", UILanguageFile);
-		memcpy(FNameFilter, uimsg, sizeof(FNameFilter));
+		FNameFilter = _get_lang_msg("FILEDLG_SETUP_FILTER", L"setup files (*.ini)\\0*.ini\\0\\0", UILanguageFile);
 	}
 
-	/* OPENFILENAME record */
-	memset(&ofn, 0, sizeof(OPENFILENAME));
-
-	ofn.lStructSize = get_OPENFILENAME_SIZE();
-	ofn.hwndOwner   = HWin;
-	ofn.lpstrFile   = Name;
-	ofn.nMaxFile    = sizeof(Name);
-	ofn.lpstrFilter = FNameFilter;
-	ofn.nFilterIndex = 1;
-	ofn.hInstance = hInst;
-
 	if (FuncId==GSF_LOADKEY) {
-		ofn.lpstrDefExt = "cnf";
-		GetFileNamePos(ts->KeyCnfFN,&i,&j);
-		strncpy_s(Name, sizeof(Name),&(ts->KeyCnfFN[j]), _TRUNCATE);
-		memcpy(Dir,ts->KeyCnfFN,i);
-		Dir[i] = 0;
+		size_t i, j;
+		wchar_t *KeyCnfFNW = ToWcharA(ts->KeyCnfFN);
+		GetFileNamePosW(KeyCnfFNW,&i,&j);
+		wcsncpy_s(NameW, _countof(NameW),&KeyCnfFNW[j], _TRUNCATE);
+		memcpy(DirW, KeyCnfFNW, sizeof(wchar_t) * i);
+		DirW[i] = 0;
 
-		if ((strlen(Name)==0) || (_stricmp(Name,"KEYBOARD.CNF")==0))
-			strncpy_s(Name, sizeof(Name),"KEYBOARD.CNF", _TRUNCATE);
+		if ((wcslen(NameW) == 0) || (_wcsicmp(NameW, L"KEYBOARD.CNF") == 0)) {
+			wcsncpy_s(NameW, _countof(NameW),L"KEYBOARD.CNF", _TRUNCATE);
+		}
 	}
 	else {
-		ofn.lpstrDefExt = "ini";
-		GetFileNamePos(ts->SetupFName,&i,&j);
-		strncpy_s(Name, sizeof(Name),&(ts->SetupFName[j]), _TRUNCATE);
-		memcpy(Dir,ts->SetupFName,i);
-		Dir[i] = 0;
+		size_t i, j;
+		wchar_t *SetupFNameW = ToWcharA(ts->SetupFName);
+		GetFileNamePosW(SetupFNameW,&i,&j);
+		wcsncpy_s(NameW, _countof(NameW),&SetupFNameW[j], _TRUNCATE);
+		memcpy(DirW, SetupFNameW, sizeof(wchar_t) * i);
+		DirW[i] = 0;
 
-		if ((strlen(Name)==0) || (_stricmp(Name,"TERATERM.INI")==0))
-			strncpy_s(Name, sizeof(Name),"TERATERM.INI", _TRUNCATE);
+		if ((wcslen(NameW) == 0) || (_wcsicmp(NameW, L"TERATERM.INI") == 0)) {
+			wcsncpy_s(NameW, _countof(NameW), L"TERATERM.INI", _TRUNCATE);
+		}
 	}
 
-	if (strlen(Dir)==0)
-		strncpy_s(Dir, sizeof(Dir),ts->HomeDir, _TRUNCATE);
+	if (wcslen(DirW) == 0) {
+		wchar_t *HomeDirW = ToWcharA(ts->HomeDir);
+		wcsncpy_s(DirW, _countof(DirW), HomeDirW, _TRUNCATE);
+		free(HomeDirW);
+	}
 
-	SetCurrentDirectoryA(Dir);
+	SetCurrentDirectoryW(DirW);
 
+	/* OPENFILENAME record */
+	OPENFILENAMEW ofn = {};
+	ofn.lStructSize = get_OPENFILENAME_SIZE();
+	ofn.hwndOwner   = HWin;
+	ofn.lpstrFile   = NameW;
+	ofn.nMaxFile    = sizeof(NameW);
+	ofn.lpstrFilter = FNameFilter;
+	ofn.nFilterIndex = 1;
+	ofn.hInstance = hInst;
+
+	BOOL Ok;
 	switch (FuncId) {
 	case GSF_SAVE:
+		ofn.lpstrDefExt = L"ini";
 		ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_SHOWHELP;
 		// \x8F\x89\x8A\xFA\x83t\x83@\x83C\x83\x8B\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82\xF0\x83v\x83\x8D\x83O\x83\x89\x83\x80\x96{\x91̂\xAA\x82\xA0\x82\xE9\x89ӏ\x8A\x82ɌŒ肷\x82\xE9 (2005.1.6 yutaka)
 		// \x93ǂݍ\x9E\x82܂ꂽteraterm.ini\x82\xAA\x82\xA0\x82\xE9\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82ɌŒ肷\x82\xE9\x81B
@@ -4703,28 +4709,36 @@
 		// \x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xF0\x8A܂܂Ȃ\xA2\x8C`\x82Ńf\x83B\x83\x8C\x83N\x83g\x83\x8A\x82\xF0\x8Ew\x92肷\x82\xE9\x82悤\x82ɂ\xB5\x82\xBD\x81B(2006.9.16 maya)
 //		ofn.lpstrInitialDir = __argv[0];
 //		ofn.lpstrInitialDir = ts->SetupFName;
-		ofn.lpstrInitialDir = Dir;
-		get_lang_msg("FILEDLG_SAVE_SETUP_TITLE", uimsg, sizeof(uimsg), "Tera Term: Save setup", UILanguageFile);
-		ofn.lpstrTitle = uimsg;
-		Ok = GetSaveFileName(&ofn);
-		if (Ok)
-			strncpy_s(ts->SetupFName, sizeof(ts->SetupFName),Name, _TRUNCATE);
+		ofn.lpstrInitialDir = DirW;
+		ofn.lpstrTitle = _get_lang_msg("FILEDLG_SAVE_SETUP_TITLE", L"Tera Term: Save setup", UILanguageFile);
+		Ok = _GetSaveFileNameW(&ofn);
+		if (Ok) {
+			char *Name = ToCharW(NameW);
+			strncpy_s(ts->SetupFName, sizeof(ts->SetupFName), Name, _TRUNCATE);
+			free(Name);
+		}
 		break;
 	case GSF_RESTORE:
+		ofn.lpstrDefExt = L"ini";
 		ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_SHOWHELP;
-		get_lang_msg("FILEDLG_RESTORE_SETUP_TITLE", uimsg, sizeof(uimsg), "Tera Term: Restore setup", UILanguageFile);
-		ofn.lpstrTitle = uimsg;
-		Ok = GetOpenFileName(&ofn);
-		if (Ok)
-			strncpy_s(ts->SetupFName, sizeof(ts->SetupFName),Name, _TRUNCATE);
+		ofn.lpstrTitle = _get_lang_msg("FILEDLG_RESTORE_SETUP_TITLE", L"Tera Term: Restore setup", UILanguageFile);
+		Ok = _GetOpenFileNameW(&ofn);
+		if (Ok) {
+			char *Name = ToCharW(NameW);
+			strncpy_s(ts->SetupFName, sizeof(ts->SetupFName), Name, _TRUNCATE);
+			free(Name);
+		}
 		break;
 	case GSF_LOADKEY:
+		ofn.lpstrDefExt = L"cnf";
 		ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_SHOWHELP;
-		get_lang_msg("FILEDLG_LOAD_KEYMAP_TITLE", uimsg, sizeof(uimsg), "Tera Term: Load key map", UILanguageFile);
-		ofn.lpstrTitle = uimsg;
-		Ok = GetOpenFileName(&ofn);
-		if (Ok)
-			strncpy_s(ts->KeyCnfFN, sizeof(ts->KeyCnfFN),Name, _TRUNCATE);
+		ofn.lpstrTitle = _get_lang_msg("FILEDLG_LOAD_KEYMAP_TITLE", L"Tera Term: Load key map", UILanguageFile);
+		Ok = _GetOpenFileNameW(&ofn);
+		if (Ok) {
+			char *Name = ToCharW(NameW);
+			strncpy_s(ts->KeyCnfFN, sizeof(ts->KeyCnfFN), Name, _TRUNCATE);
+			free(Name);
+		}
 		break;
 	default:
 		assert(FALSE);
@@ -4740,6 +4754,9 @@
 	}
 #endif
 
+	free(FNameFilter);
+	free((void *)ofn.lpstrTitle);
+
 	/* restore dir */
 	_SetCurrentDirectoryW(TempDir);
 

Modified: trunk/teraterm/ttpset/ttset.c
===================================================================
--- trunk/teraterm/ttpset/ttset.c	2021-02-15 15:02:50 UTC (rev 9157)
+++ trunk/teraterm/ttpset/ttset.c	2021-02-15 15:02:58 UTC (rev 9158)
@@ -3585,7 +3585,7 @@
 #define XFunction "X function keys"
 #define ShortCut "Shortcut keys"
 
-void GetInt(PKeyMap KeyMap, int KeyId, PCHAR Sect, PCHAR Key, PCHAR FName)
+static void GetInt(PKeyMap KeyMap, int KeyId, const char *Sect, const char *Key, const char *FName)
 {
 	char Temp[11];
 	WORD Num;


Ttssh2-commit メーリングリストの案内
アーカイブの一覧に戻る