UserInputUtils.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // UserInputUtils.cpp
  2. #include "StdAfx.h"
  3. #include "Common/StdInStream.h"
  4. #include "Common/StringConvert.h"
  5. #include "UserInputUtils.h"
  6. static const char kYes = 'Y';
  7. static const char kNo = 'N';
  8. static const char kYesAll = 'A';
  9. static const char kNoAll = 'S';
  10. static const char kAutoRename = 'U';
  11. static const char kQuit = 'Q';
  12. static const char *kFirstQuestionMessage = "?\n";
  13. static const char *kHelpQuestionMessage =
  14. "(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename / (Q)uit? ";
  15. // return true if pressed Quite;
  16. // in: anAll
  17. // out: anAll, anYes;
  18. NUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream)
  19. {
  20. (*outStream) << kFirstQuestionMessage;
  21. for(;;)
  22. {
  23. (*outStream) << kHelpQuestionMessage;
  24. AString scannedString = g_StdIn.ScanStringUntilNewLine();
  25. scannedString.Trim();
  26. if(!scannedString.IsEmpty())
  27. switch(::MyCharUpper(scannedString[0]))
  28. {
  29. case kYes:
  30. return NUserAnswerMode::kYes;
  31. case kNo:
  32. return NUserAnswerMode::kNo;
  33. case kYesAll:
  34. return NUserAnswerMode::kYesAll;
  35. case kNoAll:
  36. return NUserAnswerMode::kNoAll;
  37. case kAutoRename:
  38. return NUserAnswerMode::kAutoRename;
  39. case kQuit:
  40. return NUserAnswerMode::kQuit;
  41. }
  42. }
  43. }
  44. UString GetPassword(CStdOutStream *outStream)
  45. {
  46. (*outStream) << "\nEnter password:";
  47. outStream->Flush();
  48. AString oemPassword = g_StdIn.ScanStringUntilNewLine();
  49. return MultiByteToUnicodeString(oemPassword, CP_OEMCP);
  50. }