Skip to content

Commit 5fce38e

Browse files
committed
Merge branch 'develop'
2 parents 4abce77 + 5f1b927 commit 5fce38e

15 files changed

Lines changed: 146 additions & 77 deletions

File tree

contrib/epee/include/file_io_utils.h

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
#include <iostream>
3636
#include <boost/filesystem.hpp>
37-
37+
#include <boost/filesystem/fstream.hpp>
3838

3939
#ifndef MAKE64
4040
#define MAKE64(low,high) ((__int64)(((DWORD)(low)) | ((__int64)((DWORD)(high))) << 32))
@@ -261,15 +261,14 @@ namespace file_io_utils
261261
typedef int native_filesystem_handle;
262262
#endif
263263

264-
265264
inline
266265
bool save_string_to_file(const std::string& path_to_file, const std::string& str)
267266
{
268267

269268
try
270269
{
271270
std::ofstream fstream;
272-
fstream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
271+
fstream.exceptions(std::ofstream::failbit | std::ofstream::badbit);
273272
fstream.open(path_to_file, std::ios_base::binary | std::ios_base::out | std::ios_base::trunc);
274273
fstream << str;
275274
fstream.close();
@@ -282,7 +281,25 @@ namespace file_io_utils
282281
}
283282
}
284283

284+
inline bool save_string_to_file(const std::wstring& path_to_file, const std::string& str)
285+
{
285286

287+
try
288+
{
289+
boost::filesystem::ofstream fstream;
290+
fstream.exceptions(boost::filesystem::ofstream::failbit | boost::filesystem::ofstream::badbit);
291+
fstream.open(path_to_file, std::ios_base::binary | std::ios_base::out | std::ios_base::trunc);
292+
fstream << str;
293+
fstream.close();
294+
return true;
295+
}
296+
297+
catch (...)
298+
{
299+
return false;
300+
}
301+
}
302+
286303

287304
inline
288305
bool save_buff_to_file(const std::string& path_to_file, const void* pbuff, size_t counter)
@@ -352,7 +369,6 @@ namespace file_io_utils
352369
return false;
353370
}
354371

355-
356372
inline
357373
bool load_file_to_string(const std::string& path_to_file, std::string& target_str)
358374
{
@@ -382,6 +398,34 @@ namespace file_io_utils
382398
}
383399
}
384400

