Index: code/trunk/src/core/ArgumentCompletionFunctions.cc
===================================================================
--- code/trunk/src/core/ArgumentCompletionFunctions.cc	(revision 2662)
+++ code/trunk/src/core/ArgumentCompletionFunctions.cc	(revision 2710)
@@ -27,10 +27,10 @@
  */
 
+#include "ArgumentCompletionFunctions.h"
+
 #include <iostream>
 #include <map>
-
 #include <boost/filesystem.hpp>
 
-#include "ArgumentCompletionFunctions.h"
 #include "CoreIncludes.h"
 #include "Identifier.h"
@@ -63,10 +63,10 @@
                     startdirectory = ".";
                 }
-#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
+#ifdef ORXONOX_PLATFORM_WINDOWS
                 else
                 {
                     std::string dir = startdirectory.string();
                     if (dir.size() > 0 && dir[dir.size() - 1] == ':')
-                        startdirectory = dir + "/";
+                        startdirectory = dir + CP_SLASH;
                 }
 #endif
@@ -78,5 +78,5 @@
                 {
                     if (boost::filesystem::is_directory(*file))
-                        dirlist.push_back(ArgumentCompletionListElement((*file).string() + "/", getLowercase((*file).string()) + "/", (*file).leaf() + "/"));
+                        dirlist.push_back(ArgumentCompletionListElement((*file).string() + CP_SLASH, getLowercase((*file).string()) + "/", (*file).leaf() + "/"));
                     else
                         filelist.push_back(ArgumentCompletionListElement((*file).string(), getLowercase((*file).string()), (*file).leaf()));
Index: code/trunk/src/core/BaseObject.cc
===================================================================
--- code/trunk/src/core/BaseObject.cc	(revision 2662)
+++ code/trunk/src/core/BaseObject.cc	(revision 2710)
@@ -33,5 +33,7 @@
 
 #include "BaseObject.h"
-#include "tinyxml/tinyxml.h"
+
+#include <tinyxml/tinyxml.h>
+
 #include "CoreIncludes.h"
 #include "EventIncludes.h"
Index: code/trunk/src/core/CMakeLists.txt
===================================================================
--- code/trunk/src/core/CMakeLists.txt	(revision 2662)
+++ code/trunk/src/core/CMakeLists.txt	(revision 2710)
@@ -1,3 +1,22 @@
-SET(CORE_SRC_FILES
+ #
+ #             ORXONOX - the hottest 3D action shooter ever to exist
+ #                             > www.orxonox.net <
+ #
+ #        This program is free software; you can redistribute it and/or
+ #         modify it under the terms of the GNU General Public License
+ #        as published by the Free Software Foundation; either version 2
+ #            of the License, or (at your option) any later version.
+ #
+ #       This program is distributed in the hope that it will be useful,
+ #        but WITHOUT ANY WARRANTY; without even the implied warranty of
+ #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ #                 GNU General Public License for more details.
+ #
+ #   You should have received a copy of the GNU General Public License along
+ #      with this program; if not, write to the Free Software Foundation,
+ #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ #
+
+SET_SOURCE_FILES(CORE_SRC_FILES
   Clock.cc
   ConfigFileManager.cc
@@ -41,33 +60,28 @@
   TclBind.cc
   TclThreadManager.cc
+)
+ADD_SUBDIRECTORY(input)
+GET_ALL_HEADER_FILES(CORE_HDR_FILES)
+SET(CORE_FILES ${CORE_SRC_FILES} ${CORE_HDR_FILES})
 
-  tolua/tolua_bind.cc
+GENERATE_SOURCE_GROUPS(${CORE_FILES})
+GENERATE_TOLUA_BINDINGS(Core CORE_FILES INPUTFILES LuaBind.h CommandExecutor.h)
+
+ADD_LIBRARY(core SHARED ${CORE_FILES})
+
+SET_TARGET_PROPERTIES(core PROPERTIES DEFINE_SYMBOL "CORE_SHARED_BUILD")
+TARGET_LINK_LIBRARIES(core
+  ${OGRE_LIBRARY}
+  ${Boost_THREAD_LIBRARY}
+  ${Boost_FILESYSTEM_LIBRARY}
+  ${Boost_SYSTEM_LIBRARY}
+  ${Boost_DATE_TIME_LIBRARY} # MSVC only
+  ${LUA_LIBRARIES}
+  cpptcl_orxonox
+  ois_orxonox
+  tinyxml++_orxonox
+  tolua++_orxonox
+  util
 )
 
-ADD_SOURCE_DIRECTORY(CORE_SRC_FILES input)
-
-GET_TARGET_PROPERTY(TOLUA_EXE tolua_orxonox LOCATION)
-ADD_CUSTOM_COMMAND(
-  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.cc ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.h
-  COMMAND ${TOLUA_EXE} -n Core -o ../../src/core/tolua/tolua_bind.cc -H ../../src/core/tolua/tolua_bind.h ../../src/core/tolua/tolua.pkg
-  DEPENDS
-    tolua_orxonox
-    tolua/tolua.pkg
-    LuaBind.h
-    CommandExecutor.h
-  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib
-)
-
-ADD_LIBRARY(core SHARED ${CORE_SRC_FILES})
-
-TARGET_LINK_LIBRARIES(core
-  ${OGRE_LIBRARIES}
-  ${Boost_thread_LIBRARIES}
-  ${Boost_filesystem_LIBRARIES}
-  lua_orxonox
-  cpptcl_orxonox
-  ois_orxonox
-  tinyxml_orxonox
-  tolualib_orxonox
-  util
-)
+ORXONOX_INSTALL(core)
Index: code/trunk/src/core/CommandExecutor.h
===================================================================
--- code/trunk/src/core/CommandExecutor.h	(revision 2662)
+++ code/trunk/src/core/CommandExecutor.h	(revision 2710)
@@ -36,11 +36,10 @@
 #include "CommandEvaluation.h"
 
-namespace orxonox // tolua_export
-{ // tolua_export
+// tolua_begin
+namespace orxonox
+{
     class _CoreExport CommandExecutor
-    /*
-    class CommandExecutor { // tolua_export
-    */
     {
+// tolua_end
         public:
             static bool execute(const std::string& command, bool useTcl = true); // tolua_export
Index: code/trunk/src/core/CommandLine.cc
===================================================================
--- code/trunk/src/core/CommandLine.cc	(revision 2662)
+++ code/trunk/src/core/CommandLine.cc	(revision 2710)
@@ -29,6 +29,8 @@
 #include "CommandLine.h"
 
+#include <boost/filesystem.hpp>
 #include "util/String.h"
 #include "util/SubString.h"
+#include "Core.h"
 
 namespace orxonox
@@ -299,9 +301,11 @@
         this->_parse(args);
 
+        std::string filename = CommandLine::getValue("optionsFile").getString();
+        boost::filesystem::path filepath(Core::getConfigPath() / filename);
+
         // look for additional arguments in given file or start.ini as default
         // They will not overwrite the arguments given directly
         std::ifstream file;
-        std::string filename = CommandLine::getValue("optionsFile").getString();
-        file.open(filename.c_str());
+        file.open(filepath.file_string().c_str());
         args.clear();
         if (file)
Index: code/trunk/src/core/ConfigFileManager.cc
===================================================================
--- code/trunk/src/core/ConfigFileManager.cc	(revision 2662)
+++ code/trunk/src/core/ConfigFileManager.cc	(revision 2710)
@@ -30,8 +30,11 @@
 
 #include <cassert>
+#include <boost/filesystem.hpp>
+
 #include "util/Convert.h"
 #include "util/String.h"
 #include "ConsoleCommand.h"
 #include "ConfigValueContainer.h"
+#include "Core.h"
 
 namespace orxonox
@@ -220,123 +223,128 @@
     void ConfigFile::load(bool bCreateIfNotExisting)
     {
-        // Be sure we start from new
+        // Be sure we start from new in the memory
         this->clear();
 
-        // This creates the config file if it's not existing
-        std::ofstream createFile;
-        createFile.open(this->filename_.c_str(), std::fstream::app);
-        createFile.close();
+        // Get default file if necessary and available
+        boost::filesystem::path filepath(Core::getConfigPath() / this->filename_);
+        if (!boost::filesystem::exists(filepath))
+        {
+            // Try to get default one from the media folder
+            boost::filesystem::path defaultFilepath(Core::getMediaPath() / "defaultConfig" / this->filename_);
+            if (boost::filesystem::exists(defaultFilepath))
+            {
+                boost::filesystem::copy_file(defaultFilepath, filepath);
+            }
+        }
 
         // Open the file
         std::ifstream file;
-        file.open(this->filename_.c_str(), std::fstream::in);
-
-        if (!file.is_open())
-        {
-            COUT(1) << "An error occurred in ConfigFileManager.cc:" << std::endl;
-            COUT(1) << "Error: Couldn't open config-file \"" << this->filename_ << "\"." << std::endl;
-            return;
-        }
-
-        char linearray[CONFIG_FILE_MAX_LINELENGHT];
-
-        ConfigFileSection* newsection = 0;
-
-        while (file.good() && !file.eof())
-        {
-            file.getline(linearray, CONFIG_FILE_MAX_LINELENGHT);
-
-            std::string line = std::string(linearray);
-
-            std::string temp = getStripped(line);
-            if (!isEmpty(temp) && !isComment(temp))
-            {
-                size_t   pos1 = temp.find('[');
-                if (pos1 == 0) pos1 = line.find('['); else pos1 = std::string::npos;
-                size_t   pos2 = line.find(']');
-
-                if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1)
+        file.open(filepath.file_string().c_str(), std::fstream::in);
+        if (file.is_open())
+        {
+
+            char linearray[CONFIG_FILE_MAX_LINELENGHT];
+
+            ConfigFileSection* newsection = 0;
+
+            while (file.good() && !file.eof())
+            {
+                file.getline(linearray, CONFIG_FILE_MAX_LINELENGHT);
+
+                std::string line = std::string(linearray);
+
+                std::string temp = getStripped(line);
+                if (!isEmpty(temp) && !isComment(temp))
                 {
-                    // New section
-                    std::string comment = line.substr(pos2 + 1);
-                    if (isComment(comment))
-                        newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1), comment);
-                    else
-                        newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1));
-                    this->sections_.insert(this->sections_.end(), newsection);
-                    continue;
-                }
-            }
-
-            if (newsection != 0)
-            {
-                if (isComment(line))
-                {
-                    // New comment
-                    newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryComment(removeTrailingWhitespaces(line)));
-                    continue;
-                }
-                else
-                {
-                    size_t pos1 = line.find('=');
-
-                    if (pos1 != std::string::npos && pos1 > 0)
+                    size_t   pos1 = temp.find('[');
+                    if (pos1 == 0) pos1 = line.find('['); else pos1 = std::string::npos;
+                    size_t   pos2 = line.find(']');
+
+                    if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1)
                     {
-                        // New entry
-                        size_t pos2 = line.find('[');
-                        size_t pos3 = line.find(']');
-                        size_t commentposition = getNextCommentPosition(line, pos1 + 1);
-                        while (isBetweenQuotes(line, commentposition))
-                        {
-                            commentposition = getNextCommentPosition(line, commentposition + 1);
-                        }
-                        std::string value = "", comment = "";
-                        if (commentposition == std::string::npos)
-                        {
-                            value = removeTrailingWhitespaces(line.substr(pos1 + 1));
-                        }
+                        // New section
+                        std::string comment = line.substr(pos2 + 1);
+                        if (isComment(comment))
+                            newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1), comment);
                         else
-                        {
-                            value = removeTrailingWhitespaces(line.substr(pos1 + 1, commentposition - pos1 - 1));
-                            comment = removeTrailingWhitespaces(line.substr(commentposition));
-                        }
-
-                        if (pos2 != std::string::npos && pos3 != std::string::npos && pos3 > pos2 + 1)
-                        {
-                            // There might be an array index
-                            unsigned int index = 0;
-                            if (ConvertValue(&index, line.substr(pos2 + 1, pos3 - pos2 - 1)))
-                            {
-                                // New array
-                                std::list<ConfigFileEntry*>::iterator it = newsection->getEntryIterator(getStripped(line.substr(0, pos2)), index, value, false);
-                                (*it)->setValue(value);
-                                (*it)->setComment(comment);
-                                continue;
-                            }
-                        }
-
-                        // New value
-                        newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryValue(getStripped(line.substr(0, pos1)), value, false, comment));
+                            newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1));
+                        this->sections_.insert(this->sections_.end(), newsection);
                         continue;
                     }
                 }
