Revision: 10498 https://osdn.net/projects/ttssh2/scm/svn/commits/10498 Author: zmatsuo Date: 2023-01-16 00:07:09 +0900 (Mon, 16 Jan 2023) Log Message: ----------- TTXttyrecでUnicodeファイル名で保存できるようにした - GetSaveFileName() を TTGetSaveFileNameW() に切り替え - TTXttyplay.c は Unicodeファイル名化は行っていない - 警告対応 - 真偽値として使われる代入のまわりでは、丸括弧の使用をお勧めします - Please include winsock2.h before windows.h - この警告の根本対策の影響範囲はとても広そう - common/teraterm.h の #define _WINSOCKAPI_ 近辺 Modified Paths: -------------- trunk/TTXSamples/TTXttyrec/TTXttyplay.c trunk/TTXSamples/TTXttyrec/TTXttyrec.c -------------- next part -------------- Modified: trunk/TTXSamples/TTXttyrec/TTXttyplay.c =================================================================== --- trunk/TTXSamples/TTXttyrec/TTXttyplay.c 2023-01-15 15:07:00 UTC (rev 10497) +++ trunk/TTXSamples/TTXttyrec/TTXttyplay.c 2023-01-15 15:07:09 UTC (rev 10498) @@ -1,3 +1,5 @@ +#include <winsock2.h> +#include <ws2tcpip.h> #include "teraterm.h" #include "tttypes.h" #include "ttplugin.h" @@ -5,12 +7,11 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <windows.h> -#include <winsock2.h> -#include <ws2tcpip.h> #include "inifile_com.h" +#include "ttcommdlg.h" +#include "codeconv.h" #include "gettimeofday.h" @@ -470,22 +471,22 @@ } static int PASCAL TTXProcessCommand(HWND hWin, WORD cmd) { - OPENFILENAME ofn; - switch (cmd) { case ID_MENU_REPLAY: if (!pvar->enable) { + TTOPENFILENAMEW ofn; + wchar_t *openfn; + memset(&ofn, 0, sizeof(ofn)); - ofn.lStructSize = get_OPENFILENAME_SIZE(); ofn.hwndOwner = hWin; - ofn.lpstrFilter = "ttyrec(*.tty)\0*.tty\0All files(*.*)\0*.*\0\0"; - ofn.lpstrFile = pvar->openfn; - ofn.nMaxFile = sizeof(pvar->openfn); - ofn.lpstrDefExt = "tty"; - // ofn.lpstrTitle = ""; + ofn.lpstrFilter = L"ttyrec(*.tty)\0*.tty\0All files(*.*)\0*.*\0\0"; + ofn.lpstrDefExt = L"tty"; + // ofn.lpstrTitle = L""; ofn.Flags = OFN_FILEMUSTEXIST; - if (GetOpenFileName(&ofn)) { + if (TTGetOpenFileNameW(&ofn, &openfn)) { + WideCharToACP_t(openfn, pvar->openfn, sizeof(pvar->openfn)); + free(openfn); pvar->ReplaceHostDlg = TRUE; // Call New-Connection dialog SendMessage(hWin, WM_COMMAND, MAKELONG(ID_FILE_NEWCONNECTION, 0), 0); Modified: trunk/TTXSamples/TTXttyrec/TTXttyrec.c =================================================================== --- trunk/TTXSamples/TTXttyrec/TTXttyrec.c 2023-01-15 15:07:00 UTC (rev 10497) +++ trunk/TTXSamples/TTXttyrec/TTXttyrec.c 2023-01-15 15:07:09 UTC (rev 10498) @@ -1,15 +1,16 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <winsock2.h> +#include <ws2tcpip.h> + #include "teraterm.h" #include "tttypes.h" #include "ttplugin.h" #include "tt_res.h" -#include <winsock2.h> -#include <ws2tcpip.h> - #include "inifile_com.h" +#include "ttcommdlg.h" #include "gettimeofday.h" @@ -53,7 +54,7 @@ items = GetMenuItemCount(menu); for (i=0; i<items; i++) { - if (m = GetSubMenu(menu, i)) { + if ((m = GetSubMenu(menu, i))) { subitems = GetMenuItemCount(m); for (j=0; j<subitems; j++) { cur_id = GetMenuItemID(m, j); @@ -192,12 +193,6 @@ static int PASCAL TTXProcessCommand(HWND hWin, WORD cmd) { - OPENFILENAME ofn; - char fname[MAX_PATH]; - char buff[20]; - - fname[0] = '\0'; - if (cmd==ID_MENUITEM) { if (pvar->record) { if (pvar->fh != INVALID_HANDLE_VALUE) { @@ -208,25 +203,29 @@ CheckMenuItem(pvar->FileMenu, ID_MENUITEM, MF_BYCOMMAND | MF_UNCHECKED); } else { + TTOPENFILENAMEW ofn; + wchar_t *fname; + if (pvar->fh != INVALID_HANDLE_VALUE) { CloseHandle(pvar->fh); } memset(&ofn, 0, sizeof(ofn)); - ofn.lStructSize = get_OPENFILENAME_SIZE(); ofn.hwndOwner = hWin; - ofn.lpstrFilter = "ttyrec(*.tty)\0*.tty\0All files(*.*)\0*.*\0\0"; - ofn.lpstrFile = fname; - ofn.nMaxFile = sizeof(fname); - ofn.lpstrDefExt = "tty"; - // ofn.lpstrTitle = ""; + ofn.lpstrFilter = L"ttyrec(*.tty)\0*.tty\0All files(*.*)\0*.*\0\0"; + ofn.lpstrFile = NULL; + ofn.lpstrDefExt = L"tty"; + ofn.lpstrInitialDir = pvar->ts->LogDirW; + //ofn.lpstrTitle = L""; ofn.Flags = OFN_OVERWRITEPROMPT; - if (GetSaveFileName(&ofn)) { - pvar->fh = CreateFile(fname, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (TTGetSaveFileNameW(&ofn, &fname)) { + pvar->fh = CreateFileW(fname, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + free(fname); if (pvar->fh != INVALID_HANDLE_VALUE) { pvar->record = TRUE; CheckMenuItem(pvar->FileMenu, ID_MENUITEM, MF_BYCOMMAND | MF_CHECKED); if (pvar->rec_stsize) { + char buff[20]; _snprintf_s(buff, sizeof(buff), _TRUNCATE, "\033[8;%d;%dt", pvar->ts->TerminalHeight, pvar->ts->TerminalWidth); WriteData(pvar->fh, buff, (int)strlen(buff));