Index: /orxonox/trunk/src/lib/gui/gui_exec.cc
===================================================================
--- /orxonox/trunk/src/lib/gui/gui_exec.cc	(revision 5020)
+++ /orxonox/trunk/src/lib/gui/gui_exec.cc	(revision 5021)
@@ -202,8 +202,9 @@
 void GuiExec::writeToFile(Widget* widget)
 {
-  this->CONFIG_FILE = fopen(this->confFile, "w");
-  if(this->CONFIG_FILE)
-    this->writeFileText(widget, 0);
-  fclose(this->CONFIG_FILE);
+  IniParser iniParser;
+  this->writeFileText(widget, &iniParser, 0);
+  char* fileName = ResourceManager::homeDirCheck(confFile);
+  iniParser.writeFile(fileName);
+  delete fileName;
 }
 
@@ -211,17 +212,18 @@
  *  Actually writes into the configuration file to the disk.
  * @param widget from which Widget on should be saved.
+ * @param parser the IniParser to write to.
  * @param depth initially "0", and grows higher, while new Groups are bundeled.
 */
-void GuiExec::writeFileText(Widget* widget, int depth)
-{
-  int counter = 0;
-  while(counter < depth &&((widget->optionType > GUI_NOTHING
-                              &&(static_cast<Option*>(widget)->isSaveable()))
-                             ||(widget->optionType < GUI_NOTHING
-                                && static_cast<Packer*>(widget)->getGroupName())))
-    {
-      fprintf(this->CONFIG_FILE, "  ", depth);
-      counter++;
-    }
+void GuiExec::writeFileText(Widget* widget, IniParser* parser, int depth)
+{
+//   int counter = 0;
+//   while(counter < depth &&((widget->optionType > GUI_NOTHING
+//                               &&(static_cast<Option*>(widget)->isSaveable()))
+//                              ||(widget->optionType < GUI_NOTHING
+//                                 && static_cast<Packer*>(widget)->getGroupName())))
+//     {
+//       fprintf(this->CONFIG_FILE, "  ", depth);
+//       counter++;
+//     }
 
   // check if it is a Packer, and if it is, check if it has a name and if there is something in it.
@@ -230,11 +232,10 @@
       if(static_cast<Packer*>(widget)->getGroupName())
         {
-          fprintf(CONFIG_FILE, "[%s]\n", static_cast<Packer*>(widget)->getGroupName());
-          this->writeFileText(static_cast<Packer*>(widget)->down, depth+1);
-          fprintf(CONFIG_FILE, "\n");
+          parser->addSection(static_cast<Packer*>(widget)->getGroupName());
+          this->writeFileText(static_cast<Packer*>(widget)->down, parser, depth+1);
         }
       else
         {
-          this->writeFileText(static_cast<Packer*>(widget)->down, depth);
+          this->writeFileText(static_cast<Packer*>(widget)->down, parser, depth);
         }
     }
@@ -242,8 +243,8 @@
   if(widget->optionType > GUI_NOTHING)
     if (static_cast<Option*>(widget)->isSaveable())
-      fprintf(CONFIG_FILE, "%s = %s\n", static_cast<Option*>(widget)->title, static_cast<Option*>(widget)->save());
+      parser->addVar(static_cast<Option*>(widget)->title, static_cast<Option*>(widget)->save());
 
   if(widget->next != NULL)
-    this->writeFileText(widget->next, depth);
+    this->writeFileText(widget->next, parser, depth);
 }
 
Index: /orxonox/trunk/src/lib/gui/gui_exec.h
===================================================================
--- /orxonox/trunk/src/lib/gui/gui_exec.h	(revision 5020)
+++ /orxonox/trunk/src/lib/gui/gui_exec.h	(revision 5021)
@@ -14,4 +14,5 @@
 class CheckButton;
 using namespace std;
+class IniParser;
 
 //! Class that creates the execute-Options.
@@ -41,5 +42,5 @@
   int shouldsave();
   void writeToFile(Widget* widget);
-  void writeFileText(Widget* widget, int depth);
+  void writeFileText(Widget* widget, IniParser* parser, int depth);
   void readFromFile(Widget* widget);
   static void readFileText(Widget* widget, void* varInfo);
