Skip to content

Commit

Permalink
Now using case insensitive search for file Garmin/GarminDevice.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Diesner authored and Andreas Diesner committed May 7, 2013
1 parent d883fd6 commit 6aaf15b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/deviceManager.cpp
Expand Up @@ -25,6 +25,7 @@
#include "garminFilebasedDevice.h"

#include "edge305Device.h"
#include "gpsFunctions.h"

#include <algorithm>
#include <string>
Expand Down Expand Up @@ -140,13 +141,15 @@ void DeviceManager::startFindDevices() {
while ( (ent = getmntent(mounts)) != NULL ) {
string filesystype = ent->mnt_type;
string mountPath = ent->mnt_dir;
Log::dbg("Searching on ["+mountPath+"] ["+filesystype+"]");
if (filesystype.compare("vfat") == 0) {
Log::dbg("Searching on ["+mountPath+"] ["+filesystype+"]");
GpsDevice *dev = createGarminDeviceFromPath(mountPath, NULL);
if (dev != NULL) {
dev->setBackupPath(backupPath);
gpsDeviceList.push_back(dev);
}
} else {
Log::dbg("Not searching on ["+mountPath+"] ["+filesystype+"] - wrong fstype.");
}
}

Expand Down Expand Up @@ -209,6 +212,7 @@ void DeviceManager::startFindDevices() {

if ((deviceEnabled) && (name!=NULL)) {
if (name->GetText() != NULL) {
string devName = name->GetText();
for(unsigned int i=0; i < gpsDeviceList.size(); i++)
{
// Device exists, and is configured in configuration
Expand All @@ -217,10 +221,10 @@ void DeviceManager::startFindDevices() {
}
}
if (currentDevice == NULL) { // no device found
Log::dbg("Creating device "+devName+" from configuration.");

currentDevice = createGarminDeviceFromPath(storagePath, NULL);
if (currentDevice == NULL) {
string devName = name->GetText();
if (Log::enabledDbg()) { Log::dbg("Device from configuration - no XML found for "+devName); }

//TODO: Create a pseudo configuration file for this device
Expand All @@ -236,12 +240,16 @@ void DeviceManager::startFindDevices() {
}
currentDevice = createGarminDeviceFromPath(storagePath, doc);
delete(doc);
} else {
Log::dbg("Created device "+devName+" from existing GarminDevice.xml configuration.");
}

if (currentDevice != NULL) {
currentDevice->setBackupPath(backupPath);
gpsDeviceList.push_back(currentDevice);
}
} else {
Log::dbg("Ignoring device "+devName+" from configuration - existing device with same name exists.");
}
}
}
Expand Down Expand Up @@ -320,17 +328,32 @@ GpsDevice * DeviceManager::createGarminDeviceFromPath(string devicepath, TiXmlDo
}

bool garminDirFound = false;
string dirname = "";
while ((dirp = readdir(dp)) != NULL) {
string dir = string(dirp->d_name);
if (dir.compare("Garmin") == 0) {
dirname = string(dirp->d_name);
if (GpsFunctions::iequals(dirname, "Garmin")) {
garminDirFound = true;
break;
}
}
closedir(dp);

if (garminDirFound) {
string fullPath = devicepath + "/Garmin/GarminDevice.xml";
string basePath = devicepath + "/" + dirname;
string fullPath = basePath +"/GarminDevice.xml";

// Ignore case search for file GarminDevice.xml
if((dp = opendir(basePath.c_str())) != NULL) {
while ((dirp = readdir(dp)) != NULL) {
string entry = string(dirp->d_name);
if (GpsFunctions::iequals(entry, "GarminDevice.xml")) {
fullPath = basePath + "/" + entry;
break;
}
}
closedir(dp);
}

doc = new TiXmlDocument(fullPath);
deleteXmlDoc = true;
if (!doc->LoadFile()) {
Expand Down
11 changes: 11 additions & 0 deletions src/gpsFunctions.h
Expand Up @@ -188,6 +188,17 @@ class GpsFunctions {
return in;
}

static bool iequals(const string& a, const string& b)
{
unsigned int sz = a.size();
if (b.size() != sz)
return false;
for (unsigned int i = 0; i < sz; ++i)
if (tolower(a[i]) != tolower(b[i]))
return false;
return true;
}

};

#endif // GPSFUNCTIONS_H_INCLUDED

0 comments on commit 6aaf15b

Please sign in to comment.