本文整理汇总了C++中fc::path类的典型用法代码示例。如果您正苦于以下问题:C++ path类的具体用法?C++ path怎么用?C++ path使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了path类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: import
cafs::link cafs::import( const fc::path& p ) {
if( !fc::exists(p) ) {
FC_THROW_MSG( "Path does not exist %s", p.string() );
}
if( fc::is_regular_file( p ) ) {
if( fc::file_size(p) > IMBED_THRESHOLD ) {
auto file_head = import_file(p);
fc::vector<char> data(MAX_CHUNK_SIZE);
fc::datastream<char*> ds(data.data()+1, data.size()-1);
fc::raw::pack( ds, file_head );
data[0] = cafs::file_header_type;
//fc::datastream<const char*> ds2(data.data()+1, data.size()-1);
//file_header tmp;
//fc::raw::unpack( ds2, tmp );
//slog( "test unpack %s", fc::json::to_string( tmp ).c_str() );
data.resize( ds.tellp() );
//slog( "pre randomized... '%s'", fc::to_hex( data.data(), 16 ).c_str() );
size_t seed = randomize(data, *((uint64_t*)fc::sha1::hash(data.data(),data.size()).data()) );
auto chunk_head = slice_chunk( data );
//slog( "slice chunk %s", fc::json::to_string( chunk_head ).c_str() );
store_chunk( chunk_head, data );
return link( chunk_head.calculate_id(), seed );
} else { // no header, just raw data from the file stored in the chunk
fc::vector<char> data( fc::file_size(p)+1 );
data[0] = file_data_type;
fc::ifstream ifile( p.string(), fc::ifstream::binary );
ifile.read( data.data()+1, data.size()-1 );
size_t seed = randomize(data, *((uint64_t*)fc::sha1::hash(data.data(),data.size()).data()) );
auto chunk_head = slice_chunk( data );
store_chunk( chunk_head, data );
return link( chunk_head.calculate_id(), seed );
}
}
else if( fc::is_directory(p) ) {
auto dir = import_directory(p);
fc::vector<char> data(MAX_CHUNK_SIZE);
fc::datastream<char*> ds(data.data()+1, data.size()-1);
fc::raw::pack( ds, dir );
data[0] = directory_type;
data.resize( ds.tellp()+1 );
size_t seed = randomize(data, *((uint64_t*)fc::sha1::hash(data.data(),data.size()).data()) );
auto chunk_head = slice_chunk( data );
link l( chunk_head.calculate_id(), seed );
store_chunk( chunk_head, data );
return l;
}
FC_THROW_MSG( "Unsupported file type while importing '%s'", p.string() );
return cafs::link();
}
示例2:
fc::string detail::process_impl::windows_shell_escape_command(const fc::path& exe, const vector<string>& args) {
fc::stringstream command_line;
command_line << windows_shell_escape(exe.string());
for (unsigned i = 0; i < args.size(); ++i)
command_line << " " << windows_shell_escape(args[i]);
return command_line.str();
}
示例3: import_bitcoin_wallet
std::vector<fc::ecc::private_key> import_bitcoin_wallet( const fc::path& wallet_dat, const std::string& passphrase )
{ try {
wallet_db db( wallet_dat.to_native_ansi_path().c_str() );
return collect_keys( db, passphrase );
} FC_RETHROW_EXCEPTIONS( warn, "" ) }
示例4: load_genesis
signed_transaction load_genesis( const fc::path& csv, uint64_t& total_coins )
{
total_coins = 0;
signed_transaction coinbase;
coinbase.version = 0;
// coinbase.valid_after = 0;
// coinbase.valid_blocks = 0;
std::ifstream in(csv.generic_string().c_str(), std::ios::binary);
std::string line;
std::getline( in, line );
while( in.good() )
{
std::stringstream ss(line);
std::string addr;
uint64_t amnt;
ss >> addr >> amnt;
total_coins += amnt;
coinbase.outputs.push_back(
trx_output( claim_by_pts_output( bts::pts_address(addr) ), amnt, asset::bts) );
std::getline( in, line );
}
return coinbase;
}
示例5: compile_json_to_source
void compile_json_to_source(
const fc::path& source_file_name,
const fc::path& prologue_file_name,
const fc::path& json_file_name,
const fc::path& epilogue_file_name
)
{
fc::mutable_variant_object template_context;
template_context[ "source_file_name"] = source_file_name.string();
template_context["prologue_file_name"] = prologue_file_name.string();
template_context[ "json_file_name"] = json_file_name.string();
template_context["epilogue_file_name"] = epilogue_file_name.string();
std::ofstream source_file(source_file_name.string());
if (prologue_file_name.string() != "")
{
std::ifstream prologue_file(prologue_file_name.string());
std::stringstream ss_prologue_file;
ss_prologue_file << prologue_file.rdbuf();
source_file << format_string(ss_prologue_file.str(), template_context);
}
std::ifstream json_file(json_file_name.string());
std::string line;
bool first = true;
while (std::getline(json_file, line))
{
if (first)
first = false;
else
source_file << ",\n";
source_file << " " << bts::utilities::escape_string_for_c_source_code(line);
}
if (epilogue_file_name.string() != "")
{
std::ifstream epilogue_file(epilogue_file_name.string());
std::stringstream ss_epilogue_file;
ss_epilogue_file << epilogue_file.rdbuf();
source_file << format_string(ss_epilogue_file.str(), template_context);
}
return;
}
示例6: import_electrum_wallet
std::vector<fc::ecc::private_key> import_electrum_wallet( const fc::path& wallet_dat, const std::string& passphrase )
{ try {
std::vector<fc::ecc::private_key> keys;
electrumwallet wallet( wallet_dat.to_native_ansi_path());
if( !wallet.ok() ) FC_THROW_EXCEPTION( fc::invalid_arg_exception, "invalid electrum wallet");
wallet.derivekeys( passphrase );
return wallet.keys();
} FC_RETHROW_EXCEPTIONS( warn, "" ) }
示例7: create_genesis_block
void create_genesis_block(fc::path genesis_json_file)
{
vector<fc::ecc::private_key> delegate_private_keys;
genesis_block_config config;
config.precision = BTS_BLOCKCHAIN_PRECISION;
config.timestamp = bts::blockchain::now();
config.base_symbol = BTS_BLOCKCHAIN_SYMBOL;
config.base_name = BTS_BLOCKCHAIN_NAME;
config.base_description = BTS_BLOCKCHAIN_DESCRIPTION;
config.supply = BTS_BLOCKCHAIN_INITIAL_SHARES;
// set our fake random number generator to generate deterministic keys
set_random_seed_for_testing(fc::sha512());
std::ofstream key_stream( genesis_json_file.string() + ".keypairs" );
//create a script for importing the delegate keys
std::ofstream delegate_key_import_stream(genesis_json_file.string() + ".log");
delegate_key_import_stream << CLI_PROMPT_SUFFIX " enable_output false" << std::endl;
std::cout << "*** creating delegate public/private key pairs ***" << std::endl;
for( uint32_t i = 0; i < BTS_BLOCKCHAIN_NUM_DELEGATES; ++i )
{
name_config delegate_account;
delegate_account.name = "delegate" + fc::to_string(i);
fc::ecc::private_key delegate_private_key = fc::ecc::private_key::generate();
delegate_private_keys.push_back( delegate_private_key );
auto delegate_public_key =delegate_private_key.get_public_key();
delegate_account.owner = delegate_public_key;
delegate_account.is_delegate = true;
config.names.push_back(delegate_account);
config.balances.push_back( std::make_pair( pts_address(fc::ecc::public_key_data(delegate_account.owner)), BTS_BLOCKCHAIN_INITIAL_SHARES/BTS_BLOCKCHAIN_NUM_DELEGATES) );
//output public/private key pair for each delegate to a file
string wif_key = bts::utilities::key_to_wif( delegate_private_key );
key_stream << std::string(delegate_account.owner) << " " << wif_key << std::endl;
//add command to import the delegate keys into a client
delegate_key_import_stream << CLI_PROMPT_SUFFIX " wallet_import_private_key " << wif_key << " " << delegate_account.name << " false" << std::endl;
}
delegate_key_import_stream << CLI_PROMPT_SUFFIX " enable_output true" << std::endl;
fc::json::save_to_file( config, genesis_json_file);
}
示例8: options
bts_xt_client_test_config()
{
// parse command-line options
boost::program_options::options_description option_config("Allowed options");
option_config.add_options()("bts-client-exe", boost::program_options::value<std::string>(), "full path to the executable to test")
("bts-server-exe", boost::program_options::value<std::string>(), "full path to the server executable for testing client-server mode")
("extra-help", "display this help message");
boost::program_options::variables_map option_variables;
try
{
boost::program_options::store(boost::program_options::command_line_parser(boost::unit_test::framework::master_test_suite().argc,
boost::unit_test::framework::master_test_suite().argv).
options(option_config).run(), option_variables);
boost::program_options::notify(option_variables);
}
catch (boost::program_options::error&)
{
std::cerr << "Error parsing command-line options\n\n";
std::cerr << option_config << "\n";
exit(1);
}
if (option_variables.count("extra-help"))
{
std::cout << option_config << "\n";
exit(0);
}
if (option_variables.count("bts-client-exe"))
bts_client_exe = option_variables["bts-client-exe"].as<std::string>().c_str();
if (option_variables.count("bts-server-exe"))
bts_server_exe = option_variables["bts-server-exe"].as<std::string>().c_str();
std::cout << "Testing " << bts_client_exe.string() << "\n";
std::cout << "Using config directory " << config_directory.string() << "\n";
fc::create_directories(config_directory);
boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_messages);
}
示例9: open
void profile::open( const fc::path& profile_dir, const std::string& password )
{ try {
ilog("opening profile: ${profile_dir}",("profile_dir",profile_dir));
my->_profile_name = profile_dir.filename().generic_wstring();
fc::create_directories( profile_dir );
fc::create_directories( profile_dir / "addressbook" );
fc::create_directories( profile_dir / "idents" );
fc::create_directories( profile_dir / "mail" );
fc::create_directories( profile_dir / "mail" / "inbox" );
fc::create_directories( profile_dir / "mail" / "draft" );
fc::create_directories( profile_dir / "mail" / "pending" );
fc::create_directories( profile_dir / "mail" / "sent" );
fc::create_directories( profile_dir / "chat" );
fc::create_directories( profile_dir / "request" );
fc::create_directories( profile_dir / "authorization" );
ilog("loading master key file:" KEYHOTEE_MASTER_KEY_FILE);
auto profile_cfg_key = fc::sha512::hash( password.c_str(), password.size() );
std::vector<char> stretched_seed_data;
try {
stretched_seed_data = fc::aes_load( profile_dir / KEYHOTEE_MASTER_KEY_FILE, profile_cfg_key );
}
catch (fc::exception& /* e */)
{ //try to open legacy name for key file
wlog("Could not open " KEYHOTEE_MASTER_KEY_FILE ", trying to open legacy key file (.strecthed_seed).");
stretched_seed_data = fc::aes_load( profile_dir / ".stretched_seed", profile_cfg_key );
}
ilog("opening profile databases");
my->_keychain.set_seed( fc::raw::unpack<fc::sha512>(stretched_seed_data) );
my->_addressbook->open( profile_dir / "addressbook", profile_cfg_key );
my->_idents.open( profile_dir / "idents" );
my->_inbox_db->open( profile_dir / "mail" / "inbox", profile_cfg_key );
my->_draft_db->open( profile_dir / "mail" / "draft", profile_cfg_key );
my->_pending_db->open( profile_dir / "mail" / "pending", profile_cfg_key );
my->_sent_db->open( profile_dir / "mail" / "sent", profile_cfg_key );
my->_chat_db->open( profile_dir / "chat", profile_cfg_key );
my->_request_db->open( profile_dir / "request", profile_cfg_key );
my->_auth_db->open( profile_dir / "authorization", profile_cfg_key );
my->_last_sync_time.open( profile_dir / "mail" / "last_recv", true );
if( *my->_last_sync_time == fc::time_point())
{
*my->_last_sync_time = fc::time_point::now() - fc::days(5);
ilog("set last_sync_time to ${t}",("t",*my->_last_sync_time));
}
else
ilog("loaded last_sync_time = ${t}",("t",*my->_last_sync_time));
ilog("finished opening profile");
} FC_RETHROW_EXCEPTIONS( warn, "", ("profile_dir",profile_dir) ) }
示例10: open
void open( const fc::path& dir, bool create = true, size_t cache_size = 0 )
{ try {
FC_ASSERT( !is_open(), "Database is already open!" );
ldb::Options opts;
opts.comparator = &_comparer;
opts.create_if_missing = create;
opts.max_open_files = 64;
opts.compression = leveldb::kNoCompression;
if( cache_size > 0 )
{
opts.write_buffer_size = cache_size / 4; // up to two write buffers may be held in memory simultaneously
_cache.reset( leveldb::NewLRUCache( cache_size / 2 ) );
opts.block_cache = _cache.get();
}
if( ldb::kMajorVersion > 1 || ( leveldb::kMajorVersion == 1 && leveldb::kMinorVersion >= 16 ) )
{
// LevelDB versions before 1.16 consider short writes to be corruption. Only trigger error
// on corruption in later versions.
opts.paranoid_checks = true;
}
_read_options.verify_checksums = true;
_iter_options.verify_checksums = true;
_iter_options.fill_cache = false;
_sync_options.sync = true;
// Given path must exist to succeed toNativeAnsiPath
fc::create_directories( dir );
std::string ldbPath = dir.to_native_ansi_path();
ldb::DB* ndb = nullptr;
const auto ntrxstat = ldb::DB::Open( opts, ldbPath.c_str(), &ndb );
if( !ntrxstat.ok() )
{
elog( "Failure opening database: ${db}\nStatus: ${msg}", ("db",dir)("msg",ntrxstat.ToString()) );
FC_THROW_EXCEPTION( level_pod_map_open_failure, "Failure opening database: ${db}\nStatus: ${msg}",
("db",dir)("msg",ntrxstat.ToString()) );
}
_db.reset( ndb );
try_upgrade_db( dir, ndb, fc::get_typename<Value>::name(), sizeof( Value ) );
} FC_CAPTURE_AND_RETHROW( (dir)(create)(cache_size) ) }
示例11: close
void peer_database_impl::close() {
std::vector<potential_peer_record> peer_records;
peer_records.reserve(_potential_peer_set.size());
std::copy(_potential_peer_set.begin(), _potential_peer_set.end(), std::back_inserter(peer_records));
try {
fc::path peer_database_filename_dir = _peer_database_filename.parent_path();
if (!fc::exists(peer_database_filename_dir)) {
fc::create_directories(peer_database_filename_dir);
}
fc::json::save_to_file(peer_records, _peer_database_filename);
}
catch (const fc::exception &e) {
elog("error saving peer database to file ${peer_database_filename}",
("peer_database_filename", _peer_database_filename));
}
_potential_peer_set.clear();
}
示例12: open
void open( const fc::path& dir, bool create = true, size_t cache_size = 0 )
{ try {
ldb::Options opts;
opts.comparator = &_comparer;
opts.create_if_missing = create;
if (cache_size) {
_cache.reset(leveldb::NewLRUCache(cache_size));
opts.block_cache = _cache.get();
}
/*
if( ldb::kMajorVersion > 1 || ( leveldb::kMajorVersion == 1 && leveldb::kMinorVersion >= 16 ) )
{
// LevelDB versions before 1.16 consider short writes to be corruption. Only trigger error
// on corruption in later versions.
opts.paranoid_checks = true;
}
opts.max_open_files = 64;
_read_options.verify_checksums = true;
_iter_options.verify_checksums = true;
_iter_options.fill_cache = false;
_sync_options.sync = true;
*/
/// \warning Given path must exist to succeed toNativeAnsiPath
fc::create_directories(dir);
std::string ldbPath = dir.to_native_ansi_path();
ldb::DB* ndb = nullptr;
auto ntrxstat = ldb::DB::Open( opts, ldbPath.c_str(), &ndb );
if( !ntrxstat.ok() )
{
FC_THROW_EXCEPTION( db_in_use_exception, "Unable to open database ${db}\n\t${msg}",
("db",dir)
("msg",ntrxstat.ToString())
);
}
_db.reset(ndb);
try_upgrade_db( dir,ndb, fc::get_typename<Value>::name(),sizeof(Value) );
} FC_RETHROW_EXCEPTIONS( warn, "" ) }
示例13: open
void mmap_struct_base::open( const fc::path& file, size_t s, bool create )
{
if( !fc::exists( file ) || fc::file_size(file) != s )
{
fc::ofstream out( file );
char buffer[1024];
memset( buffer, 0, sizeof(buffer) );
size_t bytes_left = s;
while( bytes_left > 0 )
{
size_t to_write = std::min<size_t>(bytes_left, sizeof(buffer) );
out.write( buffer, to_write );
bytes_left -= to_write;
}
}
std::string filePath = file.to_native_ansi_path();
_file_mapping.reset( new fc::file_mapping( filePath.c_str(), fc::read_write ) );
_mapped_region.reset( new fc::mapped_region( *_file_mapping, fc::read_write, 0, s ) );
}
示例14: open
void open( const fc::path& dir, bool create = true )
{
ldb::Options opts;
opts.create_if_missing = create;
opts.comparator = & _comparer;
/// \waring Given path must exist to succeed toNativeAnsiPath
fc::create_directories(dir);
std::string ldbPath = dir.to_native_ansi_path();
ldb::DB* ndb = nullptr;
auto ntrxstat = ldb::DB::Open( opts, ldbPath.c_str(), &ndb );
if( !ntrxstat.ok() )
{
FC_THROW_EXCEPTION( db_in_use_exception, "Unable to open database ${db}\n\t${msg}",
("db",dir)
("msg",ntrxstat.ToString())
);
}
_db.reset(ndb);
UpgradeDbIfNecessary(dir,ndb, fc::get_typename<Value>::name(),sizeof(Value));
}
示例15: import_file
/**
* Imports the file chunks into the database, but does not
* import the file_header itself as a chunk, as it may be
* imbedded within another chunk.
*
* @pre is_regular_file(p)
*/
cafs::file_header cafs::import_file( const fc::path& p ) {
file_header head;
head.file_size = fc::file_size(p);
fc::vector<char> chunk( MAX_CHUNK_SIZE );
// divide file up into chunks and slices
fc::ifstream in( p.string(), fc::ifstream::binary );
uint32_t r = 0;
while( r < head.file_size ) {
size_t some = fc::min( size_t(chunk.size()), size_t(head.file_size-r) );
in.read( chunk.data(), some );
size_t seed = randomize(chunk, *((uint64_t*)fc::sha1::hash(chunk.data(),chunk.size()).data()) );
chunk.resize(some);
auto chunk_head = slice_chunk(chunk);
auto chunk_id = store_chunk( chunk_head, chunk );
head.add_chunk( chunk_id, seed, chunk_head );
r += some;
}
return head;
}