// SwordIndex.cpp: implementation of the SwordIndex class. // ////////////////////////////////////////////////////////////////////// #include "ApplicationInterface.h" #include "SwordIndex.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// const WCHAR* configDir=L"\\Program Files\\sword"; const CHAR* swordConfigDir="/Program Files/sword/"; const WCHAR* configFile=L"\\Program Files\\sword\\mods.conf"; const WCHAR* autoInstallDir=L"\\Program Files\\sword\\newmods"; const CHAR* swordAutoInstallDir="/Program Files/sword/newmods/"; TCHAR* defBookNames[66]={ L"Gen",L"Exo",L"Lev",L"Num",L"Deu",L"Jos",L"Jud",L"Rut",L"1Sa", L"2Sa",L"1Ki",L"2Ki",L"1Ch",L"2Ch",L"Ezr",L"Neh",L"Est",L"Job",L"Psa",L"Pro",L"Ecc",L"Son",L"Isa",L"Jer", L"Lam",L"Eze",L"Dan",L"Hos",L"Joe",L"Amo",L"Oba",L"Jon",L"Mic",L"Nah",L"Hab",L"Zep",L"Hag",L"Zec",L"Mal", L"Mat",L"Mar",L"Luk",L"Joh",L"Act",L"Rom",L"1Co",L"2Co",L"Gal",L"Eph",L"Phi",L"Col", L"1Th",L"2Th",L"1Ti",L"2Ti",L"Tit",L"Phi",L"Heb",L"Jas",L"1Pe",L"2Pe",L"1Jo",L"2Jo",L"3Jo",L"Jud",L"Rev", }; sword::SWMgr* SwordIndex::manager; int SwordIndex::indices=0; std::map* SwordIndex::texts; SwordIndex::SwordIndex() { initManager(); if (texts->begin()!=texts->end()) { bookNames=defBookNames; verse=new sword::VerseKey("Gen 1:1"); verse->Persist(1); mark=new sword::VerseKey("Gen 1:1"); mark->Persist(1); book=1; setModule(texts->begin()->second); } else bible=0; } SwordIndex::~SwordIndex() { leaveManager(); if (verse) delete verse; if (mark) delete mark; } void SwordIndex::initManager() { if (indices==0) { //We need a manager //make sure the right files are available CreateDirectory(configDir,NULL); CreateDirectory(autoInstallDir,NULL); HANDLE newConf=CreateFile(configFile,GENERIC_WRITE,0,NULL,CREATE_NEW,0,0); if (newConf!=INVALID_HANDLE_VALUE) { DWORD check=0; std::string line1="[Globals]\r\n"; std::string line2="AutoInstall="; line2+=String(swordAutoInstallDir); line2+="\r\n"; WriteFile(newConf,line1.c_str(),line1.length(),&check,NULL); WriteFile(newConf,line2.c_str(),line2.length(),&check,NULL); CloseHandle(newConf); } texts=new ModuleMap(); __try { manager=new sword::SWMgr(swordConfigDir,true, new sword::SWFilterMgr() ); //get the available bibles out of here sword::ModMap::iterator it; sword::SWModule* curMod = 0; for (it = manager->Modules.begin(); it != manager->Modules.end(); it++) { curMod = (*it).second; if (!strcmp(curMod->Type(), "Biblical Texts")) { curMod->AddStripFilter(new sword::ThMLHTML()); (*texts)[curMod->Name()]=curMod; } } } __except (EXCEPTION_EXECUTE_HANDLER) { manager=0; texts->clear(); }; } indices++; } void SwordIndex::leaveManager() { indices--; if (indices==0) { if (manager!=0) delete manager; delete texts; } } UString SwordIndex::toString() { UString result=toUString(String(verse->getShortText())); return result; } UString SwordIndex::bookName(int book) { // return toUString(String(getBook(book).prefAbbrev)); return UString(defBookNames[book-1]); } void SwordIndex::setBook(int book) { this->book=book; if (book<=otBookCount()) { verse->Testament(1); verse->Book((char)book); } else { verse->Testament(2); verse->Book((char)book-otBookCount()); } } sword::sbook SwordIndex::getBook(int book) { book--; //we now need to start at 0 if (bookbooks[0][book]); else if (bookbooks[1][book-otBookCount()]); else return (verse->books[1][bookCount()-otBookCount()-1]); } int SwordIndex::chapCount() { return getBook(book).chapmax; } void SwordIndex::setChap(int chap) { verse->Chapter(chap); } int SwordIndex::getChap() { return verse->Chapter(); } int SwordIndex::verseCount() { return getBook(book).versemax[verse->Chapter()-1]; } void SwordIndex::setVerse(int verse) { this->verse->Verse(verse); } int SwordIndex::getVerse() { return verse->Verse(); } String SwordIndex::verseText() { return String(bible->StripText()); } void SwordIndex::setMark() { mark->copyFrom(verse); } void SwordIndex::jumpBack() { verse->copyFrom(mark); } void SwordIndex::next() { verse->increment(1); } void SwordIndex::setModule(Module m) { bible=m; bible->setKey(verse); }