--- a/upplay.cpp
+++ b/upplay.cpp
@@ -26,11 +26,14 @@
#include <QObject>
#include <QTimer>
#include <QStringList>
+#include <QSettings>
+#include <QMessageBox>
#include <libupnpp/upnpplib.hxx>
#include <libupnpp/log.hxx>
#include "application.h"
+#include "upadapt/upputils.h"
using namespace UPnPP;
@@ -95,17 +98,38 @@
if ((cp = getenv("UPPLAY_LOGLEVEL"))) {
Logger::getTheLog("")->setLogLevel(Logger::LogLevel(atoi(cp)));
}
+ QSettings settings;
+ string ifname = qs2utf8s(settings.value("netifname").toString().trimmed());
+ if (!ifname.empty()) {
+ cerr << "Initializing library with interface " << ifname << endl;
+ }
+
+ // Note that the lib init may fail here if ifname is wrong.
+ // The later discovery would call the lib init again (because
+ // the singleton is still null), which would retry the init,
+ // without an interface this time, which would probably succeed,
+ // so that things may still mostly work, which is confusing and the
+ // reason we do the retry here instead.
+ LibUPnP *mylib = LibUPnP::getLibUPnP(false, 0, ifname);
+ if (!mylib || !mylib->ok()) {
+ if (mylib)
+ cerr << mylib->errAsString("main", mylib->getInitError()) << endl;
+ if (ifname.empty()) {
+ QMessageBox::warning(0, "Upplay", app.tr("Lib init failed"));
+ return 1;
+ } else {
+ QMessageBox::warning(0, "Upplay",
+ app.tr("Lib init failed for ") +
+ settings.value("netifname").toString() +
+ app.tr(". Retrying with null interface"));
+ mylib = LibUPnP::getLibUPnP();
+ if (!mylib || !mylib->ok()) {
+ QMessageBox::warning(0, "Upplay", app.tr("Lib init failed"));
+ return 1;
+ }
+ }
+ }
- LibUPnP *mylib = LibUPnP::getLibUPnP();
- if (!mylib) {
- cerr << "Can't get LibUPnP" << endl;
- return 1;
- }
- if (!mylib->ok()) {
- cerr << "Lib init failed: " <<
- mylib->errAsString("main", mylib->getInitError()) << endl;
- return 1;
- }
if ((cp = getenv("UPPLAY_UPNPLOGFILENAME"))) {
char *cp1 = getenv("UPPLAY_UPNPLOGLEVEL");
int loglevel = LibUPnP::LogLevelNone;
@@ -117,7 +141,8 @@
int(LibUPnP::LogLevelDebug) : loglevel;
if (loglevel != LibUPnP::LogLevelNone) {
- mylib->setLogFileName(cp, LibUPnP::LogLevel(loglevel));
+ if (mylib)
+ mylib->setLogFileName(cp, LibUPnP::LogLevel(loglevel));
}
}