-            }
-        }
-
-        file.close();
-
-        COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl;
-
-        // Save the file in case something changed (like stripped whitespaces)
-        this->save();
-
-        // Update all ConfigValueContainers
-        this->updateConfigValues();
+
+                if (newsection != 0)
+                {
+                    if (isComment(line))
+                    {
+                        // New comment
+                        newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryComment(removeTrailingWhitespaces(line)));
+                        continue;
+                    }
+                    else
+                    {
+                        size_t pos1 = line.find('=');
+
+                        if (pos1 != std::string::npos && pos1 > 0)
+                        {
+                            // New entry
+                            size_t pos2 = line.find('[');
+                            size_t pos3 = line.find(']');
+                            size_t commentposition = getNextCommentPosition(line, pos1 + 1);
+                            while (isBetweenQuotes(line, commentposition))
+                            {
+                                commentposition = getNextCommentPosition(line, commentposition + 1);
+                            }
+                            std::string value = "", comment = "";
+                            if (commentposition == std::string::npos)
+                            {
+                                value = removeTrailingWhitespaces(line.substr(pos1 + 1));
+                            }
+                            else
+                            {
+                                value = removeTrailingWhitespaces(line.substr(pos1 + 1, commentposition - pos1 - 1));
+                                comment = removeTrailingWhitespaces(line.substr(commentposition));
+                            }
+
+                            if (pos2 != std::string::npos && pos3 != std::string::npos && pos3 > pos2 + 1)
+                            {
+                                // There might be an array index
+                                unsigned int index = 0;
+                                if (ConvertValue(&index, line.substr(pos2 + 1, pos3 - pos2 - 1)))
+                                {
+                                    // New array
+                                    std::list<ConfigFileEntry*>::iterator it = newsection->getEntryIterator(getStripped(line.substr(0, pos2)), index, value, false);
+                                    (*it)->setValue(value);
+                                    (*it)->setComment(comment);
+                                    continue;
+                                }
+                            }
+
+                            // New value
+                            newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryValue(getStripped(line.substr(0, pos1)), value, false, comment));
+                            continue;
+                        }
+                    }
+                }
+            }
+
+            file.close();
+
+            COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl;
+
+            // Save the file in case something changed (like stripped whitespaces)
+            this->save();
+
+            // Update all ConfigValueContainers
+            this->updateConfigValues();
+        } // end file.is_open()
     }
 
     void ConfigFile::save() const
     {
+        boost::filesystem::path filepath(Core::getConfigPath() / this->filename_);
+
         std::ofstream file;
-        file.open(this->filename_.c_str(), std::fstream::out);
+        file.open(filepath.file_string().c_str(), std::fstream::out);
         file.setf(std::ios::fixed, std::ios::floatfield);
         file.precision(6);
Index: code/trunk/src/core/Core.cc
===================================================================
--- code/trunk/src/core/Core.cc	(revision 2662)
+++ code/trunk/src/core/Core.cc	(revision 2710)
@@ -33,11 +33,38 @@
 
 #include "Core.h"
+
 #include <cassert>
+#include <fstream>
+#include <cstdlib>
+#include <cstdio>
+#include <boost/filesystem.hpp>
+
+#ifdef ORXONOX_PLATFORM_WINDOWS
+#  include <windows.h>
+#elif defined(ORXONOX_PLATFORM_APPLE)
+#  include <sys/param.h>
+#  include <mach-o/dyld.h>
+#else /* Linux */
+#  include <sys/types.h>
+#  include <unistd.h>
+#endif
+
+#include "SpecialConfig.h"
+#include "util/Exception.h"
 #include "Language.h"
 #include "CoreIncludes.h"
 #include "ConfigValueIncludes.h"
+#include "LuaBind.h"
+#include "CommandLine.h"
 
 namespace orxonox
 {
+    //! Path to the parent directory of the ones above if program was installed with relativ pahts
+    static boost::filesystem::path rootPath_g;
+    static boost::filesystem::path executablePath_g;            //!< Path to the executable
+    static boost::filesystem::path mediaPath_g;                 //!< Path to the media file folder
+    static boost::filesystem::path configPath_g;                //!< Path to the config file folder
+    static boost::filesystem::path logPath_g;                   //!< Path to the log file folder
+
     bool Core::bShowsGraphics_s = false;
     bool Core::bHasServer_s     = false;
@@ -46,5 +73,9 @@
     bool Core::bIsMaster_s      = false;
 
-    Core* Core::singletonRef_s = 0;
+    bool Core::isDevBuild_s     = false;
+    Core* Core::singletonRef_s  = 0;
+
+    SetCommandLineArgument(mediaPath, "").information("PATH");
+    SetCommandLineArgument(directory, "").information("DIR");
 
     /**
@@ -58,7 +89,17 @@
         assert(Core::singletonRef_s == 0);
         Core::singletonRef_s = this;
+
         this->bInitializeRandomNumberGenerator_ = false;
-
         this->setConfigValues();
+
+        // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used
+        OutputHandler::getOutStream().setLogPath(Core::getLogPathString());
+
+        // Possible media path override by the command line
+        if (!CommandLine::getArgument("mediaPath")->hasDefaultValue())
+        {
+            //std::string mediaPath = CommandLine::getValue("mediaPath");
+            Core::tsetMediaPath(CommandLine::getValue("mediaPath"));
+        }
     }
 
@@ -77,9 +118,25 @@
     void Core::setConfigValues()
     {
-        SetConfigValue(softDebugLevelConsole_, 3).description("The maximal level of debug output shown in the console").callback(this, &Core::debugLevelChanged);
-        SetConfigValue(softDebugLevelLogfile_, 3).description("The maximal level of debug output shown in the logfile").callback(this, &Core::debugLevelChanged);
-        SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged);
+#ifdef NDEBUG
+        const unsigned int defaultLevelConsole = 1;
+        const unsigned int defaultLevelLogfile = 3;
+        const unsigned int defaultLevelShell   = 1;
+#else
+        const unsigned int defaultLevelConsole = 3;
+        const unsigned int defaultLevelLogfile = 4;
+        const unsigned int defaultLevelShell   = 3;
+#endif
+        SetConfigValue(softDebugLevelConsole_, defaultLevelConsole)
+            .description("The maximal level of debug output shown in the console").callback(this, &Core::debugLevelChanged);
+        SetConfigValue(softDebugLevelLogfile_, defaultLevelLogfile)
+            .description("The maximal level of debug output shown in the logfile").callback(this, &Core::debugLevelChanged);
+        SetConfigValue(softDebugLevelShell_, defaultLevelShell)
+            .description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged);
+
         SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged);
         SetConfigValue(bInitializeRandomNumberGenerator_, true).description("If true, all random actions are different each time you start the game").callback(this, &Core::initializeRandomNumberGenerator);
+
+        SetConfigValue(mediaPathString_, Core::getMediaPathPOSIXString())
+            .description("Relative path to the game data.").callback(this, &Core::mediaPathChanged);
     }
 
@@ -109,4 +166,13 @@
         // Read the translation file after the language was configured
         Language::getLanguage().readTranslatedLanguageFile();
+    }
+
+    /**
+    @brief
+        Callback function if the media path has changed.
+    */
+    void Core::mediaPathChanged()
+    {
+        mediaPath_g = boost::filesystem::path(this->mediaPathString_);
     }
 
@@ -177,4 +243,55 @@
     }
 
+    /**
+    @brief
+        Temporary sets the media path
+    @param path
+        The new media path
+    */
+    void Core::_tsetMediaPath(const std::string& path)
+    {
+        ModifyConfigValue(mediaPathString_, tset, path);
+    }
+
+    /*static*/ const boost::filesystem::path& Core::getMediaPath()
+    {
+        return mediaPath_g;
+    }
+    /*static*/ std::string Core::getMediaPathString()
+    {
+        return mediaPath_g.directory_string() + CP_SLASH;
+    }
+    /*static*/ std::string Core::getMediaPathPOSIXString()
+    {
+        return mediaPath_g.string() + '/';
+        
+    }
+
+    /*static*/ const boost::filesystem::path& Core::getConfigPath()
+    {
+        return configPath_g;
+    }
+    /*static*/ std::string Core::getConfigPathString()
+    {
+        return configPath_g.directory_string() + CP_SLASH;
+    }
+    /*static*/ std::string Core::getConfigPathPOSIXString()
+    {
+        return configPath_g.string() + '/';
+    }
+
+    /*static*/ const boost::filesystem::path& Core::getLogPath()
+    {
+        return logPath_g;
+    }
+    /*static*/ std::string Core::getLogPathString()
+    {
+        return logPath_g.directory_string() + CP_SLASH;
+    }
+    /*static*/ std::string Core::getLogPathPOSIXString()
+    {
+        return logPath_g.string() + '/';
+    }
+
     void Core::initializeRandomNumberGenerator()
     {
@@ -187,3 +304,163 @@
         }
     }
