summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Application')
-rw-r--r--Swiften/Application/ApplicationPathProvider.h1
-rw-r--r--Swiften/Application/MacOSXApplicationPathProvider.cpp14
-rw-r--r--Swiften/Application/MacOSXApplicationPathProvider.h1
-rw-r--r--Swiften/Application/UnitTest/ApplicationPathProviderTest.cpp8
-rw-r--r--Swiften/Application/UnixApplicationPathProvider.h14
-rw-r--r--Swiften/Application/WindowsApplicationPathProvider.cpp11
-rw-r--r--Swiften/Application/WindowsApplicationPathProvider.h2
7 files changed, 51 insertions, 0 deletions
diff --git a/Swiften/Application/ApplicationPathProvider.h b/Swiften/Application/ApplicationPathProvider.h
index ba671ee..cf97299 100644
--- a/Swiften/Application/ApplicationPathProvider.h
+++ b/Swiften/Application/ApplicationPathProvider.h
@@ -20,6 +20,7 @@ namespace Swift {
boost::filesystem::path getAvatarDir() const;
virtual boost::filesystem::path getHomeDir() const = 0;
virtual boost::filesystem::path getSettingsDir() const = 0;
+ virtual boost::filesystem::path getExecutableDir() const = 0;
boost::filesystem::path getProfileDir(const String& profile) const;
protected:
diff --git a/Swiften/Application/MacOSXApplicationPathProvider.cpp b/Swiften/Application/MacOSXApplicationPathProvider.cpp
index 3b9a797..7e4931a 100644
--- a/Swiften/Application/MacOSXApplicationPathProvider.cpp
+++ b/Swiften/Application/MacOSXApplicationPathProvider.cpp
@@ -7,6 +7,7 @@
#include "Swiften/Application/MacOSXApplicationPathProvider.h"
#include <iostream>
+#include <mach-o/dyld.h>
namespace Swift {
@@ -28,4 +29,17 @@ boost::filesystem::path MacOSXApplicationPathProvider::getHomeDir() const {
return boost::filesystem::path(getenv("HOME"));
}
+
+boost::filesystem::path MacOSXApplicationPathProvider::getExecutableDir() const {
+ ByteArray path;
+ uint32_t size = 4096;
+ path.resize(size);
+ if (_NSGetExecutablePath(path, &size) == 0) {
+ return boost::filesystem::path(path.toString().getUTF8Data()).parent_path();
+ }
+ else {
+ return boost::filesystem::path();
+ }
+}
+
}
diff --git a/Swiften/Application/MacOSXApplicationPathProvider.h b/Swiften/Application/MacOSXApplicationPathProvider.h
index c1d86d0..e03c753 100644
--- a/Swiften/Application/MacOSXApplicationPathProvider.h
+++ b/Swiften/Application/MacOSXApplicationPathProvider.h
@@ -15,5 +15,6 @@ namespace Swift {
virtual boost::filesystem::path getHomeDir() const;
boost::filesystem::path getSettingsDir() const;
+ virtual boost::filesystem::path getExecutableDir() const;
};
}
diff --git a/Swiften/Application/UnitTest/ApplicationPathProviderTest.cpp b/Swiften/Application/UnitTest/ApplicationPathProviderTest.cpp
index 7cb277a..75b8639 100644
--- a/Swiften/Application/UnitTest/ApplicationPathProviderTest.cpp
+++ b/Swiften/Application/UnitTest/ApplicationPathProviderTest.cpp
@@ -8,12 +8,14 @@
#include <cppunit/extensions/TestFactoryRegistry.h>
#include "Swiften/Application/PlatformApplicationPathProvider.h"
+#include "Swiften/Base/String.h"
using namespace Swift;
class ApplicationPathProviderTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ApplicationPathProviderTest);
CPPUNIT_TEST(testGetSettingsDir);
+ CPPUNIT_TEST(testGetExecutableDir);
CPPUNIT_TEST_SUITE_END();
public:
@@ -33,6 +35,12 @@ class ApplicationPathProviderTest : public CppUnit::TestFixture {
boost::filesystem::remove(dir);
}
+
+ void testGetExecutableDir() {
+ boost::filesystem::path dir = testling_->getExecutableDir();
+ CPPUNIT_ASSERT(boost::filesystem::is_directory(dir));
+ CPPUNIT_ASSERT(String(dir.string()).endsWith("UnitTest"));
+ }
private:
ApplicationPathProvider* testling_;
diff --git a/Swiften/Application/UnixApplicationPathProvider.h b/Swiften/Application/UnixApplicationPathProvider.h
index 04387f7..170d53a 100644
--- a/Swiften/Application/UnixApplicationPathProvider.h
+++ b/Swiften/Application/UnixApplicationPathProvider.h
@@ -9,6 +9,7 @@
#include "Swiften/Application/ApplicationPathProvider.h"
#include <iostream>
+#include <unistd.h>
namespace Swift {
class UnixApplicationPathProvider : public ApplicationPathProvider {
@@ -30,6 +31,19 @@ namespace Swift {
}
return result;
}
+
+ virtual boost::filesystem::path getExecutableDir() const {
+ ByteArray path;
+ path.resize(SSIZE_MAX);
+ size_t size = readlink("/proc/self/exe", path.getData(), path.getSize());
+ if (size > 0) {
+ path.resize(size);
+ return boost::filesystem::path(path.toString().getUTF8Data()).parent_path();
+ }
+ else {
+ return boost::filesystem::path();
+ }
+ }
};
}
diff --git a/Swiften/Application/WindowsApplicationPathProvider.cpp b/Swiften/Application/WindowsApplicationPathProvider.cpp
index 3fdcb88..2e84e90 100644
--- a/Swiften/Application/WindowsApplicationPathProvider.cpp
+++ b/Swiften/Application/WindowsApplicationPathProvider.cpp
@@ -6,9 +6,20 @@
#include "Swiften/Application/WindowsApplicationPathProvider.h"
+#include <windows.h>
+
+#include "Swiften/Base/ByteArray.h"
+
namespace Swift {
WindowsApplicationPathProvider::WindowsApplicationPathProvider(const String& name) : ApplicationPathProvider(name) {
}
+boost::filesystem::path WindowsApplicationPathProvider::getExecutableDir() const {
+ ByteArray data;
+ data.resize(2048);
+ GetModuleFileName(NULL, data.getData(), data.getSize());
+ return boost::filesystem::path(data.toString().getUTF8Data()).parent_path();
+}
+
}
diff --git a/Swiften/Application/WindowsApplicationPathProvider.h b/Swiften/Application/WindowsApplicationPathProvider.h
index 0d6862e..1ba4298 100644
--- a/Swiften/Application/WindowsApplicationPathProvider.h
+++ b/Swiften/Application/WindowsApplicationPathProvider.h
@@ -26,5 +26,7 @@ namespace Swift {
char* homeDirRaw = getenv("USERPROFILE");
return boost::filesystem::path(homeDirRaw);
}
+
+ virtual boost::filesystem::path getExecutableDir() const;
};
}