本文整理汇总了C++中LVContainerRef类的典型用法代码示例。如果您正苦于以下问题:C++ LVContainerRef类的具体用法?C++ LVContainerRef怎么用?C++ LVContainerRef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LVContainerRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: env
jbyteArray scanBookCoverInternal
(JNIEnv * _env, jclass _class, jstring _path)
{
CRJNIEnv env(_env);
lString16 path = env.fromJavaString(_path);
CRLog::debug("scanBookCoverInternal(%s) called", LCSTR(path));
lString16 arcname, item;
LVStreamRef res;
jbyteArray array = NULL;
LVContainerRef arc;
if (!LVSplitArcName(path, arcname, item)) {
// not in archive
LVStreamRef stream = LVOpenFileStream(path.c_str(), LVOM_READ);
if (!stream.isNull()) {
arc = LVOpenArchieve(stream);
if (!arc.isNull()) {
// ZIP-based format
if (DetectEpubFormat(stream)) {
// EPUB
// extract coverpage from epub
res = GetEpubCoverpage(arc);
}
} else {
res = GetFB2Coverpage(stream);
if (res.isNull()) {
doc_format_t fmt;
if (DetectPDBFormat(stream, fmt)) {
res = GetPDBCoverpage(stream);
}
}
}
}
} else {
CRLog::debug("scanBookCoverInternal() : is archive, item=%s, arc=%s", LCSTR(item), LCSTR(arcname));
LVStreamRef arcstream = LVOpenFileStream(arcname.c_str(), LVOM_READ);
if (!arcstream.isNull()) {
arc = LVOpenArchieve(arcstream);
if (!arc.isNull()) {
LVStreamRef stream = arc->OpenStream(item.c_str(), LVOM_READ);
if (!stream.isNull()) {
CRLog::debug("scanBookCoverInternal() : archive stream opened ok, parsing");
res = GetFB2Coverpage(stream);
if (res.isNull()) {
doc_format_t fmt;
if (DetectPDBFormat(stream, fmt)) {
res = GetPDBCoverpage(stream);
}
}
}
}
}
}
if (!res.isNull())
array = env.streamToJByteArray(res);
if (array != NULL)
CRLog::debug("scanBookCoverInternal() : returned cover page array");
else
CRLog::debug("scanBookCoverInternal() : cover page data not found");
return array;
}
示例2: getDirectoryFonts
bool getDirectoryFonts( lString16Collection & pathList, lString16 ext, lString16Collection & fonts, bool absPath )
{
int foundCount = 0;
lString16 path;
for (int di=0; di<pathList.length();di++ ) {
path = pathList[di];
LVContainerRef dir = LVOpenDirectory(path.c_str());
if(!dir.isNull()) {
CRLog::trace("Checking directory %s", UnicodeToUtf8(path).c_str() );
for(int i=0; i < dir->GetObjectCount(); i++ ) {
const LVContainerItemInfo * item = dir->GetObjectInfo(i);
lString16 fileName = item->GetName();
if ( !item->IsContainer() && fileName.length()>4 && lString16(fileName, fileName.length()-4, 4)==ext ) {
lString16 fn;
if ( absPath ) {
fn = path;
if (!fn.empty() && fn[fn.length()-1]!=PATH_SEPARATOR_CHAR)
fn << PATH_SEPARATOR_CHAR;
}
fn << fileName;
foundCount++;
fonts.add(fn);
}
}
}
}
return foundCount > 0;
}
示例3: LCSTR
bool HyphDictionaryList::open(lString16 hyphDirectory, bool clear)
{
CRLog::info("HyphDictionaryList::open(%s)", LCSTR(hyphDirectory) );
if (clear) {
_list.clear();
addDefault();
}
if ( hyphDirectory.empty() )
return true;
//LVAppendPathDelimiter( hyphDirectory );
LVContainerRef container;
LVStreamRef stream;
if ( (hyphDirectory.endsWith("/") || hyphDirectory.endsWith("\\")) && LVDirectoryExists(hyphDirectory) ) {
container = LVOpenDirectory( hyphDirectory.c_str(), L"*.*" );
} else if ( LVFileExists(hyphDirectory) ) {
stream = LVOpenFileStream( hyphDirectory.c_str(), LVOM_READ );
if ( !stream.isNull() )
container = LVOpenArchieve( stream );
}
if ( !container.isNull() ) {
int len = container->GetObjectCount();
int count = 0;
CRLog::info("%d items found in hyph directory", len);
for ( int i=0; i<len; i++ ) {
const LVContainerItemInfo * item = container->GetObjectInfo( i );
lString16 name = item->GetName();
lString16 suffix;
HyphDictType t = HDT_NONE;
if ( name.endsWith(".pdb") ) {
suffix = "_hyphen_(Alan).pdb";
t = HDT_DICT_ALAN;
} else if ( name.endsWith(".pattern") ) {
suffix = ".pattern";
t = HDT_DICT_TEX;
} else
continue;
lString16 filename = hyphDirectory + name;
lString16 id = name;
lString16 title = name;
if ( title.endsWith( suffix ) )
title.erase( title.length() - suffix.length(), suffix.length() );
_list.add( new HyphDictionary( t, title, id, filename ) );
count++;
}
CRLog::info("%d dictionaries added to list", _list.length());
return true;
} else {
CRLog::info("no hyphenation dictionary items found in hyph directory %s", LCSTR(hyphDirectory));
}
return false;
}
示例4: EpubGetRootFilePath
lString16 EpubGetRootFilePath(LVContainerRef m_arc)
{
// check root media type
lString16 rootfilePath;
lString16 rootfileMediaType;
// read container.xml
{
LVStreamRef container_stream = m_arc->OpenStream(L"META-INF/container.xml", LVOM_READ);
if ( !container_stream.isNull() ) {
ldomDocument * doc = LVParseXMLStream( container_stream );
if ( doc ) {
ldomNode * rootfile = doc->nodeFromXPath( lString16(L"container/rootfiles/rootfile") );
if ( rootfile && rootfile->isElement() ) {
rootfilePath = rootfile->getAttributeValue(L"full-path");
rootfileMediaType = rootfile->getAttributeValue(L"media-type");
}
delete doc;
}
}
}
if ( rootfilePath.empty() || rootfileMediaType!=L"application/oebps-package+xml" )
return lString16::empty_str;
return rootfilePath;
}
示例5: findImagesFromDirectory
static void findImagesFromDirectory( lString16 dir, lString16Collection & files ) {
LVAppendPathDelimiter(dir);
if ( !LVDirectoryExists(dir) )
return;
LVContainerRef cont = LVOpenDirectory(dir.c_str());
if ( !cont.isNull() ) {
for ( int i=0; i<cont->GetObjectCount(); i++ ) {
const LVContainerItemInfo * item = cont->GetObjectInfo(i);
if ( !item->IsContainer() ) {
lString16 name = item->GetName();
name.lowercase();
if ( name.endsWith(".png") || name.endsWith(".jpg") || name.endsWith(".gif")
|| name.endsWith(".jpeg") ) {
files.add(dir + item->GetName());
}
}
}
}
}
示例6: dumpZip
static void dumpZip( LVContainerRef arc ) {
lString16 arcName = LVExtractFilenameWithoutExtension( arc->GetName() );
if ( arcName.empty() )
arcName = L"unziparc";
lString16 outDir = lString16("/tmp/") + arcName;
LVCreateDirectory(outDir);
for ( int i=0; i<arc->GetObjectCount(); i++ ) {
const LVContainerItemInfo * info = arc->GetObjectInfo(i);
if ( !info->IsContainer() ) {
lString16 outFileName = outDir + L"/" + info->GetName();
LVCreateDirectory(LVExtractPath(outFileName));
LVStreamRef in = arc->OpenStream(info->GetName(), LVOM_READ);
LVStreamRef out = LVOpenFileStream(outFileName.c_str(), LVOM_WRITE);
if ( !in.isNull() && !out.isNull() ) {
CRLog::trace("Writing %s", LCSTR(outFileName));
LVPumpStream(out.get(), in.get());
}
}
}
}
示例7: getDirectoryFonts
bool getDirectoryFonts( lString16Collection & pathList, lString16Collection & ext, lString16Collection & fonts, bool absPath )
{
int foundCount = 0;
lString16 path;
for ( int di=0; di<pathList.length();di++ ) {
path = pathList[di];
LVContainerRef dir = LVOpenDirectory(path.c_str());
if ( !dir.isNull() ) {
CRLog::trace("Checking directory %s", UnicodeToUtf8(path).c_str() );
for ( int i=0; i < dir->GetObjectCount(); i++ ) {
const LVContainerItemInfo * item = dir->GetObjectInfo(i);
lString16 fileName = item->GetName();
lString8 fn = UnicodeToLocal(fileName);
//printf(" test(%s) ", fn.c_str() );
if ( !item->IsContainer() ) {
bool found = false;
lString16 lc = fileName;
lc.lowercase();
for ( int j=0; j<ext.length(); j++ ) {
if ( lc.endsWith(ext[j]) ) {
found = true;
break;
}
}
if ( !found )
continue;
lString16 fn;
if ( absPath ) {
fn = path;
if ( !fn.empty() && fn[fn.length()-1]!=PATH_SEPARATOR_CHAR)
fn << PATH_SEPARATOR_CHAR;
}
fn << fileName;
foundCount++;
fonts.add( fn );
}
}
}
}
return foundCount > 0;
}
示例8: LVAppendPathDelimiter
//TODO: place TinyDictionary to separate file
CRTinyDict::CRTinyDict( const lString16& config )
{
lString16 path = config;
LVAppendPathDelimiter( path );
LVContainerRef dir = LVOpenDirectory( config.c_str() );
if ( !dir )
dir = LVOpenDirectory( LVExtractPath(config).c_str() );
if ( !dir.isNull() ) {
int count = dir->GetSize();
lString16 indexExt(".index");
for ( int i=0; i<count; i++ ) {
const LVContainerItemInfo * item = dir->GetObjectInfo( i );
if ( !item->IsContainer() ) {
lString16 name = item->GetName();
if ( name.endsWith( indexExt ) ) {
lString16 nameBase = name.substr( 0, name.length() - indexExt.length() );
lString16 name1 = nameBase + ".dict";
lString16 name2 = nameBase + ".dict.dz";
lString16 dataName;
int index = -1;
for ( int n=0; n<count; n++ ) {
const LVContainerItemInfo * item2 = dir->GetObjectInfo( n );
if ( !item2->IsContainer() ) {
if ( item2->GetName() == name1 || item2->GetName() == name2 ) {
index = n;
dataName = item2->GetName();
break;
}
}
}
if ( index>=0 ) {
// found pair
dicts.add(UnicodeToUtf8(path + name).c_str(), UnicodeToUtf8(path + dataName).c_str());
}
}
}
}
}
CRLog::info( "%d dictionaries opened", dicts.length() );
}
示例9: env
/*
* Class: org_coolreader_crengine_Engine
* Method: scanBookCoverInternal
* Signature: (Ljava/lang/String;)[B
*/
JNIEXPORT jbyteArray JNICALL Java_org_coolreader_crengine_Engine_scanBookCoverInternal
(JNIEnv * _env, jobject _engine, jstring _path) {
CRJNIEnv env(_env);
lString16 path = env.fromJavaString(_path);
CRLog::debug("scanBookCoverInternal(%s) called", LCSTR(path));
lString16 arcname, item;
LVStreamRef res;
jbyteArray array = NULL;
LVContainerRef arc;
if (!LVSplitArcName(path, arcname, item)) {
// not in archive
LVStreamRef stream = LVOpenFileStream(path.c_str(), LVOM_READ);
if (!stream.isNull()) {
arc = LVOpenArchieve(stream);
if (!arc.isNull()) {
// ZIP-based format
if (DetectEpubFormat(stream)) {
// EPUB
// extract coverpage from epub
res = GetEpubCoverpage(arc);
}
} else {
doc_format_t fmt;
if (DetectPDBFormat(stream, fmt)) {
res = GetPDBCoverpage(stream);
}
}
}
}
if (!res.isNull())
array = env.streamToJByteArray(res);
if (array != NULL)
CRLog::debug("scanBookCoverInternal() : returned cover page array");
else
CRLog::debug("scanBookCoverInternal() : cover page data not found");
return array;
}
示例10: GetBookProperties
static bool GetBookProperties(const char *name, BookProperties * pBookProps)
{
CRLog::trace("GetBookProperties( %s )", name);
// check archieve
lString16 arcPathName;
lString16 arcItemPathName;
bool isArchiveFile = LVSplitArcName( lString16(name), arcPathName, arcItemPathName );
// open stream
LVStreamRef stream = LVOpenFileStream( (isArchiveFile ? arcPathName : Utf8ToUnicode(lString8(name))).c_str() , LVOM_READ);
if (!stream) {
CRLog::error("cannot open file %s", name);
return false;
}
if ( DetectEpubFormat( stream ) ) {
CRLog::trace("GetBookProperties() : epub format detected");
return GetEPUBBookProperties( name, stream, pBookProps );
}
time_t t = (time_t)time(0);
if ( isArchiveFile ) {
int arcsize = (int)stream->GetSize();
LVContainerRef container = LVOpenArchieve(stream);
if ( container.isNull() ) {
CRLog::error( "Cannot read archive contents from %s", LCSTR(arcPathName) );
return false;
}
stream = container->OpenStream(arcItemPathName.c_str(), LVOM_READ);
if ( stream.isNull() ) {
CRLog::error( "Cannot open archive file item stream %s", LCSTR(lString16(name)) );
return false;
}
}
struct stat fs;
if ( !stat( name, &fs ) ) {
t = fs.st_mtime;
}
// read document
#if COMPACT_DOM==1
ldomDocument doc(stream, 0);
#else
ldomDocument doc;
#endif
ldomDocumentWriter writer(&doc, true);
doc.setNodeTypes( fb2_elem_table );
doc.setAttributeTypes( fb2_attr_table );
doc.setNameSpaceTypes( fb2_ns_table );
LVXMLParser parser( stream, &writer );
CRLog::trace( "checking format..." );
if ( !parser.CheckFormat() ) {
return false;
}
CRLog::trace( "parsing..." );
if ( !parser.Parse() ) {
return false;
}
CRLog::trace( "parsed" );
#if 0
char ofname[512];
sprintf(ofname, "%s.xml", name);
CRLog::trace(" writing to file %s", ofname);
LVStreamRef out = LVOpenFileStream(ofname, LVOM_WRITE);
doc.saveToStream(out, "utf16");
#endif
lString16 authors = extractDocAuthors( &doc, lString16("|"), false );
lString16 title = extractDocTitle( &doc );
lString16 language = extractDocLanguage( &doc ).lowercase();
lString16 series = extractDocSeries( &doc, &pBookProps->seriesNumber );
#if SERIES_IN_AUTHORS==1
if ( !series.empty() )
authors << " " << series;
#endif
pBookProps->title = title;
pBookProps->author = authors;
pBookProps->series = series;
pBookProps->filesize = (long)stream->GetSize();
pBookProps->filename = lString16(name);
pBookProps->filedate = getDateTimeString( t );
pBookProps->language = language;
return true;
}
示例11: GetBookProperties
int GetBookProperties(char *name, struct BookProperties* pBookProps, int localLanguage)
{
CRLog::trace("GetBookProperties( %s )", name);
memset(pBookProps, 0, sizeof(BookProperties) );
// open stream
LVStreamRef stream = LVOpenFileStream(name, LVOM_READ);
if (!stream) {
CRLog::error("cannot open file %s", name);
return 0;
}
// check archieve
#ifdef USE_ZLIB
LVContainerRef arc;
//printf("start opening arc\n");
//for ( int i=0; i<1000; i++ )
//for ( int kk=0; kk<1000; kk++)
{
arc = LVOpenArchieve( stream );
//printf("end opening arc\n");
if (!arc.isNull())
{
CRLog::trace("%s is archive with %d items", name, arc->GetObjectCount());
// archieve
const LVContainerItemInfo * bestitem = NULL;
const LVContainerItemInfo * fb2item = NULL;
const LVContainerItemInfo * fbditem = NULL;
for (int i=0; i<arc->GetObjectCount(); i++)
{
const LVContainerItemInfo * item = arc->GetObjectInfo(i);
if (item)
{
if ( !item->IsContainer() )
{
lString16 name( item->GetName() );
if ( name.length() > 5 )
{
name.lowercase();
const lChar16 * pext = name.c_str() + name.length() - 4;
if ( pext[0]=='.' && pext[1]=='f' && pext[2]=='b' && pext[3]=='2') {
fb2item = item;
} else if ( pext[0]=='.' && pext[1]=='f' && pext[2]=='b' && pext[3]=='d') {
fbditem = item;
}
}
}
}
}
bestitem = fb2item;
if ( fbditem )
bestitem = fbditem;
if ( !bestitem )
return 0;
CRLog::trace( "opening item %s from archive", UnicodeToUtf8(bestitem->GetName()).c_str() );
//printf("start opening stream\n");
//for ( int k=0; k<1000; k++ ) {
stream = arc->OpenStream( bestitem->GetName(), LVOM_READ );
char buf[8192];
stream->Read(buf, 8192, NULL );
//}
//printf("end opening stream\n");
if ( stream.isNull() )
return 0;
CRLog::trace( "stream created" );
// opened archieve stream
}
}
#endif //USE_ZLIB
// read document
#if COMPACT_DOM==1
ldomDocument doc(stream, 0);
#else
ldomDocument doc;
#endif
ldomDocumentWriter writer(&doc, true);
doc.setNodeTypes( fb2_elem_table );
doc.setAttributeTypes( fb2_attr_table );
doc.setNameSpaceTypes( fb2_ns_table );
LVXMLParser parser( stream, &writer );
CRLog::trace( "checking format..." );
if ( !parser.CheckFormat() ) {
return 0;
}
CRLog::trace( "parsing..." );
if ( !parser.Parse() ) {
return 0;
}
CRLog::trace( "parsed" );
#if 0
char ofname[512];
sprintf(ofname, "%s.xml", name);
CRLog::trace(" writing to file %s", ofname);
LVStreamRef out = LVOpenFileStream(ofname, LVOM_WRITE);
doc.saveToStream(out, "utf16");
#endif
lString16 authors = extractDocAuthors( &doc );
lString16 title = extractDocTitle( &doc );
lString16 series = extractDocSeriesReverse( &doc );
//.........这里部分代码省略.........
示例12: ImportEpubDocument
bool ImportEpubDocument( LVStreamRef stream, ldomDocument * m_doc, LVDocViewCallback * progressCallback, CacheLoadingCallback * formatCallback )
{
LVContainerRef arc = LVOpenArchieve( stream );
if ( arc.isNull() )
return false; // not a ZIP archive
// check root media type
lString16 rootfilePath = EpubGetRootFilePath(arc);
if ( rootfilePath.empty() )
return false;
EncryptedDataContainer * decryptor = new EncryptedDataContainer(arc);
if (decryptor->open()) {
CRLog::debug("EPUB: encrypted items detected");
}
LVContainerRef m_arc = LVContainerRef(decryptor);
if (decryptor->hasUnsupportedEncryption()) {
// DRM!!!
createEncryptedEpubWarningDocument(m_doc);
return true;
}
m_doc->setContainer(m_arc);
// read content.opf
EpubItems epubItems;
//EpubItem * epubToc = NULL; //TODO
LVArray<EpubItem*> spineItems;
lString16 codeBase;
//lString16 css;
//
{
codeBase=LVExtractPath(rootfilePath, false);
CRLog::trace("codeBase=%s", LCSTR(codeBase));
}
LVStreamRef content_stream = m_arc->OpenStream(rootfilePath.c_str(), LVOM_READ);
if ( content_stream.isNull() )
return false;
lString16 ncxHref;
lString16 coverId;
LVEmbeddedFontList fontList;
EmbeddedFontStyleParser styleParser(fontList);
// reading content stream
{
ldomDocument * doc = LVParseXMLStream( content_stream );
if ( !doc )
return false;
CRPropRef m_doc_props = m_doc->getProps();
lString16 author = doc->textFromXPath( lString16(L"package/metadata/creator"));
lString16 title = doc->textFromXPath( lString16(L"package/metadata/title"));
m_doc_props->setString(DOC_PROP_TITLE, title);
m_doc_props->setString(DOC_PROP_AUTHORS, author );
for ( int i=1; i<50; i++ ) {
ldomNode * item = doc->nodeFromXPath( lString16(L"package/metadata/identifier[") + lString16::itoa(i) + L"]" );
if (!item)
break;
lString16 key = item->getText();
if (decryptor->setManglingKey(key)) {
CRLog::debug("Using font mangling key %s", LCSTR(key));
break;
}
}
CRLog::info("Author: %s Title: %s", LCSTR(author), LCSTR(title));
for ( int i=1; i<20; i++ ) {
ldomNode * item = doc->nodeFromXPath( lString16(L"package/metadata/meta[") + lString16::itoa(i) + L"]" );
if ( !item )
break;
lString16 name = item->getAttributeValue(L"name");
lString16 content = item->getAttributeValue(L"content");
if ( name == L"cover" )
coverId = content;
else if ( name==L"calibre:series" )
m_doc_props->setString(DOC_PROP_SERIES_NAME, content );
else if ( name==L"calibre:series_index" )
m_doc_props->setInt(DOC_PROP_SERIES_NUMBER, content.atoi() );
}
// items
for ( int i=1; i<50000; i++ ) {
ldomNode * item = doc->nodeFromXPath( lString16(L"package/manifest/item[") + lString16::itoa(i) + L"]" );
if ( !item )
break;
lString16 href = item->getAttributeValue(L"href");
lString16 mediaType = item->getAttributeValue(L"media-type");
lString16 id = item->getAttributeValue(L"id");
if ( !href.empty() && !id.empty() ) {
if ( id==coverId ) {
// coverpage file
lString16 coverFileName = codeBase + href;
//.........这里部分代码省略.........
示例13: OpenStream
virtual LVStreamRef OpenStream( const lChar16 * fname, lvopen_mode_t mode ) {
LVStreamRef res = _container->OpenStream(fname, mode);
if (res.isNull())
return res;
if (isEncryptedItem(fname))
return LVStreamRef(new FontDemanglingStream(res, _fontManglingKey));
return res;
}
示例14: open
bool open() {
LVStreamRef stream = _container->OpenStream(L"META-INF/encryption.xml", LVOM_READ);
if (stream.isNull())
return false;
EncCallback enccallback(this);
LVXMLParser parser(stream, &enccallback, false, false);
if (!parser.Parse())
return false;
if (_list.length())
return true;
return false;
}
示例15: GetSize
/// returns object size (file size or directory entry count)
virtual lverror_t GetSize( lvsize_t * pSize ) { return _container->GetSize(pSize); }