+
+    /**
+    @brief
+        Performs the rather lower level operations just after
+        int main() has been called.
+    @remarks
+        This gets called AFTER pre-main stuff like AddFactory,
+        SetConsoleCommand, etc.
+    */
+    /*static*/ void Core::postMainInitialisation()
+    {
+        // set location of the executable
+        Core::setExecutablePath();
+
+        // Determine whether we have an installed or a binary dir run
+        // The latter occurs when simply running from the build directory
+        Core::checkDevBuild();
+
+        // Make sure the directories we write in exist or else make them
+        Core::createDirectories();
+    }
+
+    /**
+    @brief
+        Compares the executable path with the working directory
+    */
+    /*static*/ void Core::setExecutablePath()
+    {
+#ifdef ORXONOX_PLATFORM_WINDOWS
+        // get executable module
+        TCHAR buffer[1024];
+        if (GetModuleFileName(NULL, buffer, 1024) == 0)
+            ThrowException(General, "Could not retrieve executable path.");
+
+#elif defined(ORXONOX_PLATFORM_APPLE)
+        char buffer[1024];
+        unsigned long path_len = 1023;
+        if (_NSGetExecutablePath(buffer, &path_len))
+            ThrowException(General, "Could not retrieve executable path.");
+
+#else /* Linux */
+        /* written by Nicolai Haehnle <prefect_@gmx.net> */
+
+        /* Get our PID and build the name of the link in /proc */
+        char linkname[64]; /* /proc/<pid>/exe */
+        if (snprintf(linkname, sizeof(linkname), "/proc/%i/exe", getpid()) < 0)
+        {
+            /* This should only happen on large word systems. I'm not sure
+               what the proper response is here.
+               Since it really is an assert-like condition, aborting the
+               program seems to be in order. */
+            assert(false);
+        }
+
+        /* Now read the symbolic link */
+        char buffer[1024];
+        int ret;
+        ret = readlink(linkname, buffer, 1024);
+        /* In case of an error, leave the handling up to the caller */
+        if (ret == -1)
+            ThrowException(General, "Could not retrieve executable path.");
+
+        /* Ensure proper NUL termination */
+        buffer[ret] = 0;
+#endif
+
+        executablePath_g = boost::filesystem::path(buffer);
+#ifndef ORXONOX_PLATFORM_APPLE
+        executablePath_g = executablePath_g.branch_path(); // remove executable name
+#endif
+    }
+
+    /**
+    @brief
+        Checks for "orxonox_dev_build.keep_me" in the executable diretory.
+        If found it means that this is not an installed run, hence we
+        don't write the logs and config files to ~/.orxonox
+    */
+    /*static*/ void Core::checkDevBuild()
+    {
+        if (boost::filesystem::exists(executablePath_g / "orxonox_dev_build.keep_me"))
+        {
+            COUT(1) << "Running from the build tree." << std::endl;
+            Core::isDevBuild_s = true;
+            mediaPath_g  = ORXONOX_MEDIA_DEV_PATH;
+            configPath_g = ORXONOX_CONFIG_DEV_PATH;
+            logPath_g    = ORXONOX_LOG_DEV_PATH;
+        }
+        else
+        {
+#ifdef INSTALL_COPYABLE // --> relative paths
+            // Also set the root path
+            boost::filesystem::path relativeExecutablePath(ORXONOX_RUNTIME_INSTALL_PATH);
+            rootPath_g = executablePath_g;
+            while (!boost::filesystem::equivalent(rootPath_g / relativeExecutablePath, executablePath_g) || rootPath_g.empty())
+                rootPath_g = rootPath_g.branch_path();
+            if (rootPath_g.empty())
+                ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
+
+            // Using paths relative to the install prefix, complete them
+            mediaPath_g  = rootPath_g / ORXONOX_MEDIA_INSTALL_PATH;
+            configPath_g = rootPath_g / ORXONOX_CONFIG_INSTALL_PATH;
+            logPath_g    = rootPath_g / ORXONOX_LOG_INSTALL_PATH;
+#else
+            // There is no root path, so don't set it at all
+
+            mediaPath_g  = ORXONOX_MEDIA_INSTALL_PATH;
+
+            // Get user directory
+#  ifdef ORXONOX_PLATFORM_UNIX /* Apple? */
+            char* userDataPathPtr(getenv("HOME"));
+#  else
+            char* userDataPathPtr(getenv("APPDATA"));
+#  endif
+            if (userDataPathPtr == NULL)
+                ThrowException(General, "Could not retrieve user data path.");
+            boost::filesystem::path userDataPath(userDataPathPtr);
+            userDataPath /= ".orxonox";
+
+            configPath_g = userDataPath / ORXONOX_CONFIG_INSTALL_PATH;
+            logPath_g    = userDataPath / ORXONOX_LOG_INSTALL_PATH;
+#endif
+        }
+
+        // Option to put all the config and log files in a separate folder
+        if (!CommandLine::getArgument("directory")->hasDefaultValue())
+        {
+            std::string directory(CommandLine::getValue("directory"));
+            configPath_g = configPath_g / directory;
+            logPath_g    = logPath_g    / directory;
+        }
+    }
+
+    /*
+    @brief
+        Checks for the log and the config directory and creates them
+        if necessary. Otherwise me might have problems opening those files.
+    */
+    /*static*/ void Core::createDirectories()
+    {
+        std::vector<std::pair<boost::filesystem::path, std::string> > directories;
+        directories.push_back(std::pair<boost::filesystem::path, std::string>
+            (boost::filesystem::path(configPath_g), "config"));
+        directories.push_back(std::pair<boost::filesystem::path, std::string>
+            (boost::filesystem::path(logPath_g),    "log"));
+
+        for (std::vector<std::pair<boost::filesystem::path, std::string> >::iterator it = directories.begin();
+            it != directories.end(); ++it)
+        {
+            if (boost::filesystem::exists(it->first) && !boost::filesystem::is_directory(it->first))
+            {
+                ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \
+                                         Please remove " + it->first.file_string());
+            }
+            if (boost::filesystem::create_directories(it->first)) // function may not return true at all (bug?)
+            {
+                COUT(4) << "Created " << it->second << " directory" << std::endl;
+            }
+        }
+    }
 }
