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