diff options
author | kh1 <karsten.heimrich@nokia.com> | 2012-03-15 14:53:47 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@nokia.com> | 2012-03-19 16:14:04 +0100 |
commit | be3b47d0d504a3409ce66bd77bb8c0acff87c4f5 (patch) | |
tree | 09dfb02d484a4f395991972b828da71400fb761a /src/libs/7zip/unix/CPP/7zip/UI/Console/UserInputUtils.cpp | |
parent | 9fd62353cf7f973d78cd2093328ac15b5c4980b6 (diff) |
Reorganize the tree, have better ifw.pri. Shadow build support.
Change-Id: I01fb12537f863ed0744979973c7e4153889cc5cb
Reviewed-by: Tim Jenssen <tim.jenssen@nokia.com>
Diffstat (limited to 'src/libs/7zip/unix/CPP/7zip/UI/Console/UserInputUtils.cpp')
-rw-r--r-- | src/libs/7zip/unix/CPP/7zip/UI/Console/UserInputUtils.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/UserInputUtils.cpp b/src/libs/7zip/unix/CPP/7zip/UI/Console/UserInputUtils.cpp new file mode 100644 index 000000000..4733e4ffb --- /dev/null +++ b/src/libs/7zip/unix/CPP/7zip/UI/Console/UserInputUtils.cpp @@ -0,0 +1,96 @@ +// UserInputUtils.cpp + +#include "StdAfx.h" + +#include "Common/StdInStream.h" +#include "Common/StringConvert.h" + +#include "UserInputUtils.h" + +#ifdef USE_FLTK +// the programs like file-roller or xarchiver do not support archives with password +// these programs freeze because p7zip is waiting for a password +// defining USE_FLTK allows p7zip to use a popup in order to ask the password. +#include <FL/Fl.H> +#include <FL/Fl_Window.H> +#include <FL/fl_ask.H> +#else +#ifdef ENV_HAVE_GETPASS +#include <pwd.h> +#include <unistd.h> +#include "Common/MyException.h" +#endif +#endif + +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; + } + } +} + +UString GetPassword(CStdOutStream *outStream,bool verify) +{ +#ifdef USE_FLTK + const char *r = fl_password("Enter password", 0); + AString oemPassword = ""; + if (r) oemPassword = r; +#else /* USE_FLTK */ +#ifdef ENV_HAVE_GETPASS + (*outStream) << "\nEnter password (will not be echoed) :"; + outStream->Flush(); + AString oemPassword = getpass(""); + if (verify) + { + (*outStream) << "Verify password (will not be echoed) :"; + outStream->Flush(); + AString oemPassword2 = getpass(""); + if (oemPassword != oemPassword2) throw "password verification failed"; + } +#else + (*outStream) << "\nEnter password:"; + outStream->Flush(); + AString oemPassword = g_StdIn.ScanStringUntilNewLine(); +#endif +#endif /* USE_FLTK */ + return MultiByteToUnicodeString(oemPassword, CP_OEMCP); +} |