Index: code/trunk/src/core/Core.h
===================================================================
--- code/trunk/src/core/Core.h	(revision 2662)
+++ code/trunk/src/core/Core.h	(revision 2710)
@@ -44,4 +44,14 @@
 #include "util/OutputHandler.h"
 
+// Only allow main to access postMainInitialisation, so we need a forward declaration
+int main(int, char**);
+// boost::filesystem header has quite a large tail, use forward declaration
+namespace boost { namespace filesystem
+{
+    struct path_traits;
+    template<class String, class Traits> class basic_path;
+    typedef basic_path< std::string, path_traits> path;
+} }
+
 namespace orxonox
 {
@@ -49,10 +59,10 @@
     class _CoreExport Core : public OrxonoxClass
     {
+        friend int ::main(int, char**); // sets isDevBuild_s
+
         public:
             Core();
             ~Core();
             void setConfigValues();
-            void debugLevelChanged();
-            void languageChanged();
 
             static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; }
@@ -62,4 +72,18 @@
             static const std::string& getLanguage();
             static void  resetLanguage();
+
+            static bool isDevBuild() { return Core::isDevBuild_s; }
+
+            static void tsetMediaPath(const std::string& path)
+            { assert(singletonRef_s); singletonRef_s->_tsetMediaPath(path); }
+            static const boost::filesystem::path& getMediaPath();
+            static const boost::filesystem::path& getConfigPath();
+            static const boost::filesystem::path& getLogPath();
+            static std::string getMediaPathString();
+            static std::string getConfigPathString();
+            static std::string getLogPathString();
+            static std::string getMediaPathPOSIXString();
+            static std::string getConfigPathPOSIXString();
+            static std::string getLogPathPOSIXString();
 
             // fast access global variables.
@@ -79,4 +103,13 @@
             void resetLanguageIntern();
             void initializeRandomNumberGenerator();
+            void debugLevelChanged();
+            void languageChanged();
+            void mediaPathChanged();
+            void _tsetMediaPath(const std::string& path);
+
+            static void postMainInitialisation();
+            static void checkDevBuild();
+            static void setExecutablePath();
+            static void createDirectories();
 
             int softDebugLevel_;                            //!< The debug level
@@ -85,5 +118,6 @@
             int softDebugLevelShell_;                       //!< The debug level for the ingame shell
             std::string language_;                          //!< The language
-            bool bInitializeRandomNumberGenerator_;          //!< If true, srand(time(0)) is called
+            bool bInitializeRandomNumberGenerator_;         //!< If true, srand(time(0)) is called
+            std::string mediaPathString_;                   //!< Path to the data/media file folder as string
 
             static bool bShowsGraphics_s;                   //!< global variable that tells whether to show graphics
@@ -93,4 +127,6 @@
             static bool bIsMaster_s;
 
+            static bool isDevBuild_s;                       //!< True for builds in the build directory (not installed)
+
             static Core* singletonRef_s;
     };
Index: code/trunk/src/core/CorePrereqs.h
===================================================================
--- code/trunk/src/core/CorePrereqs.h	(revision 2662)
+++ code/trunk/src/core/CorePrereqs.h	(revision 2710)
@@ -35,5 +35,5 @@
 #define _CorePrereqs_H__
 
-#include "util/OrxonoxPlatform.h"
+#include "OrxonoxConfig.h"
 
 #include <string>
@@ -42,5 +42,5 @@
 // Shared library settings
 //-----------------------------------------------------------------------
-#if (ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32) && !defined( CORE_STATIC_BUILD )
+#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( CORE_STATIC_BUILD )
 #  ifdef CORE_SHARED_BUILD
 #    define _CoreExport __declspec(dllexport)
Index: code/trunk/src/core/Factory.h
===================================================================
--- code/trunk/src/core/Factory.h	(revision 2662)
+++ code/trunk/src/core/Factory.h	(revision 2710)
@@ -49,5 +49,4 @@
 #include <map>
 #include <string>
-#include "util/Integers.h"
 
 namespace orxonox
Index: code/trunk/src/core/Functor.h
===================================================================
--- code/trunk/src/core/Functor.h	(revision 2662)
+++ code/trunk/src/core/Functor.h	(revision 2710)
@@ -436,5 +436,5 @@
 
 // disable annoying warning about forcing value to boolean
