1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
|
static bool AnyMessageDisplayed=false; // For console -idn switch.
// Purely user interface function. Gets and returns user input.
UIASKREP_RESULT uiAskReplace(std::wstring &Name,int64 FileSize,RarTime *FileTime,uint Flags)
{
wchar SizeText1[20],DateStr1[50],SizeText2[20],DateStr2[50];
FindData ExistingFD={}; // Init in case find fails.
FindFile::FastFind(Name,&ExistingFD);
itoa(ExistingFD.Size,SizeText1,ASIZE(SizeText1));
ExistingFD.mtime.GetText(DateStr1,ASIZE(DateStr1),false);
if (FileSize==INT64NDF || FileTime==NULL)
{
eprintf(L"\n");
eprintf(St(MAskOverwrite),Name.c_str());
}
else
{
itoa(FileSize,SizeText2,ASIZE(SizeText2));
FileTime->GetText(DateStr2,ASIZE(DateStr2),false);
if ((Flags & UIASKREP_F_EXCHSRCDEST)==0)
eprintf(St(MAskReplace),Name.c_str(),SizeText1,DateStr1,SizeText2,DateStr2);
else
eprintf(St(MAskReplace),Name.c_str(),SizeText2,DateStr2,SizeText1,DateStr1);
}
bool AllowRename=(Flags & UIASKREP_F_NORENAME)==0;
int Choice=0;
do
{
Choice=Ask(St(AllowRename ? MYesNoAllRenQ : MYesNoAllQ));
} while (Choice==0); // 0 means invalid input.
switch(Choice)
{
case 1:
return UIASKREP_R_REPLACE;
case 2:
return UIASKREP_R_SKIP;
case 3:
return UIASKREP_R_REPLACEALL;
case 4:
return UIASKREP_R_SKIPALL;
}
if (AllowRename && Choice==5)
{
mprintf(St(MAskNewName));
getwstr(Name);
return UIASKREP_R_RENAME;
}
return UIASKREP_R_CANCEL;
}
void uiStartArchiveExtract(bool Extract,const std::wstring &ArcName)
{
mprintf(St(Extract ? MExtracting : MExtrTest), ArcName.c_str());
}
bool uiStartFileExtract(const std::wstring &FileName,bool Extract,bool Test,bool Skip)
{
return true;
}
void uiExtractProgress(int64 CurFileSize,int64 TotalFileSize,int64 CurSize,int64 TotalSize)
{
// We set the total size to 0 to update only the current progress and keep
// the total progress intact in WinRAR. Unlike WinRAR, console RAR has only
// the total progress and updates it with current values in such case.
int CurPercent=TotalSize!=0 ? ToPercent(CurSize,TotalSize) : ToPercent(CurFileSize,TotalFileSize);
mprintf(L"\b\b\b\b%3d%%",CurPercent);
}
void uiProcessProgress(const char *Command,int64 CurSize,int64 TotalSize)
{
int CurPercent=ToPercent(CurSize,TotalSize);
mprintf(L"\b\b\b\b%3d%%",CurPercent);
}
void uiMsgStore::Msg()
{
// When creating volumes, AnyMessageDisplayed must be reset for UIEVENT_NEWARCHIVE,
// so it ignores this and all earlier messages like UIEVENT_PROTECTEND
// and UIEVENT_PROTECTEND, because they precede "Creating archive" message
// and do not interfere with -idn and file names. If we do not ignore them,
// uiEolAfterMsg() in uiStartFileAddit() can cause unneeded carriage return
// in archiving percent after creating a new volume with -v -idn (and -rr
// for UIEVENT_PROTECT*) switches. AnyMessageDisplayed is set for messages
// after UIEVENT_NEWARCHIVE, so archiving percent with -idn is moved to
// next line and does not delete their last characters.
// Similarly we ignore UIEVENT_RRTESTINGEND for volumes, because it is issued
// before "Testing archive" and would add an excessive \n otherwise.
AnyMessageDisplayed=(Code!=UIEVENT_NEWARCHIVE && Code!=UIEVENT_RRTESTINGEND);
switch(Code)
{
case UIERROR_SYSERRMSG:
case UIERROR_GENERALERRMSG:
Log(NULL,L"\n%ls",Str[0]);
break;
case UIERROR_CHECKSUM:
Log(Str[0],St(MCRCFailed),Str[1]);
break;
case UIERROR_CHECKSUMENC:
Log(Str[0],St(MEncrBadCRC),Str[1]);
break;
case UIERROR_CHECKSUMPACKED:
Log(Str[0],St(MDataBadCRC),Str[1],Str[0]);
break;
case UIERROR_BADPSW:
Log(Str[0],St(MWrongFilePassword),Str[1]);
break;
case UIWAIT_BADPSW:
Log(Str[0],St(MWrongPassword));
break;
case UIERROR_MEMORY:
mprintf(L"\n");
Log(NULL,St(MErrOutMem));
break;
case UIERROR_FILEOPEN:
Log(Str[0],St(MCannotOpen),Str[1]);
break;
case UIERROR_FILECREATE:
Log(Str[0],St(MCannotCreate),Str[1]);
break;
case UIERROR_FILECLOSE:
Log(NULL,St(MErrFClose),Str[0]);
break;
case UIERROR_FILESEEK:
Log(NULL,St(MErrSeek),Str[0]);
break;
case UIERROR_FILEREAD:
mprintf(L"\n");
Log(Str[0],St(MErrRead),Str[1]);
break;
case UIERROR_FILEWRITE:
Log(Str[0],St(MErrWrite),Str[1]);
break;
#ifndef SFX_MODULE
case UIERROR_FILEDELETE:
Log(Str[0],St(MCannotDelete),Str[1]);
break;
case UIERROR_RECYCLEFAILED:
Log(Str[0],St(MRecycleFailed));
break;
case UIERROR_FILERENAME:
Log(Str[0],St(MErrRename),Str[1],Str[2]);
break;
#endif
case UIERROR_FILEATTR:
Log(Str[0],St(MErrChangeAttr),Str[1]);
break;
case UIERROR_FILECOPY:
Log(Str[0],St(MCopyError),Str[1],Str[2]);
break;
case UIERROR_FILECOPYHINT:
Log(Str[0],St(MCopyErrorHint));
mprintf(L" "); // For progress percent.
break;
case UIERROR_DIRCREATE:
Log(Str[0],St(MExtrErrMkDir),Str[1]);
break;
case UIERROR_SLINKCREATE:
Log(Str[0],St(MErrCreateLnkS),Str[1]);
break;
case UIERROR_HLINKCREATE:
Log(NULL,St(MErrCreateLnkH),Str[0]);
break;
case UIERROR_NOLINKTARGET:
Log(NULL,St(MErrLnkTarget));
mprintf(L" "); // For progress percent.
break;
case UIERROR_NEEDADMIN:
Log(NULL,St(MNeedAdmin));
break;
case UIERROR_ARCBROKEN:
mprintf(L"\n"); // So it is not merged with preceding UIERROR_HEADERBROKEN.
Log(Str[0],St(MErrBrokenArc));
break;
case UIERROR_HEADERBROKEN:
Log(Str[0],St(MHeaderBroken));
break;
case UIERROR_MHEADERBROKEN:
Log(Str[0],St(MMainHeaderBroken));
break;
case UIERROR_FHEADERBROKEN:
Log(Str[0],St(MLogFileHead),Str[1]);
break;
case UIERROR_SUBHEADERBROKEN:
Log(Str[0],St(MSubHeadCorrupt));
break;
case UIERROR_SUBHEADERUNKNOWN:
Log(Str[0],St(MSubHeadUnknown));
break;
case UIERROR_SUBHEADERDATABROKEN:
Log(Str[0],St(MSubHeadDataCRC),Str[1]);
break;
case UIERROR_RRDAMAGED:
Log(Str[0],St(MRRDamaged));
break;
case UIERROR_UNKNOWNMETHOD:
Log(Str[0],St(MUnknownMeth),Str[1]);
break;
case UIERROR_UNKNOWNENCMETHOD:
{
wchar Msg[256];
swprintf(Msg,ASIZE(Msg),St(MUnkEncMethod),Str[1]);
Log(Str[0],L"%s: %s",Msg,Str[2]);
}
break;
#ifndef SFX_MODULE
case UIERROR_RENAMING:
Log(Str[0],St(MRenaming),Str[1],Str[2]);
break;
case UIERROR_NEWERRAR:
Log(Str[0],St(MNewerRAR));
break;
#endif
case UIERROR_RECVOLDIFFSETS:
Log(NULL,St(MRecVolDiffSets),Str[0],Str[1]);
break;
case UIERROR_RECVOLALLEXIST:
mprintf(St(MRecVolAllExist));
break;
case UIERROR_RECONSTRUCTING:
mprintf(St(MReconstructing));
break;
case UIERROR_RECVOLCANNOTFIX:
mprintf(St(MRecVolCannotFix));
break;
case UIERROR_EXTRDICTOUTMEM:
Log(Str[0],St(MExtrDictOutMem),Num[0]);
#ifdef _WIN_32
Log(Str[0],St(MSuggest64bit));
#endif
break;
case UIERROR_UNEXPEOF:
Log(Str[0],St(MLogUnexpEOF));
break;
case UIERROR_TRUNCSERVICE:
{
const wchar *Type=nullptr;
if (wcscmp(Str[1],SUBHEAD_TYPE_QOPEN)==0)
Type=St(MHeaderQO);
else
if (wcscmp(Str[1],SUBHEAD_TYPE_RR)==0)
Type=St(MHeaderRR);
if (Type!=nullptr)
Log(Str[0],St(MTruncService),Type);
}
break;
case UIERROR_BADARCHIVE:
Log(Str[0],St(MBadArc),Str[0]);
break;
case UIERROR_CMTBROKEN:
Log(Str[0],St(MLogCommBrk));
break;
case UIERROR_INVALIDNAME:
Log(Str[0],St(MInvalidName),Str[1]);
mprintf(L"\n"); // Needed when called from CmdExtract::ExtractCurrentFile.
break;
#ifndef SFX_MODULE
case UIERROR_OPFAILED:
Log(NULL,St(MOpFailed));
break;
case UIERROR_NEWRARFORMAT:
Log(Str[0],St(MNewRarFormat));
break;
#endif
case UIERROR_NOFILESTOEXTRACT:
mprintf(St(MExtrNoFiles));
break;
case UIERROR_MISSINGVOL:
Log(Str[0],St(MAbsNextVol),Str[0]);
mprintf(L" "); // For progress percent.
break;
#ifndef SFX_MODULE
case UIERROR_NEEDPREVVOL:
Log(Str[0],St(MUnpCannotMerge),Str[1]);
break;
case UIERROR_UNKNOWNEXTRA:
Log(Str[0],St(MUnknownExtra),Str[1]);
break;
case UIERROR_CORRUPTEXTRA:
Log(Str[0],St(MCorruptExtra),Str[1],Str[2]);
break;
#endif
#if !defined(SFX_MODULE) && defined(_WIN_ALL)
case UIERROR_NTFSREQUIRED:
Log(NULL,St(MNTFSRequired),Str[0]);
break;
#endif
#if !defined(SFX_MODULE) && defined(_WIN_ALL)
case UIERROR_ACLBROKEN:
Log(Str[0],St(MACLBroken),Str[1]);
break;
case UIERROR_ACLUNKNOWN:
Log(Str[0],St(MACLUnknown),Str[1]);
break;
case UIERROR_ACLSET:
Log(Str[0],St(MACLSetError),Str[1]);
break;
case UIERROR_STREAMBROKEN:
Log(Str[0],St(MStreamBroken),Str[1]);
break;
case UIERROR_STREAMUNKNOWN:
Log(Str[0],St(MStreamUnknown),Str[1]);
break;
#endif
case UIERROR_INCOMPATSWITCH:
mprintf(St(MIncompatSwitch),Str[0],Num[0]);
break;
case UIERROR_PATHTOOLONG:
Log(NULL,L"\n%ls%ls%ls",Str[0],Str[1],Str[2]);
Log(NULL,St(MPathTooLong));
break;
#ifndef SFX_MODULE
case UIERROR_DIRSCAN:
Log(NULL,St(MScanError),Str[0]);
break;
#endif
case UIERROR_UOWNERBROKEN:
Log(Str[0],St(MOwnersBroken),Str[1]);
break;
case UIERROR_UOWNERGETOWNERID:
Log(Str[0],St(MErrGetOwnerID),Str[1]);
break;
case UIERROR_UOWNERGETGROUPID:
Log(Str[0],St(MErrGetGroupID),Str[1]);
break;
case UIERROR_UOWNERSET:
Log(Str[0],St(MSetOwnersError),Str[1]);
break;
case UIERROR_ULINKREAD:
Log(NULL,St(MErrLnkRead),Str[0]);
break;
case UIERROR_ULINKEXIST:
Log(NULL,St(MSymLinkExists),Str[0]);
break;
case UIERROR_READERRTRUNCATED:
Log(NULL,St(MErrReadTrunc),Str[0]);
break;
case UIERROR_READERRCOUNT:
Log(NULL,St(MErrReadCount),Num[0]);
break;
case UIERROR_DIRNAMEEXISTS:
Log(NULL,St(MDirNameExists));
break;
case UIERROR_TRUNCPSW:
eprintf(St(MTruncPsw),Num[0]);
eprintf(L"\n");
break;
case UIERROR_ADJUSTVALUE:
Log(NULL,St(MAdjustValue),Str[0],Str[1]);
break;
case UIERROR_SKIPUNSAFELINK:
Log(NULL,St(MSkipUnsafeLink),Str[0],Str[1]);
break;
#ifndef SFX_MODULE
case UIMSG_STRING:
mprintf(L"\n%s",Str[0]);
break;
#endif
case UIMSG_CORRECTINGNAME:
Log(Str[0],St(MCorrectingName));
break;
case UIMSG_BADARCHIVE:
mprintf(St(MBadArc),Str[0]);
break;
case UIMSG_CREATING:
mprintf(St(MCreating),Str[0]);
break;
case UIMSG_RENAMING:
mprintf(St(MRenaming),Str[0],Str[1]);
break;
case UIMSG_RECVOLCALCCHECKSUM:
mprintf(St(MCalcCRCAllVol));
break;
case UIMSG_RECVOLFOUND:
mprintf(St(MRecVolFound),Num[0]);
break;
case UIMSG_RECVOLMISSING:
mprintf(St(MRecVolMissing),Num[0]);
break;
case UIMSG_MISSINGVOL:
mprintf(St(MAbsNextVol),Str[0]);
break;
case UIMSG_RECONSTRUCTING:
mprintf(St(MReconstructing));
break;
case UIMSG_CHECKSUM:
mprintf(St(MCRCFailed),Str[0]);
break;
case UIMSG_FAT32SIZE:
mprintf(St(MFAT32Size));
mprintf(L" "); // For progress percent.
break;
case UIMSG_SKIPENCARC:
Log(NULL,St(MSkipEncArc),Str[0]);
break;
case UIEVENT_RRTESTINGSTART:
mprintf(L"%s ",St(MTestingRR));
break;
}
}
bool uiGetPassword(UIPASSWORD_TYPE Type,const std::wstring &FileName,
SecPassword *Password,CheckPassword *CheckPwd)
{
// Unlike GUI we cannot provide Cancel button here, so we use the empty
// password to abort. Otherwise user not knowing a password would need to
// press Ctrl+C multiple times to quit from infinite password request loop.
return GetConsolePassword(Type,FileName,Password) && Password->IsSet();
}
bool uiIsGlobalPasswordSet()
{
return false;
}
void uiAlarm(UIALARM_TYPE Type)
{
if (uiSoundNotify==SOUND_NOTIFY_ON)
{
static clock_t LastTime=-10; // Negative to always beep first time.
if ((MonoClock()-LastTime)/CLOCKS_PER_SEC>5)
{
#ifdef _WIN_ALL
MessageBeep(-1);
#else
putwchar('\007');
#endif
LastTime=MonoClock();
}
}
}
bool uiAskNextVolume(std::wstring &VolName)
{
eprintf(St(MAskNextVol),VolName.c_str());
return Ask(St(MContinueQuit))!=2;
}
void uiAskRepeatRead(const std::wstring &FileName,bool &Ignore,bool &All,bool &Retry,bool &Quit)
{
eprintf(St(MErrReadInfo));
int Code=Ask(St(MIgnoreAllRetryQuit));
Ignore=(Code==1);
All=(Code==2);
Quit=(Code==4);
Retry=!Ignore && !All && !Quit; // Default also for invalid input, not just for 'Retry'.
}
bool uiAskRepeatWrite(const std::wstring &FileName,bool DiskFull)
{
mprintf(L"\n");
Log(NULL,St(DiskFull ? MNotEnoughDisk:MErrWrite),FileName.c_str());
return Ask(St(MRetryAbort))==1;
}
bool uiDictLimit(CommandData *Cmd,const std::wstring &FileName,uint64 DictSize,uint64 MaxDictSize)
{
mprintf(L"\n%s",FileName.c_str());
const uint64 GB=1024*1024*1024; // We display sizes in GB here.
// Include the reminder for switches like -md6400m.
DictSize=DictSize/GB+(DictSize%GB!=0 ? 1:0);
// Exclude reminder for in case it is less than archive dictionary size,
// but still more than nearest GB value. Otherwise we could have message
// like "7 GB dictionary exceeds 7 GB limit", where first 7 might be actually
// 6272 MB and second is 6400 MB.
MaxDictSize/=GB;
mprintf(St(MDictNotAllowed),(uint)DictSize,(uint)MaxDictSize,(uint)DictSize);
mprintf(St(MDictExtrAnyway),(uint)DictSize,(uint)DictSize);
mprintf(L"\n");
return false; // Stop extracting.
}
#ifndef SFX_MODULE
const wchar *uiGetMonthName(uint Month)
{
static MSGID MonthID[12]={
MMonthJan,MMonthFeb,MMonthMar,MMonthApr,MMonthMay,MMonthJun,
MMonthJul,MMonthAug,MMonthSep,MMonthOct,MMonthNov,MMonthDec
};
return St(MonthID[Month]);
}
#endif
void uiEolAfterMsg()
{
if (AnyMessageDisplayed)
{
// Avoid deleting several last characters of any previous error message
// with percentage indicator in -idn mode.
AnyMessageDisplayed=false;
mprintf(L"\n");
}
}
|