Revision: 9912 https://osdn.net/projects/ttssh2/scm/svn/commits/9912 Author: zmatsuo Date: 2022-05-08 22:25:03 +0900 (Sun, 08 May 2022) Log Message: ----------- TERATERM.INI 保存時のファイル名選択ダイアログのフォルダを変更 - GetOpenFileNameW() のダイアログ - 最後に使用した ttermpro.exe のフォルダを開くようだ - 実行ファイル名を元に最後の利用フォルダを保存している? - 起動時に読み込んだ TERATERM.INI のフォルダを開くようにした - Windowsのバージョンによって動作が異なっているかもしれない Modified Paths: -------------- trunk/teraterm/teraterm/vtwin.cpp -------------- next part -------------- Modified: trunk/teraterm/teraterm/vtwin.cpp =================================================================== --- trunk/teraterm/teraterm/vtwin.cpp 2022-05-07 11:54:06 UTC (rev 9911) +++ trunk/teraterm/teraterm/vtwin.cpp 2022-05-08 13:25:03 UTC (rev 9912) @@ -4484,7 +4484,6 @@ /* GetSetupFname function id */ typedef enum { - GSF_SAVE, // Save setup GSF_RESTORE, // Restore setup GSF_LOADKEY, // Load key map } GetSetupFnameFuncId; @@ -4549,27 +4548,6 @@ 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 - // \x82\xB1\x82\xEA\x82ɂ\xE6\x82\xE8\x81A/F= \x82Ŏw\x92肳\x82ꂽ\x88ʒu\x82ɕۑ\xB6\x82\xB3\x82\xEA\x82\xE9\x82悤\x82ɂȂ\xE9\x81B(2005.1.26 yutaka) - // Windows Vista \x82ł̓t\x83@\x83C\x83\x8B\x96\xBC\x82܂Ŏw\x92肷\x82\xE9\x82\xC6 NULL \x82Ɠ\xAF\x82\xB6\x8B\x93\x93\xAE\x82\xF0\x82\xB7\x82\xE9\x82悤\x82Ȃ̂ŁA - // \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 = DirW; - ofn.lpstrTitle = _get_lang_msg("FILEDLG_SAVE_SETUP_TITLE", L"Tera Term: Save setup", UILanguageFileW); - Ok = GetSaveFileNameW(&ofn); - if (Ok) { - free(ts->SetupFNameW); - ts->SetupFNameW = _wcsdup(NameW); - 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; @@ -4623,14 +4601,78 @@ void CVTWindow::OnSetupSave() { - wchar_t *PrevSetupFNW = _wcsdup(ts.SetupFNameW); + PTTSet pts = &ts; + const wchar_t *UILanguageFileW = pts->UILanguageFileW; + + // save current dir + // GetSaveFileNameW() \x82\xAA\x83J\x83\x8C\x83\x93\x83g\x83t\x83H\x83\x8B\x83_\x82\xF0\x95ύX\x82\xB5\x82Ă\xB5\x82܂\xA4\x82\xBD\x82\xDF + wchar_t *cur_dir; + hGetCurrentDirectoryW(&cur_dir); + + wchar_t *filter = _get_lang_msg("FILEDLG_SETUP_FILTER", + L"setup files (*.ini)\\0*.ini\\0\\0", UILanguageFileW); + wchar_t *title = _get_lang_msg("FILEDLG_SAVE_SETUP_TITLE", + L"Tera Term: Save setup", UILanguageFileW); + + // ini\x83t\x83@\x83C\x83\x8B\x82̂\xA0\x82\xE9\x83t\x83H\x83\x8B\x83_ + wchar_t *DirW = ExtractDirNameW(pts->SetupFNameW); + + // \x83J\x83\x8C\x83\x93\x83g\x82\xF0ini\x83t\x83@\x83C\x83\x8B\x82̂\xA0\x82\xE9\x83t\x83H\x83\x8B\x83_\x82ɂ\xB5\x82Ă\xA8\x82\xAD + // \x83_\x83C\x83A\x83\x8D\x83O\x82\xAA\x8AJ\x82\xAD\x82Ƃ\xAB\x82ɁA + // \x83J\x83\x8C\x83\x93\x83g\x82\xF0\x83I\x81[\x83v\x83\x93\x82\xB7\x82邽\x82\xDF(7\x88ȑO?) + SetCurrentDirectoryW(DirW); + + // \x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xF0\x83t\x83\x8B\x83p\x83X\x82ŏ\x89\x8A\x{227B0B5}\x82Ă\xA8\x82\xAD + // \x83_\x83C\x83A\x83\x8D\x83O\x82\xAA\x8AJ\x82\xAD\x82Ƃ\xAB\x82ɁA + // \x83t\x83@\x83C\x83\x8B\x82̃p\x83X\x82\xF0\x83I\x81[\x83v\x83\x93\x82\xB7\x82邽\x82\xDF(7\x88ȍ~?) + wchar_t NameW[MAX_PATH]; + wcsncpy_s(NameW, _countof(NameW), pts->SetupFNameW, _TRUNCATE); + + /* OPENFILENAME record */ + OPENFILENAMEW ofn = {}; + ofn.lStructSize = get_OPENFILENAME_SIZEW(); + ofn.hwndOwner = m_hWnd; + ofn.lpstrFile = NameW; + ofn.nMaxFile = _countof(NameW); + ofn.lpstrFilter = filter; + ofn.nFilterIndex = 1; + ofn.hInstance = hInst; + ofn.lpstrDefExt = L"ini"; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_SHOWHELP; + ofn.lpstrInitialDir = DirW; // \x8F\x89\x82߂ĊJ\x82\xAD\x82Ƃ\xAB\x82Ɏg\x97p\x82\xB3\x82\xEA\x82\xE9,2\x89\xF1\x96ڈȍ~\x82͍Ō\xE3\x82ɗ\x98\x97p\x82\xB5\x82\xBD\x83t\x83H\x83\x8B\x83_\x82ɂȂ\xE9(7\x88ȍ~?) + ofn.lpstrTitle = title; + HelpId = HlpSetupSave; - BOOL Ok = _GetSetupFname(HVTWin,GSF_SAVE,&ts); + BOOL Ok = GetSaveFileNameW(&ofn); +#if defined(_DEBUG) + if (!Ok) { + DWORD Err = GetLastError(); + DWORD DlgErr = CommDlgExtendedError(); + assert(Err == 0 && DlgErr == 0); + } +#endif + + free(filter); + free(title); + free(DirW); + + /* restore dir */ + SetCurrentDirectoryW(cur_dir); + free(cur_dir); + if (! Ok) { - free(PrevSetupFNW); + // \x83L\x83\x83\x83\x93\x83Z\x83\x8B return; } + // \x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xF0\x93\xFC\x82\xEA\x91ւ\xA6\x82\xE9 + wchar_t *PrevSetupFNW = _wcsdup(ts.SetupFNameW); // \x91O\x82̃t\x83@\x83C\x83\x8B\x82\xF0\x8Ao\x82\xA6\x82Ă\xA8\x82\xAD + free(pts->SetupFNameW); + pts->SetupFNameW = _wcsdup(NameW); + char *Name = ToCharW(NameW); + strncpy_s(pts->SetupFName, sizeof(pts->SetupFName), Name, _TRUNCATE); + free(Name); + // \x8F\x91\x82\xAB\x8D\x9E\x82݂ł\xAB\x82邩? const DWORD attr = GetFileAttributesW(ts.SetupFNameW); if ((attr & FILE_ATTRIBUTE_DIRECTORY ) == 0 && (attr & FILE_ATTRIBUTE_READONLY) != 0) {