[ttssh2-commit] [10402] DnDでのscp送信を修正

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2022年 12月 11日 (日) 21:07:56 JST


Revision: 10402
          https://osdn.net/projects/ttssh2/scm/svn/commits/10402
Author:   zmatsuo
Date:     2022-12-11 21:07:56 +0900 (Sun, 11 Dec 2022)
Log Message:
-----------
DnDでのscp送信を修正

- タイマーを使ったscp送信を変更
- 修正後
  - ファイル送信と同じ仕組みで送信
  - タイマーでscpの送信状況をポーリング
  - 送信完了したら完了メッセージを飛ばすようにした
- 従来
  - タイマー内で送信処理を行っていた

Modified Paths:
--------------
    trunk/teraterm/common/tttypes.h
    trunk/teraterm/teraterm/vtwin.cpp
    trunk/teraterm/teraterm/vtwin.h

-------------- next part --------------
Modified: trunk/teraterm/common/tttypes.h
===================================================================
--- trunk/teraterm/common/tttypes.h	2022-12-11 12:07:47 UTC (rev 10401)
+++ trunk/teraterm/common/tttypes.h	2022-12-11 12:07:56 UTC (rev 10402)
@@ -45,7 +45,6 @@
 #define IdPrnProcTimer       9
 #define IdCancelConnectTimer 10  // add (2007.1.10 yutaka)
 #define IdPasteDelayTimer    11
-#define IdScpSendingTimer    12
 
   /* Window Id */
 #define IdVT  1

Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2022-12-11 12:07:47 UTC (rev 10401)
+++ trunk/teraterm/teraterm/vtwin.cpp	2022-12-11 12:07:56 UTC (rev 10402)
@@ -108,6 +108,7 @@
 #include "themedlg.h"
 #include "ttcmn_static.h"
 #include "ttcmn_notify2.h"
+#include "scp.h"
 
 #include <initguid.h>
 #if _MSC_VER < 1600
@@ -134,11 +135,6 @@
 
 static int AutoDisconnectedPort = -1;
 
-static BOOL SendScpDoing;
-static WCHAR **DropListsSendScp;
-static int DropListCountSendScp;
-static int DropListsSendScpIndex;
-
 UnicodeDebugParam_t UnicodeDebugParam;
 typedef struct {
 	char dbcs_lead_byte;
@@ -486,6 +482,7 @@
 	ShowWindow(CmdShow);
 	ChangeCaret();
 
+	DropInit();
 	DropLists = NULL;
 	DropListCount = 0;
 
@@ -1488,6 +1485,8 @@
 
 	Notify2Uninitialize((NotifyIcon *)cv.NotifyIcon);
 	cv.NotifyIcon = NULL;
+
+	DropUninit();
 }
 
 static void EscapeFilename(const wchar_t *src, wchar_t *dest)
@@ -1527,61 +1526,28 @@
 }
 
 /* \x93\xFC\x97͂̓t\x83@\x83C\x83\x8B\x82̂\xDD(\x83t\x83H\x83\x8B\x83_\x82͊܂܂\xEA\x82Ȃ\xA2) */