Index: /orxonox/trunk/src/lib/util/ini_parser.cc
===================================================================
--- /orxonox/trunk/src/lib/util/ini_parser.cc	(revision 5020)
+++ /orxonox/trunk/src/lib/util/ini_parser.cc	(revision 5021)
@@ -116,4 +116,5 @@
     char lineBuffer[PARSELINELENGHT];
     char buffer[PARSELINELENGHT];
+    const char* lineBegin;
     char* ptr;
 
@@ -122,11 +123,15 @@
       // get next line
       fgets (lineBuffer, PARSELINELENGHT, stream);
+      lineBegin = lineBuffer;
       // remove newline char, and \0-terminate
       if( (ptr = strchr( lineBuffer, '\n')) != NULL)
         *ptr = 0;
+      // cut up to the beginning of the line.
+      while((*lineBegin == ' ' || *lineBegin == '\t') && lineBegin < lineBuffer + strlen(lineBuffer))
+        ++lineBegin;
+      if (strlen(lineBegin) <= 1 || *lineBegin == '#' || *lineBegin == ';')
+        continue;//printf("empty Line\n");
       // check for section identifyer
-      if (strlen(lineBuffer) <= 1)
-        ;//printf("empty Line\n");
-      else if( sscanf (lineBuffer, "[%s", buffer) == 1)
+      else if( sscanf (lineBegin, "[%s", buffer) == 1)
       {
         if( (ptr = strchr( buffer, ']')) != NULL)
@@ -137,25 +142,22 @@
       }
       // check for Entry identifier (Entry = Value)
-      else if( (ptr = strchr( lineBuffer, '=')) != NULL)
+      else if( (ptr = strchr( lineBegin, '=')) != NULL)
       {
         if (currentSection == NULL)
         {
-          PRINTF(2)("Not in a Section yet for %s\n", lineBuffer);
+          PRINTF(2)("Not in a Section yet for %s\n", lineBegin);
           continue;
         }
-        if( ptr == lineBuffer)
+        if( ptr == lineBegin)
           continue;
         char* valueBegin = ptr+1;
-        while ((*valueBegin == ' ' || *valueBegin == '\t') && valueBegin <= lineBuffer + strlen(lineBuffer))
+        while ((*valueBegin == ' ' || *valueBegin == '\t') && valueBegin <= lineBegin + strlen(lineBegin))
           ++valueBegin;
-        char* nameBegin = lineBuffer;
-        while ((*nameBegin == ' ' || *nameBegin == '\t') && nameBegin < ptr)
-          ++nameBegin;
         char* nameEnd = ptr-1;
-        while ((*nameEnd == ' ' || *nameEnd == '\t' ) && nameEnd >= nameBegin)
+        while ((*nameEnd == ' ' || *nameEnd == '\t' ) && nameEnd >= lineBegin)
           --nameEnd;
         nameEnd[1] = '\0';
 
-        this->addVar(nameBegin, valueBegin);
+        this->addVar(lineBegin, valueBegin);
       }
     }
@@ -173,6 +175,4 @@
 {
   FILE*    stream;           //!< The stream we use to read the file.
-  if (sections != NULL)
-    deleteSections();
   if( fileName == NULL)
     return false;
@@ -191,5 +191,5 @@
       while (sectionEnum)
       {
-        fprintf(stream, " [%s]\n", sectionEnum->name);
+        fprintf(stream, "\n [%s]\n", sectionEnum->name);
 
         tIterator<IniEntry>* entryIt = sectionEnum->entries->getIterator();
@@ -197,5 +197,5 @@
         while (entryEnum)
         {
-          fprintf(stream, " %s = %s\n", entryEnum->name, entryEnum->value);
+          fprintf(stream, "   %s = %s\n", entryEnum->name, entryEnum->value);
 
           entryEnum = entryIt->nextElement();
@@ -213,4 +213,10 @@
 }
 
+/**
+ * adds a section to the list of Sections,
+ * if no Section list is availiable, it will create it
+ * @param sectionName the Name of the section to add
+ * @return true on success... there is only success or segfault :)
+ */
 bool IniParser::addSection(const char* sectionName)
 {
@@ -224,4 +230,6 @@
   this->currentSection = newSection;
   this->sections->add(newSection);
+  PRINTF(0)("Added Section %s\n", sectionName);
+  return true;
 }
 