-#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
+#ifdef ORXONOX_COMPILER_MSVC
 #pragma warning(push)
 #pragma warning(disable:4100 4800)
@@ -475,5 +475,5 @@
 }
 
-#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
+#ifdef ORXONOX_COMPILER_MSVC
 #pragma warning(pop)
 #endif
Index: code/trunk/src/core/IRC.h
===================================================================
--- code/trunk/src/core/IRC.h	(revision 2662)
+++ code/trunk/src/core/IRC.h	(revision 2710)
@@ -32,6 +32,6 @@
 #include "CorePrereqs.h"
 
+#include <cpptcl/cpptcl.h>
 #include "OrxonoxClass.h"
-#include "cpptcl/CppTcl.h"
 
 namespace orxonox
Index: code/trunk/src/core/Identifier.h
===================================================================
--- code/trunk/src/core/Identifier.h	(revision 2662)
+++ code/trunk/src/core/Identifier.h	(revision 2710)
@@ -61,5 +61,5 @@
 #include <utility>
 #include <typeinfo>
-#include <stdlib.h>
+#include <cstdlib>
 #include <cassert>
 
@@ -68,5 +68,4 @@
 #include "Super.h"
 #include "Functor.h"
-#include "util/Integers.h"
 #include "util/Debug.h"
 #include "util/String.h"
