[Ttssh2-commit] [8440] ファイルの送信、ファイル名のペーストをsendmemに移動

scmno****@osdn***** scmno****@osdn*****
2019年 12月 14日 (土) 00:12:40 JST


Revision: 8440
          https://osdn.net/projects/ttssh2/scm/svn/commits/8440
Author:   zmatsuo
Date:     2019-12-14 00:12:40 +0900 (Sat, 14 Dec 2019)
Log Message:
-----------
ファイルの送信、ファイル名のペーストをsendmemに移動

Modified Paths:
--------------
    branches/unicode_buf/teraterm/teraterm/sendmem.cpp
    branches/unicode_buf/teraterm/teraterm/sendmem.h
    branches/unicode_buf/teraterm/teraterm/vtwin.cpp

-------------- next part --------------
Modified: branches/unicode_buf/teraterm/teraterm/sendmem.cpp
===================================================================
--- branches/unicode_buf/teraterm/teraterm/sendmem.cpp	2019-12-13 15:12:30 UTC (rev 8439)
+++ branches/unicode_buf/teraterm/teraterm/sendmem.cpp	2019-12-13 15:12:40 UTC (rev 8440)
@@ -35,6 +35,18 @@
 #include "ttcommon.h"
 #include "ftdlg_lite.h"
 
+#include "ttwinman.h"		// for ts
+
+#define	SENDMEM_USE_OLD_API	0
+
+#if SENDMEM_USE_OLD_API
+#include "ttftypes.h"		// for TFileVar
+#include "filesys.h"		// for SendVar
+#include "codeconv.h"		// for ToCharW()
+#else
+#include "../ttpmacro/fileread.h"
+#endif
+
 #include "sendmem.h"
 
 // \x91\x97\x90M\x92\x86\x82\xC9VTWIN\x82ɔr\x91\xBC\x82\xF0\x82\xA9\x82\xAF\x82\xE9
@@ -490,3 +502,54 @@
 	free(sm->UILanguageFile);
 	free(sm);
 }
+
+#if SENDMEM_USE_OLD_API
+BOOL SendMemSendFile(const wchar_t *filename, BOOL binary)
+{
+	char *FileNameA = ToCharW(filename);
+	strncpy_s(SendVar->FullName, sizeof(SendVar->FullName), FileNameA,  _TRUNCATE);
+	free(FileNameA);
+
+	SendVar->DirLen = 0;
+	ts.TransBin = binary == FALSE ? 0 : 1;
+	FileSendStart();
+	return TRUE;
+}
+#else
+BOOL SendMemSendFile(const wchar_t *filename, BOOL binary)
+{
+	binary = FALSE;
+
+	size_t str_len;
+	wchar_t *str_ptr = LoadFileWW(filename, &str_len);
+	if (str_ptr == NULL) {
+		return FALSE;
+	}
+	str_len *= sizeof(wchar_t);
+
+	SendMem *sm = SendMemInit(str_ptr, str_len, SendMemTypeTextLF);
+	SendMemInitDialog(sm, hInst, HVTWin, ts.UILanguageFile);
+	SendMemInitDialogCaption(sm, L"send file");			// title
+	SendMemInitDialogFilename(sm, filename);
+	SendMemStart(sm);
+	return TRUE;
+}
+#endif
+
+/**
+ *	\x92Z\x82\xA2\x95\xB6\x8E\x9A\x97\xF1\x82𑗐M\x82\xB7\x82\xE9
+ *	@param[in]	str		malloc\x82\xB3\x82ꂽ\x97̈\xE6\x82̕\xB6\x8E\x9A\x97\xF1
+ *						\x91\x97\x90M\x8C\xE3 free() \x82\xB3\x82\xEA\x82\xE9
+ *	TODO
+ *		CBSendStart() @clipboar.c \x82Ɠ\x9D\x8D\x87
+ */
+BOOL SendMemPasteString(wchar_t *str)
+{
+	const size_t len = wcslen(str);
+	CommTextOutW(&cv, str, len);
+	if (ts.LocalEcho > 0) {
+		CommTextEchoW(&cv, str, len);
+	}
+
+	return TRUE;
+}

Modified: branches/unicode_buf/teraterm/teraterm/sendmem.h
===================================================================
--- branches/unicode_buf/teraterm/teraterm/sendmem.h	2019-12-13 15:12:30 UTC (rev 8439)
+++ branches/unicode_buf/teraterm/teraterm/sendmem.h	2019-12-13 15:12:40 UTC (rev 8440)
@@ -50,6 +50,10 @@
 BOOL SendMemStart(SendMem *sm);		// \x91\x97\x90M\x8AJ\x8En
 void SendMemFinish(SendMem *sm);
 
