bool GetConsolePassword(UIPASSWORD_TYPE Type,const wchar *FileName,SecPassword *Password) { uiAlarm(UIALARM_QUESTION); while (true) { if (Type==UIPASSWORD_GLOBAL) eprintf(L"\n%s: ",St(MAskPsw)); else eprintf(St(MAskPswFor),FileName); wchar PlainPsw[MAXPASSWORD]; GetPasswordText(PlainPsw,ASIZE(PlainPsw)); if (*PlainPsw==0 && Type==UIPASSWORD_GLOBAL) return false; if (Type==UIPASSWORD_GLOBAL) { eprintf(St(MReAskPsw)); wchar CmpStr[MAXPASSWORD]; GetPasswordText(CmpStr,ASIZE(CmpStr)); if (*CmpStr==0 || wcscmp(PlainPsw,CmpStr)!=0) { eprintf(St(MNotMatchPsw)); cleandata(PlainPsw,sizeof(PlainPsw)); cleandata(CmpStr,sizeof(CmpStr)); continue; } cleandata(CmpStr,sizeof(CmpStr)); } Password->Set(PlainPsw); cleandata(PlainPsw,sizeof(PlainPsw)); break; } return true; }
// We allow this function to return 0 in case of invalid input, // because it might be convenient to press Enter to some not dangerous // prompts like "insert disk with next volume". We should call this function // again in case of 0 in dangerous prompt such as overwriting file. int Ask(const wchar *AskStr) { uiAlarm(UIALARM_QUESTION); const int MaxItems=10; wchar Item[MaxItems][40]; int ItemKeyPos[MaxItems],NumItems=0; for (const wchar *NextItem=AskStr;NextItem!=NULL;NextItem=wcschr(NextItem+1,'_')) { wchar *CurItem=Item[NumItems]; wcsncpyz(CurItem,NextItem+1,ASIZE(Item[0])); wchar *EndItem=wcschr(CurItem,'_'); if (EndItem!=NULL) *EndItem=0; int KeyPos=0,CurKey; while ((CurKey=CurItem[KeyPos])!=0) { bool Found=false; for (int I=0;I<NumItems && !Found;I++) if (toupperw(Item[I][ItemKeyPos[I]])==toupperw(CurKey)) Found=true; if (!Found && CurKey!=' ') break; KeyPos++; } ItemKeyPos[NumItems]=KeyPos; NumItems++; } for (int I=0;I<NumItems;I++) { eprintf(I==0 ? (NumItems>4 ? L"\n":L" "):L", "); int KeyPos=ItemKeyPos[I]; for (int J=0;J<KeyPos;J++) eprintf(L"%c",Item[I][J]); eprintf(L"[%c]%ls",Item[I][KeyPos],&Item[I][KeyPos+1]); } eprintf(L" "); wchar Str[50]; getwstr(Str,ASIZE(Str)); wchar Ch=toupperw(Str[0]); for (int I=0;I<NumItems;I++) if (Ch==Item[I][ItemKeyPos[I]]) return I+1; return 0; }
void ErrorHandler::Exit(RAR_EXIT ExitCode) { uiAlarm(UIALARM_ERROR); Throw(ExitCode); }