forked from lthn/blockchain
filesystem unicode support: WIP2
This commit is contained in:
parent
7706f0d6ac
commit
ceb1739f23
2 changed files with 24 additions and 7 deletions
|
|
@ -695,7 +695,7 @@ namespace log_space
|
|||
class file_output_stream : public ibase_log_stream
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, std::ofstream*> named_log_streams;
|
||||
typedef std::map<std::string, boost::filesystem::ofstream*> named_log_streams;
|
||||
|
||||
file_output_stream( const std::string& default_log_file_name, const std::string& log_path )
|
||||
{
|
||||
|
|
@ -720,20 +720,21 @@ namespace log_space
|
|||
private:
|
||||
named_log_streams m_log_file_names;
|
||||
std::wstring m_default_log_path_w;
|
||||
std::ofstream* m_pdefault_file_stream;
|
||||
boost::filesystem::ofstream* m_pdefault_file_stream;
|
||||
std::string m_log_rotate_cmd;
|
||||
std::string m_default_log_filename;
|
||||
uint64_t m_max_logfile_size;
|
||||
|
||||
|
||||
// gets utf-8 encoded string
|
||||
std::ofstream* add_new_stream_and_open(const char* pstream_name)
|
||||
boost::filesystem::ofstream* add_new_stream_and_open(const char* pstream_name)
|
||||
{
|
||||
//log_space::rotate_log_file((m_default_log_path + "\\" + pstream_name).c_str());
|
||||
boost::system::error_code ec;
|
||||
boost::filesystem::create_directories(m_default_log_path_w, ec);
|
||||
std::ofstream* pstream = (m_log_file_names[pstream_name] = new std::ofstream);
|
||||
boost::filesystem::ofstream* pstream = (m_log_file_names[pstream_name] = new boost::filesystem::ofstream);
|
||||
std::wstring target_path = m_default_log_path_w + L"/" + epee::string_encoding::utf8_to_wstring(pstream_name);
|
||||
|
||||
pstream->open( target_path.c_str(), std::ios_base::out | std::ios::app /*ios_base::trunc */);
|
||||
if(pstream->fail())
|
||||
return NULL;
|
||||
|
|
@ -756,7 +757,7 @@ namespace log_space
|
|||
|
||||
virtual bool out_buffer( const char* buffer, int buffer_len, int log_level, int color, const char* plog_name = NULL )
|
||||
{
|
||||
std::ofstream* m_target_file_stream = m_pdefault_file_stream;
|
||||
boost::filesystem::ofstream* m_target_file_stream = m_pdefault_file_stream;
|
||||
if(plog_name)
|
||||
{ //find named stream
|
||||
named_log_streams::iterator it = m_log_file_names.find(plog_name);
|
||||
|
|
@ -774,7 +775,7 @@ namespace log_space
|
|||
/*
|
||||
if(m_max_logfile_size)
|
||||
{
|
||||
std::ofstream::pos_type pt = m_target_file_stream->tellp();
|
||||
boost::filesystem::ofstream::pos_type pt = m_target_file_stream->tellp();
|
||||
uint64_t current_sz = pt;
|
||||
if(current_sz > m_max_logfile_size)
|
||||
{
|
||||
|
|
@ -821,7 +822,8 @@ namespace log_space
|
|||
misc_utils::call_sys_cmd(m_log_rotate_cmd_local_copy);
|
||||
}
|
||||
|
||||
m_target_file_stream->open( (m_default_log_path + "/" + log_file_name).c_str(), std::ios_base::out | std::ios::app /*ios_base::trunc */);
|
||||
|
||||
m_target_file_stream->open( (m_default_log_path + "/" + log_file_name).c_str(), std::ios_base::out | std::ios::app / * ios_base::trunc * /);
|
||||
if(m_target_file_stream->fail())
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,6 +122,21 @@ int main(int argc, char* argv[])
|
|||
// setup custom terminate functions
|
||||
std::set_terminate(&terminate_handler_func);
|
||||
|
||||
////
|
||||
|
||||
std::string utf8_str = "\xd0\x92\xd0\xb0\xd1\x81\xd0\xb8\xd1\x81\xd1\x83\xd0\xb0\xd0\xbb\xd0\xb8\xd1\x9d";
|
||||
|
||||
boost::system::error_code ec;
|
||||
|
||||
boost::filesystem::create_directory(boost::filesystem::path(epee::string_encoding::utf8_to_wstring(std::string("utf8_to_wstring_") + utf8_str)), ec);
|
||||
std::cout << "utf8_to_wstring: ec = " << ec << std::endl;
|
||||
|
||||
boost::filesystem::create_directory(boost::filesystem::path(std::string("utf8_") + utf8_str), ec);
|
||||
std::cout << "utf8: ec = " << ec << std::endl;
|
||||
|
||||
return 0;
|
||||
|
||||
////
|
||||
po::options_description desc_cmd_only("Command line options");
|
||||
po::options_description desc_cmd_sett("Command line options and settings options", 130, 83);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue