[sword-svn] r3865 - trunk/bindings/java-jni/jni

scribe at crosswire.org scribe at crosswire.org
Mon Sep 13 06:34:36 EDT 2021


Author: scribe
Date: 2021-09-13 06:34:36 -0400 (Mon, 13 Sep 2021)
New Revision: 3865

Modified:
   trunk/bindings/java-jni/jni/swordstub.cpp
Log:
java-jni bindings:
	Added new preferred Android path: /sdcard/Documents/sword/
	Added strip of search term before passing to SWModule::search


Modified: trunk/bindings/java-jni/jni/swordstub.cpp
===================================================================
--- trunk/bindings/java-jni/jni/swordstub.cpp	2021-07-31 10:20:47 UTC (rev 3864)
+++ trunk/bindings/java-jni/jni/swordstub.cpp	2021-09-13 10:34:36 UTC (rev 3865)
@@ -60,6 +60,7 @@
 
 namespace {
 bool firstInit = true;
+bool firstInstallInit = true;
 JavaVM *javaVM = nullptr;
 WebMgr *mgr = nullptr;
 InstallMgr *installMgr = nullptr;
@@ -71,7 +72,8 @@
 JNIEnv *bibleSyncListenerEnv = nullptr;
 #endif
 SWBuf STORAGE_BASE;
-const char *SDCARD_PATH = "/sdcard/sword";
+const char *OLD_SDCARD_PATH = "/sdcard/sword";
+const char *SDCARD_PATH = "/sdcard/Documents/sword";
 const char *AND_BIBLE_MODULES_PATH = "/sdcard/Android/data/net.bible.android.activity/files";
 //ANativeActivity *_activity;
 
@@ -215,14 +217,13 @@
 		SWLog::setSystemLog(new AndroidLogger());
 		SWLog::getSystemLog()->setLogLevel(SWLog::LOG_DEBUG);
 		StringMgr::setSystemStringMgr(new AndroidStringMgr());
-		firstInit = false;
 	}
 	if (!mgr) {
 SWLOGD("libsword: init() begin");
 		SWBuf baseDir  = SDCARD_PATH;
 		SWBuf confPath = baseDir + "/mods.d/globals.conf";
 		// be sure we have at least some config file already out there
-		if (!FileMgr::existsFile(confPath.c_str())) {
+		if (!FileMgr::existsFile(confPath.c_str()) && firstInit) {
 SWLOGD("libsword: init() sword config not found, attempting to create parent of: %s", confPath.c_str());
 			FileMgr::createParent(confPath.c_str());
 			remove(confPath.c_str());
@@ -233,16 +234,30 @@
 			config.save();
 		}
 		if (!FileMgr::existsFile(confPath.c_str())) {
+			baseDir = OLD_SDCARD_PATH;
+			confPath = baseDir + "/mods.d/globals.conf";
+			SWLOGD("libsword: init() sword config STILL not found, switching to STORAGE_PATH (parent of): %s", confPath.c_str());
+			if (!FileMgr::existsFile(confPath.c_str()) && firstInit) {
+				FileMgr::createParent(confPath.c_str());
+				remove(confPath.c_str());
+				SWLOGD("libsword: init() saving basic: %s", confPath.c_str());
+				SWConfig config(confPath.c_str());
+				config["Globals"]["HiAndroid"] = "weeee";
+				config.save();
+			}
+		}
+		if (!FileMgr::existsFile(confPath.c_str())) {
 			baseDir = STORAGE_BASE;
 			confPath = baseDir + "/mods.d/globals.conf";
-SWLOGD("libsword: init() sword config STILL not found, attempting to create parent of: %s", confPath.c_str());
-			FileMgr::createParent(confPath.c_str());
-			remove(confPath.c_str());
-
+SWLOGD("libsword: init() sword config STILL not found, switching to STORAGE_PATH (parent of): %s", confPath.c_str());
+			if (!FileMgr::existsFile(confPath.c_str()) && firstInit) {
+				FileMgr::createParent(confPath.c_str());
+				remove(confPath.c_str());
 SWLOGD("libsword: init() saving basic: %s", confPath.c_str());
-			SWConfig config(confPath.c_str());
-			config["Globals"]["HiAndroid"] = "weeee";
-			config.save();
+				SWConfig config(confPath.c_str());
+				config["Globals"]["HiAndroid"] = "weeee";
+				config.save();
+			}
 		}
 		confPath = STORAGE_BASE + "/extraConfig.conf";
 		bool exists = FileMgr::existsFile(confPath.c_str());
@@ -262,9 +277,13 @@
 		mgr->augmentModules(AND_BIBLE_MODULES_PATH, true);
 		// if our basedir isn't the sdcard, let's augment the sdcard
 		if (strcmp(baseDir.c_str(), SDCARD_PATH)) { // NOLINT(bugprone-suspicious-string-compare)
-SWLOGD("libsword: init() augmenting modules from: %s", SDCARD_PATH);
+			SWLOGD("libsword: init() augmenting modules from: %s", SDCARD_PATH);
 			mgr->augmentModules(SDCARD_PATH, true);
 		}
+		if (strcmp(baseDir.c_str(), OLD_SDCARD_PATH)) { // NOLINT(bugprone-suspicious-string-compare)
+SWLOGD("libsword: init() augmenting modules from: %s", OLD_SDCARD_PATH);
+			mgr->augmentModules(OLD_SDCARD_PATH, true);
+		}
 		// if our basedir isn't the private storage base, let's augment the private
 		// storage base in case a previous version of the app stored modules there.
 		if (strcmp(baseDir.c_str(), STORAGE_BASE)) { // NOLINT(bugprone-suspicious-string-compare)
@@ -276,11 +295,14 @@
 		LocaleMgr::getSystemLocaleMgr()->loadConfigDir(SWBuf(STORAGE_BASE + "/uilocales.d").c_str());
 		LocaleMgr::getSystemLocaleMgr()->loadConfigDir((SWBuf(SDCARD_PATH) + "/locales.d").c_str());
 		LocaleMgr::getSystemLocaleMgr()->loadConfigDir((SWBuf(SDCARD_PATH) + "/uilocales.d").c_str());
+		LocaleMgr::getSystemLocaleMgr()->loadConfigDir((SWBuf(OLD_SDCARD_PATH) + "/locales.d").c_str());
+		LocaleMgr::getSystemLocaleMgr()->loadConfigDir((SWBuf(OLD_SDCARD_PATH) + "/uilocales.d").c_str());
 
 		mgr->setGlobalOption("Footnotes", "On");
 		mgr->setGlobalOption("Cross-references", "On");
 SWLOGD("libsword: init() end.");
 	}
+	firstInit = false;
 }
 
 void initInstall(JNIEnv *env, jobject progressReporter = nullptr) {
@@ -296,7 +318,7 @@
 		SWBuf confPath = baseDir + "/InstallMgr.conf";
 		// be sure we have at least some config file already out there
 SWLOGD("initInstall: confPath: %s", confPath.c_str());
-		if (!FileMgr::existsFile(confPath.c_str())) {
+		if (!FileMgr::existsFile(confPath.c_str()) && firstInstallInit) {
 SWLOGD("initInstall: file doesn't exist: %s", confPath.c_str());
 			FileMgr::createParent(confPath.c_str());
 			SWConfig config(confPath.c_str());
@@ -304,18 +326,32 @@
 			config.save();
 		}
 		if (!FileMgr::existsFile(confPath.c_str())) {
+			baseDir = OLD_SDCARD_PATH;
+			confPath = baseDir + "/InstallMgr.conf";
+			if (!FileMgr::existsFile(confPath.c_str()) && firstInstallInit) {
+				SWLOGD("initInstall: file STILL doesn't exist, switching to STORAGE_BASE (parent of): %s", confPath.c_str());
+				FileMgr::createParent(confPath.c_str());
+				SWConfig config(confPath.c_str());
+				config["General"]["PassiveFTP"] = "true";
+				config.save();
+			}
+		}
+		if (!FileMgr::existsFile(confPath.c_str())) {
 			baseDir = STORAGE_BASE;
 			confPath = baseDir + "/InstallMgr.conf";
-SWLOGD("initInstall: file STILL doesn't exist, attempting to create parent of: %s", confPath.c_str());
-			FileMgr::createParent(confPath.c_str());
-			SWConfig config(confPath.c_str());
-			config["General"]["PassiveFTP"] = "true";
-			config.save();
+			if (!FileMgr::existsFile(confPath.c_str()) && firstInstallInit) {
+SWLOGD("initInstall: file STILL doesn't exist, switching to STORAGE_BASE (parent of): %s", confPath.c_str());
+				FileMgr::createParent(confPath.c_str());
+				SWConfig config(confPath.c_str());
+				config["General"]["PassiveFTP"] = "true";
+				config.save();
+			}
 		}
 		installMgr = new InstallMgr(baseDir, installStatusReporter);
 		if (disclaimerConfirmed) installMgr->setUserDisclaimerConfirmed(true);
 SWLOGD("initInstall: instantiated InstallMgr with baseDir: %s", baseDir.c_str());
 	}
+	firstInstallInit = false;
 }
 
 #ifdef BIBLESYNC
@@ -1804,7 +1840,8 @@
 			}
 			*parser = module->getKeyText();
 			lscope = parser->parseVerseList(scope, *parser, true);
-			result = module->search(expression, srchType, flags, &lscope, nullptr, &percentUpdate, peeuuu);
+			SWBuf searchTerm = module->stripText(expression);
+			result = module->search(searchTerm.c_str(), srchType, flags, &lscope, nullptr, &percentUpdate, peeuuu);
 			delete parser;
 		}
 		else	result = module->search(expression, srchType, flags, nullptr, nullptr, &percentUpdate, peeuuu);



More information about the sword-cvs mailing list