Index: code/trunk/src/core/Language.cc
===================================================================
--- code/trunk/src/core/Language.cc	(revision 2662)
+++ code/trunk/src/core/Language.cc	(revision 2710)
@@ -35,4 +35,5 @@
 
 #include <fstream>
+#include <boost/filesystem.hpp>
 
 #include "Core.h"
@@ -205,12 +206,14 @@
         COUT(4) << "Read default language file." << std::endl;
 
+        boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_));
+
         // This creates the file if it's not existing
         std::ofstream createFile;
-        createFile.open(getFilename(this->defaultLanguage_).c_str(), std::fstream::app);
+        createFile.open(filepath.file_string().c_str(), std::fstream::app);
         createFile.close();
 
         // Open the file
         std::ifstream file;
-        file.open(getFilename(this->defaultLanguage_).c_str(), std::fstream::in);
+        file.open(filepath.file_string().c_str(), std::fstream::in);
 
         if (!file.is_open())
@@ -254,7 +257,9 @@
         COUT(4) << "Read translated language file (" << Core::getLanguage() << ")." << std::endl;
 
+        boost::filesystem::path filepath(Core::getConfigPath() / getFilename(Core::getLanguage()));
+
         // Open the file
         std::ifstream file;
-        file.open(getFilename(Core::getLanguage()).c_str(), std::fstream::in);
+        file.open(filepath.file_string().c_str(), std::fstream::in);
 
         if (!file.is_open())
@@ -308,7 +313,9 @@
         COUT(4) << "Language: Write default language file." << std::endl;
 
+        boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_));
+
         // Open the file
         std::ofstream file;
-        file.open(getFilename(this->defaultLanguage_).c_str(), std::fstream::out);
+        file.open(filepath.file_string().c_str(), std::fstream::out);
 
         if (!file.is_open())
Index: code/trunk/src/core/Loader.cc
===================================================================
--- code/trunk/src/core/Loader.cc	(revision 2662)
+++ code/trunk/src/core/Loader.cc	(revision 2710)
@@ -28,4 +28,7 @@
 
 #include "Loader.h"
+
+#include <tinyxml/ticpp.h>
+
 #include "XMLFile.h"
 #include "BaseObject.h"
@@ -39,6 +42,4 @@
 #include "util/Exception.h"
 
