diff options
author | 2015-01-11 08:10:25 +0100 | |
---|---|---|
committer | 2015-01-11 08:10:25 +0100 | |
commit | 6a23c2f3b766cf4fc7028628f76b5ff9396383f0 (patch) | |
tree | a01e16637118ae0c80f337119898bdf18f081e24 /3rdparty/lzma/CPP/7zip/UI/Console/UserInputUtils.cpp | |
parent | 45ac9b351e0076c371de4c7453f59567b27b1cb6 (diff) |
Added full lzma sdk source (nw)
Diffstat (limited to '3rdparty/lzma/CPP/7zip/UI/Console/UserInputUtils.cpp')
-rw-r--r-- | 3rdparty/lzma/CPP/7zip/UI/Console/UserInputUtils.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/3rdparty/lzma/CPP/7zip/UI/Console/UserInputUtils.cpp b/3rdparty/lzma/CPP/7zip/UI/Console/UserInputUtils.cpp new file mode 100644 index 00000000000..754680090bc --- /dev/null +++ b/3rdparty/lzma/CPP/7zip/UI/Console/UserInputUtils.cpp @@ -0,0 +1,87 @@ +// UserInputUtils.cpp + +#include "StdAfx.h" + +#include "Common/StdInStream.h" +#include "Common/StringConvert.h" + +#include "UserInputUtils.h" + +static const char kYes = 'Y'; +static const char kNo = 'N'; +static const char kYesAll = 'A'; +static const char kNoAll = 'S'; +static const char kAutoRenameAll = 'U'; +static const char kQuit = 'Q'; + +static const char *kFirstQuestionMessage = "?\n"; +static const char *kHelpQuestionMessage = + "(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename all / (Q)uit? "; + +// return true if pressed Quite; + +NUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream) +{ + (*outStream) << kFirstQuestionMessage; + for (;;) + { + (*outStream) << kHelpQuestionMessage; + outStream->Flush(); + AString scannedString = g_StdIn.ScanStringUntilNewLine(); + scannedString.Trim(); + if (!scannedString.IsEmpty()) + switch( + ::MyCharUpper( + #ifdef UNDER_CE + (wchar_t) + #endif + scannedString[0])) + { + case kYes: + return NUserAnswerMode::kYes; + case kNo: + return NUserAnswerMode::kNo; + case kYesAll: + return NUserAnswerMode::kYesAll; + case kNoAll: + return NUserAnswerMode::kNoAll; + case kAutoRenameAll: + return NUserAnswerMode::kAutoRenameAll; + case kQuit: + return NUserAnswerMode::kQuit; + } + } +} + +#ifdef _WIN32 +#ifndef UNDER_CE +#define MY_DISABLE_ECHO +#endif +#endif + +UString GetPassword(CStdOutStream *outStream) +{ + (*outStream) << "\nEnter password" + #ifdef MY_DISABLE_ECHO + " (will not be echoed)" + #endif + ":"; + outStream->Flush(); + + #ifdef MY_DISABLE_ECHO + HANDLE console = GetStdHandle(STD_INPUT_HANDLE); + bool wasChanged = false; + DWORD mode = 0; + if (console != INVALID_HANDLE_VALUE && console != 0) + if (GetConsoleMode(console, &mode)) + wasChanged = (SetConsoleMode(console, mode & ~ENABLE_ECHO_INPUT) != 0); + UString res = g_StdIn.ScanUStringUntilNewLine(); + if (wasChanged) + SetConsoleMode(console, mode); + (*outStream) << "\n"; + outStream->Flush(); + return res; + #else + return g_StdIn.ScanUStringUntilNewLine(); + #endif +} |