aboutsummaryrefslogtreecommitdiff
path: root/src/simplewallet/simplewallet.cpp
diff options
context:
space:
mode:
authorrbrunner7 <rbrunner@dreamshare.ch>2018-02-22 19:52:55 +0100
committerrbrunner7 <rbrunner@dreamshare.ch>2018-02-25 12:57:58 +0100
commit430268224d71bfc6a359f20c6db712462ce0bb25 (patch)
treef095671ade4fa74e93fac65a442cb7c4c587f812 /src/simplewallet/simplewallet.cpp
parentMerge pull request #3245 (diff)
downloadmonero-430268224d71bfc6a359f20c6db712462ce0bb25.tar.xz
Wallet2 + CLI wallet: UTF-8 support for filenames and paths under Windows
Diffstat (limited to 'src/simplewallet/simplewallet.cpp')
-rw-r--r--src/simplewallet/simplewallet.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index c67a6bc6c..958fe5edc 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -64,6 +64,11 @@
#include "wallet/wallet_args.h"
#include <stdexcept>
+#ifdef WIN32
+#include <boost/locale.hpp>
+#include <boost/filesystem.hpp>
+#endif
+
#ifdef HAVE_READLINE
#include "readline_buffer.h"
#endif
@@ -130,6 +135,28 @@ namespace
const command_line::arg_descriptor< std::vector<std::string> > arg_command = {"command", ""};
+#ifdef WIN32
+ // Translate from CP850 to UTF-8;
+ // std::getline for a Windows console returns a string in CP437 or CP850; as simplewallet,
+ // like all of Monero, is assumed to work internally with UTF-8 throughout, even on Windows
+ // (although only implemented partially), a translation to UTF-8 is needed for input.
+ //
+ // Note that if a program is started inside the MSYS2 shell somebody already translates
+ // console input to UTF-8, but it's not clear how one could detect that in order to avoid
+ // double-translation; this code here thus breaks UTF-8 input within a MSYS2 shell,
+ // unfortunately.
+ //
+ // Note also that input for passwords is NOT translated, to remain compatible with any
+ // passwords containing special characters that predate this switch to UTF-8 support.
+ static std::string cp850_to_utf8(const std::string &cp850_str)
+ {
+ boost::locale::generator gen;
+ gen.locale_cache_enabled(true);
+ std::locale loc = gen("en_US.CP850");
+ return boost::locale::conv::to_utf<char>(cp850_str, loc);
+ }
+#endif
+
std::string input_line(const std::string& prompt)
{
#ifdef HAVE_READLINE
@@ -139,6 +166,9 @@ namespace
std::string buf;
std::getline(std::cin, buf);
+#ifdef WIN32
+ buf = cp850_to_utf8(buf);
+#endif
return epee::string_tools::trim(buf);
}
@@ -6751,6 +6781,12 @@ void simple_wallet::commit_or_save(std::vector<tools::wallet2::pending_tx>& ptx_
//----------------------------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
+#ifdef WIN32
+ // Activate UTF-8 support for Boost filesystem classes on Windows
+ std::locale::global(boost::locale::generator().generate(""));
+ boost::filesystem::path::imbue(std::locale());
+#endif
+
po::options_description desc_params(wallet_args::tr("Wallet options"));
tools::wallet2::init_options(desc_params);
command_line::add_arg(desc_params, arg_wallet_file);