-#include "tinyxml/ticpp.h"
-
 namespace orxonox
 {
Index: code/trunk/src/core/LuaBind.cc
===================================================================
--- code/trunk/src/core/LuaBind.cc	(revision 2662)
+++ code/trunk/src/core/LuaBind.cc	(revision 2710)
@@ -32,9 +32,15 @@
 #include <map>
 
-#include "lua/lua.hpp"
-#include "tolua/tolua++.h"
-#include "tolua/tolua_bind.h"
+extern "C" {
+#include <lua.h>
+#include <lualib.h>
+}
+#include <tolua/tolua++.h>
+#include <boost/filesystem.hpp>
+
 #include "util/String.h"
-#include "CoreIncludes.h"
+#include "util/Debug.h"
+#include "ToluaBindCore.h"
+#include "Core.h"
 
 namespace orxonox
@@ -46,4 +52,6 @@
     assert(LuaBind::singletonRef_s == 0);
     LuaBind::singletonRef_s = this;
+
+    this->includePath_ = Core::getMediaPathPOSIXString();
 
     luaState_ = lua_open();
@@ -78,7 +86,9 @@
   void LuaBind::loadFile(std::string filename, bool luaTags)
   {
+    boost::filesystem::path filepath(filename);
+
     output_ = "";
     std::ifstream file;
-    file.open(filename.c_str(), std::fstream::in);
+    file.open(filepath.file_string().c_str(), std::fstream::in);
 
     if (!file.is_open())
Index: code/trunk/src/core/LuaBind.h
===================================================================
--- code/trunk/src/core/LuaBind.h	(revision 2662)
+++ code/trunk/src/core/LuaBind.h	(revision 2710)
@@ -39,5 +39,5 @@
 
 extern "C" {
-#include <lua/lua.h>
+#include <lua.h>
 }
 
@@ -46,11 +46,11 @@
 #include <string>
 
-namespace orxonox // tolua_export
-{ // tolua_export
+// tolua_begin
+namespace orxonox
+{
   class _CoreExport LuaBind
   {
-  /*
-  class LuaBind { // tolua_export
-  */
+
+// tolua_end
     struct LoadS {
       const char *s;
Index: code/trunk/src/core/RootGameState.cc
===================================================================
--- code/trunk/src/core/RootGameState.cc	(revision 2662)
+++ code/trunk/src/core/RootGameState.cc	(revision 2710)
@@ -135,5 +135,5 @@
     {
         // Don't catch errors when having a debugger in msvc
-#if ORXONOX_COMPILER != ORXONOX_COMPILER_MSVC || defined(NDEBUG)
+#if !defined(ORXONOX_COMPILER_MSVC) || defined(NDEBUG)
         try
         {
@@ -158,5 +158,5 @@
 
             this->deactivate();
-#if ORXONOX_COMPILER != ORXONOX_COMPILER_MSVC || defined(NDEBUG)
+#if !defined(ORXONOX_COMPILER_MSVC) || defined(NDEBUG)
         }
         // Note: These are all unhandled exceptions that should not have made its way here!
Index: code/trunk/src/core/TclBind.cc
===================================================================
--- code/trunk/src/core/TclBind.cc	(revision 2662)
+++ code/trunk/src/core/TclBind.cc	(revision 2710)
@@ -62,5 +62,6 @@
     void TclBind::setDataPath(const std::string& datapath)
     {
-        this->tclLibPath_ = datapath + "/tcl" + TCL_VERSION + "/";
+        // String has POSIX slashes
+        this->tclLibPath_ = datapath + "tcl" + TCL_VERSION + '/';
         this->bSetTclLibPath_ = true;
 
Index: code/trunk/src/core/TclBind.h
===================================================================
--- code/trunk/src/core/TclBind.h	(revision 2662)
+++ code/trunk/src/core/TclBind.h	(revision 2710)
@@ -32,5 +32,5 @@
 #include "CorePrereqs.h"
 
-#include "cpptcl/CppTcl.h"
+#include <cpptcl/cpptcl.h>
 
 namespace orxonox
Index: code/trunk/src/core/TclThreadManager.h
===================================================================
--- code/trunk/src/core/TclThreadManager.h	(revision 2662)
+++ code/trunk/src/core/TclThreadManager.h	(revision 2710)
@@ -40,5 +40,5 @@
 #include <boost/thread/thread.hpp>
 
-#include "cpptcl/CppTcl.h"
+#include <cpptcl/cpptcl.h>
 #include "core/OrxonoxClass.h"
 
Index: code/trunk/src/core/Template.cc
===================================================================
--- code/trunk/src/core/Template.cc	(revision 2662)
+++ code/trunk/src/core/Template.cc	(revision 2710)
@@ -29,8 +29,9 @@
 #include "Template.h"
 
+#include <tinyxml/ticpp.h>
+
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
 #include "util/Debug.h"
-#include "tinyxml/ticpp.h"
 
 namespace orxonox
Index: code/trunk/src/core/Template.h
===================================================================
--- code/trunk/src/core/Template.h	(revision 2662)
+++ code/trunk/src/core/Template.h	(revision 2710)
@@ -34,6 +34,6 @@
 #include "CorePrereqs.h"
 
+#include <tinyxml/tinyxml.h>
 #include "BaseObject.h"
-#include "tinyxml/tinyxml.h"
 
 namespace orxonox
Index: code/trunk/src/core/XMLPort.h
===================================================================
--- code/trunk/src/core/XMLPort.h	(revision 2662)
+++ code/trunk/src/core/XMLPort.h	(revision 2710)
@@ -44,8 +44,8 @@
 
 #include <cassert>
+#include <tinyxml/ticpp.h>
 #include "util/Debug.h"
 #include "util/Exception.h"
 #include "util/MultiType.h"
-#include "tinyxml/ticpp.h"
 #include "XMLIncludes.h"
 #include "Executor.h"
Index: code/trunk/src/core/input/CMakeLists.txt
===================================================================
--- code/trunk/src/core/input/CMakeLists.txt	(revision 2662)
+++ code/trunk/src/core/input/CMakeLists.txt	(revision 2710)
@@ -1,3 +1,3 @@
-SET( SRC_FILES
+ADD_SOURCE_FILES(CORE_SRC_FILES
   Button.cc
   CalibratorCallback.cc
@@ -12,4 +12,2 @@
   SimpleInputState.cc
 )
-
-ADD_SOURCE_FILES(SRC_FILES)
Index: code/trunk/src/core/input/KeyBinder.cc
===================================================================
--- code/trunk/src/core/input/KeyBinder.cc	(revision 2662)
+++ code/trunk/src/core/input/KeyBinder.cc	(revision 2710)
@@ -36,4 +36,5 @@
 #include <fstream>
 #include <string>
+#include <boost/filesystem.hpp>
 
 #include "util/Convert.h"
@@ -42,4 +43,5 @@
 #include "core/CoreIncludes.h"
 #include "core/ConfigFileManager.h"
+#include "core/Core.h"
 #include "InputCommands.h"
 #include "InputManager.h"
@@ -246,5 +248,5 @@
         True if loading succeeded.
     */
-    void KeyBinder::loadBindings(const std::string& filename, const std::string& defaultFilename)
+    void KeyBinder::loadBindings(const std::string& filename)
     {
         COUT(3) << "KeyBinder: Loading key bindings..." << std::endl;
@@ -253,14 +255,4 @@
             return;
 
-        // get bindings from default file if filename doesn't exist.
-        std::ifstream infile;
-        infile.open(filename.c_str());
-        if (!infile)
-        {
-            ConfigFileManager::getInstance().setFilename(this->configFile_, defaultFilename);
-            ConfigFileManager::getInstance().saveAs(this->configFile_, filename);
-        }
-        else
-            infile.close();
         ConfigFileManager::getInstance().setFilename(this->configFile_, filename);
 
Index: code/trunk/src/core/input/KeyBinder.h
===================================================================
--- code/trunk/src/core/input/KeyBinder.h	(revision 2662)
+++ code/trunk/src/core/input/KeyBinder.h	(revision 2710)
@@ -61,5 +61,5 @@
         virtual ~KeyBinder();
 
-        void loadBindings(const std::string& filename, const std::string& defaultFilename);
+        void loadBindings(const std::string& filename);
         void clearBindings();
         bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false);
