// Prepares a sample Bible. // The output of this is supposed to be manually put into the source tree, folder "samples". // This will be used to quickly create a sample Bible, that is fast, even on mobile devices. void demo_prepare_sample_bible () { Database_Bibles database_bibles; // Remove the Bible to remove all stuff that might have been in it. database_bibles.deleteBible (demo_sample_bible_name ()); search_logic_delete_bible (demo_sample_bible_name ()); // Create a new one. database_bibles.createBible (demo_sample_bible_name ()); // Location of the USFM files for the sample Bible. string directory = filter_url_create_root_path ("demo"); vector <string> files = filter_url_scandir (directory); for (auto file : files) { // Only process the USFM files. if (filter_url_get_extension (file) == "usfm") { cout << file << endl; // Read the USFM. file = filter_url_create_path (directory, file); string usfm = filter_url_file_get_contents (file); usfm = filter_string_str_replace (" ", " ", usfm); // Import the USFM into the Bible. vector <BookChapterData> book_chapter_data = usfm_import (usfm, styles_logic_standard_sheet ()); for (auto data : book_chapter_data) { Bible_Logic::storeChapter (demo_sample_bible_name (), data.book, data.chapter, data.data); } } } // Clean the destination location for the Bible. string destination = sample_bible_bible_path (); filter_url_rmdir (destination); // Copy the Bible data to the destination. string source = database_bibles.bibleFolder (demo_sample_bible_name ()); filter_url_dir_cp (source, destination); // Clean the destination location for the Bible search index. destination = sample_bible_index_path (); filter_url_rmdir (destination); // Create destination location. filter_url_mkdir (destination); // Copy the index files over to the destination. source = search_logic_index_folder (); files = filter_url_scandir (source); for (auto file : files) { if (file.find (demo_sample_bible_name ()) != string::npos) { string source_file = filter_url_create_path (source, file); string destination_file = filter_url_create_path (destination, file); filter_url_file_cp (source_file, destination_file); } } }
// Copies the search index of Bible $original to Bible $destination. void search_logic_copy_bible (string original, string destination) { string original_fragment = search_logic_bible_fragment (original); original_fragment = filter_url_basename (original_fragment); string destination_fragment = search_logic_bible_fragment (destination); destination_fragment = filter_url_basename (destination_fragment); vector <string> files = filter_url_scandir (search_logic_index_folder ()); for (auto & file : files) { if (file.find (original_fragment) == 0) { string original_path = filter_url_create_path (search_logic_index_folder (), file); string destination_file = destination_fragment + file.substr (original_fragment.length ()); string destination_path = filter_url_create_path (search_logic_index_folder (), destination_file); filter_url_file_cp (original_path, destination_path); } } }
// Copies the entire directory $input to a directory named $output. // It will recursively copy the inner directories also. void filter_url_dir_cp (const string & input, const string & output) { // Create the output directory. filter_url_mkdir (output); // Check on all files in the input directory. vector <string> files = filter_url_scandir (input); for (auto & file : files) { string input_path = filter_url_create_path (input, file); string output_path = filter_url_create_path (output, file); if (filter_url_is_dir (input_path)) { // Create output directory. filter_url_mkdir (output_path); // Handle the new input directory. filter_url_dir_cp (input_path, output_path); } else { // Copy input file to output. filter_url_file_cp (input_path, output_path); } } }
void export_quickbible (string bible, bool log) { string directory = filter_url_create_path (Export_Logic::bibleDirectory (bible), "quickbible"); if (!file_or_dir_exists (directory)) filter_url_mkdir (directory); Database_Bibles database_bibles; string stylesheet = Database_Config_Bible::getExportStylesheet (bible); string yet_contents; yet_contents.append (export_quickbible_tabify ("info", "shortName", bible)); yet_contents.append (export_quickbible_tabify ("info", "longName", bible)); yet_contents.append (export_quickbible_tabify ("info", "description", bible)); yet_contents.append (export_quickbible_tabify ("info", "locale", "en")); vector <int> books = database_bibles.getBooks (bible); for (auto book : books) { string bookname = Database_Books::getEnglishFromId (book); yet_contents.append (export_quickbible_tabify ("book_name", convert_to_string (book), bookname, "")); } for (auto book : books) { // The .yet to .yes converter only handles books > 0. if (book) { vector <int> chapters = database_bibles.getChapters (bible, book); for (auto chapter : chapters) { // The .yet to .yes converter only handles chapters > 0. if (chapter) { Filter_Text filter_text = Filter_Text (bible); filter_text.initializeHeadingsAndTextPerVerse (true); string usfm = database_bibles.getChapter (bible, book, chapter); filter_text.addUsfmCode (usfm); filter_text.run (stylesheet); map <int, string> text = filter_text.getVersesText (); for (auto & element : text) { int verse = element.first; // The .yet to .yes converter only handles verses > 0. if (verse) { string bk = convert_to_string (book); string ch = convert_to_string (chapter); string vs = convert_to_string (element.first); string tx = element.second; if (tx.empty ()) tx = "empty"; yet_contents.append (export_quickbible_tabify ("verse", bk, ch, vs, tx)); } } } } } } string bible_yet = filter_url_create_path (directory, "bible.yet"); filter_url_file_put_contents (bible_yet, yet_contents); string yet2yes_jar = filter_url_create_root_path ("export", "YetToYes2.jar"); string bible_yes = filter_url_create_path (directory, "bible.yes"); filter_shell_run ("", "java", { "-jar", yet2yes_jar, bible_yet, bible_yes }, NULL, NULL); string quickbible_html_source = filter_url_create_root_path ("export", "quickbible.html"); string quickbible_html_destination = filter_url_create_path (directory, "quickbible.html"); filter_url_file_cp (quickbible_html_source, quickbible_html_destination); Database_State::clearExport (bible, 0, Export_Logic::export_quick_bible); if (log) Database_Logs::log (translate("Exported to Quick Bible") + " " + bible, Filter_Roles::translator ()); }