| 1 |
/* |
| 2 |
* (C) 2020 TeraTerm Project |
| 3 |
* All rights reserved. |
| 4 |
* |
| 5 |
* Redistribution and use in source and binary forms, with or without |
| 6 |
* modification, are permitted provided that the following conditions |
| 7 |
* are met: |
| 8 |
* |
| 9 |
* 1. Redistributions of source code must retain the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer. |
| 11 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 12 |
* notice, this list of conditions and the following disclaimer in the |
| 13 |
* documentation and/or other materials provided with the distribution. |
| 14 |
* 3. The name of the author may not be used to endorse or promote products |
| 15 |
* derived from this software without specific prior written permission. |
| 16 |
* |
| 17 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR |
| 18 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 19 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 20 |
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
*/ |
| 28 |
|
| 29 |
/* TERATERM.EXE, file transfer routines */ |
| 30 |
#include <stdio.h> |
| 31 |
#include <windows.h> |
| 32 |
#include <htmlhelp.h> |
| 33 |
#include <assert.h> |
| 34 |
#include <stdlib.h> |
| 35 |
#define _CRTDBG_MAP_ALLOC |
| 36 |
#include <crtdbg.h> |
| 37 |
|
| 38 |
#include "teraterm.h" |
| 39 |
#include "tttypes.h" |
| 40 |
#include "protodlg.h" |
| 41 |
#include "ttwinman.h" |
| 42 |
#include "commlib.h" |
| 43 |
#include "ttcommon.h" |
| 44 |
#include "ttdde.h" |
| 45 |
#include "ttlib.h" |
| 46 |
#include "dlglib.h" |
| 47 |
#include "vtterm.h" |
| 48 |
#include "ftlib.h" |
| 49 |
#include "buffer.h" |
| 50 |
#include "helpid.h" |
| 51 |
#include "codeconv.h" |
| 52 |
#include "asprintf.h" |
| 53 |
|
| 54 |
#include "filesys_log_res.h" |
| 55 |
|
| 56 |
#include "filesys.h" |
| 57 |
#include "filesys_proto.h" |
| 58 |
#include "tt_res.h" |
| 59 |
#include "filesys_win32.h" |
| 60 |
|
| 61 |
#include "kermit.h" |
| 62 |
#include "xmodem.h" |
| 63 |
#include "ymodem.h" |
| 64 |
#include "zmodem.h" |
| 65 |
#include "bplus.h" |
| 66 |
#include "quickvan.h" |
| 67 |
|
| 68 |
#define OpKmtRcv 3 |
| 69 |
#define OpKmtGet 4 |
| 70 |
#define OpKmtSend 5 |
| 71 |
#define OpKmtFin 6 |
| 72 |
#define OpXRcv 7 |
| 73 |
#define OpXSend 8 |
| 74 |
#define OpZRcv 9 |
| 75 |
#define OpZSend 10 |
| 76 |
#define OpBPRcv 11 |
| 77 |
#define OpBPSend 12 |
| 78 |
#define OpQVRcv 13 |
| 79 |
#define OpQVSend 14 |
| 80 |
#define OpYRcv 15 |
| 81 |
#define OpYSend 16 |
| 82 |
|
| 83 |
#define PROTO_KMT 1 |
| 84 |
#define PROTO_XM 2 |
| 85 |
#define PROTO_ZM 3 |
| 86 |
#define PROTO_BP 4 |
| 87 |
#define PROTO_QV 5 |
| 88 |
#define PROTO_YM 6 |
| 89 |
|
| 90 |
#define TitKmtRcv L"Kermit Receive" |
| 91 |
#define TitKmtGet L"Kermit Get" |
| 92 |
#define TitKmtSend L"Kermit Send" |
| 93 |
#define TitKmtFin L"Kermit Finish" |
| 94 |
#define TitXRcv L"XMODEM Receive" |
| 95 |
#define TitXSend L"XMODEM Send" |
| 96 |
#define TitYRcv L"YMODEM Receive" |
| 97 |
#define TitYSend L"YMODEM Send" |
| 98 |
#define TitZRcv L"ZMODEM Receive" |
| 99 |
#define TitZSend L"ZMODEM Send" |
| 100 |
#define TitQVRcv L"Quick-VAN Receive" |
| 101 |
#define TitQVSend L"Quick-VAN Send" |
| 102 |
|
| 103 |
static PFileVarProto FileVar = NULL; |
| 104 |
static int ProtoId; |
| 105 |
static PProtoDlg PtDlg = NULL; |
| 106 |
static BOOL cv_ProtoFlag = FALSE; |
| 107 |
|
| 108 |
static void _SetDlgTime(TFileVarProto *fv, DWORD elapsed, int bytes) |
| 109 |
{ |
| 110 |
SetDlgTime(fv->HWin, IDC_PROTOELAPSEDTIME, fv->StartTime, fv->ByteCount); |
| 111 |
} |
| 112 |
|
| 113 |
static void _SetDlgPaketNum(struct FileVarProto *fv, LONG Num) |
| 114 |
{ |
| 115 |
SetDlgNum(fv->HWin, IDC_PROTOPKTNUM, Num); |
| 116 |
} |
| 117 |
|
| 118 |
static void _SetDlgByteCount(struct FileVarProto *fv, LONG Num) |
| 119 |
{ |
| 120 |
SetDlgNum(fv->HWin, IDC_PROTOBYTECOUNT, Num); |
| 121 |
} |
| 122 |
|
| 123 |
static void _SetDlgPercent(struct FileVarProto *fv, LONG a, LONG b, int *p) |
| 124 |
{ |
| 125 |
SetDlgPercent(fv->HWin, IDC_PROTOPERCENT, IDC_PROTOPROGRESS, a, b, p); |
| 126 |
} |
| 127 |
|
| 128 |
static void _SetDlgProtoText(struct FileVarProto *fv, const char *text) |
| 129 |
{ |
| 130 |
SetDlgItemText(fv->HWin, IDC_PROTOPROT, text); |
| 131 |
} |
| 132 |
|
| 133 |
static void _SetDlgProtoFileName(struct FileVarProto *fv, const char *filename) |
| 134 |
{ |
| 135 |
if (filename == NULL) { |
| 136 |
SetDlgItemTextA(fv->HWin, IDC_PROTOFNAME, ""); |
| 137 |
return; |
| 138 |
} |
| 139 |
// �t�@�C����(�������p�X�Z�p���[�^�����������\��) |
| 140 |
const char *s = filename; |
| 141 |
const char *p = strrchr(filename, '\\'); |
| 142 |
if (p == NULL) { |
| 143 |
p = strrchr(filename, '/'); |
| 144 |
} |
| 145 |
if (p != NULL) { |
| 146 |
s = p + 1; |
| 147 |
} |
| 148 |
assert(fv->HWin != NULL); |
| 149 |
SetDlgItemTextW(fv->HWin, IDC_PROTOFNAME, wc::fromUtf8(s)); |
| 150 |
} |
| 151 |
|
| 152 |
static void _InitDlgProgress(struct FileVarProto *fv, int *CurProgStat) |
| 153 |
{ |
| 154 |
InitDlgProgress(fv->HWin, IDC_PROTOPROGRESS, CurProgStat); |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* �t�@�C���������� |
| 159 |
* |
| 160 |
* @return �t�@�C���� UTF-8 |
| 161 |
* NULL�����������t�@�C�������� |
| 162 |
* �s�v���������� free() �������� |
| 163 |
*/ |
| 164 |
static char *GetNextFname(PFileVarProto fv) |
| 165 |
{ |
| 166 |
wchar_t *f = fv->FileNames[fv->FNCount]; |
| 167 |
if (f == NULL) { |
| 168 |
/* no more file name */ |
| 169 |
return NULL; |
| 170 |
} |
| 171 |
fv->FNCount++; |
| 172 |
char *u8 = ToU8W(f); |
| 173 |
return u8; |
| 174 |
} |
| 175 |
|
| 176 |
/** |
| 177 |
* �_�E�����[�h�p�X������ |
| 178 |
* |
| 179 |
* @return ���M�t�H���_(�I�[���p�X�Z�p���[�^'\\'���t������������) |
| 180 |
* �s�v���������� free() �������� |
| 181 |
*/ |
| 182 |
static char *GetRecievePath(struct FileVarProto *fv) |
| 183 |
{ |
| 184 |
return ToU8W(fv->RecievePath); |
| 185 |
} |
| 186 |
|
| 187 |
static void FTSetTimeOut(PFileVarProto fv, int T) |
| 188 |
{ |
| 189 |
KillTimer(fv->HMainWin, IdProtoTimer); |
| 190 |
if (T==0) return; |
| 191 |
SetTimer(fv->HMainWin, IdProtoTimer, T*1000, NULL); |
| 192 |
} |
| 193 |
|
| 194 |
static void SetDialogCation(struct FileVarProto *fv, const char *key, const wchar_t *default_caption) |
| 195 |
{ |
| 196 |
const wchar_t *UILanguageFile = ts.UILanguageFileW; |
| 197 |
wchar_t *uimsg; |
| 198 |
wchar_t *caption; |
| 199 |
GetI18nStrWW("Tera Term", key, default_caption, UILanguageFile, &uimsg); |
| 200 |
aswprintf(&caption, L"Tera Term: %s", uimsg); |
| 201 |
free(uimsg); |
| 202 |
free((void *)fv->DlgCaption); |
| 203 |
fv->DlgCaption = caption; |
| 204 |
} |
| 205 |
|
| 206 |
static BOOL NewFileVar_(PFileVarProto *pfv) |
| 207 |
{ |
| 208 |
if (*pfv != NULL) { |
| 209 |
return TRUE; |
| 210 |
} |
| 211 |
TFileVarProto *fv = (TFileVarProto *)malloc(sizeof(TFileVarProto)); |
| 212 |
if (fv == NULL) |
| 213 |
return FALSE; |
| 214 |
memset(fv, 0, sizeof(*fv)); |
| 215 |
|
| 216 |
// ���M�t�H���_ |
| 217 |
wchar_t FileDirExpanded[MAX_PATH]; |
| 218 |
ExpandEnvironmentStringsW(ts.FileDirW, FileDirExpanded, _countof(FileDirExpanded)); |
| 219 |
AppendSlashW(FileDirExpanded, _countof(FileDirExpanded)); |
| 220 |
fv->RecievePath = _wcsdup(FileDirExpanded); |
| 221 |
|
| 222 |
fv->FileOpen = FALSE; |
| 223 |
fv->OverWrite = ((ts.FTFlag & FT_RENAME) == 0); |
| 224 |
fv->HMainWin = HVTWin; |
| 225 |
fv->Success = FALSE; |
| 226 |
fv->NoMsg = FALSE; |
| 227 |
fv->HideDialog = FALSE; |
| 228 |
|
| 229 |
fv->file = FilesysCreateWin32(); |
| 230 |
|
| 231 |
fv->GetNextFname = GetNextFname; |
| 232 |
fv->GetRecievePath = GetRecievePath; |
| 233 |
fv->FTSetTimeOut = FTSetTimeOut; |
| 234 |
fv->SetDialogCation = SetDialogCation; |
| 235 |
|
| 236 |
fv->InitDlgProgress = _InitDlgProgress; |
| 237 |
fv->SetDlgTime = _SetDlgTime; |
| 238 |
fv->SetDlgPaketNum = _SetDlgPaketNum; |
| 239 |
fv->SetDlgByteCount = _SetDlgByteCount; |
| 240 |
fv->SetDlgPercent = _SetDlgPercent; |
| 241 |
fv->SetDlgProtoText = _SetDlgProtoText; |
| 242 |
fv->SetDlgProtoFileName = _SetDlgProtoFileName; |
| 243 |
|
| 244 |
*pfv = fv; |
| 245 |
return TRUE; |
| 246 |
} |
| 247 |
|
| 248 |
static void FreeFileVar_(PFileVarProto *pfv) |
| 249 |
{ |
| 250 |
PFileVarProto fv = *pfv; |
| 251 |
if (fv == NULL) { |
| 252 |
return; |
| 253 |
} |
| 254 |
|
| 255 |
if (fv->Destroy != NULL) { |
| 256 |
fv->Destroy(fv); |
| 257 |
} |
| 258 |
|
| 259 |
if (fv->FileNames != NULL) { |
| 260 |
free(fv->FileNames); |
| 261 |
} |
| 262 |
fv->file->FileSysDestroy(fv->file); |
| 263 |
free(fv->DlgCaption); |
| 264 |
fv->DlgCaption = NULL; |
| 265 |
free(fv); |
| 266 |
|
| 267 |
*pfv = NULL; |
| 268 |
} |
| 269 |
|
| 270 |
static int _ProtoSetOpt(PFileVarProto fv, int request, ...) |
| 271 |
{ |
| 272 |
va_list ap; |
| 273 |
va_start(ap, request); |
| 274 |
int r = fv->SetOptV(fv, request, ap); |
| 275 |
va_end(ap); |
| 276 |
return r; |
| 277 |
} |
| 278 |
|
| 279 |
static BOOL OpenProtoDlg(PFileVarProto fv, int IdProto, int Mode, WORD Opt1, WORD Opt2) |
| 280 |
{ |
| 281 |
PProtoDlg pd; |
| 282 |
|
| 283 |
ProtoId = IdProto; |
| 284 |
|
| 285 |
switch (ProtoId) { |
| 286 |
case PROTO_KMT: |
| 287 |
KmtCreate(fv); |
| 288 |
break; |
| 289 |
case PROTO_XM: |
| 290 |
XCreate(fv); |
| 291 |
break; |
| 292 |
case PROTO_YM: |
| 293 |
YCreate(fv); |
| 294 |
break; |
| 295 |
case PROTO_ZM: |
| 296 |
ZCreate(fv); |
| 297 |
break; |
| 298 |
case PROTO_BP: |
| 299 |
BPCreate(fv); |
| 300 |
break; |
| 301 |
case PROTO_QV: |
| 302 |
QVCreate(fv); |
| 303 |
break; |
| 304 |
default: |
| 305 |
assert(FALSE); |
| 306 |
return FALSE; |
| 307 |
break; |
| 308 |
} |
| 309 |
|
| 310 |
switch (ProtoId) { |
| 311 |
case PROTO_KMT: |
| 312 |
_ProtoSetOpt(fv, KMT_MODE, Mode); |
| 313 |
break; |
| 314 |
case PROTO_XM: |
| 315 |
_ProtoSetOpt(fv, XMODEM_MODE, Mode); |
| 316 |
_ProtoSetOpt(fv, XMODEM_OPT, Opt1); |
| 317 |
_ProtoSetOpt(fv, XMODEM_TEXT_FLAG, 1 - (Opt2 & 1)); |
| 318 |
break; |
| 319 |
case PROTO_YM: |
| 320 |
_ProtoSetOpt(fv, YMODEM_MODE, Mode); |
| 321 |
_ProtoSetOpt(fv, YMODEM_OPT, Opt1); |
| 322 |
break; |
| 323 |
case PROTO_ZM: |
| 324 |
_ProtoSetOpt(fv, ZMODEM_MODE, Mode); |
| 325 |
_ProtoSetOpt(fv, ZMODEM_BINFLAG, (Opt1 & 1) != 0); |
| 326 |
break; |
| 327 |
case PROTO_BP: |
| 328 |
_ProtoSetOpt(fv, BPLUS_MODE, Mode); |
| 329 |
break; |
| 330 |
case PROTO_QV: |
| 331 |
_ProtoSetOpt(fv, QUICKVAN_MODE, Mode); |
| 332 |
break; |
| 333 |
} |
| 334 |
|
| 335 |
pd = new CProtoDlg(); |
| 336 |
if (pd==NULL) |
| 337 |
{ |
| 338 |
return FALSE; |
| 339 |
} |
| 340 |
CProtoDlgInfo info; |
| 341 |
info.UILanguageFileW = ts.UILanguageFileW; |
| 342 |
info.HMainWin = fv->HMainWin; |
| 343 |
pd->Create(hInst, HVTWin, &info); |
| 344 |
fv->HWin = pd->m_hWnd; |
| 345 |
|
| 346 |
BOOL r = fv->Init(fv, &cv, &ts); |
| 347 |
if (r == FALSE) { |
| 348 |
fv->Destroy(fv); |
| 349 |
return FALSE; |
| 350 |
} |
| 351 |
SetWindowTextW(fv->HWin, fv->DlgCaption); |
| 352 |
|
| 353 |
PtDlg = pd; |
| 354 |
return TRUE; |
| 355 |
} |
| 356 |
|
| 357 |
static void CloseProtoDlg(void) |
| 358 |
{ |
| 359 |
if (PtDlg!=NULL) |
| 360 |
{ |
| 361 |
PtDlg->DestroyWindow(); |
| 362 |
PtDlg = NULL; |
| 363 |
|
| 364 |
::KillTimer(FileVar->HMainWin,IdProtoTimer); |
| 365 |
{ // Quick-VAN special code |
| 366 |
//if ((ProtoId==PROTO_QV) && |
| 367 |
// (((PQVVar)ProtoVar)->QVMode==IdQVSend)) |
| 368 |
if (FileVar->OpId == OpQVSend) |
| 369 |
CommBinaryOut(&cv,"\015",1); |
| 370 |
} |
| 371 |
} |
| 372 |
} |
| 373 |
|
| 374 |
static BOOL ProtoStart(void) |
| 375 |
{ |
| 376 |
if (cv_ProtoFlag) |
| 377 |
return FALSE; |
| 378 |
if (FileSnedIsSending()) |
| 379 |
{ // �t�@�C�����M�� |
| 380 |
FreeFileVar_(&FileVar); |
| 381 |
return FALSE; |
| 382 |
} |
| 383 |
|
| 384 |
NewFileVar_(&FileVar); |
| 385 |
|
| 386 |
if (FileVar==NULL) |
| 387 |
{ |
| 388 |
return FALSE; |
| 389 |
} |
| 390 |
cv_ProtoFlag = TRUE; |
| 391 |
return TRUE; |
| 392 |
} |
| 393 |
|
| 394 |
void ProtoEnd(void) |
| 395 |
{ |
| 396 |
if (! cv_ProtoFlag) |
| 397 |
return; |
| 398 |
cv_ProtoFlag = FALSE; |
| 399 |
|
| 400 |
/* Enable transmit delay (serial port) */ |
| 401 |
cv.DelayFlag = TRUE; |
| 402 |
TalkStatus = IdTalkKeyb; |
| 403 |
|
| 404 |
CloseProtoDlg(); |
| 405 |
|
| 406 |
if ((FileVar!=NULL) && FileVar->Success) |
| 407 |
EndDdeCmnd(1); |
| 408 |
else |
| 409 |
EndDdeCmnd(0); |
| 410 |
|
| 411 |
FreeFileVar_(&FileVar); |
| 412 |
} |
| 413 |
|
| 414 |
/* �_�C�A���O���������������� */ |
| 415 |
static void CenterCommonDialog(HWND hDlg) |
| 416 |
{ |
| 417 |
/* hDlg���e���_�C�A���O���E�B���h�E�n���h�� */ |
| 418 |
HWND hWndDlgRoot = GetParent(hDlg); |
| 419 |
CenterWindow(hWndDlgRoot, GetParent(hWndDlgRoot)); |
| 420 |
} |
| 421 |
|
| 422 |
/* Hook function for XMODEM file name dialog box */ |
| 423 |
static UINT_PTR CALLBACK XFnHook(HWND Dialog, UINT Message, WPARAM wParam, LPARAM lParam) |
| 424 |
{ |
| 425 |
static const DlgTextInfo text_info[] = { |
| 426 |
{ IDC_XOPT, "DLG_XOPT" }, |
| 427 |
{ IDC_XOPTCHECK, "DLG_XOPT_CHECKSUM" }, |
| 428 |
{ IDC_XOPTCRC, "DLG_XOPT_CRC" }, |
| 429 |
{ IDC_XOPT1K, "DLG_XOPT_1K" }, |
| 430 |
{ IDC_XOPTBIN, "DLG_XOPT_BINARY" }, |
| 431 |
}; |
| 432 |
WORD Hi, Lo; |
| 433 |
LPLONG pl; |
| 434 |
LPOFNOTIFY notify; |
| 435 |
const wchar_t *UILanguageFileW = ts.UILanguageFileW; |
| 436 |
static HFONT DlgXoptFont; |
| 437 |
|
| 438 |
switch (Message) { |
| 439 |
case WM_INITDIALOG: { |
| 440 |
LPOPENFILENAMEW ofn = (LPOPENFILENAMEW)lParam; |
| 441 |
LOGFONTA logfont; |
| 442 |
HFONT font; |
| 443 |
const char *UILanguageFile = ts.UILanguageFile; |
| 444 |
|
| 445 |
pl = (LPLONG)ofn->lCustData; |
| 446 |
SetWindowLongPtr(Dialog, DWLP_USER, (LONG_PTR)pl); |
| 447 |
|
| 448 |
font = (HFONT)SendMessage(Dialog, WM_GETFONT, 0, 0); |
| 449 |
GetObject(font, sizeof(LOGFONT), &logfont); |
| 450 |
if (get_lang_font("DLG_TAHOMA_FONT", Dialog, &logfont, &DlgXoptFont, UILanguageFile)) { |
| 451 |
SendDlgItemMessage(Dialog, IDC_XOPT, WM_SETFONT, (WPARAM)DlgXoptFont, MAKELPARAM(TRUE,0)); |
| 452 |
SendDlgItemMessage(Dialog, IDC_XOPTCHECK, WM_SETFONT, (WPARAM)DlgXoptFont, MAKELPARAM(TRUE,0)); |
| 453 |
SendDlgItemMessage(Dialog, IDC_XOPTCRC, WM_SETFONT, (WPARAM)DlgXoptFont, MAKELPARAM(TRUE,0)); |
| 454 |
SendDlgItemMessage(Dialog, IDC_XOPT1K, WM_SETFONT, (WPARAM)DlgXoptFont, MAKELPARAM(TRUE,0)); |
| 455 |
SendDlgItemMessage(Dialog, IDC_XOPTBIN, WM_SETFONT, (WPARAM)DlgXoptFont, MAKELPARAM(TRUE,0)); |
| 456 |
} |
| 457 |
else { |
| 458 |
DlgXoptFont = NULL; |
| 459 |
} |
| 460 |
|
| 461 |
SetI18nDlgStrsW(Dialog, "Tera Term", text_info, _countof(text_info), UILanguageFileW); |
| 462 |
|
| 463 |
if (LOWORD(*pl)==0xFFFF) { // Send |
| 464 |
ShowDlgItem(Dialog, IDC_XOPT1K, IDC_XOPT1K); |
| 465 |
Hi = 0; |
| 466 |
if (HIWORD(*pl) == Xopt1kCRC || HIWORD(*pl) == Xopt1kCksum) { |
| 467 |
Hi = 1; |
| 468 |
} |
| 469 |
SetRB(Dialog, Hi, IDC_XOPT1K, IDC_XOPT1K); |
| 470 |
} |
| 471 |
else { // Recv |
| 472 |
ShowDlgItem(Dialog, IDC_XOPTCHECK, IDC_XOPTCRC); |
| 473 |
Hi = HIWORD(*pl); |
| 474 |
if (Hi == Xopt1kCRC) { |
| 475 |
Hi = XoptCRC; |
| 476 |
} |
| 477 |
else if (Hi == Xopt1kCksum) { |
| 478 |
Hi = XoptCheck; |
| 479 |
} |
| 480 |
SetRB(Dialog, Hi, IDC_XOPTCHECK, IDC_XOPTCRC); |
| 481 |
|
| 482 |
ShowDlgItem(Dialog,IDC_XOPTBIN,IDC_XOPTBIN); |
| 483 |
SetRB(Dialog,LOWORD(*pl),IDC_XOPTBIN,IDC_XOPTBIN); |
| 484 |
} |
| 485 |
CenterCommonDialog(Dialog); |
| 486 |
return TRUE; |
| 487 |
} |
| 488 |
case WM_COMMAND: // for old style dialog |
| 489 |
switch (LOWORD(wParam)) { |
| 490 |
case IDOK: |
| 491 |
pl = (LPLONG)GetWindowLongPtr(Dialog,DWLP_USER); |
| 492 |
if (pl!=NULL) |
| 493 |
{ |
| 494 |
if (LOWORD(*pl)==0xFFFF) { // Send |
| 495 |
Lo = 0xFFFF; |
| 496 |
|
| 497 |
GetRB(Dialog, &Hi, IDC_XOPT1K, IDC_XOPT1K); |
| 498 |
if (Hi > 0) { // force CRC if 1K |
| 499 |
Hi = Xopt1kCRC; |
| 500 |
} |
| 501 |
else { |
| 502 |
Hi = XoptCRC; |
| 503 |
} |
| 504 |
} |
| 505 |
else { // Recv |
| 506 |
GetRB(Dialog, &Lo, IDC_XOPTBIN, IDC_XOPTBIN); |
| 507 |
GetRB(Dialog, &Hi, IDC_XOPTCHECK, IDC_XOPTCRC); |
| 508 |
} |
| 509 |
*pl = MAKELONG(Lo,Hi); |
| 510 |
} |
| 511 |
if (DlgXoptFont != NULL) { |
| 512 |
DeleteObject(DlgXoptFont); |
| 513 |
} |
| 514 |
break; |
| 515 |
case IDCANCEL: |
| 516 |
if (DlgXoptFont != NULL) { |
| 517 |
DeleteObject(DlgXoptFont); |
| 518 |
} |
| 519 |
break; |
| 520 |
} |
| 521 |
break; |
| 522 |
case WM_NOTIFY: // for Explorer-style dialog |
| 523 |
notify = (LPOFNOTIFY)lParam; |
| 524 |
switch (notify->hdr.code) { |
| 525 |
case CDN_FILEOK: |
| 526 |
pl = (LPLONG)GetWindowLongPtr(Dialog,DWLP_USER); |
| 527 |
if (pl!=NULL) { |
| 528 |
if (LOWORD(*pl) == 0xFFFF) { // Send |
| 529 |
Lo = 0xFFFF; |
| 530 |
|
| 531 |
GetRB(Dialog, &Hi, IDC_XOPT1K, IDC_XOPT1K); |
| 532 |
if (Hi > 0) { // force CRC if 1K |
| 533 |
Hi = Xopt1kCRC; |
| 534 |
} |
| 535 |
else { |
| 536 |
Hi = XoptCRC; |
| 537 |
} |
| 538 |
} |
| 539 |
else { // Recv |
| 540 |
GetRB(Dialog, &Lo, IDC_XOPTBIN, IDC_XOPTBIN); |
| 541 |
GetRB(Dialog, &Hi, IDC_XOPTCHECK, IDC_XOPTCRC); |
| 542 |
} |
| 543 |
*pl = MAKELONG(Lo, Hi); |
| 544 |
} |
| 545 |
if (DlgXoptFont != NULL) { |
| 546 |
DeleteObject(DlgXoptFont); |
| 547 |
} |
| 548 |
break; |
| 549 |
} |
| 550 |
break; |
| 551 |
} |
| 552 |
return FALSE; |
| 553 |
} |
| 554 |
|
| 555 |
/** |
| 556 |
* �_�C�A���O���f�t�H���g�t�@�C���������� |
| 557 |
* �t�B���^(ts.FileSendFilter)�����C���h�J�[�h���������A |
| 558 |
* �����t�@�C���������������� |
| 559 |
* �f�t�H���g���t�@�C�������������� |
| 560 |
* |
| 561 |
* @param[in] path �t�@�C���������������������p�X |
| 562 |
* (lpstrInitialDir �������������p�X) |
| 563 |
* @retval NULL �f�t�H���g�t�@�C�������� |
| 564 |
* @retval NULL���O �f�t�H���g�t�@�C��(�s�v����������free()��������) |
| 565 |
*/ |
| 566 |
static wchar_t *GetCommonDialogDefaultFilenameW(const wchar_t *path) |
| 567 |
{ |
| 568 |
const char *FileSendFilterA = ts.FileSendFilter; |
| 569 |
if (strlen(FileSendFilterA) == 0) { |
| 570 |
return NULL; |
| 571 |
} |
| 572 |
|
| 573 |
// �t�B���^�����C���h�J�[�h���������A�����t�@�C���������������� |
| 574 |
// �����������f�t�H���g���t�@�C���������������� (2008.5.18 maya) |
| 575 |
wchar_t *filename = NULL; |
| 576 |
if (!isInvalidFileNameChar(FileSendFilterA)) { |
| 577 |
wchar_t file[MAX_PATH]; |
| 578 |
wcsncpy_s(file, _countof(file), path, _TRUNCATE); |
| 579 |
AppendSlashW(file, _countof(file)); |
| 580 |
wchar_t *FileSendFilterW = ToWcharA(FileSendFilterA); |
| 581 |
wcsncat_s(file, _countof(file), FileSendFilterW, _TRUNCATE); |
| 582 |
DWORD attr = GetFileAttributesW(file); |
| 583 |
if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY) == 0) { |
| 584 |
// �t�@�C������������ |
| 585 |
filename = _wcsdup(file); |
| 586 |
} |
| 587 |
free(FileSendFilterW); |
| 588 |
} |
| 589 |
|
| 590 |
return filename; |
| 591 |
} |
| 592 |
|
| 593 |
wchar_t **MakeStrArrayFromArray(wchar_t **strs) |
| 594 |
{ |
| 595 |
// ���������� |
| 596 |
size_t strs_count = 0; |
| 597 |
size_t strs_len = 0; |
| 598 |
while(1) { |
| 599 |
const wchar_t *f = strs[strs_count]; |
| 600 |
if (f == NULL) { |
| 601 |
break; |
| 602 |
} |
| 603 |
strs_count++; |
| 604 |
size_t len = wcslen(f) + 1; // len = 1 when "\0" |
| 605 |
strs_len += len; |
| 606 |
} |
| 607 |
|
| 608 |
// 1���������� |
| 609 |
size_t ptrs_len = sizeof(char *) * (strs_count + 1); |
| 610 |
char *pool = (char *)malloc(ptrs_len + strs_len * sizeof(wchar_t)); |
| 611 |
wchar_t **ptrs = (wchar_t **)pool; |
| 612 |
wchar_t *strpool = (wchar_t *)(pool + ptrs_len); |
| 613 |
for (int i = 0 ; i < strs_count; i++) { |
| 614 |
size_t len = wcslen(strs[i]) + 1; |
| 615 |
len = len * sizeof(wchar_t); |
| 616 |
memcpy(strpool, strs[i], len); |
| 617 |
ptrs[i] = strpool; |
| 618 |
strpool += len; |
| 619 |
} |
| 620 |
ptrs[strs_count] = NULL; |
| 621 |
return ptrs; |
| 622 |
} |
| 623 |
|
| 624 |
wchar_t **MakeStrArrayFromStr(const wchar_t *str) |
| 625 |
{ |
| 626 |
const wchar_t *strs[2]; |
| 627 |
strs[0] = str; |
| 628 |
strs[1] = NULL; |
| 629 |
wchar_t **ret = MakeStrArrayFromArray((wchar_t **)strs); |
| 630 |
return ret; |
| 631 |
} |
| 632 |
|
| 633 |
wchar_t **MakeFileArrayMultiSelect(const wchar_t *lpstrFile) |
| 634 |
{ |
| 635 |
// ���������� |
| 636 |
size_t file_count = 0; |
| 637 |
const wchar_t *p = lpstrFile; |
| 638 |
const wchar_t *path = p; |
| 639 |
size_t len = wcslen(p); |
| 640 |
p += len + 1; |
| 641 |
while(1) { |
| 642 |
len = wcslen(p); |
| 643 |
if (len == 0) { |
| 644 |
break; |
| 645 |
} |
| 646 |
p += len + 1; |
| 647 |
file_count++; |
| 648 |
} |
| 649 |
|
| 650 |
if (file_count == 0) { |
| 651 |
// 1�������I������������ |
| 652 |
return MakeStrArrayFromStr(lpstrFile); |
| 653 |
} |
| 654 |
|
| 655 |
// �p�X + �t�@�C���� �������� |
| 656 |
size_t ptr_len = sizeof(wchar_t *) * (file_count + 1); |
| 657 |
wchar_t **filenames = (wchar_t **)malloc(ptr_len); |
| 658 |
len = wcslen(path); |
| 659 |
p = path + (len + 1); |
| 660 |
size_t filelen_sum = 0; |
| 661 |
for (int i = 0 ; i < file_count; i++) { |
| 662 |
size_t filelen = aswprintf(&filenames[i], L"%s\\%s", path, p); |
| 663 |
filelen_sum += filelen + 1; |
| 664 |
len = wcslen(p); |
| 665 |
p += len + 1; |
| 666 |
} |
| 667 |
filenames[file_count] = NULL; |
| 668 |
|
| 669 |
wchar_t **ret = MakeStrArrayFromArray(filenames); |
| 670 |
|
| 671 |
for (int i = 0 ; i < file_count; i++) { |
| 672 |
free(filenames[i]); |
| 673 |
} |
| 674 |
|
| 675 |
return ret; |
| 676 |
} |
| 677 |
|
| 678 |
static wchar_t **_GetXFname(HWND HWin, BOOL Receive, const wchar_t *caption, LPLONG Option) |
| 679 |
{ |
| 680 |
wchar_t FileDirExpanded[MAX_PATH]; |
| 681 |
ExpandEnvironmentStringsW(ts.FileDirW, FileDirExpanded, _countof(FileDirExpanded)); |
| 682 |
wchar_t *CurDir = FileDirExpanded; |
| 683 |
|
| 684 |
wchar_t *filterW = ToWcharA(ts.FileSendFilter); |
| 685 |
wchar_t *FNFilter = GetCommonDialogFilterWW(!Receive ? filterW : NULL, ts.UILanguageFileW); |
| 686 |
free(filterW); |
| 687 |
|
| 688 |
wchar_t FullName[MAX_PATH]; |
| 689 |
FullName[0] = 0; |
| 690 |
if (!Receive) { |
| 691 |
wchar_t *default_filename = GetCommonDialogDefaultFilenameW(CurDir); |
| 692 |
if (default_filename != NULL) { |
| 693 |
wcsncpy_s(FullName, _countof(FullName), default_filename, _TRUNCATE); |
| 694 |
free(default_filename); |
| 695 |
} |
| 696 |
} |
| 697 |
|
| 698 |
OPENFILENAMEW ofn = {}; |
| 699 |
ofn.lStructSize = get_OPENFILENAME_SIZE(); |
| 700 |
ofn.hwndOwner = HWin; |
| 701 |
ofn.lpstrFilter = FNFilter; |
| 702 |
ofn.nFilterIndex = 1; |
| 703 |
ofn.lpstrFile = FullName; |
| 704 |
ofn.nMaxFile = _countof(FullName); |
| 705 |
ofn.lpstrInitialDir = CurDir; |
| 706 |
LONG opt = *Option; |
| 707 |
if (! Receive) |
| 708 |
{ |
| 709 |
ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; |
| 710 |
opt = opt | 0xFFFF; |
| 711 |
} |
| 712 |
else { |
| 713 |
ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT; |
| 714 |
} |
| 715 |
ofn.Flags |= OFN_ENABLETEMPLATE | OFN_ENABLEHOOK | OFN_EXPLORER | OFN_ENABLESIZING; |
| 716 |
ofn.Flags |= OFN_SHOWHELP; |
| 717 |
ofn.lCustData = (LPARAM)&opt; |
| 718 |
ofn.lpstrTitle = caption; |
| 719 |
ofn.lpfnHook = XFnHook; |
| 720 |
ofn.lpTemplateName = MAKEINTRESOURCEW(IDD_XOPT); |
| 721 |
ofn.hInstance = hInst; |
| 722 |
|
| 723 |
/* save current dir */ |
| 724 |
wchar_t TempDir[MAX_PATH]; |
| 725 |
GetCurrentDirectoryW(_countof(TempDir), TempDir); |
| 726 |
BOOL Ok; |
| 727 |
if (!Receive) |
| 728 |
{ |
| 729 |
Ok = GetOpenFileNameW(&ofn); |
| 730 |
} |
| 731 |
else { |
| 732 |
Ok = GetSaveFileNameW(&ofn); |
| 733 |
} |
| 734 |
free(FNFilter); |
| 735 |
SetCurrentDirectoryW(TempDir); |
| 736 |
|
| 737 |
wchar_t **ret = NULL; |
| 738 |
if (Ok) { |
| 739 |
if (Receive) |
| 740 |
*Option = opt; |
| 741 |
else |
| 742 |
*Option = MAKELONG(LOWORD(*Option),HIWORD(opt)); |
| 743 |
|
| 744 |
ret = MakeStrArrayFromStr(FullName); |
| 745 |
} |
| 746 |
|
| 747 |
return ret; |
| 748 |
} |
| 749 |
|
| 750 |
/** |
| 751 |
* OnIdle()#teraterm.cpp�����R�[�������� |
| 752 |
* cv_ProtoFlag �� 0 ���O������ |
| 753 |
* @retval 0 continue |
| 754 |
* 1/2 ActiveWin(�O���[�o������)���l(IdVT=1/IdTek=2) |
| 755 |
* �� ������������������������ |
| 756 |
*/ |
| 757 |
int ProtoDlgParse(void) |
| 758 |
{ |
| 759 |
int P; |
| 760 |
|
| 761 |
P = ActiveWin; |
| 762 |
if (PtDlg==NULL) |
| 763 |
return P; |
| 764 |
|
| 765 |
CommReceive(&cv); //�_�C�A���O�\���������M�����f�[�^�����������������������������s������ |
| 766 |
|
| 767 |
PFileVarProto fv = FileVar; |
| 768 |
if (fv->Parse(fv, &cv)) |
| 769 |
P = 0; /* continue */ |
| 770 |
else { |
| 771 |
CommSend(&cv); |
| 772 |
ProtoEnd(); |
| 773 |
} |
| 774 |
return P; |
| 775 |
} |
| 776 |
|
| 777 |
void ProtoDlgTimeOut(void) |
| 778 |
{ |
| 779 |
if (PtDlg!=NULL) { |
| 780 |
PFileVarProto fv = FileVar; |
| 781 |
fv->TimeOutProc(fv, &cv); |
| 782 |
} |
| 783 |
} |
| 784 |
|
| 785 |
void ProtoDlgCancel(void) |
| 786 |
{ |
| 787 |
if (PtDlg!=NULL) { |
| 788 |
PFileVarProto fv = FileVar; |
| 789 |
fv->Cancel(fv, &cv); |
| 790 |
ProtoEnd(); |
| 791 |
} |
| 792 |
} |
| 793 |
|
| 794 |
static INT_PTR CALLBACK GetFnDlg(HWND Dialog, UINT Message, WPARAM wParam, LPARAM lParam) |
| 795 |
{ |
| 796 |
static const DlgTextInfo text_info[] = { |
| 797 |
{ 0, "DLG_GETFN_TITLE" }, |
| 798 |
{ IDC_FILENAME, "DLG_GETFN_FILENAME" }, |
| 799 |
{ IDOK, "BTN_OK" }, |
| 800 |
{ IDCANCEL, "BTN_CANCEL" }, |
| 801 |
{ IDC_GETFNHELP, "BTN_HELP" }, |
| 802 |
}; |
| 803 |
PFileVarProto fv; |
| 804 |
wchar_t TempFull[MAX_PATH]; |
| 805 |
const wchar_t *UILanguageFileW = ts.UILanguageFileW; |
| 806 |
|
| 807 |
switch (Message) { |
| 808 |
case WM_INITDIALOG: |
| 809 |
fv = (PFileVarProto)lParam; |
| 810 |
SetWindowLongPtr(Dialog, DWLP_USER, lParam); |
| 811 |
SendDlgItemMessage(Dialog, IDC_GETFN, EM_LIMITTEXT, sizeof(TempFull)-1,0); |
| 812 |
SetI18nDlgStrsW(Dialog, "Tera Term", text_info, _countof(text_info), UILanguageFileW); |
| 813 |
return TRUE; |
| 814 |
|
| 815 |
case WM_COMMAND: |
| 816 |
fv = (PFileVarProto)GetWindowLongPtr(Dialog,DWLP_USER); |
| 817 |
switch (LOWORD(wParam)) { |
| 818 |
case IDOK: |
| 819 |
if (fv!=NULL) { |
| 820 |
GetDlgItemTextW(Dialog, IDC_GETFN, TempFull, _countof(TempFull)); |
| 821 |
if (wcslen(TempFull)==0) { |
| 822 |
fv->FileNames = NULL; |
| 823 |
return TRUE; |
| 824 |
} |
| 825 |
fv->FileNames = MakeStrArrayFromStr(TempFull); |
| 826 |
} |
| 827 |
EndDialog(Dialog, 1); |
| 828 |
return TRUE; |
| 829 |
case IDCANCEL: |
| 830 |
EndDialog(Dialog, 0); |
| 831 |
return TRUE; |
| 832 |
case IDC_GETFNHELP: |
| 833 |
if (fv!=NULL) { |
| 834 |
// �����o�������w���vID���������� |
| 835 |
PostMessage(fv->HMainWin,WM_USER_DLGHELP2,0,0); |
| 836 |
} |
| 837 |
break; |
| 838 |
} |
| 839 |
} |
| 840 |
return FALSE; |
| 841 |
} |
| 842 |
|
| 843 |
static BOOL _GetGetFname(HWND HWin, PFileVarProto fv, PTTSet ts) |
| 844 |
{ |
| 845 |
SetDialogFont(ts->DialogFontNameW, ts->DialogFontPoint, ts->DialogFontCharSet, |
| 846 |
ts->UILanguageFileW, "Tera Term", "DLG_SYSTEM_FONT"); |
| 847 |
return (BOOL)TTDialogBoxParam(hInst, |
| 848 |
MAKEINTRESOURCE(IDD_GETFNDLG), |
| 849 |
HWin, GetFnDlg, (LPARAM)fv); |
| 850 |
} |
| 851 |
|
| 852 |
static UINT_PTR CALLBACK TransFnHook(HWND Dialog, UINT Message, WPARAM wParam, LPARAM lParam) |
| 853 |
{ |
| 854 |
static const DlgTextInfo text_info[] = { |
| 855 |
{ IDC_FOPT, "DLG_FOPT" }, |
| 856 |
{ IDC_FOPTBIN, "DLG_FOPT_BINARY" }, |
| 857 |
}; |
| 858 |
LPWORD pw; |
| 859 |
LPOFNOTIFY notify; |
| 860 |
static HFONT DlgFoptFont; |
| 861 |
|
| 862 |
switch (Message) { |
| 863 |
case WM_INITDIALOG: { |
| 864 |
const char *UILanguageFile = ts.UILanguageFile; |
| 865 |
const wchar_t *UILanguageFileW = ts.UILanguageFileW; |
| 866 |
LPOPENFILENAMEW ofn = (LPOPENFILENAMEW)lParam; |
| 867 |
HFONT font; |
| 868 |
LOGFONTA logfont; |
| 869 |
pw = (LPWORD)ofn->lCustData; |
| 870 |
SetWindowLongPtr(Dialog, DWLP_USER, (LONG_PTR)pw); |
| 871 |
|
| 872 |
font = (HFONT)SendMessage(Dialog, WM_GETFONT, 0, 0); |
| 873 |
GetObject(font, sizeof(LOGFONT), &logfont); |
| 874 |
if (get_lang_font("DLG_TAHOMA_FONT", Dialog, &logfont, &DlgFoptFont, UILanguageFile)) { |
| 875 |
SendDlgItemMessage(Dialog, IDC_FOPT, WM_SETFONT, (WPARAM)DlgFoptFont, MAKELPARAM(TRUE,0)); |
| 876 |
SendDlgItemMessage(Dialog, IDC_FOPTBIN, WM_SETFONT, (WPARAM)DlgFoptFont, MAKELPARAM(TRUE,0)); |
| 877 |
SendDlgItemMessage(Dialog, IDC_FOPTAPPEND, WM_SETFONT, (WPARAM)DlgFoptFont, MAKELPARAM(TRUE,0)); |
| 878 |
SendDlgItemMessage(Dialog, IDC_PLAINTEXT, WM_SETFONT, (WPARAM)DlgFoptFont, MAKELPARAM(TRUE,0)); |
| 879 |
SendDlgItemMessage(Dialog, IDC_TIMESTAMP, WM_SETFONT, (WPARAM)DlgFoptFont, MAKELPARAM(TRUE,0)); |
| 880 |
} |
| 881 |
else { |
| 882 |
DlgFoptFont = NULL; |
| 883 |
} |
| 884 |
|
| 885 |
SetI18nDlgStrsW(Dialog, "Tera Term", text_info, _countof(text_info), UILanguageFileW); |
| 886 |
|
| 887 |
SetRB(Dialog,*pw & 1,IDC_FOPTBIN,IDC_FOPTBIN); |
| 888 |
|
| 889 |
CenterCommonDialog(Dialog); |
| 890 |
|
| 891 |
return TRUE; |
| 892 |
} |
| 893 |
case WM_COMMAND: // for old style dialog |
| 894 |
switch (LOWORD(wParam)) { |
| 895 |
case IDOK: |
| 896 |
pw = (LPWORD)GetWindowLongPtr(Dialog,DWLP_USER); |
| 897 |
if (pw!=NULL) |
| 898 |
GetRB(Dialog,pw,IDC_FOPTBIN,IDC_FOPTBIN); |
| 899 |
if (DlgFoptFont != NULL) { |
| 900 |
DeleteObject(DlgFoptFont); |
| 901 |
} |
| 902 |
break; |
| 903 |
case IDCANCEL: |
| 904 |
if (DlgFoptFont != NULL) { |
| 905 |
DeleteObject(DlgFoptFont); |
| 906 |
} |
| 907 |
break; |
| 908 |
} |
| 909 |
break; |
| 910 |
case WM_NOTIFY: // for Explorer-style dialog |
| 911 |
notify = (LPOFNOTIFY)lParam; |
| 912 |
switch (notify->hdr.code) { |
| 913 |
case CDN_FILEOK: |
| 914 |
pw = (LPWORD)GetWindowLongPtr(Dialog,DWLP_USER); |
| 915 |
if (pw!=NULL) |
| 916 |
GetRB(Dialog,pw,IDC_FOPTBIN,IDC_FOPTBIN); |
| 917 |
if (DlgFoptFont != NULL) { |
| 918 |
DeleteObject(DlgFoptFont); |
| 919 |
} |
| 920 |
break; |
| 921 |
} |
| 922 |
break; |
| 923 |
} |
| 924 |
return FALSE; |
| 925 |
} |
| 926 |
|
| 927 |
/* GetMultiFname function id */ |
| 928 |
#define GMF_KERMIT 0 /* Kermit Send */ |
| 929 |
#define GMF_Z 1 /* ZMODEM Send */ |
| 930 |
#define GMF_QV 2 /* Quick-VAN Send */ |
| 931 |
#define GMF_Y 3 /* YMODEM Send */ |
| 932 |
|
| 933 |
|
| 934 |
static wchar_t **_GetMultiFname(HWND hWnd, WORD FuncId, const wchar_t *caption, LPWORD Option) |
| 935 |
{ |
| 936 |
#define FnStrMemSize 4096 |
| 937 |
wchar_t TempDir[MAX_PATH]; |
| 938 |
const wchar_t *UILanguageFileW = ts.UILanguageFileW; |
| 939 |
|
| 940 |
wchar_t FileDirExpanded[MAX_PATH]; |
| 941 |
ExpandEnvironmentStringsW(ts.FileDirW, FileDirExpanded, _countof(FileDirExpanded)); |
| 942 |
wchar_t *CurDir = FileDirExpanded; |
| 943 |
|
| 944 |
/* save current dir */ |
| 945 |
GetCurrentDirectoryW(_countof(TempDir), TempDir); |
| 946 |
|
| 947 |
wchar_t *FnStrMem = (wchar_t *)malloc(FnStrMemSize * sizeof(wchar_t)); |
| 948 |
if (FnStrMem == NULL) { |
| 949 |
MessageBeep(0); |
| 950 |
return FALSE; |
| 951 |
} |
| 952 |
FnStrMem[0] = 0; |
| 953 |
|
| 954 |
wchar_t *filterW = ToWcharA(ts.FileSendFilter); |
| 955 |
wchar_t *FNFilter = GetCommonDialogFilterWW(filterW, UILanguageFileW); |
| 956 |
free(filterW); |
| 957 |
|
| 958 |
wchar_t *default_filename = GetCommonDialogDefaultFilenameW(CurDir); |
| 959 |
if (default_filename != NULL) { |
| 960 |
wcsncpy_s(FnStrMem, FnStrMemSize, default_filename, _TRUNCATE); |
| 961 |
free(default_filename); |
| 962 |
} |
| 963 |
|
| 964 |
OPENFILENAMEW ofn = {}; |
| 965 |
ofn.lStructSize = get_OPENFILENAME_SIZE(); |
| 966 |
ofn.hwndOwner = hWnd; |
| 967 |
ofn.lpstrFilter = FNFilter; |
| 968 |
ofn.nFilterIndex = 1; |
| 969 |
ofn.lpstrFile = FnStrMem; |
| 970 |
ofn.nMaxFile = FnStrMemSize; |
| 971 |
ofn.lpstrTitle= caption; |
| 972 |
ofn.lpstrInitialDir = CurDir; |
| 973 |
ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; |
| 974 |
ofn.Flags |= OFN_ALLOWMULTISELECT | OFN_EXPLORER; |
| 975 |
ofn.Flags |= OFN_SHOWHELP; |
| 976 |
ofn.lCustData = 0; |
| 977 |
if (FuncId==GMF_Z) { |
| 978 |
ofn.Flags |= OFN_ENABLETEMPLATE | OFN_ENABLEHOOK | OFN_EXPLORER | OFN_ENABLESIZING; |
| 979 |
ofn.lCustData = (LPARAM)Option; |
| 980 |
ofn.lpfnHook = TransFnHook; |
| 981 |
ofn.lpTemplateName = MAKEINTRESOURCEW(IDD_FOPT); |
| 982 |
} else if (FuncId==GMF_Y) { |
| 983 |
// TODO: YMODEM |
| 984 |
|
| 985 |
} |
| 986 |
|
| 987 |
ofn.hInstance = hInst; |
| 988 |
|
| 989 |
BOOL Ok = GetOpenFileNameW(&ofn); |
| 990 |
free(FNFilter); |
| 991 |
|
| 992 |
wchar_t **ret = NULL; |
| 993 |
if (Ok) { |
| 994 |
// multiple selection |
| 995 |
ret = MakeFileArrayMultiSelect(FnStrMem); |
| 996 |
} |
| 997 |
free(FnStrMem); |
| 998 |
|
| 999 |
/* restore dir */ |
| 1000 |
SetCurrentDirectoryW(TempDir); |
| 1001 |
|
| 1002 |
return ret; |
| 1003 |
} |
| 1004 |
|
| 1005 |
static void KermitStart(int mode) |
| 1006 |
{ |
| 1007 |
if (! ProtoStart()) |
| 1008 |
return; |
| 1009 |
|
| 1010 |
TalkStatus = IdTalkQuiet; |
| 1011 |
|
| 1012 |
/* disable transmit delay (serial port) */ |
| 1013 |
cv.DelayFlag = FALSE; |
| 1014 |
|
| 1015 |
if (! OpenProtoDlg(FileVar,PROTO_KMT,mode,0,0)) |
| 1016 |
ProtoEnd(); |
| 1017 |
} |
| 1018 |
|
| 1019 |
/** |
| 1020 |
* Kermit ���M |
| 1021 |
* |
| 1022 |
* @param[in] filename ���M�t�@�C����(NULL�������A�_�C�A���O���I������) |
| 1023 |
*/ |
| 1024 |
BOOL KermitStartSend(const wchar_t *filename) |
| 1025 |
{ |
| 1026 |
if (FileVar !=NULL) |
| 1027 |
return FALSE; |
| 1028 |
if (!NewFileVar_(&FileVar)) |
| 1029 |
return FALSE; |
| 1030 |
TFileVarProto *fv = FileVar; |
| 1031 |
|
| 1032 |
FileVar->OpId = OpKmtSend; |
| 1033 |
|
| 1034 |
SetDialogCation(fv, "FILEDLG_TRANS_TITLE_KMTSEND", TitKmtSend); |
| 1035 |
|
| 1036 |
if (filename == NULL) { |
| 1037 |
WORD w = 0; |
| 1038 |
wchar_t **filenames = _GetMultiFname(fv->HMainWin, GMF_KERMIT, fv->DlgCaption, &w); |
| 1039 |
if (filenames == NULL) { |
| 1040 |
FreeFileVar_(&FileVar); |
| 1041 |
return FALSE; |
| 1042 |
} |
| 1043 |
fv->FileNames = filenames; |
| 1044 |
} |
| 1045 |
else { |
| 1046 |
fv->FileNames = MakeStrArrayFromStr(filename); |
| 1047 |
FileVar->NoMsg = TRUE; |
| 1048 |
} |
| 1049 |
KermitStart(IdKmtSend); |
| 1050 |
|
| 1051 |
return TRUE; |
| 1052 |
} |
| 1053 |
|
| 1054 |
/** |
| 1055 |
* Kermit ���M |
| 1056 |
*/ |
| 1057 |
BOOL KermitGet(const wchar_t *filename) |
| 1058 |
{ |
| 1059 |
if (FileVar !=NULL) |
| 1060 |
return FALSE; |
| 1061 |
if (!NewFileVar_(&FileVar)) |
| 1062 |
return FALSE; |
| 1063 |
|
| 1064 |
TFileVarProto *fv = FileVar; |
| 1065 |
FileVar->OpId = OpKmtSend; |
| 1066 |
|
| 1067 |
SetDialogCation(fv, "FILEDLG_TRANS_TITLE_KMTGET", TitKmtGet); |
| 1068 |
|
| 1069 |
if (filename == NULL) { |
| 1070 |
if (! _GetGetFname(FileVar->HMainWin,FileVar, &ts) || FileVar->FileNames == NULL) { |
| 1071 |
FreeFileVar_(&FileVar); |
| 1072 |
return FALSE; |
| 1073 |
} |
| 1074 |
} |
| 1075 |
else { |
| 1076 |
FileVar->FileNames = MakeStrArrayFromStr(filename); |
| 1077 |
FileVar->NoMsg = TRUE; |
| 1078 |
} |
| 1079 |
KermitStart(IdKmtGet); |
| 1080 |
|
| 1081 |
return TRUE; |
| 1082 |
} |
| 1083 |
|
| 1084 |
/** |
| 1085 |
* Kermit ���M |
| 1086 |
*/ |
| 1087 |
BOOL KermitStartRecive(BOOL macro) |
| 1088 |
{ |
| 1089 |
if (FileVar !=NULL) |
| 1090 |
return FALSE; |
| 1091 |
if (!NewFileVar_(&FileVar)) |
| 1092 |
return FALSE; |
| 1093 |
|
| 1094 |
TFileVarProto *fv = FileVar; |
| 1095 |
FileVar->OpId = OpKmtRcv; |
| 1096 |
|
| 1097 |
SetDialogCation(fv, "FILEDLG_TRANS_TITLE_KMTRCV", TitKmtRcv); |
| 1098 |
|
| 1099 |
if (macro) { |
| 1100 |
// �}�N������ |
| 1101 |
FileVar->NoMsg = TRUE; |
| 1102 |
} |
| 1103 |
KermitStart(IdKmtReceive); |
| 1104 |
|
| 1105 |
return TRUE; |
| 1106 |
} |
| 1107 |
|
| 1108 |
/** |
| 1109 |
* Kermit finish |
| 1110 |
*/ |
| 1111 |
BOOL KermitFinish(BOOL macro) |
| 1112 |
{ |
| 1113 |
if (FileVar !=NULL) |
| 1114 |
return FALSE; |
| 1115 |
if (!NewFileVar_(&FileVar)) |
| 1116 |
return FALSE; |
| 1117 |
|
| 1118 |
TFileVarProto *fv = FileVar; |
| 1119 |
|
| 1120 |
FileVar->OpId = OpKmtFin; |
| 1121 |
|
| 1122 |
SetDialogCation(fv, "FILEDLG_TRANS_TITLE_KMTFIN", TitKmtFin); |
| 1123 |
|
| 1124 |
if (macro) { |
| 1125 |
FileVar->NoMsg = TRUE; |
| 1126 |
} |
| 1127 |
KermitStart(IdKmtFinish); |
| 1128 |
|
| 1129 |
return TRUE; |
| 1130 |
} |
| 1131 |
|
| 1132 |
/** |
| 1133 |
* XMODEM���M |
| 1134 |
* |
| 1135 |
* @param[in] filename ���M�t�@�C����(NULL�������A�_�C�A���O���I������) |
| 1136 |
* @param[in] ParamBinaryFlag |
| 1137 |
* @param[in] ParamXmodemOpt |
| 1138 |
*/ |
| 1139 |
BOOL XMODEMStartReceive(const wchar_t *filename, WORD ParamBinaryFlag, WORD ParamXmodemOpt) |
| 1140 |
{ |
| 1141 |
if (FileVar !=NULL) |
| 1142 |
return FALSE; |
| 1143 |
if (!NewFileVar_(&FileVar)) |
| 1144 |
return FALSE; |
| 1145 |
|
| 1146 |
TFileVarProto *fv = FileVar; |
| 1147 |
FileVar->OpId = OpXRcv; |
| 1148 |
|
| 1149 |
SetDialogCation(fv, "FILEDLG_TRANS_TITLE_XRCV", TitXRcv); |
| 1150 |
|
| 1151 |
if (filename == NULL) { |
| 1152 |
LONG Option = MAKELONG(ts.XmodemBin,ts.XmodemOpt); |
| 1153 |
wchar_t **filenames = _GetXFname(HVTWin, TRUE, fv->DlgCaption, &Option); |
| 1154 |
if (filenames == NULL) { |
| 1155 |
FreeFileVar_(&FileVar); |
| 1156 |
return FALSE; |
| 1157 |
} |
| 1158 |
fv->FileNames = filenames; |
| 1159 |
int tmp = HIWORD(Option); |
| 1160 |
if (IsXoptCRC(tmp)) { |
| 1161 |
if (IsXopt1k(ts.XmodemOpt)) { |
| 1162 |
ts.XmodemOpt = Xopt1kCRC; |
| 1163 |
} |
| 1164 |
else { |
| 1165 |
ts.XmodemOpt = XoptCRC; |
| 1166 |
} |
| 1167 |
} |
| 1168 |
else { |
| 1169 |
if (IsXopt1k(ts.XmodemOpt)) { |
| 1170 |
ts.XmodemOpt = Xopt1kCksum; |
| 1171 |
} |
| 1172 |
else { |
| 1173 |
ts.XmodemOpt = XoptCheck; |
| 1174 |
} |
| 1175 |
} |
| 1176 |
ts.XmodemBin = LOWORD(Option); |
| 1177 |
} |
| 1178 |
else { |
| 1179 |
fv->FileNames = MakeStrArrayFromStr(filename); |
| 1180 |
if (IsXopt1k(ts.XmodemOpt)) { |
| 1181 |
if (IsXoptCRC(ParamXmodemOpt)) { |
| 1182 |
// CRC |
| 1183 |
ts.XmodemOpt = Xopt1kCRC; |
| 1184 |
} |
| 1185 |
else { // Checksum |
| 1186 |
ts.XmodemOpt = Xopt1kCksum; |
| 1187 |
} |
| 1188 |
} |
| 1189 |
else { |
| 1190 |
if (IsXoptCRC(ParamXmodemOpt)) { |
| 1191 |
ts.XmodemOpt = XoptCRC; |
| 1192 |
} |
| 1193 |
else { |
| 1194 |
ts.XmodemOpt = XoptCheck; |
| 1195 |
} |
| 1196 |
} |
| 1197 |
ts.XmodemBin = ParamBinaryFlag; |
| 1198 |
FileVar->NoMsg = TRUE; |
| 1199 |
} |
| 1200 |
|
| 1201 |
if (! ProtoStart()) { |
| 1202 |
return FALSE; |
| 1203 |
} |
| 1204 |
|
| 1205 |
TalkStatus = IdTalkQuiet; |
| 1206 |
|
| 1207 |
/* disable transmit delay (serial port) */ |
| 1208 |
cv.DelayFlag = FALSE; |
| 1209 |
|
| 1210 |
int mode = IdXReceive; |
| 1211 |
if (! OpenProtoDlg(FileVar,PROTO_XM,mode, ts.XmodemOpt,ts.XmodemBin)) { |
| 1212 |
ProtoEnd(); |
| 1213 |
return FALSE; |
| 1214 |
} |
| 1215 |
|
| 1216 |
return TRUE; |
| 1217 |
} |
| 1218 |
|
| 1219 |
/** |
| 1220 |
* XMODEM���M |
| 1221 |
* |
| 1222 |
* @param[in] filename ���M�t�@�C����(NULL�������A�_�C�A���O���I������) |
| 1223 |
* @param[in] ParamXmodemOpt |
| 1224 |
*/ |
| 1225 |
BOOL XMODEMStartSend(const wchar_t *filename, WORD ParamXmodemOpt) |
| 1226 |
{ |
| 1227 |
if (FileVar !=NULL) |
| 1228 |
return FALSE; |
| 1229 |
if (!NewFileVar_(&FileVar)) |
| 1230 |
return FALSE; |
| 1231 |
|
| 1232 |
TFileVarProto *fv = FileVar; |
| 1233 |
FileVar->OpId = OpXSend; |
| 1234 |
|
| 1235 |
SetDialogCation(fv, "FILEDLG_TRANS_TITLE_XSEND", TitXSend); |
| 1236 |
|
| 1237 |
if (filename == NULL) { |
| 1238 |
LONG Option = MAKELONG(ts.XmodemBin,ts.XmodemOpt); |
| 1239 |
wchar_t **filenames = _GetXFname(HVTWin, FALSE, fv->DlgCaption, &Option); |
| 1240 |
if (filenames == NULL) { |
| 1241 |
FreeFileVar_(&FileVar); |
| 1242 |
return FALSE; |
| 1243 |
} |
| 1244 |
fv->FileNames = filenames; |
| 1245 |
int tmp = HIWORD(Option); |
| 1246 |
if (IsXopt1k(tmp)) { |
| 1247 |
if (IsXoptCRC(ts.XmodemOpt)) { |
| 1248 |
ts.XmodemOpt = Xopt1kCRC; |
| 1249 |
} |
| 1250 |
else { |
| 1251 |
ts.XmodemOpt = Xopt1kCksum; |
| 1252 |
} |
| 1253 |
} |
| 1254 |
else { |
| 1255 |
if (IsXoptCRC(ts.XmodemOpt)) { |
| 1256 |
ts.XmodemOpt = XoptCRC; |
| 1257 |
} |
| 1258 |
else { |
| 1259 |
ts.XmodemOpt = XoptCheck; |
| 1260 |
} |
| 1261 |
} |
| 1262 |
} |
| 1263 |
else { |
| 1264 |
fv->FileNames = MakeStrArrayFromStr(filename); |
| 1265 |
if (IsXoptCRC(ts.XmodemOpt)) { |
| 1266 |
if (IsXopt1k(ParamXmodemOpt)) { |
| 1267 |
ts.XmodemOpt = Xopt1kCRC; |
| 1268 |
} |
| 1269 |
else { |
| 1270 |
ts.XmodemOpt = XoptCRC; |
| 1271 |
} |
| 1272 |
} |
| 1273 |
else { |
| 1274 |
if (IsXopt1k(ParamXmodemOpt)) { |
| 1275 |
ts.XmodemOpt = Xopt1kCksum; |
| 1276 |
} |
| 1277 |
else { |
| 1278 |
ts.XmodemOpt = XoptCheck; |
| 1279 |
} |
| 1280 |
} |
| 1281 |
FileVar->NoMsg = TRUE; |
| 1282 |
} |
| 1283 |
|
| 1284 |
if (! ProtoStart()) { |
| 1285 |
return FALSE; |
| 1286 |
} |
| 1287 |
|
| 1288 |
TalkStatus = IdTalkQuiet; |
| 1289 |
|
| 1290 |
/* disable transmit delay (serial port) */ |
| 1291 |
cv.DelayFlag = FALSE; |
| 1292 |
|
| 1293 |
int mode = IdXSend; |
| 1294 |
if (! OpenProtoDlg(FileVar,PROTO_XM,mode, ts.XmodemOpt,ts.XmodemBin)) { |
| 1295 |
ProtoEnd(); |
| 1296 |
return FALSE; |
| 1297 |
} |
| 1298 |
|
| 1299 |
return TRUE; |
| 1300 |
} |
| 1301 |
|
| 1302 |
/** |
| 1303 |
* YMODEM���M |
| 1304 |
* |
| 1305 |
* @param[in] macro TURE�������}�N�������������� |
| 1306 |
*/ |
| 1307 |
BOOL YMODEMStartReceive(BOOL macro) |
| 1308 |
{ |
| 1309 |
if (FileVar != NULL) { |
| 1310 |
return FALSE; |
| 1311 |
} |
| 1312 |
if (!NewFileVar_(&FileVar)) { |
| 1313 |
return FALSE; |
| 1314 |
} |
| 1315 |
|
| 1316 |
TFileVarProto *fv = FileVar; |
| 1317 |
|
| 1318 |
if (macro) { |
| 1319 |
FileVar->NoMsg = TRUE; |
| 1320 |
} |
| 1321 |
|
| 1322 |
if (! ProtoStart()) |
| 1323 |
return FALSE; |
| 1324 |
|
| 1325 |
FileVar->OpId = OpYRcv; |
| 1326 |
|
| 1327 |
SetDialogCation(fv, "FILEDLG_TRANS_TITLE_YRCV", TitYRcv); |
| 1328 |
|
| 1329 |
// �t�@�C���]�������I�v�V������"Yopt1K"�����������B |
| 1330 |
WORD Opt = Yopt1K; |
| 1331 |
// _SetFileVar(FileVar); |
| 1332 |
|
| 1333 |
TalkStatus = IdTalkQuiet; |
| 1334 |
|
| 1335 |
/* disable transmit delay (serial port) */ |
| 1336 |
cv.DelayFlag = FALSE; |
| 1337 |
|
| 1338 |
if (! OpenProtoDlg(FileVar,PROTO_YM,IdYReceive,Opt,0)) { |
| 1339 |
ProtoEnd(); |
| 1340 |
return FALSE; |
| 1341 |
} |
| 1342 |
|
| 1343 |
return TRUE; |
| 1344 |
} |
| 1345 |
|
| 1346 |
/** |
| 1347 |
* YMODEM���M |
| 1348 |
* |
| 1349 |
* @param[in] filename ���M�t�@�C����(NULL�������A�_�C�A���O���I������) |
| 1350 |
*/ |
| 1351 |
BOOL YMODEMStartSend(const wchar_t *filename) |
| 1352 |
{ |
| 1353 |
if (FileVar != NULL) { |
| 1354 |
return FALSE; |
| 1355 |
} |
| 1356 |
if (!NewFileVar_(&FileVar)) { |
| 1357 |
return FALSE; |
| 1358 |
} |
| 1359 |
|
| 1360 |
if (! ProtoStart()) |
| 1361 |
return FALSE; |
| 1362 |
|
| 1363 |
TFileVarProto *fv = FileVar; |
| 1364 |
|
| 1365 |
SetDialogCation(fv, "FILEDLG_TRANS_TITLE_YSEND", TitYSend); |
| 1366 |
|
| 1367 |
// �t�@�C���]�������I�v�V������"Yopt1K"�����������B |
| 1368 |
// TODO: "Yopt1K", "YoptG", "YoptSingle"�������������������AIDD_FOPT���g�������K�v�����B |
| 1369 |
WORD Opt = Yopt1K; |
| 1370 |
FileVar->OpId = OpYSend; |
| 1371 |
if (filename == NULL) { |
| 1372 |
wchar_t **filenames = _GetMultiFname(fv->HMainWin, GMF_Y, fv->DlgCaption, &Opt); |
| 1373 |
if (filenames == NULL) { |
| 1374 |
ProtoEnd(); |
| 1375 |
return FALSE; |
| 1376 |
} |
| 1377 |
//ts.XmodemBin = Opt; |
| 1378 |
fv->FileNames = filenames; |
| 1379 |
} |
| 1380 |
else { |
| 1381 |
fv->FileNames = MakeStrArrayFromStr(filename); |
| 1382 |
FileVar->NoMsg = TRUE; |
| 1383 |
} |
| 1384 |
|
| 1385 |
TalkStatus = IdTalkQuiet; |
| 1386 |
|
| 1387 |
/* disable transmit delay (serial port) */ |
| 1388 |
cv.DelayFlag = FALSE; |
| 1389 |
|
| 1390 |
if (! OpenProtoDlg(FileVar,PROTO_YM, IdYSend,Opt,0)) { |
| 1391 |
ProtoEnd(); |
| 1392 |
return FALSE; |
| 1393 |
} |
| 1394 |
|
| 1395 |
return TRUE; |
| 1396 |
} |
| 1397 |
|
| 1398 |
/** |
| 1399 |
* ZMODEM���M |
| 1400 |
* |
| 1401 |
* @param[in] macro TURE�������}�N�������������� |
| 1402 |
* @param[in] autostart TURE�����������X�^�[�g |
| 1403 |
*/ |
| 1404 |
BOOL ZMODEMStartReceive(BOOL macro, BOOL autostart) |
| 1405 |
{ |
| 1406 |
if (FileVar != NULL) { |
| 1407 |
return FALSE; |
| 1408 |
} |
| 1409 |
if (!NewFileVar_(&FileVar)) { |
| 1410 |
return FALSE; |
| 1411 |
} |
| 1412 |
|
| 1413 |
if (macro) { |
| 1414 |
FileVar->NoMsg = TRUE; |
| 1415 |
} |
| 1416 |
int mode = autostart ? IdZAutoR : IdZReceive; |
| 1417 |
|
| 1418 |
if (! ProtoStart()) |
| 1419 |
return FALSE; |
| 1420 |
|
| 1421 |
TFileVarProto *fv = FileVar; |
| 1422 |
|
| 1423 |
/* IdZReceive or IdZAutoR */ |
| 1424 |
FileVar->OpId = OpZRcv; |
| 1425 |
|
| 1426 |
SetDialogCation(fv, "FILEDLG_TRANS_TITLE_ZRCV", TitZRcv); |
| 1427 |
|
| 1428 |
TalkStatus = IdTalkQuiet; |
| 1429 |
|
| 1430 |
/* disable transmit delay (serial port) */ |
| 1431 |
cv.DelayFlag = FALSE; |
| 1432 |
|
| 1433 |
WORD Opt = 0; |
| 1434 |
if (! OpenProtoDlg(FileVar,PROTO_ZM,mode,Opt,0)) { |
| 1435 |
ProtoEnd(); |
| 1436 |
return FALSE; |
| 1437 |
} |
| 1438 |
|
| 1439 |
return TRUE; |
| 1440 |
} |
| 1441 |
|
| 1442 |
/** |
| 1443 |
* ZMODEM���M |
| 1444 |
* |
| 1445 |
* @param[in] filename ���M�t�@�C����(NULL�������A�_�C�A���O���I������) |
| 1446 |
* @param[in] ParamBinaryFlag binary mode |
| 1447 |
* @param[in] autostart TURE�����������X�^�[�g |
| 1448 |
*/ |
| 1449 |
BOOL ZMODEMStartSend(const wchar_t *filename, WORD ParamBinaryFlag, BOOL autostart) |
| 1450 |
{ |
| 1451 |
if (FileVar != NULL) { |
| 1452 |
return FALSE; |
| 1453 |
} |
| 1454 |
if (!NewFileVar_(&FileVar)) { |
| 1455 |
return FALSE; |
| 1456 |
} |
| 1457 |
|
| 1458 |
int mode = autostart ? IdZAutoS : IdZSend; |
| 1459 |
|
| 1460 |
if (! ProtoStart()) |
| 1461 |
return FALSE; |
| 1462 |
|
| 1463 |
TFileVarProto *fv = FileVar; |
| 1464 |
|
| 1465 |
SetDialogCation(fv, "FILEDLG_TRANS_TITLE_ZSEND", TitZSend); |
| 1466 |
|
| 1467 |
WORD Opt = ts.XmodemBin; |
| 1468 |
FileVar->OpId = OpZSend; |
| 1469 |
if (filename == NULL) { |
| 1470 |
wchar_t **filenames = _GetMultiFname(fv->HMainWin, GMF_Z, fv->DlgCaption, &Opt); |
| 1471 |
if (filenames == NULL) { |
| 1472 |
if (mode == IdZAutoS) { |
| 1473 |
CommRawOut(&cv, "\030\030\030\030\030\030\030\030\b\b\b\b\b\b\b\b\b\b", 18); |
| 1474 |
} |
| 1475 |
ProtoEnd(); |
| 1476 |
return FALSE; |
| 1477 |
} |
| 1478 |
fv->FileNames = filenames; |
| 1479 |
ts.XmodemBin = Opt; |
| 1480 |
} |
| 1481 |
else { |
| 1482 |
fv->FileNames = MakeStrArrayFromStr(filename); |
| 1483 |
ts.XmodemBin = ParamBinaryFlag; |
| 1484 |
FileVar->NoMsg = TRUE; |
| 1485 |
} |
| 1486 |
|
| 1487 |
TalkStatus = IdTalkQuiet; |
| 1488 |
|
| 1489 |
/* disable transmit delay (serial port) */ |
| 1490 |
cv.DelayFlag = FALSE; |
| 1491 |
|
| 1492 |
if (! OpenProtoDlg(FileVar,PROTO_ZM,mode,Opt,0)) { |
| 1493 |
ProtoEnd(); |
| 1494 |
return FALSE; |
| 1495 |
} |
| 1496 |
|
| 1497 |
return TRUE; |
| 1498 |
} |
| 1499 |
|
| 1500 |
static wchar_t **_GetTransFname(HWND hWnd, const wchar_t *DlgCaption) |
| 1501 |
{ |
| 1502 |
wchar_t TempDir[MAX_PATH]; |
| 1503 |
wchar_t FileName[MAX_PATH]; |
| 1504 |
const wchar_t *UILanguageFileW = ts.UILanguageFileW; |
| 1505 |
|
| 1506 |
wchar_t FileDirExpanded[MAX_PATH]; |
| 1507 |
ExpandEnvironmentStringsW(ts.FileDirW, FileDirExpanded, _countof(FileDirExpanded)); |
| 1508 |
wchar_t *CurDir = FileDirExpanded; |
| 1509 |
|
| 1510 |
/* save current dir */ |
| 1511 |
GetCurrentDirectoryW(_countof(TempDir), TempDir); |
| 1512 |
|
| 1513 |
wchar_t *filterW = ToWcharA(ts.FileSendFilter); |
| 1514 |
wchar_t *FNFilter = GetCommonDialogFilterWW(filterW, UILanguageFileW); |
| 1515 |
free(filterW); |
| 1516 |
|
| 1517 |
OPENFILENAMEW ofn = {}; |
| 1518 |
ofn.lStructSize = get_OPENFILENAME_SIZE(); |
| 1519 |
ofn.hwndOwner = hWnd; |
| 1520 |
ofn.lpstrFilter = FNFilter; |
| 1521 |
ofn.nFilterIndex = 1; |
| 1522 |
ofn.lpstrFile = FileName; |
| 1523 |
ofn.nMaxFile = _countof(FileName); |
| 1524 |
ofn.lpstrInitialDir = CurDir; |
| 1525 |
ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_SHOWHELP; |
| 1526 |
ofn.lpstrTitle = DlgCaption; |
| 1527 |
ofn.hInstance = hInst; |
| 1528 |
|
| 1529 |
BOOL Ok = GetOpenFileNameW(&ofn); |
| 1530 |
free(FNFilter); |
| 1531 |
|
| 1532 |
wchar_t **ret = NULL; |
| 1533 |
if (Ok) { |
| 1534 |
ret = MakeStrArrayFromStr(FileName); |
| 1535 |
} |
| 1536 |
/* restore dir */ |
| 1537 |
SetCurrentDirectoryW(TempDir); |
| 1538 |
return ret; |
| 1539 |
} |
| 1540 |
|
| 1541 |
BOOL BPStartSend(const wchar_t *filename) |
| 1542 |
{ |
| 1543 |
if (FileVar != NULL) { |
| 1544 |
return FALSE; |
| 1545 |
} |
| 1546 |
if (!NewFileVar_(&FileVar)) { |
| 1547 |
return FALSE; |
| 1548 |
} |
| 1549 |
|
| 1550 |
TFileVarProto *fv = FileVar; |
| 1551 |
FileVar->OpId = OpBPSend; |
| 1552 |
|
| 1553 |
SetDialogCation(fv, "FILEDLG_TRANS_TITLE_BPSEND", TitBPSend); |
| 1554 |
|
| 1555 |
if (! ProtoStart()) |
| 1556 |
return FALSE; |
| 1557 |
|
| 1558 |
if (filename == NULL) { |
| 1559 |
wchar_t **filenames = _GetTransFname(fv->HMainWin, FileVar->DlgCaption); |
| 1560 |
if (filenames == NULL) { |
| 1561 |
ProtoEnd(); |
| 1562 |
return FALSE; |
| 1563 |
} |
| 1564 |
fv->FileNames = filenames; |
| 1565 |
} |
| 1566 |
else { |
| 1567 |
fv->FileNames = MakeStrArrayFromStr(filename); |
| 1568 |
fv->NoMsg = TRUE; |
| 1569 |
} |
| 1570 |
|
| 1571 |
TalkStatus = IdTalkQuiet; |
| 1572 |
|
| 1573 |
/* disable transmit delay (serial port) */ |
| 1574 |
cv.DelayFlag = FALSE; |
| 1575 |
|
| 1576 |
if (! OpenProtoDlg(FileVar,PROTO_BP, IdBPSend,0,0)) { |
| 1577 |
ProtoEnd(); |
| 1578 |
return FALSE; |
| 1579 |
} |
| 1580 |
|
| 1581 |
return TRUE; |
| 1582 |
} |
| 1583 |
|
| 1584 |
BOOL BPStartReceive(BOOL macro, BOOL autostart) |
| 1585 |
{ |
| 1586 |
if (FileVar != NULL) |
| 1587 |
return FALSE; |
| 1588 |
if (!NewFileVar_(&FileVar)) |
| 1589 |
return FALSE; |
| 1590 |
|
| 1591 |
TFileVarProto *fv = FileVar; |
| 1592 |
int mode = autostart ? IdBPAuto : IdBPReceive; |
| 1593 |
|
| 1594 |
if (macro) { |
| 1595 |
FileVar->NoMsg = TRUE; |
| 1596 |
} |
| 1597 |
|
| 1598 |
if (! ProtoStart()) |
| 1599 |
return FALSE; |
| 1600 |
|
| 1601 |
/* IdBPReceive or IdBPAuto */ |
| 1602 |
FileVar->OpId = OpBPRcv; |
| 1603 |
|
| 1604 |
SetDialogCation(fv, "FILEDLG_TRANS_TITLE_BPRCV", TitBPRcv); |
| 1605 |
|
| 1606 |
TalkStatus = IdTalkQuiet; |
| 1607 |
|
| 1608 |
/* disable transmit delay (serial port) */ |
| 1609 |
cv.DelayFlag = FALSE; |
| 1610 |
|
| 1611 |
if (! OpenProtoDlg(FileVar,PROTO_BP,mode,0,0)) { |
| 1612 |
ProtoEnd(); |
| 1613 |
return FALSE; |
| 1614 |
} |
| 1615 |
|
| 1616 |
return TRUE; |
| 1617 |
} |
| 1618 |
|
| 1619 |
BOOL QVStartReceive(BOOL macro) |
| 1620 |
{ |
| 1621 |
if (FileVar != NULL) { |
| 1622 |
return FALSE; |
| 1623 |
} |
| 1624 |
if (!NewFileVar_(&FileVar)) { |
| 1625 |
return FALSE; |
| 1626 |
} |
| 1627 |
|
| 1628 |
if (macro) { |
| 1629 |
FileVar->NoMsg = TRUE; |
| 1630 |
} |
| 1631 |
int mode = IdQVReceive; |
| 1632 |
|
| 1633 |
if (! ProtoStart()) |
| 1634 |
return FALSE; |
| 1635 |
|
| 1636 |
TFileVarProto *fv = FileVar; |
| 1637 |
|
| 1638 |
FileVar->OpId = OpQVRcv; |
| 1639 |
|
| 1640 |
SetDialogCation(fv, "FILEDLG_TRANS_TITLE_QVRCV", TitQVRcv); |
| 1641 |
|
| 1642 |
TalkStatus = IdTalkQuiet; |
| 1643 |
|
| 1644 |
/* disable transmit delay (serial port) */ |
| 1645 |
cv.DelayFlag = FALSE; |
| 1646 |
|
| 1647 |
if (! OpenProtoDlg(FileVar,PROTO_QV,mode,0,0)) { |
| 1648 |
ProtoEnd(); |
| 1649 |
return FALSE; |
| 1650 |
} |
| 1651 |
|
| 1652 |
return TRUE; |
| 1653 |
} |
| 1654 |
|
| 1655 |
BOOL QVStartSend(const wchar_t *filename) |
| 1656 |
{ |
| 1657 |
if (FileVar != NULL) { |
| 1658 |
return FALSE; |
| 1659 |
} |
| 1660 |
if (!NewFileVar_(&FileVar)) { |
| 1661 |
return FALSE; |
| 1662 |
} |
| 1663 |
|
| 1664 |
TFileVarProto *fv = FileVar; |
| 1665 |
|
| 1666 |
if (! ProtoStart()) |
| 1667 |
return FALSE; |
| 1668 |
|
| 1669 |
FileVar->OpId = OpQVSend; |
| 1670 |
|
| 1671 |
SetDialogCation(fv, "FILEDLG_TRANS_TITLE_QVSEND", TitQVSend); |
| 1672 |
|
| 1673 |
if (filename == NULL) { |
| 1674 |
WORD Opt; |
| 1675 |
wchar_t **filenames = _GetMultiFname(fv->HMainWin, GMF_QV, fv->DlgCaption, &Opt); |
| 1676 |
if (filenames == NULL) { |
| 1677 |
ProtoEnd(); |
| 1678 |
return FALSE; |
| 1679 |
} |
| 1680 |
fv->FileNames = filenames; |
| 1681 |
} |
| 1682 |
else { |
| 1683 |
fv->FileNames = MakeStrArrayFromStr(filename); |
| 1684 |
FileVar->NoMsg = TRUE; |
| 1685 |
} |
| 1686 |
|
| 1687 |
TalkStatus = IdTalkQuiet; |
| 1688 |
|
| 1689 |
/* disable transmit delay (serial port) */ |
| 1690 |
cv.DelayFlag = FALSE; |
| 1691 |
|
| 1692 |
if (! OpenProtoDlg(FileVar,PROTO_QV,IdQVSend,0,0)) { |
| 1693 |
ProtoEnd(); |
| 1694 |
return FALSE; |
| 1695 |
} |
| 1696 |
|
| 1697 |
return TRUE; |
| 1698 |
} |
| 1699 |
|
| 1700 |
BOOL IsFileVarNULL() |
| 1701 |
{ |
| 1702 |
return FileVar == NULL; |
| 1703 |
} |
| 1704 |
|
| 1705 |
BOOL ProtoGetProtoFlag(void) |
| 1706 |
{ |
| 1707 |
return cv_ProtoFlag; |
| 1708 |
} |