[rkward] rkward: Make RKCommonFunctions::getRKWardDataDir() more robust (and a bit faster), by

Thomas Friedrichsmeier null at kde.org
Thu May 3 18:54:52 UTC 2018


Git commit eca332c5bfe0a0e02df3e59427673455bef45ef4 by Thomas Friedrichsmeier.
Committed on 03/05/2018 at 18:51.
Pushed by tfry into branch 'master'.

Make RKCommonFunctions::getRKWardDataDir() more robust (and a bit faster), by
- using QStandardPaths::AppDataLocation instead of GenericDataLocation
  (see https://mail.kde.org/pipermail/kde-frameworks-devel/2018-May/063151.html)
- looking at all found candidates, and pick the one with the correct version (if any)
- caching the result

M  +17   -2    rkward/misc/rkcommonfunctions.cpp
M  +1    -5    rkward/rkward.cpp

https://commits.kde.org/rkward/eca332c5bfe0a0e02df3e59427673455bef45ef4

diff --git a/rkward/misc/rkcommonfunctions.cpp b/rkward/misc/rkcommonfunctions.cpp
index 09f7dccb..22117efa 100644
--- a/rkward/misc/rkcommonfunctions.cpp
+++ b/rkward/misc/rkcommonfunctions.cpp
@@ -2,7 +2,7 @@
                           rkcommonfunctions  -  description
                              -------------------
     begin                : Mon Oct 17 2005
-    copyright            : (C) 2005, 2006, 2007, 2009, 2010, 2011 by Thomas Friedrichsmeier
+    copyright            : (C) 2005-2018 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -26,6 +26,8 @@
 #include <kxmlguiclient.h>
 
 #include "../settings/rksettingsmodulegeneral.h"
+#include "../version.h"
+#include "../debug.h"
 
 namespace RKCommonFunctions {
 	void removeNamedElementsRecursive (const QStringList &names, QDomNode &parent) {
@@ -155,7 +157,20 @@ namespace RKCommonFunctions {
 	}
 
 	QString getRKWardDataDir () {
-		return (QStandardPaths::locate (QStandardPaths::GenericDataLocation, "rkward/resource.ver").replace ("resource.ver", QString ()));
+		static QString rkward_data_dir;
+		if (rkward_data_dir.isNull ()) {
+			QStringList candidates = QStandardPaths::locateAll (QStandardPaths::AppDataLocation, "resource.ver");
+			for (int i = 0; i < candidates.size (); ++i) {
+				QFile resource_ver (candidates[i]);
+				if (resource_ver.open (QIODevice::ReadOnly) && (resource_ver.read (100).trimmed () == RKWARD_VERSION)) {
+					rkward_data_dir = candidates[i].replace ("resource.ver", QString ());
+					return rkward_data_dir;
+				}
+			}
+			rkward_data_dir = "";   // prevents checking again
+			RK_DEBUG(APP, DL_WARNING, "resource.ver not found. Data path(s): %s", qPrintable (QStandardPaths::standardLocations (QStandardPaths::AppDataLocation).join (':')));
+		}
+		return rkward_data_dir;
 	}
 
 	QString getUseableRKWardSavefileName (const QString &prefix, const QString &postfix) {
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 30b8fffb..6a778b8a 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -84,8 +84,6 @@
 #include "windows/rkdebugmessagewindow.h"
 #include "rkconsole.h"
 #include "debug.h"
-#include "version.h"
-
 
 #include "agents/showedittextfileagent.h"	// TODO: see below: needed purely for linking!
 #include "dialogs/rkreadlinedialog.h"	// TODO: see below: needed purely for linking!
@@ -199,10 +197,8 @@ void RKWardMainWindow::doPostInit () {
 	RK_TRACE (APP);
 
 	// Check installation first
-	QFile resource_ver (RKCommonFunctions::getRKWardDataDir () + "resource.ver");
-	if (!(resource_ver.open (QIODevice::ReadOnly) && (resource_ver.read (100).trimmed () == RKWARD_VERSION))) {
+	if (RKCommonFunctions::getRKWardDataDir ().isEmpty ()) {
 		KMessageBox::error (this, i18n ("<p>RKWard either could not find its resource files at all, or only an old version of those files. The most likely cause is that the last installation failed to place the files in the correct place. This can lead to all sorts of problems, from single missing features to complete failure to function.</p><p><b>You should quit RKWard, now, and fix your installation</b>. For help with that, see <a href=\"http://rkward.kde.org/compiling\">http://rkward.kde.org/compiling</a>.</p>"), i18n ("Broken installation"), KMessageBox::Notify | KMessageBox::AllowLink);
-		RK_DEBUG(APP, DL_WARNING, "resource.ver not found. Data path(s): %s", qPrintable (QStandardPaths::standardLocations (QStandardPaths::GenericDataLocation).join (':')));
 	}
 
 	QStringList open_urls = RKGlobals::startup_options.take ("initial_urls").toStringList ();



More information about the rkward-tracker mailing list