void search_logic_delete_chapter (string bible, int book, int chapter) { string fragment = search_logic_chapter_file (bible, book, chapter); fragment = filter_url_basename (fragment); vector <string> files = filter_url_scandir (search_logic_index_folder ()); for (auto & file : files) { if (file.find (fragment) == 0) { string path = filter_url_create_path (search_logic_index_folder (), file); filter_url_unlink (path); } } }
// 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); } } }
// 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); } } }
// Creates a sample Bible. // Creating a Sample Bible used to take a relatively long time, in particular on low power devices. // The new and current method does a simple copy operation and that is fast. void demo_create_sample_bible () { Database_Logs::log ("Creating sample Bible"); // Remove and create the sample Bible. Database_Bibles database_bibles; database_bibles.deleteBible (demo_sample_bible_name ()); database_bibles.createBible (demo_sample_bible_name ()); // Remove index for the sample Bible. search_logic_delete_bible (demo_sample_bible_name ()); // Copy the Bible data. string source = sample_bible_bible_path (); string destination = database_bibles.bibleFolder (demo_sample_bible_name ()); filter_url_dir_cp (source, destination); // Copy the Bible search index. source = sample_bible_index_path (); destination = search_logic_index_folder (); filter_url_dir_cp (source, destination); Database_Logs::log ("Sample Bible was created"); }
string search_logic_bible_fragment (string bible) { return filter_url_create_path (search_logic_index_folder (), bible + "_"); }