| 1 |
/* Tera Term |
| 2 |
Copyright(C) 1994-1998 T. Teranishi |
| 3 |
All rights reserved. */ |
| 4 |
|
| 5 |
/* TERATERM.EXE, file transfer routines */ |
| 6 |
#include "stdafx.h" |
| 7 |
#include "teraterm.h" |
| 8 |
#include "tttypes.h" |
| 9 |
#include "ttftypes.h" |
| 10 |
#ifdef TERATERM32 |
| 11 |
#include "tt_res.h" |
| 12 |
#else |
| 13 |
#include "tt_res16.h" |
| 14 |
#endif |
| 15 |
#include "ftdlg.h" |
| 16 |
#include "protodlg.h" |
| 17 |
#include "ttwinman.h" |
| 18 |
#include "commlib.h" |
| 19 |
#include "ttcommon.h" |
| 20 |
#include "ttdde.h" |
| 21 |
#include "ttlib.h" |
| 22 |
#include "helpid.h" |
| 23 |
|
| 24 |
#include "filesys.h" |
| 25 |
|
| 26 |
PFileVar LogVar = NULL; |
| 27 |
PFileVar SendVar = NULL; |
| 28 |
PFileVar FileVar = NULL; |
| 29 |
static PCHAR ProtoVar = NULL; |
| 30 |
static int ProtoId; |
| 31 |
|
| 32 |
static BYTE LogLast = 0; |
| 33 |
BOOL FileLog = FALSE; |
| 34 |
BOOL BinLog = FALSE; |
| 35 |
BOOL DDELog = FALSE; |
| 36 |
static BOOL FileRetrySend, FileRetryEcho, FileCRSend; |
| 37 |
static BYTE FileByte; |
| 38 |
|
| 39 |
static BOOL FSend = FALSE; |
| 40 |
|
| 41 |
static HMODULE HTTFILE = NULL; |
| 42 |
static int TTFILECount = 0; |
| 43 |
|
| 44 |
PGetSetupFname GetSetupFname; |
| 45 |
PGetTransFname GetTransFname; |
| 46 |
PGetMultiFname GetMultiFname; |
| 47 |
PGetGetFname GetGetFname; |
| 48 |
PSetFileVar SetFileVar; |
| 49 |
PGetXFname GetXFname; |
| 50 |
PProtoInit ProtoInit; |
| 51 |
PProtoParse ProtoParse; |
| 52 |
PProtoTimeOutProc ProtoTimeOutProc; |
| 53 |
PProtoCancel ProtoCancel; |
| 54 |
|
| 55 |
#define IdGetSetupFname 1 |
| 56 |
#define IdGetTransFname 2 |
| 57 |
#define IdGetMultiFname 3 |
| 58 |
#define IdGetGetFname 4 |
| 59 |
#define IdSetFileVar 5 |
| 60 |
#define IdGetXFname 6 |
| 61 |
|
| 62 |
#define IdProtoInit 7 |
| 63 |
#define IdProtoParse 8 |
| 64 |
#define IdProtoTimeOutProc 9 |
| 65 |
#define IdProtoCancel 10 |
| 66 |
|
| 67 |
BOOL LoadTTFILE() |
| 68 |
{ |
| 69 |
BOOL Err; |
| 70 |
|
| 71 |
#ifdef TERATERM32 |
| 72 |
if (HTTFILE != NULL) |
| 73 |
#else |
| 74 |
if (HTTFILE >= HINSTANCE_ERROR) |
| 75 |
#endif |
| 76 |
{ |
| 77 |
TTFILECount++; |
| 78 |
return TRUE; |
| 79 |
} |
| 80 |
else |
| 81 |
TTFILECount = 0; |
| 82 |
|
| 83 |
#ifdef TERATERM32 |
| 84 |
HTTFILE = LoadLibrary("TTPFILE.DLL"); |
| 85 |
if (HTTFILE == NULL) return FALSE; |
| 86 |
#else |
| 87 |
HTTFILE = LoadLibrary("TTFILE.DLL"); |
| 88 |
if (HTTFILE < HINSTANCE_ERROR) return FALSE; |
| 89 |
#endif |
| 90 |
|
| 91 |
Err = FALSE; |
| 92 |
GetSetupFname = (PGetSetupFname)GetProcAddress(HTTFILE, |
| 93 |
MAKEINTRESOURCE(IdGetSetupFname)); |
| 94 |
if (GetSetupFname==NULL) Err = TRUE; |
| 95 |
|
| 96 |
GetTransFname = (PGetTransFname)GetProcAddress(HTTFILE, |
| 97 |
MAKEINTRESOURCE(IdGetTransFname)); |
| 98 |
if (GetTransFname==NULL) Err = TRUE; |
| 99 |
|
| 100 |
GetMultiFname = (PGetMultiFname)GetProcAddress(HTTFILE, |
| 101 |
MAKEINTRESOURCE(IdGetMultiFname)); |
| 102 |
if (GetMultiFname==NULL) Err = TRUE; |
| 103 |
|
| 104 |
GetGetFname = (PGetGetFname)GetProcAddress(HTTFILE, |
| 105 |
MAKEINTRESOURCE(IdGetGetFname)); |
| 106 |
if (GetGetFname==NULL) Err = TRUE; |
| 107 |
|
| 108 |
SetFileVar = (PSetFileVar)GetProcAddress(HTTFILE, |
| 109 |
MAKEINTRESOURCE(IdSetFileVar)); |
| 110 |
if (SetFileVar==NULL) Err = TRUE; |
| 111 |
|
| 112 |
GetXFname = (PGetXFname)GetProcAddress(HTTFILE, |
| 113 |
MAKEINTRESOURCE(IdGetXFname)); |
| 114 |
if (GetXFname==NULL) Err = TRUE; |
| 115 |
|
| 116 |
ProtoInit = (PProtoInit)GetProcAddress(HTTFILE, |
| 117 |
MAKEINTRESOURCE(IdProtoInit)); |
| 118 |
if (ProtoInit==NULL) Err = TRUE; |
| 119 |
|
| 120 |
ProtoParse = (PProtoParse)GetProcAddress(HTTFILE, |
| 121 |
MAKEINTRESOURCE(IdProtoParse)); |
| 122 |
if (ProtoParse==NULL) Err = TRUE; |
| 123 |
|
| 124 |
ProtoTimeOutProc = (PProtoTimeOutProc)GetProcAddress(HTTFILE, |
| 125 |
MAKEINTRESOURCE(IdProtoTimeOutProc)); |
| 126 |
if (ProtoTimeOutProc==NULL) Err = TRUE; |
| 127 |
|
| 128 |
ProtoCancel = (PProtoCancel)GetProcAddress(HTTFILE, |
| 129 |
MAKEINTRESOURCE(IdProtoCancel)); |
| 130 |
if (ProtoCancel==NULL) Err = TRUE; |
| 131 |
|
| 132 |
if (Err) |
| 133 |
{ |
| 134 |
FreeLibrary(HTTFILE); |
| 135 |
HTTFILE = NULL; |
| 136 |
return FALSE; |
| 137 |
} |
| 138 |
else { |
| 139 |
TTFILECount = 1; |
| 140 |
return TRUE; |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
BOOL FreeTTFILE() |
| 145 |
{ |
| 146 |
if (TTFILECount==0) return FALSE; |
| 147 |
TTFILECount--; |
| 148 |
if (TTFILECount>0) return TRUE; |
| 149 |
#ifdef TERATERM32 |
| 150 |
if (HTTFILE!=NULL) |
| 151 |
#else |
| 152 |
if (HTTFILE>=HINSTANCE_ERROR) |
| 153 |
#endif |
| 154 |
{ |
| 155 |
FreeLibrary(HTTFILE); |
| 156 |
HTTFILE = NULL; |
| 157 |
} |
| 158 |
return TRUE; |
| 159 |
} |
| 160 |
|
| 161 |
static PFileTransDlg FLogDlg = NULL; |
| 162 |
static PFileTransDlg SendDlg = NULL; |
| 163 |
static PProtoDlg PtDlg = NULL; |
| 164 |
|
| 165 |
BOOL OpenFTDlg(PFileVar fv) |
| 166 |
{ |
| 167 |
PFileTransDlg FTDlg; |
| 168 |
|
| 169 |
FTDlg = new CFileTransDlg(); |
| 170 |
|
| 171 |
if (FTDlg!=NULL) |
| 172 |
{ |
| 173 |
FTDlg->Create(fv, &cv); |
| 174 |
FTDlg->RefreshNum(); |
| 175 |
if (fv->OpId == OpLog) |
| 176 |
FTDlg->ShowWindow(SW_MINIMIZE); |
| 177 |
} |
| 178 |
|
| 179 |
if (fv->OpId==OpLog) |
| 180 |
FLogDlg = FTDlg; /* Log */ |
| 181 |
else |
| 182 |
SendDlg = FTDlg; /* File send */ |
| 183 |
|
| 184 |
return (FTDlg!=NULL); |
| 185 |
} |
| 186 |
|
| 187 |
BOOL NewFileVar(PFileVar *fv) |
| 188 |
{ |
| 189 |
if ((*fv)==NULL) |
| 190 |
{ |
| 191 |
*fv = (PFileVar)malloc(sizeof(TFileVar)); |
| 192 |
if ((*fv)!=NULL) |
| 193 |
{ |
| 194 |
memset(*fv, 0, sizeof(TFileVar)); |
| 195 |
strcpy((*fv)->FullName,ts.FileDir); |
| 196 |
AppendSlash((*fv)->FullName); |
| 197 |
(*fv)->DirLen = strlen((*fv)->FullName); |
| 198 |
(*fv)->FileOpen = FALSE; |
| 199 |
(*fv)->OverWrite = ((ts.FTFlag & FT_RENAME) == 0); |
| 200 |
(*fv)->HMainWin = HVTWin; |
| 201 |
(*fv)->Success = FALSE; |
| 202 |
(*fv)->NoMsg = FALSE; |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
return ((*fv)!=NULL); |
| 207 |
} |
| 208 |
|
| 209 |
void FreeFileVar(PFileVar *fv) |
| 210 |
{ |
| 211 |
if ((*fv)!=NULL) |
| 212 |
{ |
| 213 |
if ((*fv)->FileOpen) _lclose((*fv)->FileHandle); |
| 214 |
if ((*fv)->FnStrMemHandle>0) |
| 215 |
{ |
| 216 |
GlobalUnlock((*fv)->FnStrMemHandle); |
| 217 |
GlobalFree((*fv)->FnStrMemHandle); |
| 218 |
} |
| 219 |
free(*fv); |
| 220 |
*fv = NULL; |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
extern "C" { |
| 225 |
void LogStart() |
| 226 |
{ |
| 227 |
LONG Option; |
| 228 |
|
| 229 |
if ((FileLog) || (BinLog)) return; |
| 230 |
|
| 231 |
if (! LoadTTFILE()) return; |
| 232 |
if (! NewFileVar(&LogVar)) |
| 233 |
{ |
| 234 |
FreeTTFILE(); |
| 235 |
return; |
| 236 |
} |
| 237 |
LogVar->OpId = OpLog; |
| 238 |
|
| 239 |
if (strlen(&(LogVar->FullName[LogVar->DirLen]))==0) |
| 240 |
{ |
| 241 |
Option = MAKELONG(ts.TransBin,ts.Append); |
| 242 |
if (! (*GetTransFname)(LogVar, ts.FileDir, GTF_LOG, &Option)) |
| 243 |
{ |
| 244 |
FreeFileVar(&LogVar); |
| 245 |
FreeTTFILE(); |
| 246 |
return; |
| 247 |
} |
| 248 |
ts.TransBin = LOWORD(Option); |
| 249 |
ts.Append = HIWORD(Option); |
| 250 |
} |
| 251 |
else |
| 252 |
(*SetFileVar)(LogVar); |
| 253 |
|
| 254 |
if (ts.TransBin > 0) |
| 255 |
{ |
| 256 |
BinLog = TRUE; |
| 257 |
FileLog = FALSE; |
| 258 |
if (! CreateBinBuf()) |
| 259 |
{ |
| 260 |
FileTransEnd(OpLog); |
| 261 |
return; |
| 262 |
} |
| 263 |
} |
| 264 |
else { |
| 265 |
BinLog = FALSE; |
| 266 |
FileLog = TRUE; |
| 267 |
if (! CreateLogBuf()) |
| 268 |
{ |
| 269 |
FileTransEnd(OpLog); |
| 270 |
return; |
| 271 |
} |
| 272 |
} |
| 273 |
cv.LStart = cv.LogPtr; |
| 274 |
cv.LCount = 0; |
| 275 |
|
| 276 |
HelpId = HlpFileLog; |
| 277 |
if (ts.Append > 0) |
| 278 |
{ |
| 279 |
LogVar->FileHandle = _lopen(LogVar->FullName,OF_WRITE); |
| 280 |
if (LogVar->FileHandle>0) |
| 281 |
_llseek(LogVar->FileHandle,0,2); |
| 282 |
else |
| 283 |
LogVar->FileHandle = _lcreat(LogVar->FullName,0); |
| 284 |
} |
| 285 |
else |
| 286 |
LogVar->FileHandle = _lcreat(LogVar->FullName,0); |
| 287 |
LogVar->FileOpen = (LogVar->FileHandle>0); |
| 288 |
if (! LogVar->FileOpen) |
| 289 |
{ |
| 290 |
FileTransEnd(OpLog); |
| 291 |
return; |
| 292 |
} |
| 293 |
LogVar->ByteCount = 0; |
| 294 |
|
| 295 |
if (! OpenFTDlg(LogVar)) |
| 296 |
FileTransEnd(OpLog); |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
void LogPut1(BYTE b) |
| 301 |
{ |
| 302 |
LogLast = b; |
| 303 |
cv.LogBuf[cv.LogPtr] = b; |
| 304 |
cv.LogPtr++; |
| 305 |
if (cv.LogPtr>=InBuffSize) |
| 306 |
cv.LogPtr = cv.LogPtr-InBuffSize; |
| 307 |
|
| 308 |
if (FileLog) |
| 309 |
{ |
| 310 |
if (cv.LCount>=InBuffSize) |
| 311 |
{ |
| 312 |
cv.LCount = InBuffSize; |
| 313 |
cv.LStart = cv.LogPtr; |
| 314 |
} |
| 315 |
else cv.LCount++; |
| 316 |
} |
| 317 |
else |
| 318 |
cv.LCount = 0; |
| 319 |
|
| 320 |
if (DDELog) |
| 321 |
{ |
| 322 |
if (cv.DCount>=InBuffSize) |
| 323 |
{ |
| 324 |
cv.DCount = InBuffSize; |
| 325 |
cv.DStart = cv.LogPtr; |
| 326 |
} |
| 327 |
else cv.DCount++; |
| 328 |
} |
| 329 |
else |
| 330 |
cv.DCount = 0; |
| 331 |
} |
| 332 |
|
| 333 |
void Log1Byte(BYTE b) |
| 334 |
{ |
| 335 |
if (b==0x0d) |
| 336 |
{ |
| 337 |
LogLast = b; |
| 338 |
return; |
| 339 |
} |
| 340 |
if ((b==0x0a) && (LogLast==0x0d)) |
| 341 |
LogPut1(0x0d); |
| 342 |
LogPut1(b); |
| 343 |
} |
| 344 |
|
| 345 |
static BOOL Get1(PCHAR Buf, int *Start, int *Count, PBYTE b) |
| 346 |
{ |
| 347 |
if (*Count<=0) return FALSE; |
| 348 |
*b = Buf[*Start]; |
| 349 |
(*Start)++; |
| 350 |
if (*Start>=InBuffSize) |
| 351 |
*Start = *Start-InBuffSize; |
| 352 |
(*Count)--; |
| 353 |
return TRUE; |
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
static CRITICAL_SECTION g_filelog_lock; /* ���b�N�p���� */ |
| 359 |
|
| 360 |
void logfile_lock_initialize(void) |
| 361 |
{ |
| 362 |
InitializeCriticalSection(&g_filelog_lock); |
| 363 |
} |
| 364 |
|
| 365 |
static inline void logfile_lock(void) |
| 366 |
{ |
| 367 |
EnterCriticalSection(&g_filelog_lock); |
| 368 |
} |
| 369 |
|
| 370 |
static inline void logfile_unlock(void) |
| 371 |
{ |
| 372 |
LeaveCriticalSection(&g_filelog_lock); |
| 373 |
} |
| 374 |
|
| 375 |
// �R�����g�����O���������� |
| 376 |
void CommentLogToFile(char *buf, int size) |
| 377 |
{ |
| 378 |
DWORD wrote; |
| 379 |
|
| 380 |
if (LogVar == NULL || !LogVar->FileOpen) { |
| 381 |
::MessageBox(NULL, "It is not opened by the log file yet.", "ERROR", MB_OK|MB_ICONEXCLAMATION); |
| 382 |
return; |
| 383 |
} |
| 384 |
|
| 385 |
logfile_lock(); |
| 386 |
WriteFile((HANDLE)LogVar->FileHandle, buf, size, &wrote, NULL); |
| 387 |
WriteFile((HANDLE)LogVar->FileHandle, "\r\n", 2, &wrote, NULL); // ���s |
| 388 |
logfile_unlock(); |
| 389 |
} |
| 390 |
|
| 391 |
void LogToFile() |
| 392 |
{ |
| 393 |
PCHAR Buf; |
| 394 |
int Start, Count; |
| 395 |
BYTE b; |
| 396 |
|
| 397 |
if (! LogVar->FileOpen) return; |
| 398 |
if (FileLog) |
| 399 |
{ |
| 400 |
Buf = cv.LogBuf; |
| 401 |
Start = cv.LStart; |
| 402 |
Count = cv.LCount; |
| 403 |
} |
| 404 |
else if (BinLog) |
| 405 |
{ |
| 406 |
Buf = cv.BinBuf; |
| 407 |
Start = cv.BStart; |
| 408 |
Count = cv.BCount; |
| 409 |
} |
| 410 |
else |
| 411 |
return; |
| 412 |
|
| 413 |
if (Buf==NULL) return; |
| 414 |
if (Count==0) return; |
| 415 |
|
| 416 |
// ���b�N������(2004.8.6 yutaka) |
| 417 |
logfile_lock(); |
| 418 |
|
| 419 |
while (Get1(Buf,&Start,&Count,&b)) |
| 420 |
{ |
| 421 |
if (((cv.FilePause & OpLog)==0) && (! cv.ProtoFlag)) |
| 422 |
{ |
| 423 |
_lwrite(LogVar->FileHandle,(PCHAR)&b,1); |
| 424 |
(LogVar->ByteCount)++; |
| 425 |
} |
| 426 |
} |
| 427 |
|
| 428 |
logfile_unlock(); |
| 429 |
|
| 430 |
if (FileLog) |
| 431 |
{ |
| 432 |
cv.LStart = Start; |
| 433 |
cv.LCount = Count; |
| 434 |
} |
| 435 |
else { |
| 436 |
cv.BStart = Start; |
| 437 |
cv.BCount = Count; |
| 438 |
} |
| 439 |
if (((cv.FilePause & OpLog) !=0) || cv.ProtoFlag) return; |
| 440 |
if (FLogDlg!=NULL) |
| 441 |
FLogDlg->RefreshNum(); |
| 442 |
} |
| 443 |
|
| 444 |
BOOL CreateLogBuf() |
| 445 |
{ |
| 446 |
if (cv.HLogBuf==NULL) |
| 447 |
{ |
| 448 |
cv.HLogBuf = GlobalAlloc(GMEM_MOVEABLE,InBuffSize); |
| 449 |
cv.LogBuf = NULL; |
| 450 |
cv.LogPtr = 0; |
| 451 |
cv.LStart = 0; |
| 452 |
cv.LCount = 0; |
| 453 |
cv.DStart = 0; |
| 454 |
cv.DCount = 0; |
| 455 |
} |
| 456 |
return (cv.HLogBuf!=NULL); |
| 457 |
} |
| 458 |
|
| 459 |
void FreeLogBuf() |
| 460 |
{ |
| 461 |
if ((cv.HLogBuf==NULL) || FileLog || DDELog) return; |
| 462 |
if (cv.LogBuf!=NULL) GlobalUnlock(cv.HLogBuf); |
| 463 |
GlobalFree(cv.HLogBuf); |
| 464 |
cv.HLogBuf = NULL; |
| 465 |
cv.LogBuf = NULL; |
| 466 |
cv.LogPtr = 0; |
| 467 |
cv.LStart = 0; |
| 468 |
cv.LCount = 0; |
| 469 |
cv.DStart = 0; |
| 470 |
cv.DCount = 0; |
| 471 |
} |
| 472 |
|
| 473 |
BOOL CreateBinBuf() |
| 474 |
{ |
| 475 |
if (cv.HBinBuf==NULL) |
| 476 |
{ |
| 477 |
cv.HBinBuf = GlobalAlloc(GMEM_MOVEABLE,InBuffSize); |
| 478 |
cv.BinBuf = NULL; |
| 479 |
cv.BinPtr = 0; |
| 480 |
cv.BStart = 0; |
| 481 |
cv.BCount = 0; |
| 482 |
} |
| 483 |
return (cv.HBinBuf!=NULL); |
| 484 |
} |
| 485 |
|
| 486 |
void FreeBinBuf() |
| 487 |
{ |
| 488 |
if ((cv.HBinBuf==NULL) || BinLog) return; |
| 489 |
if (cv.BinBuf!=NULL) GlobalUnlock(cv.HBinBuf); |
| 490 |
GlobalFree(cv.HBinBuf); |
| 491 |
cv.HBinBuf = NULL; |
| 492 |
cv.BinBuf = NULL; |
| 493 |
cv.BinPtr = 0; |
| 494 |
cv.BStart = 0; |
| 495 |
cv.BCount = 0; |
| 496 |
} |
| 497 |
|
| 498 |
extern "C" { |
| 499 |
void FileSendStart() |
| 500 |
{ |
| 501 |
LONG Option; |
| 502 |
|
| 503 |
if (! cv.Ready || FSend) return; |
| 504 |
if (cv.ProtoFlag) |
| 505 |
{ |
| 506 |
FreeFileVar(&SendVar); |
| 507 |
return; |
| 508 |
} |
| 509 |
|
| 510 |
if (! LoadTTFILE()) return; |
| 511 |
if (! NewFileVar(&SendVar)) |
| 512 |
{ |
| 513 |
FreeTTFILE(); |
| 514 |
return; |
| 515 |
} |
| 516 |
SendVar->OpId = OpSendFile; |
| 517 |
|
| 518 |
FSend = TRUE; |
| 519 |
|
| 520 |
if (strlen(&(SendVar->FullName[SendVar->DirLen]))==0) |
| 521 |
{ |
| 522 |
Option = MAKELONG(ts.TransBin,0); |
| 523 |
if (! (*GetTransFname)(SendVar, ts.FileDir, GTF_SEND, &Option)) |
| 524 |
{ |
| 525 |
FileTransEnd(OpSendFile); |
| 526 |
return; |
| 527 |
} |
| 528 |
ts.TransBin = LOWORD(Option); |
| 529 |
} |
| 530 |
else |
| 531 |
(*SetFileVar)(SendVar); |
| 532 |
|
| 533 |
SendVar->FileHandle = _lopen(SendVar->FullName,OF_READ); |
| 534 |
SendVar->FileOpen = (SendVar->FileHandle>0); |
| 535 |
if (! SendVar->FileOpen) |
| 536 |
{ |
| 537 |
FileTransEnd(OpSendFile); |
| 538 |
return; |
| 539 |
} |
| 540 |
SendVar->ByteCount = 0; |
| 541 |
|
| 542 |
TalkStatus = IdTalkFile; |
| 543 |
FileRetrySend = FALSE; |
| 544 |
FileRetryEcho = FALSE; |
| 545 |
FileCRSend = FALSE; |
| 546 |
|
| 547 |
if (! OpenFTDlg(SendVar)) |
| 548 |
FileTransEnd(OpSendFile); |
| 549 |
} |
| 550 |
} |
| 551 |
|
| 552 |
void FileTransEnd(WORD OpId) |
| 553 |
/* OpId = 0: close Log and FileSend |
| 554 |
OpLog: close Log |
| 555 |
OpSendFile: close FileSend */ |
| 556 |
{ |
| 557 |
if (((OpId==0) || (OpId==OpLog)) && |
| 558 |
(FileLog || BinLog)) |
| 559 |
{ |
| 560 |
FileLog = FALSE; |
| 561 |
BinLog = FALSE; |
| 562 |
if (FLogDlg!=NULL) |
| 563 |
{ |
| 564 |
FLogDlg->DestroyWindow(); |
| 565 |
FLogDlg = NULL; |
| 566 |
} |
| 567 |
FreeFileVar(&LogVar); |
| 568 |
FreeLogBuf(); |
| 569 |
FreeBinBuf(); |
| 570 |
FreeTTFILE(); |
| 571 |
} |
| 572 |
|
| 573 |
if (((OpId==0) || (OpId==OpSendFile)) && |
| 574 |
FSend) |
| 575 |
{ |
| 576 |
FSend = FALSE; |
| 577 |
TalkStatus = IdTalkKeyb; |
| 578 |
if (SendDlg!=NULL) |
| 579 |
{ |
| 580 |
SendDlg->DestroyWindow(); |
| 581 |
SendDlg = NULL; |
| 582 |
} |
| 583 |
FreeFileVar(&SendVar); |
| 584 |
FreeTTFILE(); |
| 585 |
} |
| 586 |
|
| 587 |
EndDdeCmnd(0); |
| 588 |
} |
| 589 |
|
| 590 |
// vtwin.cpp �����R�[�������������Aextern "C"���t�����B(2004.11.3 yutaka) |
| 591 |
extern "C" { |
| 592 |
int FSOut1(BYTE b) |
| 593 |
{ |
| 594 |
if (ts.TransBin > 0) |
| 595 |
return CommBinaryOut(&cv,(PCHAR)&b,1); |
| 596 |
else if ((b>=0x20) || (b==0x09) || (b==0x0A) || (b==0x0D)) |
| 597 |
return CommTextOut(&cv,(PCHAR)&b,1); |
| 598 |
else |
| 599 |
return 1; |
| 600 |
} |
| 601 |
|
| 602 |
int FSEcho1(BYTE b) |
| 603 |
{ |
| 604 |
if (ts.TransBin > 0) |
| 605 |
return CommBinaryEcho(&cv,(PCHAR)&b,1); |
| 606 |
else |
| 607 |
return CommTextEcho(&cv,(PCHAR)&b,1); |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
extern "C" { |
| 612 |
void FileSend() |
| 613 |
{ |
| 614 |
WORD c, fc; |
| 615 |
LONG BCOld; |
| 616 |
|
| 617 |
if ((SendDlg==NULL) || |
| 618 |
((cv.FilePause & OpSendFile) !=0)) return; |
| 619 |
|
| 620 |
BCOld = SendVar->ByteCount; |
| 621 |
|
| 622 |
if (FileRetrySend) |
| 623 |
{ |
| 624 |
FileRetryEcho = (ts.LocalEcho>0); |
| 625 |
c = FSOut1(FileByte); |
| 626 |
FileRetrySend = (c==0); |
| 627 |
if (FileRetrySend) return; |
| 628 |
} |
| 629 |
|
| 630 |
if (FileRetryEcho) |
| 631 |
{ |
| 632 |
c = FSEcho1(FileByte); |
| 633 |
FileRetryEcho = (c==0); |
| 634 |
if (FileRetryEcho) return; |
| 635 |
} |
| 636 |
|
| 637 |
do { |
| 638 |
fc = _lread(SendVar->FileHandle,&FileByte,1); |
| 639 |
SendVar->ByteCount = SendVar->ByteCount + fc; |
| 640 |
|
| 641 |
if (FileCRSend && (fc==1) && (FileByte==0x0A)) |
| 642 |
{ |
| 643 |
fc = _lread(SendVar->FileHandle,&FileByte,1); |
| 644 |
SendVar->ByteCount = SendVar->ByteCount + fc; |
| 645 |
} |
| 646 |
|
| 647 |
if (fc!=0) |
| 648 |
{ |
| 649 |
c = FSOut1(FileByte); |
| 650 |
FileCRSend = (ts.TransBin==0) && (FileByte==0x0D); |
| 651 |
FileRetrySend = (c==0); |
| 652 |
if (FileRetrySend) |
| 653 |
{ |
| 654 |
if (SendVar->ByteCount != BCOld) |
| 655 |
SendDlg->RefreshNum(); |
| 656 |
return; |
| 657 |
} |
| 658 |
if (ts.LocalEcho>0) |
| 659 |
{ |
| 660 |
c = FSEcho1(FileByte); |
| 661 |
FileRetryEcho = (c==0); |
| 662 |
if (FileRetryEcho) return; |
| 663 |
} |
| 664 |
} |
| 665 |
if ((fc==0) || (SendVar->ByteCount % 100 == 0)) |
| 666 |
{ |
| 667 |
SendDlg->RefreshNum(); |
| 668 |
BCOld = SendVar->ByteCount; |
| 669 |
if (fc!=0) return; |
| 670 |
} |
| 671 |
} while (fc!=0); |
| 672 |
|
| 673 |
FileTransEnd(OpSendFile); |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
extern "C" { |
| 678 |
void FLogChangeButton(BOOL Pause) |
| 679 |
{ |
| 680 |
if (FLogDlg!=NULL) |
| 681 |
FLogDlg->ChangeButton(Pause); |
| 682 |
} |
| 683 |
} |
| 684 |
|
| 685 |
extern "C" { |
| 686 |
void FLogRefreshNum() |
| 687 |
{ |
| 688 |
if (FLogDlg!=NULL) |
| 689 |
FLogDlg->RefreshNum(); |
| 690 |
} |
| 691 |
} |
| 692 |
|
| 693 |
BOOL OpenProtoDlg(PFileVar fv, int IdProto, int Mode, WORD Opt1, WORD Opt2) |
| 694 |
{ |
| 695 |
int vsize; |
| 696 |
PProtoDlg pd; |
| 697 |
|
| 698 |
ProtoId = IdProto; |
| 699 |
|
| 700 |
switch (ProtoId) { |
| 701 |
case PROTO_KMT: |
| 702 |
vsize = sizeof(TKmtVar); |
| 703 |
break; |
| 704 |
case PROTO_XM: |
| 705 |
vsize = sizeof(TXVar); |
| 706 |
break; |
| 707 |
case PROTO_ZM: |
| 708 |
vsize = sizeof(TZVar); |
| 709 |
break; |
| 710 |
case PROTO_BP: |
| 711 |
vsize = sizeof(TBPVar); |
| 712 |
break; |
| 713 |
case PROTO_QV: |
| 714 |
vsize = sizeof(TQVVar); |
| 715 |
break; |
| 716 |
} |
| 717 |
ProtoVar = (PCHAR)malloc(vsize); |
| 718 |
if (ProtoVar==NULL) return FALSE; |
| 719 |
|
| 720 |
switch (ProtoId) { |
| 721 |
case PROTO_KMT: |
| 722 |
((PKmtVar)ProtoVar)->KmtMode = Mode; |
| 723 |
break; |
| 724 |
case PROTO_XM: |
| 725 |
((PXVar)ProtoVar)->XMode = Mode; |
| 726 |
((PXVar)ProtoVar)->XOpt = Opt1; |
| 727 |
((PXVar)ProtoVar)->TextFlag = 1 - (Opt2 & 1); |
| 728 |
break; |
| 729 |
case PROTO_ZM: |
| 730 |
((PZVar)ProtoVar)->BinFlag = (Opt1 & 1) != 0; |
| 731 |
((PZVar)ProtoVar)->ZMode = Mode; |
| 732 |
break; |
| 733 |
case PROTO_BP: |
| 734 |
((PBPVar)ProtoVar)->BPMode = Mode; |
| 735 |
break; |
| 736 |
case PROTO_QV: |
| 737 |
((PQVVar)ProtoVar)->QVMode = Mode; |
| 738 |
break; |
| 739 |
} |
| 740 |
|
| 741 |
pd = new CProtoDlg(); |
| 742 |
if (pd==NULL) |
| 743 |
{ |
| 744 |
free(ProtoVar); |
| 745 |
ProtoVar = NULL; |
| 746 |
return FALSE; |
| 747 |
} |
| 748 |
pd->Create(fv); |
| 749 |
|
| 750 |
(*ProtoInit)(ProtoId,FileVar,ProtoVar,&cv,&ts); |
| 751 |
|
| 752 |
PtDlg = pd; |
| 753 |
return TRUE; |
| 754 |
} |
| 755 |
|
| 756 |
extern "C" { |
| 757 |
void CloseProtoDlg() |
| 758 |
{ |
| 759 |
if (PtDlg!=NULL) |
| 760 |
{ |
| 761 |
PtDlg->DestroyWindow(); |
| 762 |
PtDlg = NULL; |
| 763 |
|
| 764 |
::KillTimer(FileVar->HMainWin,IdProtoTimer); |
| 765 |
if ((ProtoId==PROTO_QV) && |
| 766 |
(((PQVVar)ProtoVar)->QVMode==IdQVSend)) |
| 767 |
CommTextOut(&cv,"\015",1); |
| 768 |
if (FileVar->LogFlag) |
| 769 |
_lclose(FileVar->LogFile); |
| 770 |
FileVar->LogFile = 0; |
| 771 |
if (ProtoVar!=NULL) |
| 772 |
{ |
| 773 |
free(ProtoVar); |
| 774 |
ProtoVar = NULL; |
| 775 |
} |
| 776 |
} |
| 777 |
} |
| 778 |
} |
| 779 |
|
| 780 |
BOOL ProtoStart() |
| 781 |
{ |
| 782 |
if (cv.ProtoFlag) return FALSE; |
| 783 |
if (FSend) |
| 784 |
{ |
| 785 |
FreeFileVar(&FileVar); |
| 786 |
return FALSE; |
| 787 |
} |
| 788 |
|
| 789 |
if (! LoadTTFILE()) return FALSE; |
| 790 |
NewFileVar(&FileVar); |
| 791 |
|
| 792 |
if (FileVar==NULL) |
| 793 |
{ |
| 794 |
FreeTTFILE(); |
| 795 |
return FALSE; |
| 796 |
} |
| 797 |
cv.ProtoFlag = TRUE; |
| 798 |
return TRUE; |
| 799 |
} |
| 800 |
|
| 801 |
void ProtoEnd() |
| 802 |
{ |
| 803 |
if (! cv.ProtoFlag) return; |
| 804 |
cv.ProtoFlag = FALSE; |
| 805 |
|
| 806 |
/* Enable transmit delay (serial port) */ |
| 807 |
cv.DelayFlag = TRUE; |
| 808 |
TalkStatus = IdTalkKeyb; |
| 809 |
|
| 810 |
CloseProtoDlg(); |
| 811 |
|
| 812 |
if ((FileVar!=NULL) && FileVar->Success) |
| 813 |
EndDdeCmnd(1); |
| 814 |
else |
| 815 |
EndDdeCmnd(0); |
| 816 |
|
| 817 |
FreeTTFILE(); |
| 818 |
FreeFileVar(&FileVar); |
| 819 |
} |
| 820 |
|
| 821 |
extern "C" { |
| 822 |
int ProtoDlgParse() |
| 823 |
{ |
| 824 |
int P; |
| 825 |
|
| 826 |
P = ActiveWin; |
| 827 |
if (PtDlg==NULL) return P; |
| 828 |
|
| 829 |
if ((*ProtoParse)(ProtoId,FileVar,ProtoVar,&cv)) |
| 830 |
P = 0; /* continue */ |
| 831 |
else { |
| 832 |
CommSend(&cv); |
| 833 |
ProtoEnd(); |
| 834 |
} |
| 835 |
return P; |
| 836 |
} |
| 837 |
} |
| 838 |
|
| 839 |
extern "C" { |
| 840 |
void ProtoDlgTimeOut() |
| 841 |
{ |
| 842 |
if (PtDlg!=NULL) |
| 843 |
(*ProtoTimeOutProc)(ProtoId,FileVar,ProtoVar,&cv); |
| 844 |
} |
| 845 |
} |
| 846 |
|
| 847 |
extern "C" { |
| 848 |
void ProtoDlgCancel() |
| 849 |
{ |
| 850 |
if ((PtDlg!=NULL) && |
| 851 |
(*ProtoCancel)(ProtoId,FileVar,ProtoVar,&cv)) |
| 852 |
ProtoEnd(); |
| 853 |
} |
| 854 |
} |
| 855 |
|
| 856 |
extern "C" { |
| 857 |
void KermitStart(int mode) |
| 858 |
{ |
| 859 |
WORD w; |
| 860 |
|
| 861 |
if (! ProtoStart()) return; |
| 862 |
|
| 863 |
switch (mode) { |
| 864 |
case IdKmtSend: |
| 865 |
FileVar->OpId = OpKmtSend; |
| 866 |
if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0) |
| 867 |
{ |
| 868 |
if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_KERMIT,&w) || |
| 869 |
(FileVar->NumFname==0)) |
| 870 |
{ |
| 871 |
ProtoEnd(); |
| 872 |
return; |
| 873 |
} |
| 874 |
} |
| 875 |
else |
| 876 |
(*SetFileVar)(FileVar); |
| 877 |
break; |
| 878 |
case IdKmtReceive: |
| 879 |
FileVar->OpId = OpKmtRcv; |
| 880 |
break; |
| 881 |
case IdKmtGet: |
| 882 |
FileVar->OpId = OpKmtSend; |
| 883 |
if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0) |
| 884 |
{ |
| 885 |
if (! (*GetGetFname)(FileVar->HMainWin,FileVar) || |
| 886 |
(strlen(FileVar->FullName)==0)) |
| 887 |
{ |
| 888 |
ProtoEnd(); |
| 889 |
return; |
| 890 |
} |
| 891 |
} |
| 892 |
else |
| 893 |
(*SetFileVar)(FileVar); |
| 894 |
break; |
| 895 |
case IdKmtFinish: |
| 896 |
FileVar->OpId = OpKmtFin; |
| 897 |
break; |
| 898 |
default: |
| 899 |
ProtoEnd(); |
| 900 |
return; |
| 901 |
} |
| 902 |
TalkStatus = IdTalkQuiet; |
| 903 |
|
| 904 |
/* disable transmit delay (serial port) */ |
| 905 |
cv.DelayFlag = FALSE; |
| 906 |
|
| 907 |
if (! OpenProtoDlg(FileVar,PROTO_KMT,mode,0,0)) |
| 908 |
ProtoEnd(); |
| 909 |
} |
| 910 |
} |
| 911 |
|
| 912 |
extern "C" { |
| 913 |
void XMODEMStart(int mode) |
| 914 |
{ |
| 915 |
LONG Option; |
| 916 |
|
| 917 |
if (! ProtoStart()) return; |
| 918 |
|
| 919 |
if (mode==IdXReceive) |
| 920 |
FileVar->OpId = OpXRcv; |
| 921 |
else |
| 922 |
FileVar->OpId = OpXSend; |
| 923 |
|
| 924 |
if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0) |
| 925 |
{ |
| 926 |
Option = MAKELONG(ts.XmodemBin,ts.XmodemOpt); |
| 927 |
if (! (*GetXFname)(FileVar->HMainWin, |
| 928 |
mode==IdXReceive,&Option,FileVar,ts.FileDir)) |
| 929 |
{ |
| 930 |
ProtoEnd(); |
| 931 |
return; |
| 932 |
} |
| 933 |
ts.XmodemOpt = HIWORD(Option); |
| 934 |
ts.XmodemBin = LOWORD(Option); |
| 935 |
} |
| 936 |
else |
| 937 |
(*SetFileVar)(FileVar); |
| 938 |
|
| 939 |
if (mode==IdXReceive) |
| 940 |
FileVar->FileHandle = _lcreat(FileVar->FullName,0); |
| 941 |
else |
| 942 |
FileVar->FileHandle = _lopen(FileVar->FullName,OF_READ); |
| 943 |
|
| 944 |
FileVar->FileOpen = FileVar->FileHandle>0; |
| 945 |
if (! FileVar->FileOpen) |
| 946 |
{ |
| 947 |
ProtoEnd(); |
| 948 |
return; |
| 949 |
} |
| 950 |
TalkStatus = IdTalkQuiet; |
| 951 |
|
| 952 |
/* disable transmit delay (serial port) */ |
| 953 |
cv.DelayFlag = FALSE; |
| 954 |
|
| 955 |
if (! OpenProtoDlg(FileVar,PROTO_XM,mode, |
| 956 |
ts.XmodemOpt,ts.XmodemBin)) |
| 957 |
ProtoEnd(); |
| 958 |
} |
| 959 |
} |
| 960 |
|
| 961 |
extern "C" { |
| 962 |
void ZMODEMStart(int mode) |
| 963 |
{ |
| 964 |
WORD Opt; |
| 965 |
|
| 966 |
if (! ProtoStart()) return; |
| 967 |
|
| 968 |
if (mode==IdZSend) |
| 969 |
{ |
| 970 |
Opt = ts.XmodemBin; |
| 971 |
FileVar->OpId = OpZSend; |
| 972 |
if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0) |
| 973 |
{ |
| 974 |
if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_Z,&Opt) || |
| 975 |
(FileVar->NumFname==0)) |
| 976 |
{ |
| 977 |
ProtoEnd(); |
| 978 |
return; |
| 979 |
} |
| 980 |
ts.XmodemBin = Opt; |
| 981 |
} |
| 982 |
else |
| 983 |
(*SetFileVar)(FileVar); |
| 984 |
} |
| 985 |
else /* IdZReceive or IdZAuto */ |
| 986 |
FileVar->OpId = OpZRcv; |
| 987 |
|
| 988 |
TalkStatus = IdTalkQuiet; |
| 989 |
|
| 990 |
/* disable transmit delay (serial port) */ |
| 991 |
cv.DelayFlag = FALSE; |
| 992 |
|
| 993 |
if (! OpenProtoDlg(FileVar,PROTO_ZM,mode,Opt,0)) |
| 994 |
ProtoEnd(); |
| 995 |
} |
| 996 |
} |
| 997 |
|
| 998 |
extern "C" { |
| 999 |
void BPStart(int mode) |
| 1000 |
{ |
| 1001 |
LONG Option; |
| 1002 |
|
| 1003 |
if (! ProtoStart()) return; |
| 1004 |
if (mode==IdBPSend) |
| 1005 |
{ |
| 1006 |
FileVar->OpId = OpBPSend; |
| 1007 |
if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0) |
| 1008 |
{ |
| 1009 |
if (! (*GetTransFname)(FileVar, ts.FileDir, GTF_BP, &Option)) |
| 1010 |
{ |
| 1011 |
ProtoEnd(); |
| 1012 |
return; |
| 1013 |
} |
| 1014 |
} |
| 1015 |
else |
| 1016 |
(*SetFileVar)(FileVar); |
| 1017 |
|
| 1018 |
} |
| 1019 |
else /* IdBPReceive or IdBPAuto */ |
| 1020 |
FileVar->OpId = OpBPRcv; |
| 1021 |
|
| 1022 |
TalkStatus = IdTalkQuiet; |
| 1023 |
|
| 1024 |
/* disable transmit delay (serial port) */ |
| 1025 |
cv.DelayFlag = FALSE; |
| 1026 |
|
| 1027 |
if (! OpenProtoDlg(FileVar,PROTO_BP,mode,0,0)) |
| 1028 |
ProtoEnd(); |
| 1029 |
} |
| 1030 |
} |
| 1031 |
|
| 1032 |
extern "C" { |
| 1033 |
void QVStart(int mode) |
| 1034 |
{ |
| 1035 |
WORD W; |
| 1036 |
|
| 1037 |
if (! ProtoStart()) return; |
| 1038 |
|
| 1039 |
if (mode==IdQVSend) |
| 1040 |
{ |
| 1041 |
FileVar->OpId = OpQVSend; |
| 1042 |
if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0) |
| 1043 |
{ |
| 1044 |
if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_QV, &W) || |
| 1045 |
(FileVar->NumFname==0)) |
| 1046 |
{ |
| 1047 |
ProtoEnd(); |
| 1048 |
return; |
| 1049 |
} |
| 1050 |
} |
| 1051 |
else |
| 1052 |
(*SetFileVar)(FileVar); |
| 1053 |
} |
| 1054 |
else |
| 1055 |
FileVar->OpId = OpQVRcv; |
| 1056 |
|
| 1057 |
TalkStatus = IdTalkQuiet; |
| 1058 |
|
| 1059 |
/* disable transmit delay (serial port) */ |
| 1060 |
cv.DelayFlag = FALSE; |
| 1061 |
|
| 1062 |
if (! OpenProtoDlg(FileVar,PROTO_QV,mode,0,0)) |
| 1063 |
ProtoEnd(); |
| 1064 |
} |
| 1065 |
} |