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; }
bool TexHyph::load( lString16 fileName ) { LVStreamRef stream = LVOpenFileStream( fileName.c_str(), LVOM_READ ); if ( stream.isNull() ) return false; return load( stream ); }
bool V3DocViewWin::loadHistory( lString16 filename ) { CRLog::trace("V3DocViewWin::loadHistory( %s )", UnicodeToUtf8(filename).c_str()); _historyFileName = filename; LVStreamRef stream = LVOpenFileStream( filename.c_str(), LVOM_READ ); return loadHistory( stream ); }
bool V3DocViewWin::loadSettings( lString16 filename ) { _settingsFileName = filename; LVStreamRef stream = LVOpenFileStream( filename.c_str(), LVOM_READ ); if ( stream.isNull() ) { _docview->propsUpdateDefaults( _props ); _docview->propsApply( _props ); _wm->getScreen()->setFullUpdateInterval(_props->getIntDef(PROP_DISPLAY_FULL_UPDATE_INTERVAL, 1)); _wm->getScreen()->setTurboUpdateEnabled(_props->getIntDef(PROP_DISPLAY_TURBO_UPDATE_MODE, 0)); //setAccelerators( _wm->getAccTables().get(lString16("main"), _props) ); return false; } if ( _props->loadFromStream( stream.get() ) ) { _props->setIntDef(PROP_FILE_PROPS_FONT_SIZE, 26); _docview->propsUpdateDefaults( _props ); _docview->propsApply( _props ); _wm->getScreen()->setFullUpdateInterval(_props->getIntDef(PROP_DISPLAY_FULL_UPDATE_INTERVAL, 1)); _wm->getScreen()->setTurboUpdateEnabled(_props->getIntDef(PROP_DISPLAY_TURBO_UPDATE_MODE, 0)); setAccelerators( _wm->getAccTables().get(lString16("main"), _props) ); return true; } _docview->propsUpdateDefaults( _props ); _docview->propsApply( _props ); _wm->getScreen()->setFullUpdateInterval(_props->getIntDef(PROP_DISPLAY_FULL_UPDATE_INTERVAL, 1)); _wm->getScreen()->setTurboUpdateEnabled(_props->getIntDef(PROP_DISPLAY_TURBO_UPDATE_MODE, 0)); //setAccelerators( _wm->getAccTables().get(lString16("main"), _props) ); return false; }
bool ReaderViewNative::loadDocument( lString16 filename ) { CRLog::info("Loading document %s", LCSTR(filename)); bool res = _docview->LoadDocument(filename.c_str()); CRLog::info("Document %s is loaded %s", LCSTR(filename), (res?"successfully":"with error")); return res; }
bool V3DocViewWin::loadDictConfig( lString16 filename ) { LVStreamRef stream = LVOpenFileStream( filename.c_str(), LVOM_READ ); if ( !stream.isNull() ) { _dictConfig = filename; return true; } return false; }
bool V3DocViewWin::loadDocument( lString16 filename ) { if ( !_docview->LoadDocument( filename.c_str() ) ) { CRLog::error("V3DocViewWin::loadDocument( %s ) - failed!", UnicodeToUtf8(filename).c_str() ); return false; } //_docview->swapToCache(); _docview->restorePosition(); return true; }
bool V3DocViewWin::loadDefaultCover( lString16 filename ) { LVImageSourceRef cover = LVCreateFileCopyImageSource( filename.c_str() ); if ( !cover.isNull() ) { _docview->setDefaultCover( cover ); return true; } else { IMAGE_SOURCE_FROM_BYTES(defCover, cr3_def_cover_gif); _docview->setDefaultCover( defCover ); return false; } }
bool V3DocViewWin::saveHistory( lString16 filename ) { crtrace log; if ( filename.empty() ) filename = _historyFileName; if ( filename.empty() ) { CRLog::info("Cannot write history file - no file name specified"); return false; } CRLog::debug("Exporting bookmarks to %s", UnicodeToUtf8(_bookmarkDir).c_str()); _docview->exportBookmarks(_bookmarkDir); //use default filename _historyFileName = filename; log << "V3DocViewWin::saveHistory(" << filename << ")"; LVStreamRef stream = LVOpenFileStream( filename.c_str(), LVOM_WRITE ); if ( !stream ) { lString16 path16 = LVExtractPath( filename ); lString8 path = UnicodeToLocal( path16 ); #ifdef _WIN32 if ( !CreateDirectoryW( path16.c_str(), NULL ) ) { CRLog::error("Cannot create directory %s", path.c_str() ); } else { stream = LVOpenFileStream( filename.c_str(), LVOM_WRITE ); } #else path.erase( path.length()-1, 1 ); CRLog::warn("Cannot create settings file, trying to create directory %s", path.c_str()); if ( mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) ) { CRLog::error("Cannot create directory %s", path.c_str() ); } else { stream = LVOpenFileStream( filename.c_str(), LVOM_WRITE ); } #endif } if ( stream.isNull() ) { CRLog::error("Error while creating history file %s - position will be lost", UnicodeToUtf8(filename).c_str() ); return false; } return saveHistory( stream ); }
bool V3DocViewWin::saveSettings( lString16 filename ) { crtrace log; if ( filename.empty() ) filename = _settingsFileName; if ( filename.empty() ) return false; _settingsFileName = filename; log << "V3DocViewWin::saveSettings(" << filename << ")"; LVStreamRef stream = LVOpenFileStream( filename.c_str(), LVOM_WRITE ); if ( !stream ) { lString16 path16 = LVExtractPath( filename ); lString8 path = UnicodeToLocal( path16 ); #ifdef _WIN32 if ( !CreateDirectoryW( path16.c_str(), NULL ) ) { CRLog::error("Cannot create directory %s", path.c_str() ); } else { stream = LVOpenFileStream( filename.c_str(), LVOM_WRITE ); } #else path.erase( path.length()-1, 1 ); CRLog::warn("Cannot create settings file, trying to create directory %s", path.c_str()); if ( mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) ) { CRLog::error("Cannot create directory %s", path.c_str() ); } else { stream = LVOpenFileStream( filename.c_str(), LVOM_WRITE ); } #endif } if ( stream.isNull() ) { lString8 fn = UnicodeToUtf8( filename ); CRLog::error("Cannot open settings file %s for write", fn.c_str() ); return false; } return _props->saveToStream( stream.get() ); }
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()); } } } } }
//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() ); }
/// load stylesheet from file, with processing of import bool LVLoadStylesheetFile( lString16 pathName, lString8 & css ) { LVStreamRef file = LVOpenFileStream( pathName.c_str(), LVOM_READ ); if ( file.isNull() ) return false; lString8 txt = UnicodeToUtf8( LVReadTextFile( file ) ); lString8 txt2; const char * s = txt.c_str(); lString8 import_file; if ( LVProcessStyleSheetImport( s, import_file ) ) { lString16 importFilename = LVMakeRelativeFilename( pathName, Utf8ToUnicode(import_file) ); //lString8 ifn = UnicodeToLocal(importFilename); //const char * ifns = ifn.c_str(); if ( !importFilename.empty() ) { LVStreamRef file2 = LVOpenFileStream( importFilename.c_str(), LVOM_READ ); if ( !file2.isNull() ) txt2 = UnicodeToUtf8( LVReadTextFile( file2 ) ); } } if ( !txt2.empty() ) txt2 << "\r\n"; css = txt2 + s; return !css.empty(); }
virtual const lChar16 * GetName() const { return _name.c_str(); }