401+
inline bool load_file_to_string(const std::wstring& path_to_file, std::string& target_str)
402+
{
403+
try
404+
{
405+
boost::filesystem::ifstream fstream;
406+
fstream.exceptions(boost::filesystem::ifstream::failbit | boost::filesystem::ifstream::badbit);
407+
fstream.open(path_to_file, std::ios_base::binary | std::ios_base::in | std::ios::ate);
408+
409+
boost::filesystem::ifstream::pos_type file_size = fstream.tellg();
410+
411+
if (file_size > 1000000000)
412+
return false;//don't go crazy
413+
size_t file_size_t = static_cast<size_t>(file_size);
414+
415+
target_str.resize(file_size_t);
416+
417+
fstream.seekg(0, std::ios::beg);
418+
fstream.read((char*)target_str.data(), target_str.size());
419+
fstream.close();
420+
return true;
421+
}
422+
423+
catch (...)
424+
{
425+
return false;
426+
}
427+
}
428+
385429
template<class t_value>
386430
bool load_file_to_vector(const std::string& path_to_file, std::vector<t_value>& res)
387431
{

contrib/epee/include/string_coding.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ namespace epee
3535
{
3636
namespace string_encoding
3737
{
38+
39+
inline std::wstring utf8_to_wstring(const std::string& str)
40+
{
41+
return boost::locale::conv::utf_to_utf<wchar_t>(str.c_str(), str.c_str() + str.size());
42+
}
43+
3844
inline std::string wstring_to_utf8(const std::wstring& str)
3945
{
4046
return boost::locale::conv::utf_to_utf<char>(str.c_str(), str.c_str() + str.size());

contrib/epee/include/string_tools.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,18 @@ POP_WARNINGS
602602
return res;
603603
}
604604
//----------------------------------------------------------------------------
605-
inline std::string get_filename_from_path(const std::string& str)
605+
inline std::wstring get_extension(const std::wstring& str)
606+
{
607+
std::wstring res;
608+
std::wstring::size_type pos = str.rfind('.');
609+
if (std::wstring::npos == pos)
610+
return res;
611+
612+
res = str.substr(pos + 1, str.size() - pos);
613+
return res;
614+
}
615+
//----------------------------------------------------------------------------
616+
inline std::string get_filename_from_path(const std::string& str)
606617
{
607618
std::string res;
608619
std::string::size_type pos = str.rfind('\\');
@@ -613,9 +624,6 @@ POP_WARNINGS
613624
return res;
614625
}
615626
//----------------------------------------------------------------------------
616-
617-
618-
619627
inline std::string cut_off_extension(const std::string& str)
620628
{
621629
std::string res;
@@ -626,8 +634,18 @@ POP_WARNINGS
626634
res = str.substr(0, pos);
627635
return res;
628636
}
637+
//----------------------------------------------------------------------------
638+
inline std::wstring cut_off_extension(const std::wstring& str)
639+
{
640+
std::wstring res;
641+
std::wstring::size_type pos = str.rfind('.');
642+
if (std::wstring::npos == pos)
643+
return str;
629644

630-
//----------------------------------------------------------------------------
645+
res = str.substr(0, pos);
646+
return res;
647+
}
648+
//----------------------------------------------------------------------------
631649
#ifdef _WININET_
632650
inline std::string get_string_from_systemtime(const SYSTEMTIME& sys_time)
633651
{

src/common/boost_serialization_helper.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66

77
#include <boost/archive/binary_oarchive.hpp>
88
#include <boost/archive/binary_iarchive.hpp>
9-
9+
#include <boost/filesystem/fstream.hpp>
1010

1111
#define CHECK_PROJECT_NAME() std::string project_name = CURRENCY_NAME; ar & project_name; if(project_name != CURRENCY_NAME) {throw std::runtime_error(std::string("wrong storage file: project name in file: ") + project_name + ", expected: " + CURRENCY_NAME );}
1212

1313

1414
namespace tools
1515
{
16-
template<class t_object>
17-
bool serialize_obj_to_file(t_object& obj, const std::string& file_path)
16+
template<class t_object, class t_string>
17+
bool serialize_obj_to_file(t_object& obj, const t_string& file_path)
1818
{
1919
TRY_ENTRY();
20-
std::ofstream data_file;
20+
boost::filesystem::ofstream data_file;
2121
data_file.open( file_path , std::ios_base::binary | std::ios_base::out| std::ios::trunc);
2222
if(data_file.fail())
2323
return false;
@@ -29,12 +29,12 @@ namespace tools
2929
CATCH_ENTRY_L0("serialize_obj_to_file", false);
3030
}
3131

32-
template<class t_object>
33-
bool unserialize_obj_from_file(t_object& obj, const std::string& file_path)
32+
template<class t_object, class t_string>
33+
bool unserialize_obj_from_file(t_object& obj, const t_string& file_path)
3434
{
3535
TRY_ENTRY();
3636

37-
std::ifstream data_file;
37+
boost::filesystem::ifstream data_file;
3838
data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
3939
if(data_file.fail())
4040
return false;

src/currency_core/currency_format_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ namespace currency
12471247
txin_to_key& tk = boost::get<txin_to_key>(in);
12481248
tei.ins.back().amount = tk.amount;
12491249
tei.ins.back().kimage_or_ms_id = epee::string_tools::pod_to_hex(tk.k_image);
1250-
std::vector<size_t> absolute_offsets = relative_output_offsets_to_absolute(tk.key_offsets);
1250+
std::vector<uint64_t> absolute_offsets = relative_output_offsets_to_absolute(tk.key_offsets);
12511251
for (auto& ao : absolute_offsets)
12521252
{
12531253
tei.ins.back().global_indexes.push_back(0);

src/gui/qt-daemon/html5applicationviewer/daemon_backend.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "currency_core/alias_helper.h"
88
#include "crypto/mnemonic-encoding.h"
99
#include "common/pre_download.h"
10+
#include "string_coding.h"
1011

1112
daemon_backend::daemon_backend():m_pview(&m_view_stub),
1213
m_stop_singal_sent(false),
@@ -487,7 +488,7 @@ void daemon_backend::loop()
487488
}
488489
}
489490

490-
bool daemon_backend::open_wallet(const std::string& path, const std::string& password)
491+
bool daemon_backend::open_wallet(const std::wstring& path, const std::string& password)
491492
{
492493
CRITICAL_REGION_LOCAL(m_wallet_lock);
493494
try
@@ -534,8 +535,7 @@ bool daemon_backend::load_recent_transfers()
534535
return m_pview->set_recent_transfers(tr_hist);
535536
}
536537

537-
bool daemon_backend::generate_wallet(const std::string& path,
538-
const std::string& password, std::string& restore_seed)
538+
bool daemon_backend::generate_wallet(const std::wstring& path, const std::string& password, std::string& restore_seed)
539539
{
540540
CRITICAL_REGION_LOCAL(m_wallet_lock);
541541
try
@@ -565,8 +565,7 @@ bool daemon_backend::generate_wallet(const std::string& path,
565565

566566
}
567567

568-
bool daemon_backend::restore_wallet(const std::string& path,
569-
const std::string& restore_text, const std::string& password)
568+
bool daemon_backend::restore_wallet(const std::wstring& path, const std::string& restore_text, const std::string& password)
570569
{
571570
CRITICAL_REGION_LOCAL(m_wallet_lock);
572571
try
@@ -752,7 +751,7 @@ bool daemon_backend::update_wallet_info()
752751
wi.balance = m_wallet->balance();
753752
wi.unlocked_balance = m_wallet->unlocked_balance();
754753
wi.unconfirmed_balance = m_wallet->unconfirmed_balance();
755-
wi.path = m_wallet->get_wallet_path();
754+
wi.path = epee::string_encoding::wstring_to_utf8(m_wallet->get_wallet_path());
756755
m_pview->update_wallet_info(wi);
757756
return true;
758757
}

src/gui/qt-daemon/html5applicationviewer/daemon_backend.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ class daemon_backend : public tools::i_wallet2_callback
4545
bool start(int argc, char* argv[], view::i_view* pview_handler);
4646
bool stop();
4747
bool send_stop_signal();
48-
bool open_wallet(const std::string& path, const std::string& password);
49-
bool generate_wallet(const std::string& path, const std::string& password,
50-
std::string& restore_seed);
51-
bool restore_wallet(const std::string& path, const std::string& restore_text,
52-
const std::string& password);
48+
bool open_wallet(const std::wstring& path, const std::string& password);
49+
bool generate_wallet(const std::wstring& path, const std::string& password, std::string& restore_seed);
50+
bool restore_wallet(const std::wstring& path, const std::string& restore_text, const std::string& password);
5351
bool close_wallet();
5452
bool transfer(const view::transfer_params& tp, currency::transaction& res_tx);
5553
bool get_aliases(view::alias_set& al_set);

src/gui/qt-daemon/html5applicationviewer/html5applicationviewer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <QClipboard>
2525
#include "warnings.h"
2626
#include "net/http_client.h"
27+
#include "string_coding.h"
2728

2829
Html5ApplicationViewer::Html5ApplicationViewer():
2930
m_quit_requested(false),
@@ -541,7 +542,7 @@ QString Html5ApplicationViewer::generate_wallet()
541542
return QString();
542543

543544
std::string seed; //not used yet
544-
m_backend.generate_wallet(path.toStdString(), pass.toStdString(), seed);
545+
m_backend.generate_wallet(epee::string_encoding::utf8_to_wstring(path.toStdString()), pass.toStdString(), seed);
545546
QString res = seed.c_str();
546547
//
547548
// QString message = "This is your wallet seed phrase:\n\n";
@@ -589,7 +590,7 @@ bool Html5ApplicationViewer::restore_wallet(const QString& restore_text, const Q
589590

590591
m_config.wallets_last_used_dir = boost::filesystem::path(path.toStdString()).parent_path().string();
591592

592-
return m_backend.restore_wallet(path.toStdString(), restore_text.toStdString(), password.toStdString());
593+
return m_backend.restore_wallet(epee::string_encoding::utf8_to_wstring(path.toStdString()), restore_text.toStdString(), password.toStdString());
593594
}
594595

595596
void Html5ApplicationViewer::place_to_clipboard(const QString& data)
@@ -655,7 +656,7 @@ void Html5ApplicationViewer::open_wallet()
655656
if (!ok)
656657
return;
657658

658-
m_backend.open_wallet(path.toStdString(), pass.toStdString());
659+
m_backend.open_wallet(epee::string_encoding::utf8_to_wstring(path.toStdString()), pass.toStdString());
659660
}
660661

661662
QString Html5ApplicationViewer::get_gui_lang()

src/simplewallet/simplewallet.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "wallet/wallet_rpc_server.h"
1919
#include "crypto/mnemonic-encoding.h"
2020
#include "version.h"
21+
#include "string_coding.h"
2122

2223
#if defined(WIN32)
2324
#include <crtdbg.h>
@@ -337,7 +338,7 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas
337338
std::vector<unsigned char> restore_seed;
338339
try
339340
{
340-
restore_seed = m_wallet->generate(wallet_file, password);
341+
restore_seed = m_wallet->generate(string_encoding::convert_to_unicode(wallet_file), password);
341342
message_writer(epee::log_space::console_color_white, true) << "Generated new wallet: " << m_wallet->get_account().get_public_address_str();
342343
std::cout << "view key: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key) << std::endl << std::flush;
343344
}
@@ -375,7 +376,7 @@ bool simple_wallet::restore_wallet(const std::string &wallet_file, const std::st
375376
try
376377
{
377378
std::vector<unsigned char> seed = crypto::mnemonic_encoding::text2binary(restore_seed);
378-
m_wallet->restore(wallet_file, seed, password);
379+
m_wallet->restore(epee::string_encoding::convert_to_unicode(wallet_file), seed, password);
379380
message_writer(epee::log_space::console_color_white, true) << "Wallet restored: " << m_wallet->get_account().get_public_address_str();
380381
std::cout << "view key: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key) << std::endl << std::flush;
381382
}
@@ -408,7 +409,7 @@ bool simple_wallet::open_wallet(const string &wallet_file, const std::string& pa
408409

409410
try
410411
{
411-
m_wallet->load(m_wallet_file, password);
412+
m_wallet->load(epee::string_encoding::convert_to_unicode(m_wallet_file), password);
412413
message_writer(epee::log_space::console_color_white, true) << "Opened wallet" << (m_wallet->is_view_only() ? "watch-only" : "" ) << ": " << m_wallet->get_account().get_public_address_str();
413414
}
414415
catch (const std::exception& e)
@@ -1042,7 +1043,7 @@ bool simple_wallet::save_watch_only(const std::vector<std::string> &args)
10421043
}
10431044
try
10441045
{
1045-
m_wallet->store_keys(args[0], args[1], true);
1046+
m_wallet->store_keys(string_encoding::convert_to_unicode(args[0]), args[1], true);
10461047
success_msg_writer() << "Keys stored to " << args[0];
10471048
}
10481049
catch (const std::exception& e)
@@ -1825,7 +1826,7 @@ int main(int argc, char* argv[])
18251826
try
18261827
{
18271828
LOG_PRINT_L0("Loading wallet...");
1828-
wal.load(wallet_file, wallet_password);
1829+
wal.load(string_encoding::convert_to_unicode(wallet_file), wallet_password);
18291830
wal.init(daemon_address);
18301831
if (!offline_mode)
18311832
wal.refresh();

0 commit comments

Comments
 (0)