std::shared_ptr<OStreamFile> writeFileStream( const fs::path &path, bool createParents ) { if( createParents && path.has_parent_path() ) { fs::create_directories( path.parent_path() ); } #if defined( CINDER_MSW ) FILE *f = _wfopen( expandPath( path ).wstring().c_str(), L"wb" ); #else FILE *f = fopen( expandPath( path ).string().c_str(), "wb" ); #endif if( f ) { OStreamFileRef s = OStreamFile::create( f, true ); s->setFileName( path ); return s; } else return std::shared_ptr<OStreamFile>(); }
void file_storage::add_file(fs::path const& file, size_type size, int flags , std::time_t mtime, fs::path const& symlink_path) { TORRENT_ASSERT(size >= 0); #if BOOST_VERSION < 103600 if (!file.has_branch_path()) #else if (!file.has_parent_path()) #endif { // you have already added at least one file with a // path to the file (branch_path), which means that // all the other files need to be in the same top // directory as the first file. TORRENT_ASSERT(m_files.empty()); m_name = file.string(); } else { if (m_files.empty()) m_name = *file.begin(); } TORRENT_ASSERT(m_name == *file.begin()); m_files.push_back(file_entry()); file_entry& e = m_files.back(); e.size = size; e.path = file; e.offset = m_total_size; e.pad_file = bool(flags & pad_file); e.hidden_attribute = bool(flags & attribute_hidden); e.executable_attribute = bool(flags & attribute_executable); e.symlink_attribute = bool(flags & attribute_symlink); if (e.symlink_attribute) e.symlink_path = symlink_path.string(); e.mtime = mtime; m_total_size += size; }