| 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 |
// 0x1000 = plain text (2005.2.20 yutaka) |
| 242 |
// teraterm.ini?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?スf?スt?スH?ス?ス?スg?スI?スv?スV?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?スB(2005.5.7 yutaka) |
| 243 |
Option = MAKELONG(ts.TransBin,ts.Append | (0x1000 * ts.LogTypePlainText)); |
| 244 |
if (! (*GetTransFname)(LogVar, ts.FileDir, GTF_LOG, &Option)) |
| 245 |
{ |
| 246 |
FreeFileVar(&LogVar); |
| 247 |
FreeTTFILE(); |
| 248 |
return; |
| 249 |
} |
| 250 |
ts.TransBin = LOWORD(Option); |
| 251 |
ts.Append = HIWORD(Option); |
| 252 |
|
| 253 |
if (ts.Append & 0x1000) { |
| 254 |
ts.LogTypePlainText = 1; |
| 255 |
} else { |
| 256 |
ts.LogTypePlainText = 0; |
| 257 |
} |
| 258 |
ts.Append &= 0x1; // 1bit?ス?ス?ス}?スX?スN?ス?ス?ス?ス |
| 259 |
|
| 260 |
} |
| 261 |
else |
| 262 |
(*SetFileVar)(LogVar); |
| 263 |
|
| 264 |
if (ts.TransBin > 0) |
| 265 |
{ |
| 266 |
BinLog = TRUE; |
| 267 |
FileLog = FALSE; |
| 268 |
if (! CreateBinBuf()) |
| 269 |
{ |
| 270 |
FileTransEnd(OpLog); |
| 271 |
return; |
| 272 |
} |
| 273 |
} |
| 274 |
else { |
| 275 |
BinLog = FALSE; |
| 276 |
FileLog = TRUE; |
| 277 |
if (! CreateLogBuf()) |
| 278 |
{ |
| 279 |
FileTransEnd(OpLog); |
| 280 |
return; |
| 281 |
} |
| 282 |
} |
| 283 |
cv.LStart = cv.LogPtr; |
| 284 |
cv.LCount = 0; |
| 285 |
|
| 286 |
HelpId = HlpFileLog; |
| 287 |
if (ts.Append > 0) |
| 288 |
{ |
| 289 |
LogVar->FileHandle = _lopen(LogVar->FullName,OF_WRITE); |
| 290 |
if (LogVar->FileHandle>0) |
| 291 |
_llseek(LogVar->FileHandle,0,2); |
| 292 |
else |
| 293 |
LogVar->FileHandle = _lcreat(LogVar->FullName,0); |
| 294 |
} |
| 295 |
else |
| 296 |
LogVar->FileHandle = _lcreat(LogVar->FullName,0); |
| 297 |
LogVar->FileOpen = (LogVar->FileHandle>0); |
| 298 |
if (! LogVar->FileOpen) |
| 299 |
{ |
| 300 |
FileTransEnd(OpLog); |
| 301 |
return; |
| 302 |
} |
| 303 |
LogVar->ByteCount = 0; |
| 304 |
|
| 305 |
if (! OpenFTDlg(LogVar)) |
| 306 |
FileTransEnd(OpLog); |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
void LogPut1(BYTE b) |
| 311 |
{ |
| 312 |
LogLast = b; |
| 313 |
cv.LogBuf[cv.LogPtr] = b; |
| 314 |
cv.LogPtr++; |
| 315 |
if (cv.LogPtr>=InBuffSize) |
| 316 |
cv.LogPtr = cv.LogPtr-InBuffSize; |
| 317 |
|
| 318 |
if (FileLog) |
| 319 |
{ |
| 320 |
if (cv.LCount>=InBuffSize) |
| 321 |
{ |
| 322 |
cv.LCount = InBuffSize; |
| 323 |
cv.LStart = cv.LogPtr; |
| 324 |
} |
| 325 |
else cv.LCount++; |
| 326 |
} |
| 327 |
else |
| 328 |
cv.LCount = 0; |
| 329 |
|
| 330 |
if (DDELog) |
| 331 |
{ |
| 332 |
if (cv.DCount>=InBuffSize) |
| 333 |
{ |
| 334 |
cv.DCount = InBuffSize; |
| 335 |
cv.DStart = cv.LogPtr; |
| 336 |
} |
| 337 |
else cv.DCount++; |
| 338 |
} |
| 339 |
else |
| 340 |
cv.DCount = 0; |
| 341 |
} |
| 342 |
|
| 343 |
void Log1Byte(BYTE b) |
| 344 |
{ |
| 345 |
if (b==0x0d) |
| 346 |
{ |
| 347 |
LogLast = b; |
| 348 |
return; |
| 349 |
} |
| 350 |
if ((b==0x0a) && (LogLast==0x0d)) |
| 351 |
LogPut1(0x0d); |
| 352 |
LogPut1(b); |
| 353 |
} |
| 354 |
|
| 355 |
static BOOL Get1(PCHAR Buf, int *Start, int *Count, PBYTE b) |
| 356 |
{ |
| 357 |
if (*Count<=0) return FALSE; |
| 358 |
*b = Buf[*Start]; |
| 359 |
(*Start)++; |
| 360 |
if (*Start>=InBuffSize) |
| 361 |
*Start = *Start-InBuffSize; |
| 362 |
(*Count)--; |
| 363 |
return TRUE; |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
static CRITICAL_SECTION g_filelog_lock; /* ?ス?ス?スb?スN?スp?ス?ス?ス?ス */ |
| 369 |
|
| 370 |
void logfile_lock_initialize(void) |
| 371 |
{ |
| 372 |
InitializeCriticalSection(&g_filelog_lock); |
| 373 |
} |
| 374 |
|
| 375 |
static inline void logfile_lock(void) |
| 376 |
{ |
| 377 |
EnterCriticalSection(&g_filelog_lock); |
| 378 |
} |
| 379 |
|
| 380 |
static inline void logfile_unlock(void) |
| 381 |
{ |
| 382 |
LeaveCriticalSection(&g_filelog_lock); |
| 383 |
} |
| 384 |
|
| 385 |
// ?スR?ス?ス?ス?ス?スg?ス?ス?ス?ス?スO?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス |
| 386 |
void CommentLogToFile(char *buf, int size) |
| 387 |
{ |
| 388 |
DWORD wrote; |
| 389 |
|
| 390 |
if (LogVar == NULL || !LogVar->FileOpen) { |
| 391 |
::MessageBox(NULL, "It is not opened by the log file yet.", "ERROR", MB_OK|MB_ICONEXCLAMATION); |
| 392 |
return; |
| 393 |
} |
| 394 |
|
| 395 |
logfile_lock(); |
| 396 |
WriteFile((HANDLE)LogVar->FileHandle, buf, size, &wrote, NULL); |
| 397 |
WriteFile((HANDLE)LogVar->FileHandle, "\r\n", 2, &wrote, NULL); // ?ス?ス?スs |
| 398 |
logfile_unlock(); |
| 399 |
} |
| 400 |
|
| 401 |
void LogToFile() |
| 402 |
{ |
| 403 |
PCHAR Buf; |
| 404 |
int Start, Count; |
| 405 |
BYTE b; |
| 406 |
|
| 407 |
if (! LogVar->FileOpen) return; |
| 408 |
if (FileLog) |
| 409 |
{ |
| 410 |
Buf = cv.LogBuf; |
| 411 |
Start = cv.LStart; |
| 412 |
Count = cv.LCount; |
| 413 |
} |
| 414 |
else if (BinLog) |
| 415 |
{ |
| 416 |
Buf = cv.BinBuf; |
| 417 |
Start = cv.BStart; |
| 418 |
Count = cv.BCount; |
| 419 |
} |
| 420 |
else |
| 421 |
return; |
| 422 |
|
| 423 |
if (Buf==NULL) return; |
| 424 |
if (Count==0) return; |
| 425 |
|
| 426 |
// ?ス?ス?スb?スN?ス?ス?ス?ス?ス?ス(2004.8.6 yutaka) |
| 427 |
logfile_lock(); |
| 428 |
|
| 429 |
while (Get1(Buf,&Start,&Count,&b)) |
| 430 |
{ |
| 431 |
if (((cv.FilePause & OpLog)==0) && (! cv.ProtoFlag)) |
| 432 |
{ |
| 433 |
_lwrite(LogVar->FileHandle,(PCHAR)&b,1); |
| 434 |
(LogVar->ByteCount)++; |
| 435 |
} |
| 436 |
} |
| 437 |
|
| 438 |
logfile_unlock(); |
| 439 |
|
| 440 |
if (FileLog) |
| 441 |
{ |
| 442 |
cv.LStart = Start; |
| 443 |
cv.LCount = Count; |
| 444 |
} |
| 445 |
else { |
| 446 |
cv.BStart = Start; |
| 447 |
cv.BCount = Count; |
| 448 |
} |
| 449 |
if (((cv.FilePause & OpLog) !=0) || cv.ProtoFlag) return; |
| 450 |
if (FLogDlg!=NULL) |
| 451 |
FLogDlg->RefreshNum(); |
| 452 |
} |
| 453 |
|
| 454 |
BOOL CreateLogBuf() |
| 455 |
{ |
| 456 |
if (cv.HLogBuf==NULL) |
| 457 |
{ |
| 458 |
cv.HLogBuf = GlobalAlloc(GMEM_MOVEABLE,InBuffSize); |
| 459 |
cv.LogBuf = NULL; |
| 460 |
cv.LogPtr = 0; |
| 461 |
cv.LStart = 0; |
| 462 |
cv.LCount = 0; |
| 463 |
cv.DStart = 0; |
| 464 |
cv.DCount = 0; |
| 465 |
} |
| 466 |
return (cv.HLogBuf!=NULL); |
| 467 |
} |
| 468 |
|
| 469 |
void FreeLogBuf() |
| 470 |
{ |
| 471 |
if ((cv.HLogBuf==NULL) || FileLog || DDELog) return; |
| 472 |
if (cv.LogBuf!=NULL) GlobalUnlock(cv.HLogBuf); |
| 473 |
GlobalFree(cv.HLogBuf); |
| 474 |
cv.HLogBuf = NULL; |
| 475 |
cv.LogBuf = NULL; |
| 476 |
cv.LogPtr = 0; |
| 477 |
cv.LStart = 0; |
| 478 |
cv.LCount = 0; |
| 479 |
cv.DStart = 0; |
| 480 |
cv.DCount = 0; |
| 481 |
} |
| 482 |
|
| 483 |
BOOL CreateBinBuf() |
| 484 |
{ |
| 485 |
if (cv.HBinBuf==NULL) |
| 486 |
{ |
| 487 |
cv.HBinBuf = GlobalAlloc(GMEM_MOVEABLE,InBuffSize); |
| 488 |
cv.BinBuf = NULL; |
| 489 |
cv.BinPtr = 0; |
| 490 |
cv.BStart = 0; |
| 491 |
cv.BCount = 0; |
| 492 |
} |
| 493 |
return (cv.HBinBuf!=NULL); |
| 494 |
} |
| 495 |
|
| 496 |
void FreeBinBuf() |
| 497 |
{ |
| 498 |
if ((cv.HBinBuf==NULL) || BinLog) return; |
| 499 |
if (cv.BinBuf!=NULL) GlobalUnlock(cv.HBinBuf); |
| 500 |
GlobalFree(cv.HBinBuf); |
| 501 |
cv.HBinBuf = NULL; |
| 502 |
cv.BinBuf = NULL; |
| 503 |
cv.BinPtr = 0; |
| 504 |
cv.BStart = 0; |
| 505 |
cv.BCount = 0; |
| 506 |
} |
| 507 |
|
| 508 |
extern "C" { |
| 509 |
void FileSendStart() |
| 510 |
{ |
| 511 |
LONG Option; |
| 512 |
|
| 513 |
if (! cv.Ready || FSend) return; |
| 514 |
if (cv.ProtoFlag) |
| 515 |
{ |
| 516 |
FreeFileVar(&SendVar); |
| 517 |
return; |
| 518 |
} |
| 519 |
|
| 520 |
if (! LoadTTFILE()) return; |
| 521 |
if (! NewFileVar(&SendVar)) |
| 522 |
{ |
| 523 |
FreeTTFILE(); |
| 524 |
return; |
| 525 |
} |
| 526 |
SendVar->OpId = OpSendFile; |
| 527 |
|
| 528 |
FSend = TRUE; |
| 529 |
|
| 530 |
if (strlen(&(SendVar->FullName[SendVar->DirLen]))==0) |
| 531 |
{ |
| 532 |
Option = MAKELONG(ts.TransBin,0); |
| 533 |
if (! (*GetTransFname)(SendVar, ts.FileDir, GTF_SEND, &Option)) |
| 534 |
{ |
| 535 |
FileTransEnd(OpSendFile); |
| 536 |
return; |
| 537 |
} |
| 538 |
ts.TransBin = LOWORD(Option); |
| 539 |
} |
| 540 |
else |
| 541 |
(*SetFileVar)(SendVar); |
| 542 |
|
| 543 |
SendVar->FileHandle = _lopen(SendVar->FullName,OF_READ); |
| 544 |
SendVar->FileOpen = (SendVar->FileHandle>0); |
| 545 |
if (! SendVar->FileOpen) |
| 546 |
{ |
| 547 |
FileTransEnd(OpSendFile); |
| 548 |
return; |
| 549 |
} |
| 550 |
SendVar->ByteCount = 0; |
| 551 |
|
| 552 |
TalkStatus = IdTalkFile; |
| 553 |
FileRetrySend = FALSE; |
| 554 |
FileRetryEcho = FALSE; |
| 555 |
FileCRSend = FALSE; |
| 556 |
|
| 557 |
if (! OpenFTDlg(SendVar)) |
| 558 |
FileTransEnd(OpSendFile); |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
void FileTransEnd(WORD OpId) |
| 563 |
/* OpId = 0: close Log and FileSend |
| 564 |
OpLog: close Log |
| 565 |
OpSendFile: close FileSend */ |
| 566 |
{ |
| 567 |
if (((OpId==0) || (OpId==OpLog)) && |
| 568 |
(FileLog || BinLog)) |
| 569 |
{ |
| 570 |
FileLog = FALSE; |
| 571 |
BinLog = FALSE; |
| 572 |
if (FLogDlg!=NULL) |
| 573 |
{ |
| 574 |
FLogDlg->DestroyWindow(); |
| 575 |
FLogDlg = NULL; |
| 576 |
} |
| 577 |
FreeFileVar(&LogVar); |
| 578 |
FreeLogBuf(); |
| 579 |
FreeBinBuf(); |
| 580 |
FreeTTFILE(); |
| 581 |
} |
| 582 |
|
| 583 |
if (((OpId==0) || (OpId==OpSendFile)) && |
| 584 |
FSend) |
| 585 |
{ |
| 586 |
FSend = FALSE; |
| 587 |
TalkStatus = IdTalkKeyb; |
| 588 |
if (SendDlg!=NULL) |
| 589 |
{ |
| 590 |
SendDlg->DestroyWindow(); |
| 591 |
SendDlg = NULL; |
| 592 |
} |
| 593 |
FreeFileVar(&SendVar); |
| 594 |
FreeTTFILE(); |
| 595 |
} |
| 596 |
|
| 597 |
EndDdeCmnd(0); |
| 598 |
} |
| 599 |
|
| 600 |
// vtwin.cpp ?ス?ス?ス?ス?スR?ス[?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?スAextern "C"?ス?ス?スt?ス?ス?ス?ス?スB(2004.11.3 yutaka) |
| 601 |
extern "C" { |
| 602 |
int FSOut1(BYTE b) |
| 603 |
{ |
| 604 |
if (ts.TransBin > 0) |
| 605 |
return CommBinaryOut(&cv,(PCHAR)&b,1); |
| 606 |
else if ((b>=0x20) || (b==0x09) || (b==0x0A) || (b==0x0D)) |
| 607 |
return CommTextOut(&cv,(PCHAR)&b,1); |
| 608 |
else |
| 609 |
return 1; |
| 610 |
} |
| 611 |
|
| 612 |
int FSEcho1(BYTE b) |
| 613 |
{ |
| 614 |
if (ts.TransBin > 0) |
| 615 |
return CommBinaryEcho(&cv,(PCHAR)&b,1); |
| 616 |
else |
| 617 |
return CommTextEcho(&cv,(PCHAR)&b,1); |
| 618 |
} |
| 619 |
} |
| 620 |
|
| 621 |
extern "C" { |
| 622 |
void FileSend() |
| 623 |
{ |
| 624 |
WORD c, fc; |
| 625 |
LONG BCOld; |
| 626 |
|
| 627 |
if ((SendDlg==NULL) || |
| 628 |
((cv.FilePause & OpSendFile) !=0)) return; |
| 629 |
|
| 630 |
BCOld = SendVar->ByteCount; |
| 631 |
|
| 632 |
if (FileRetrySend) |
| 633 |
{ |
| 634 |
FileRetryEcho = (ts.LocalEcho>0); |
| 635 |
c = FSOut1(FileByte); |
| 636 |
FileRetrySend = (c==0); |
| 637 |
if (FileRetrySend) return; |
| 638 |
} |
| 639 |
|
| 640 |
if (FileRetryEcho) |
| 641 |
{ |
| 642 |
c = FSEcho1(FileByte); |
| 643 |
FileRetryEcho = (c==0); |
| 644 |
if (FileRetryEcho) return; |
| 645 |
} |
| 646 |
|
| 647 |
do { |
| 648 |
fc = _lread(SendVar->FileHandle,&FileByte,1); |
| 649 |
SendVar->ByteCount = SendVar->ByteCount + fc; |
| 650 |
|
| 651 |
if (FileCRSend && (fc==1) && (FileByte==0x0A)) |
| 652 |
{ |
| 653 |
fc = _lread(SendVar->FileHandle,&FileByte,1); |
| 654 |
SendVar->ByteCount = SendVar->ByteCount + fc; |
| 655 |
} |
| 656 |
|
| 657 |
if (fc!=0) |
| 658 |
{ |
| 659 |
c = FSOut1(FileByte); |
| 660 |
FileCRSend = (ts.TransBin==0) && (FileByte==0x0D); |
| 661 |
FileRetrySend = (c==0); |
| 662 |
if (FileRetrySend) |
| 663 |
{ |
| 664 |
if (SendVar->ByteCount != BCOld) |
| 665 |
SendDlg->RefreshNum(); |
| 666 |
return; |
| 667 |
} |
| 668 |
if (ts.LocalEcho>0) |
| 669 |
{ |
| 670 |
c = FSEcho1(FileByte); |
| 671 |
FileRetryEcho = (c==0); |
| 672 |
if (FileRetryEcho) return; |
| 673 |
} |
| 674 |
} |
| 675 |
if ((fc==0) || (SendVar->ByteCount % 100 == 0)) |
| 676 |
{ |
| 677 |
SendDlg->RefreshNum(); |
| 678 |
BCOld = SendVar->ByteCount; |
| 679 |
if (fc!=0) return; |
| 680 |
} |
| 681 |
} while (fc!=0); |
| 682 |
|
| 683 |
FileTransEnd(OpSendFile); |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
extern "C" { |
| 688 |
void FLogChangeButton(BOOL Pause) |
| 689 |
{ |
| 690 |
if (FLogDlg!=NULL) |
| 691 |
FLogDlg->ChangeButton(Pause); |
| 692 |
} |
| 693 |
} |
| 694 |
|
| 695 |
extern "C" { |
| 696 |
void FLogRefreshNum() |
| 697 |
{ |
| 698 |
if (FLogDlg!=NULL) |
| 699 |
FLogDlg->RefreshNum(); |
| 700 |
} |
| 701 |
} |
| 702 |
|
| 703 |
BOOL OpenProtoDlg(PFileVar fv, int IdProto, int Mode, WORD Opt1, WORD Opt2) |
| 704 |
{ |
| 705 |
int vsize; |
| 706 |
PProtoDlg pd; |
| 707 |
|
| 708 |
ProtoId = IdProto; |
| 709 |
|
| 710 |
switch (ProtoId) { |
| 711 |
case PROTO_KMT: |
| 712 |
vsize = sizeof(TKmtVar); |
| 713 |
break; |
| 714 |
case PROTO_XM: |
| 715 |
vsize = sizeof(TXVar); |
| 716 |
break; |
| 717 |
case PROTO_ZM: |
| 718 |
vsize = sizeof(TZVar); |
| 719 |
break; |
| 720 |
case PROTO_BP: |
| 721 |
vsize = sizeof(TBPVar); |
| 722 |
break; |
| 723 |
case PROTO_QV: |
| 724 |
vsize = sizeof(TQVVar); |
| 725 |
break; |
| 726 |
} |
| 727 |
ProtoVar = (PCHAR)malloc(vsize); |
| 728 |
if (ProtoVar==NULL) return FALSE; |
| 729 |
|
| 730 |
switch (ProtoId) { |
| 731 |
case PROTO_KMT: |
| 732 |
((PKmtVar)ProtoVar)->KmtMode = Mode; |
| 733 |
break; |
| 734 |
case PROTO_XM: |
| 735 |
((PXVar)ProtoVar)->XMode = Mode; |
| 736 |
((PXVar)ProtoVar)->XOpt = Opt1; |
| 737 |
((PXVar)ProtoVar)->TextFlag = 1 - (Opt2 & 1); |
| 738 |
break; |
| 739 |
case PROTO_ZM: |
| 740 |
((PZVar)ProtoVar)->BinFlag = (Opt1 & 1) != 0; |
| 741 |
((PZVar)ProtoVar)->ZMode = Mode; |
| 742 |
break; |
| 743 |
case PROTO_BP: |
| 744 |
((PBPVar)ProtoVar)->BPMode = Mode; |
| 745 |
break; |
| 746 |
case PROTO_QV: |
| 747 |
((PQVVar)ProtoVar)->QVMode = Mode; |
| 748 |
break; |
| 749 |
} |
| 750 |
|
| 751 |
pd = new CProtoDlg(); |
| 752 |
if (pd==NULL) |
| 753 |
{ |
| 754 |
free(ProtoVar); |
| 755 |
ProtoVar = NULL; |
| 756 |
return FALSE; |
| 757 |
} |
| 758 |
pd->Create(fv); |
| 759 |
|
| 760 |
(*ProtoInit)(ProtoId,FileVar,ProtoVar,&cv,&ts); |
| 761 |
|
| 762 |
PtDlg = pd; |
| 763 |
return TRUE; |
| 764 |
} |
| 765 |
|
| 766 |
extern "C" { |
| 767 |
void CloseProtoDlg() |
| 768 |
{ |
| 769 |
if (PtDlg!=NULL) |
| 770 |
{ |
| 771 |
PtDlg->DestroyWindow(); |
| 772 |
PtDlg = NULL; |
| 773 |
|
| 774 |
::KillTimer(FileVar->HMainWin,IdProtoTimer); |
| 775 |
if ((ProtoId==PROTO_QV) && |
| 776 |
(((PQVVar)ProtoVar)->QVMode==IdQVSend)) |
| 777 |
CommTextOut(&cv,"\015",1); |
| 778 |
if (FileVar->LogFlag) |
| 779 |
_lclose(FileVar->LogFile); |
| 780 |
FileVar->LogFile = 0; |
| 781 |
if (ProtoVar!=NULL) |
| 782 |
{ |
| 783 |
free(ProtoVar); |
| 784 |
ProtoVar = NULL; |
| 785 |
} |
| 786 |
} |
| 787 |
} |
| 788 |
} |
| 789 |
|
| 790 |
BOOL ProtoStart() |
| 791 |
{ |
| 792 |
if (cv.ProtoFlag) return FALSE; |
| 793 |
if (FSend) |
| 794 |
{ |
| 795 |
FreeFileVar(&FileVar); |
| 796 |
return FALSE; |
| 797 |
} |
| 798 |
|
| 799 |
if (! LoadTTFILE()) return FALSE; |
| 800 |
NewFileVar(&FileVar); |
| 801 |
|
| 802 |
if (FileVar==NULL) |
| 803 |
{ |
| 804 |
FreeTTFILE(); |
| 805 |
return FALSE; |
| 806 |
} |
| 807 |
cv.ProtoFlag = TRUE; |
| 808 |
return TRUE; |
| 809 |
} |
| 810 |
|
| 811 |
void ProtoEnd() |
| 812 |
{ |
| 813 |
if (! cv.ProtoFlag) return; |
| 814 |
cv.ProtoFlag = FALSE; |
| 815 |
|
| 816 |
/* Enable transmit delay (serial port) */ |
| 817 |
cv.DelayFlag = TRUE; |
| 818 |
TalkStatus = IdTalkKeyb; |
| 819 |
|
| 820 |
CloseProtoDlg(); |
| 821 |
|
| 822 |
if ((FileVar!=NULL) && FileVar->Success) |
| 823 |
EndDdeCmnd(1); |
| 824 |
else |
| 825 |
EndDdeCmnd(0); |
| 826 |
|
| 827 |
FreeTTFILE(); |
| 828 |
FreeFileVar(&FileVar); |
| 829 |
} |
| 830 |
|
| 831 |
extern "C" { |
| 832 |
int ProtoDlgParse() |
| 833 |
{ |
| 834 |
int P; |
| 835 |
|
| 836 |
P = ActiveWin; |
| 837 |
if (PtDlg==NULL) return P; |
| 838 |
|
| 839 |
if ((*ProtoParse)(ProtoId,FileVar,ProtoVar,&cv)) |
| 840 |
P = 0; /* continue */ |
| 841 |
else { |
| 842 |
CommSend(&cv); |
| 843 |
ProtoEnd(); |
| 844 |
} |
| 845 |
return P; |
| 846 |
} |
| 847 |
} |
| 848 |
|
| 849 |
extern "C" { |
| 850 |
void ProtoDlgTimeOut() |
| 851 |
{ |
| 852 |
if (PtDlg!=NULL) |
| 853 |
(*ProtoTimeOutProc)(ProtoId,FileVar,ProtoVar,&cv); |
| 854 |
} |
| 855 |
} |
| 856 |
|
| 857 |
extern "C" { |
| 858 |
void ProtoDlgCancel() |
| 859 |
{ |
| 860 |
if ((PtDlg!=NULL) && |
| 861 |
(*ProtoCancel)(ProtoId,FileVar,ProtoVar,&cv)) |
| 862 |
ProtoEnd(); |
| 863 |
} |
| 864 |
} |
| 865 |
|
| 866 |
extern "C" { |
| 867 |
void KermitStart(int mode) |
| 868 |
{ |
| 869 |
WORD w; |
| 870 |
|
| 871 |
if (! ProtoStart()) return; |
| 872 |
|
| 873 |
switch (mode) { |
| 874 |
case IdKmtSend: |
| 875 |
FileVar->OpId = OpKmtSend; |
| 876 |
if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0) |
| 877 |
{ |
| 878 |
if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_KERMIT,&w) || |
| 879 |
(FileVar->NumFname==0)) |
| 880 |
{ |
| 881 |
ProtoEnd(); |
| 882 |
return; |
| 883 |
} |
| 884 |
} |
| 885 |
else |
| 886 |
(*SetFileVar)(FileVar); |
| 887 |
break; |
| 888 |
case IdKmtReceive: |
| 889 |
FileVar->OpId = OpKmtRcv; |
| 890 |
break; |
| 891 |
case IdKmtGet: |
| 892 |
FileVar->OpId = OpKmtSend; |
| 893 |
if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0) |
| 894 |
{ |
| 895 |
if (! (*GetGetFname)(FileVar->HMainWin,FileVar) || |
| 896 |
(strlen(FileVar->FullName)==0)) |
| 897 |
{ |
| 898 |
ProtoEnd(); |
| 899 |
return; |
| 900 |
} |
| 901 |
} |
| 902 |
else |
| 903 |
(*SetFileVar)(FileVar); |
| 904 |
break; |
| 905 |
case IdKmtFinish: |
| 906 |
FileVar->OpId = OpKmtFin; |
| 907 |
break; |
| 908 |
default: |
| 909 |
ProtoEnd(); |
| 910 |
return; |
| 911 |
} |
| 912 |
TalkStatus = IdTalkQuiet; |
| 913 |
|
| 914 |
/* disable transmit delay (serial port) */ |
| 915 |
cv.DelayFlag = FALSE; |
| 916 |
|
| 917 |
if (! OpenProtoDlg(FileVar,PROTO_KMT,mode,0,0)) |
| 918 |
ProtoEnd(); |
| 919 |
} |
| 920 |
} |
| 921 |
|
| 922 |
extern "C" { |
| 923 |
void XMODEMStart(int mode) |
| 924 |
{ |
| 925 |
LONG Option; |
| 926 |
|
| 927 |
if (! ProtoStart()) return; |
| 928 |
|
| 929 |
if (mode==IdXReceive) |
| 930 |
FileVar->OpId = OpXRcv; |
| 931 |
else |
| 932 |
FileVar->OpId = OpXSend; |
| 933 |
|
| 934 |
if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0) |
| 935 |
{ |
| 936 |
Option = MAKELONG(ts.XmodemBin,ts.XmodemOpt); |
| 937 |
if (! (*GetXFname)(FileVar->HMainWin, |
| 938 |
mode==IdXReceive,&Option,FileVar,ts.FileDir)) |
| 939 |
{ |
| 940 |
ProtoEnd(); |
| 941 |
return; |
| 942 |
} |
| 943 |
ts.XmodemOpt = HIWORD(Option); |
| 944 |
ts.XmodemBin = LOWORD(Option); |
| 945 |
} |
| 946 |
else |
| 947 |
(*SetFileVar)(FileVar); |
| 948 |
|
| 949 |
if (mode==IdXReceive) |
| 950 |
FileVar->FileHandle = _lcreat(FileVar->FullName,0); |
| 951 |
else |
| 952 |
FileVar->FileHandle = _lopen(FileVar->FullName,OF_READ); |
| 953 |
|
| 954 |
FileVar->FileOpen = FileVar->FileHandle>0; |
| 955 |
if (! FileVar->FileOpen) |
| 956 |
{ |
| 957 |
ProtoEnd(); |
| 958 |
return; |
| 959 |
} |
| 960 |
TalkStatus = IdTalkQuiet; |
| 961 |
|
| 962 |
/* disable transmit delay (serial port) */ |
| 963 |
cv.DelayFlag = FALSE; |
| 964 |
|
| 965 |
if (! OpenProtoDlg(FileVar,PROTO_XM,mode, |
| 966 |
ts.XmodemOpt,ts.XmodemBin)) |
| 967 |
ProtoEnd(); |
| 968 |
} |
| 969 |
} |
| 970 |
|
| 971 |
extern "C" { |
| 972 |
void ZMODEMStart(int mode) |
| 973 |
{ |
| 974 |
WORD Opt; |
| 975 |
|
| 976 |
if (! ProtoStart()) return; |
| 977 |
|
| 978 |
if (mode==IdZSend) |
| 979 |
{ |
| 980 |
Opt = ts.XmodemBin; |
| 981 |
FileVar->OpId = OpZSend; |
| 982 |
if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0) |
| 983 |
{ |
| 984 |
if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_Z,&Opt) || |
| 985 |
(FileVar->NumFname==0)) |
| 986 |
{ |
| 987 |
ProtoEnd(); |
| 988 |
return; |
| 989 |
} |
| 990 |
ts.XmodemBin = Opt; |
| 991 |
} |
| 992 |
else |
| 993 |
(*SetFileVar)(FileVar); |
| 994 |
} |
| 995 |
else /* IdZReceive or IdZAuto */ |
| 996 |
FileVar->OpId = OpZRcv; |
| 997 |
|
| 998 |
TalkStatus = IdTalkQuiet; |
| 999 |
|
| 1000 |
/* disable transmit delay (serial port) */ |
| 1001 |
cv.DelayFlag = FALSE; |
| 1002 |
|
| 1003 |
if (! OpenProtoDlg(FileVar,PROTO_ZM,mode,Opt,0)) |
| 1004 |
ProtoEnd(); |
| 1005 |
} |
| 1006 |
} |
| 1007 |
|
| 1008 |
extern "C" { |
| 1009 |
void BPStart(int mode) |
| 1010 |
{ |
| 1011 |
LONG Option; |
| 1012 |
|
| 1013 |
if (! ProtoStart()) return; |
| 1014 |
if (mode==IdBPSend) |
| 1015 |
{ |
| 1016 |
FileVar->OpId = OpBPSend; |
| 1017 |
if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0) |
| 1018 |
{ |
| 1019 |
if (! (*GetTransFname)(FileVar, ts.FileDir, GTF_BP, &Option)) |
| 1020 |
{ |
| 1021 |
ProtoEnd(); |
| 1022 |
return; |
| 1023 |
} |
| 1024 |
} |
| 1025 |
else |
| 1026 |
(*SetFileVar)(FileVar); |
| 1027 |
|
| 1028 |
} |
| 1029 |
else /* IdBPReceive or IdBPAuto */ |
| 1030 |
FileVar->OpId = OpBPRcv; |
| 1031 |
|
| 1032 |
TalkStatus = IdTalkQuiet; |
| 1033 |
|
| 1034 |
/* disable transmit delay (serial port) */ |
| 1035 |
cv.DelayFlag = FALSE; |
| 1036 |
|
| 1037 |
if (! OpenProtoDlg(FileVar,PROTO_BP,mode,0,0)) |
| 1038 |
ProtoEnd(); |
| 1039 |
} |
| 1040 |
} |
| 1041 |
|
| 1042 |
extern "C" { |
| 1043 |
void QVStart(int mode) |
| 1044 |
{ |
| 1045 |
WORD W; |
| 1046 |
|
| 1047 |
if (! ProtoStart()) return; |
| 1048 |
|
| 1049 |
if (mode==IdQVSend) |
| 1050 |
{ |
| 1051 |
FileVar->OpId = OpQVSend; |
| 1052 |
if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0) |
| 1053 |
{ |
| 1054 |
if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_QV, &W) || |
| 1055 |
(FileVar->NumFname==0)) |
| 1056 |
{ |
| 1057 |
ProtoEnd(); |
| 1058 |
return; |
| 1059 |
} |
| 1060 |
} |
| 1061 |
else |
| 1062 |
(*SetFileVar)(FileVar); |
| 1063 |
} |
| 1064 |
else |
| 1065 |
FileVar->OpId = OpQVRcv; |
| 1066 |
|
| 1067 |
TalkStatus = IdTalkQuiet; |
| 1068 |
|
| 1069 |
/* disable transmit delay (serial port) */ |
| 1070 |
cv.DelayFlag = FALSE; |
| 1071 |
|
| 1072 |
if (! OpenProtoDlg(FileVar,PROTO_QV,mode,0,0)) |
| 1073 |
ProtoEnd(); |
| 1074 |
} |
| 1075 |
} |
| 1076 |
|
| 1077 |
/* |
| 1078 |
* $Log: filesys.cpp,v $ |
| 1079 |
* Revision 1.2 2005/02/20 14:51:29 yutakakn |
| 1080 |
* ?ス?ス?スO?スt?ス@?スC?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス"plain text"?ス?ス?ス?ス?ス?ス?スB?ス?ス?ス?ス?スI?スv?スV?ス?ス?ス?ス?ス?ス?スL?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?スA?ス?ス?スO?スt?ス@?スC?ス?ス?ス?ス |
| 1081 |
* ASCII?ス?ス?ス\?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?スB |
| 1082 |
* |
| 1083 |
* ?ス?ス?ス?ス?スA?ス?ス?ス?ス?ス?ス?ス?ス?スL?ス?ス?ス?ス?スN?ス^?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?スB |
| 1084 |
* ?ス@?スEBS |
| 1085 |
* ?ス@?スEASCII(0x00-0x1f)?ス?ス?ス?ス?ス?ス?ス?ス?ス\?ス?ス?ス?ス?ス?ス?ス?ス |
| 1086 |
* |
| 1087 |
* ?ス?ス?ス?ス?ス?ス?スA?ス?ス?スO?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?スO?ス?ス?ス?ス?ス?ス?ス?ス?スB |
| 1088 |
* ?ス@?スEHT |
| 1089 |
* ?ス@?スECR |
| 1090 |
* ?ス@?スELF |
| 1091 |
* |
| 1092 |
*/ |