+// convenient function
+BOOL SendMemSendFile(const wchar_t *filename, BOOL binary);
+BOOL SendMemPasteString(wchar_t *str);
+
 // idle\x82\xA9\x82\xE7\x82̑\x97\x90M\x97pAPI
 void SendMemContinuously(void);
 

Modified: branches/unicode_buf/teraterm/teraterm/vtwin.cpp
===================================================================
--- branches/unicode_buf/teraterm/teraterm/vtwin.cpp	2019-12-13 15:12:30 UTC (rev 8439)
+++ branches/unicode_buf/teraterm/teraterm/vtwin.cpp	2019-12-13 15:12:40 UTC (rev 8440)
@@ -93,7 +93,6 @@
 #include "codeconv.h"
 #include "layer_for_unicode.h"
 #include "sendmem.h"
-#include "../ttpmacro/fileread.h"
 
 #include "initguid.h"
 //#include "Usbiodef.h"
@@ -1838,8 +1837,11 @@
 static void PasteString(PComVar cv, const wchar_t *str, bool escape)
 {
 	wchar_t *ptr = (wchar_t *)str;
-	wchar_t *tmpbuf = NULL;
-	if (escape) {
+	wchar_t *tmpbuf;
+	if (!escape) {
+		tmpbuf = _wcsdup(str);
+	}
+	else {
 		const size_t len = wcslen(str) * sizeof(wchar_t) * 2;
 		tmpbuf = (wchar_t *)malloc(len);
 		EscapeFilename(str, tmpbuf);
@@ -1846,14 +1848,7 @@
 		ptr = tmpbuf;
 	}
 
-	// console\x82֑\x97\x90M
-	const size_t len = wcslen(ptr);
-	CommTextOutW(cv, ptr, len);
-	if (ts.LocalEcho > 0) {
-		CommTextEchoW(cv, ptr, len);
-	}
-
-	if (tmpbuf != NULL) free(tmpbuf);
+	SendMemPasteString(tmpbuf);
 }
 
 /* \x93\xFC\x97͂̓t\x83@\x83C\x83\x8B\x82̂\xDD(\x83t\x83H\x83\x8B\x83_\x82͊܂܂\xEA\x82Ȃ\xA2) */
@@ -1901,16 +1896,6 @@
 	}
 }
 
-static void sendfile(const wchar_t *filename, BOOL binary)
-{
-	char *FileNameA = ToCharW(filename);
-	strncpy_s(SendVar->FullName, sizeof(SendVar->FullName), FileNameA,  _TRUNCATE);
-	free(FileNameA);
-	SendVar->DirLen = 0;
-	ts.TransBin = binary == FALSE ? 0 : 1;
-	FileSendStart();
-}
-
 LRESULT CVTWindow::OnDropNotify(WPARAM ShowDialog, LPARAM lParam)
 {
 	// ini\x82ɕۑ\xB6\x82\xB3\x82\xEA\x82Ȃ\xA2\x81A\x8D\xA1\x8E\xC0\x8Ds\x82\xB5\x82Ă\xA2\x82\xE9Tera Term\x82ł̂ݗL\x8C\xF8\x82Ȑݒ\xE8
@@ -2039,7 +2024,7 @@
 		case DROP_TYPE_SEND_FILE:
 		case DROP_TYPE_SEND_FILE_BINARY:
 			if (SendVar==NULL && NewFileVar(&SendVar)) {
-				sendfile(FileName, DropType == DROP_TYPE_SEND_FILE ? 0 : 1);
+				SendMemSendFile(FileName, DropType == DROP_TYPE_SEND_FILE ? FALSE : TRUE);
 			}
 			break;
 		case DROP_TYPE_PASTE_FILENAME:
@@ -4525,17 +4510,7 @@
 	}
 
 	wchar_t *filename = data.filename;
-	size_t str_len;
-	wchar_t *str_ptr = LoadFileWW(filename, &str_len);
-	if (str_ptr != NULL) {
-		str_len *= sizeof(wchar_t);
-
-		SendMem *sm = SendMemInit(str_ptr, str_len, SendMemTypeTextLF);
-		SendMemInitDialog(sm, hInst, HVTWin, ts.UILanguageFile);
-		SendMemInitDialogCaption(sm, L"send file");			// title
-		SendMemInitDialogFilename(sm, filename);
-		SendMemStart(sm);
-	}
+	SendMemSendFile(filename, data.binary);
 	free(filename);
 #endif
 }


Ttssh2-commit メーリングリストの案内