aboutsummaryrefslogtreecommitdiff
path: root/src/simplewallet/simplewallet.cpp
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2018-03-05 19:15:54 +0200
committerRiccardo Spagni <ric@spagni.net>2018-03-05 19:15:54 +0200
commit237f0179b70eb795772e815f2e9ff6f056f53c22 (patch)
tree8e2e88d92272256b65652e41a5cf56881cb85f30 /src/simplewallet/simplewallet.cpp
parentMerge pull request #3343 (diff)
parentWallet2 + CLI wallet: UTF-8 support for filenames and paths under Windows (diff)
downloadmonero-237f0179b70eb795772e815f2e9ff6f056f53c22.tar.xz
Merge pull request #3313
43026822 Wallet2 + CLI wallet: UTF-8 support for filenames and paths under Windows (rbrunner7)
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 c88505404..17c74fb0a 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -65,6 +65,11 @@
#include "device/device.hpp"
#include <stdexcept>
+#ifdef WIN32
+#include <boost/locale.hpp>
+#include <boost/filesystem.hpp>
+#endif
+
#ifdef HAVE_READLINE
#include "readline_buffer.h"
#endif
@@ -132,6 +137,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
@@ -141,6 +168,9 @@ namespace
std::string buf;
std::getline(std::cin, buf);
+#ifdef WIN32
+ buf = cp850_to_utf8(buf);
+#endif
return epee::string_tools::trim(buf);
}
@@ -6928,6 +6958,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);