+/**
+ * SCP\x82Ńt\x83@\x83C\x83\x8B\x82𑗂\xE9
+ * @param Filenames		\x83t\x83@\x83C\x83\x8B\x96\xBC(\x95\xA1\x90\x94)
+ *						\x83t\x83H\x83\x8B\x83_\x82͑\x97\x82\xEA\x82Ȃ\xA2,\x83t\x83@\x83C\x83\x8B\x82̂\xDD
+ * @param FileCount		\x83t\x83@\x83C\x83\x8B\x90\x94(\x8C\xBB\x8D݂\xCD1\x88ȊO\x82͎g\x82\xA6\x82Ȃ\xA2)
+ * @param SendDir		\x91\x97\x90M\x83t\x83H\x83\x8B\x83_
+ *
+ */
 static bool SendScp(wchar_t *Filenames[], int FileCount, const char *SendDir)
 {
-	typedef int (CALLBACK *PSSH_start_scp)(char *, char *);
-	typedef int(CALLBACK * PSSH_scp_sending_status)(void);
-	static PSSH_start_scp func = NULL;
-	static PSSH_scp_sending_status func_status = NULL;
-	static HMODULE h = NULL;
-	char msg[128];
-	char *FileName;
-
-	if (h == NULL) {
-		if ( ((h = GetModuleHandle("ttxssh.dll")) == NULL) ) {
-			_snprintf_s(msg, sizeof(msg), _TRUNCATE, "GetModuleHandle(\"ttxssh.dll\")) %d", GetLastError());
-		scp_send_error:
-			::MessageBox(NULL, msg, "Tera Term: scpsend command error", MB_OK | MB_ICONERROR);
+	for (int i = 0; i < FileCount; i++) {
+		char *FileName = ToU8W(Filenames[i]);
+		BOOL r = ScpSend(FileName, ts.ScpSendDir);
+		free(FileName);
+		if (r == FALSE) {
+			::MessageBoxA(HVTWin, "scp send error", "Tera Term: error", MB_OK | MB_ICONERROR);
 			return false;
 		}
 	}
-	if (func == NULL) {
-		func = (PSSH_start_scp)GetProcAddress(h, "TTXScpSendfile");
-		if (func == NULL) {
-			_snprintf_s(msg, sizeof(msg), _TRUNCATE, "GetProcAddress(\"TTXScpSendfile\")) %d", GetLastError());
-			goto scp_send_error;
-		}
-	}
-	if (func_status == NULL) {
-		func_status = (PSSH_scp_sending_status)GetProcAddress(h, "TTXScpSendingStatus");
-		if (func_status == NULL) {
-			_snprintf_s(msg, sizeof(msg), _TRUNCATE, "GetProcAddress(\"TTXScpSendingStatus\")) %d", GetLastError());
-			goto scp_send_error;
-		}
-	}
-
-	if (SendScpDoing) {
-		if (func_status()) {
-			return false;
-		}
-		else {
-			DropListsSendScpIndex++;
-		}
-	}
-
-	FileName = ToU8W(Filenames[0]);
-	func(FileName, ts.ScpSendDir);
-	free(FileName);
-
 	return true;
 }
 
-static void StartSendScpTimer(void)
-{
-	DropListsSendScpIndex = 0;
-	SetTimer(HVTWin, IdScpSendingTimer, 100, NULL);
-}
-
 void CVTWindow::DropListFree()
 {
 	if (DropListCount > 0) {
@@ -1606,6 +1572,7 @@
 	unsigned char DropTypePaste;
 
 	HWND vtwin;
+	UINT_PTR PollingTimerID;
 
 	int FileCount;
 	int DirectoryCount;
@@ -1612,12 +1579,10 @@
 	int SendIndex;
 } DropData_t;
 
-static DropData_t *DropData;
-
 /**
  *	\x8F\x89\x8A\xFA\x89\xBB
  */
-static DropData_t *DropInit()
+void CVTWindow::DropInit()
 {
 	DropData_t *data =(DropData_t *)calloc(sizeof(*data), 1);
 	data->DefaultDropType = DROP_TYPE_CANCEL;
@@ -1624,9 +1589,16 @@
 	data->DefaultDropTypePaste = DROP_TYPE_PASTE_ESCAPE;
 	data->DefaultShowDialog = ts.ConfirmFileDragAndDrop ? true : false;
 	data->vtwin = HVTWin;
-	return data;
+
+	DropData = data;
 }
 
+void CVTWindow::DropUninit()
+{
+	free(DropData);
+	DropData = NULL;
+}
+
 /**
  *	\x91\x97\x90M\x8A\xAE\x97\xB9\x83R\x81[\x83\x8B\x83o\x83b\x83N
  */
@@ -1638,6 +1610,28 @@
 }
 
 /**
+ *	\x83^\x83C\x83}\x81[\x82\xC5SCP\x82̑\x97\x90M\x8F󋵂\xF0\x83`\x83F\x83b\x83N
+ */
+static void CALLBACK DropSendTimerProc(HWND, UINT, UINT_PTR nIDEvent, DWORD)
+{
+	DropData_t *data = (DropData_t *)nIDEvent;
+
+	// \x91\x97\x90M\x92\x86?
+	if (ScpGetStatus() == TRUE) {
+		// \x8E\x9F\x82̃^\x83C\x83}\x81[\x83C\x83\x93\x83^\x81[\x83o\x83\x8B\x82ōēx\x83`\x83F\x83b\x83N
+		return;
+	}
+
+	assert(data->PollingTimerID != 0);
+	BOOL r = KillTimer(HVTWin, data->PollingTimerID);
+	assert(r == 1); (void)r;
+	data->PollingTimerID = 0;
+
+	// \x8E\x9F\x82̑\x97\x90M\x82\xF0\x8Ds\x82\xA4
+	::PostMessage(data->vtwin, WM_USER_DROPNOTIFY, 0, 1);
+}
+
+/**
  *  \x83t\x83@\x83C\x83\x8B\x82\xAA\x83h\x83\x8D\x83b\x83v\x92ʒm
  *	@param	lparam		0	\x83t\x83@\x83C\x83\x8B\x82\xAA\x83h\x83\x8D\x83b\x83v\x82\xB3\x82ꂽ
  *							ShowDialog\x82\xAA\x8EQ\x8FƂ\xB3\x82\xEA\x82\xE9
@@ -1648,12 +1642,6 @@
 LRESULT CVTWindow::OnDropNotify(WPARAM ShowDialog, LPARAM lparam)
 {
 	DropData_t *data = DropData;
-	if (data == NULL) {
-		// \x8F\x89\x82߂ăt\x83@\x83C\x83\x8B\x82̃h\x83\x8D\x83b\x83v\x82\xAA\x94\xAD\x90\xB6\x82\xB5\x82\xBD
-		assert(lparam == 0);
-		data = DropInit();
-		DropData = data;
-	}
 
 	switch (lparam) {
 	case 0: {
@@ -1821,45 +1809,21 @@
 		}
 		case DROP_TYPE_SCP:
 		{
-			// \x82\xB7\x82ł\xC9SCP\x91\x97\x90M\x92\x86\x82Ȃ牽\x82\xE0\x82\xB5\x82Ȃ\xA2\x81B
-			if (SendScpDoing) {
-				// do nothing.
+			// send by scp
+			wchar_t **FileNames = &DropLists[i];
+			int FileCount = 1;
+			if (!SendScp(FileNames, FileCount, ts.ScpSendDir)) {
+				// \x91\x97\x90M\x83G\x83\x89\x81[
 				goto finish;
 			}
-			else {
-				// \x88ꊇ\x91\x97\x90M\x82̏ꍇ\x82̓^\x83C\x83}\x81[\x8F\x88\x97\x9D\x82\xF0\x8Ds\x82\xA4\x82\xB1\x82ƂŁA\x98A\x91\xB1\x91\x97\x90M\x82ɂ\xE6\x82\xE9
-				// \x83G\x83\x89\x81[\x82\xAA\x8BN\x82\xB1\x82\xE7\x82Ȃ\xA2\x82悤\x82ɂ\xB7\x82\xE9\x81B
-				if (data->DoSameProcess) {
-					int j;
 
-					DropListCountSendScp = DropListCount - i;
-					DropListsSendScp = (wchar_t **)malloc(sizeof(wchar_t *) * DropListCountSendScp);
+			data->PollingTimerID = SetTimer(HVTWin, (UINT_PTR)data, 100, DropSendTimerProc);
+			break;
 
-					for (j = 0; j < DropListCountSendScp; j++) {
-						DropListsSendScp[j] = _wcsdup(DropLists[j]);
-					}
-					SendScpDoing = TRUE;
-
-					StartSendScpTimer();
-					goto finish;
-				}
-				else {
-					// send by scp
-					wchar_t **FileNames = &DropLists[i];
-					int FileCount = 1;
-					if (!SendScp(FileNames, FileCount, ts.ScpSendDir)) {
-						goto finish;
-					}
-
-					// \x8E\x9F\x82̃t\x83@\x83C\x83\x8B\x82̏\x88\x97\x9D\x82\xD6
-					goto next_file;
-				}
-			}
-
 		}
 		}
+		break;
 	}
-		break;
 	case 2:
 	default:
 	finish:
@@ -2702,33 +2666,7 @@
 			//::PostMessage(HVTWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);
 		}
 	}
-	else if (nIDEvent == IdScpSendingTimer) {
-		wchar_t **FileNames;
-		int FileCount;
-		int j;
 
-		if (DropListsSendScpIndex >= DropListCountSendScp) {
-			::KillTimer(HVTWin, IdScpSendingTimer);
-
-			for (j = 0; j < DropListCountSendScp; j++) {
-				free(DropListsSendScp[j]);
-				DropListsSendScp[j] = NULL;
-			}
-			free(DropListsSendScp);
-			DropListCountSendScp = 0;
-
-			SendScpDoing = FALSE;
-		}
-		else {
-			FileNames = &DropListsSendScp[DropListsSendScpIndex];
-			FileCount = DropListCountSendScp;
-
-			SendScp(FileNames, FileCount, ts.ScpSendDir);
-		}
-
-		return;
-	}
-
 	::KillTimer(HVTWin, nIDEvent);
 
 	switch (nIDEvent) {

Modified: trunk/teraterm/teraterm/vtwin.h
===================================================================
--- trunk/teraterm/teraterm/vtwin.h	2022-12-11 12:07:47 UTC (rev 10401)
+++ trunk/teraterm/teraterm/vtwin.h	2022-12-11 12:07:56 UTC (rev 10402)
@@ -55,6 +55,9 @@
     SetupMenu, ControlMenu, WinMenu, HelpMenu;
 
   // drag and drop handle
+  void DropInit();
+  void DropUninit();
+  struct DropData_tag *DropData;
   wchar_t **DropLists;
   int DropListCount;
   void DropListFree();


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