# HG changeset patch
# User insilmaril
# Date 1228398467 0
# Node ID 79b0656dbe7d8fdc2ee252cc9f947ab126846fc4
# Parent  e47fe0d7b05bcd4a06905992b840c387d3ad5786
Changed parsing of version to allow subreleases

diff -r e47fe0d7b05b -r 79b0656dbe7d mapeditor.cpp
--- a/mapeditor.cpp	Mon Dec 01 16:44:35 2008 +0000
+++ b/mapeditor.cpp	Thu Dec 04 13:47:47 2008 +0000
@@ -1806,6 +1806,7 @@
 			return aborted; 
 		}
 
+//	cout <<"ME::save      filePath="<<filePath.toStdString()<<endl;
 		safeFilePath=filePath;
 		setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
 	} // zipped
@@ -1813,6 +1814,15 @@
 	// Create mapName and fileDir
 	makeSubDirs (fileDir);
 
+/*
+	// FIXME testing
+	cout <<"ME::save      filePath="<<filePath.toStdString()<<endl;
+	cout <<"ME::save  saveFilePath="<<safeFilePath.toStdString()<<endl;
+	cout <<"ME::save      destPath="<<destPath.toStdString()<<endl;
+	cout <<"ME::save       mapName="<<mapName.toStdString()<<endl;
+	cout <<"ME::save   mapFileName="<<mapFileName.toStdString()<<endl;
+*/
+
 	QString saveFile;
 	if (savemode==CompleteMap || xelection.isEmpty())
 	{
@@ -1821,13 +1831,6 @@
 		mapChanged=false;
 		mapUnsaved=false;
 		autosaveTimer->stop();
-		/*
-		cout <<"ME::save      filePath="<<filePath.toStdString()<<endl;
-		cout <<"ME::save  saveFilePath="<<safeFilePath.toStdString()<<endl;
-		cout <<"ME::save      destPath="<<destPath.toStdString()<<endl;
-		cout <<"ME::save       mapName="<<mapName.toStdString()<<endl;
-		cout <<"ME::save   mapFileName="<<mapFileName.toStdString()<<endl;
-		*/
 	}
 	else	
 	{
diff -r e47fe0d7b05b -r 79b0656dbe7d settings.cpp
--- a/settings.cpp	Mon Dec 01 16:44:35 2008 +0000
+++ b/settings.cpp	Thu Dec 04 13:47:47 2008 +0000
@@ -1,8 +1,153 @@
 #include <iostream>
+#include <qregexp.h>
 #include "settings.h"
-#include "misc.h"
+#include "file.h"
 
-using namespace std;
+/////////////////////////////////////////////////////////////////
+// SimpleSettings
+/////////////////////////////////////////////////////////////////
+SimpleSettings::SimpleSettings()
+{
+	clear();		 
+}
+
+SimpleSettings::~SimpleSettings()
+{
+}
+
+void SimpleSettings::clear()
+{
+	keylist.clear();
+	valuelist.clear();
+}
+
+void SimpleSettings::readSettings (const QString &path)
+{
+	QString s;
+	if (!loadStringFromDisk(path,s)) 
+	{
+		qWarning ("SimpleSettings::readSettings() Couldn't read "+path);
+		return;
+	}	
+	QStringList lines;
+	lines=QStringList::split (QRegExp("\n"),s,false);
+	int i;
+	QStringList::Iterator it=lines.begin();
+	while (it !=lines.end() )
+	{
+		i=(*it).find("=",0);
+		keylist.append((*it).left(i));
+		valuelist.append((*it).right((*it).length()-i-1));
+		it++;
+	}
+}
+
+void SimpleSettings::writeSettings (const QString &path)
+{
+	QString s;
+	QStringList::Iterator itk=keylist.begin();
+	QStringList::Iterator itv=valuelist.begin();
+
+	// First search for value in settings saved in map
+	while (itk !=keylist.end() )
+	{
+		s+=*itk+"="+*itv+"\n";
+		itk++;
+		itv++;
+	}
+	if (!saveStringToDisk(path,s)) 
+		qWarning ("SimpleSettings::writeSettings() Couldn't write "+path);
+}
+
+/*
+QString SimpleSettings::readEntry (const QString &key)
+{
+	QStringList::Iterator itk=keylist.begin();
+	QStringList::Iterator itv=valuelist.begin();
+
+	// First search for value in settings saved in map
+	while (itk !=keylist.end() )
+	{
+		if (*itk == key)
+			return *itv;
+		itk++;
+		itv++;
+	}
+	qWarning ("SimpleSettings::readEntry()  Couldn't find key "+key);
+	return "";
+}
+*/
+
+QString SimpleSettings::readEntry (const QString &key, const QString &def)
+{
+	QStringList::Iterator itk=keylist.begin();
+	QStringList::Iterator itv=valuelist.begin();
+
+	// First search for value in settings saved in map
+	while (itk !=keylist.end() )
+	{
+		if (*itk == key)
+			return *itv;
+		itk++;
+		itv++;
+	}
+	return def;
+}
+
+int SimpleSettings::readNumEntry (const QString &key, const int &def)
+{
+	QStringList::Iterator itk=keylist.begin();
+	QStringList::Iterator itv=valuelist.begin();
+
+	// First search for value in settings saved in map
+	while (itk !=keylist.end() )
+	{
+		if (*itk == key)
+		{
+			bool ok;
+			int i=(*itv).toInt(&ok,10);
+			if (ok)
+				return i;
+			else
+				return def;
+		}	
+		itk++;
+		itv++;
+	}
+	return def;
+}
+
+void SimpleSettings::setEntry (const QString &key, const QString &value)
+{
+	QStringList::Iterator itk=keylist.begin();
+	QStringList::Iterator itv=valuelist.begin();
+
+	if (!key.isEmpty() )
+	{
+		// Search for existing entry first
+		while (itk !=keylist.end() )
+		{
+			if (*itk == key)
+			{
+				if (!value.isEmpty())
+					*itv=value;
+				else
+					*itv="";
+				*itv=value;
+				return;
+			}
+			itk++;
+			itv++;
+		}
+		
+		// If no entry exists, append a new one
+		keylist.append (key);
+		valuelist.append (value);
+	}
+}
+
+
+
 /////////////////////////////////////////////////////////////////
 // Settings
 /////////////////////////////////////////////////////////////////
@@ -11,6 +156,11 @@
 	clear();		 
 }
 
+Settings::Settings(const QString & organization, const QString & application ):QSettings (organization,application)
+{
+	clear();		 
+}
+
 Settings::~Settings()
 {
 }
@@ -93,7 +243,7 @@
 	}
 }
 
-QString Settings::getXMLData (const QString &fpath)
+QString Settings::getDataXML (const QString &fpath)
 {
 	QString s;
 	QStringList::Iterator itp=pathlist.begin();
@@ -116,17 +266,3 @@
 	return s;
 }
 
-void Settings::write()
-{
-	QStringList::Iterator itp=pathlist.begin();
-	QStringList::Iterator itk=keylist.begin();
-	QStringList::Iterator itv=valuelist.begin();
-
-	while (itp !=pathlist.end() )
-	{
-		itp++;
-		itk++;
-		itv++;
-	}
-}
-
diff -r e47fe0d7b05b -r 79b0656dbe7d version.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/version.cpp	Thu Dec 04 13:47:47 2008 +0000
@@ -0,0 +1,57 @@
+#include "version.h"
+
+#include <QRegExp>
+
+bool checkVersion (const QString &v)
+{
+	// returns true, if vym is able to read file regarding 
+	// the version set with setVersion
+	return checkVersion (v,__VYM_VERSION);
+}
+
+
+bool checkVersion (const QString &v, const QString &d)
+{
+	bool ok;
+	int v1;
+	int v2;
+	int v3;
+	int d1;
+	int d2;
+	int d3;
+
+	QRegExp rx("(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})");
+	int pos=rx.indexIn (v);
+	if (pos>-1)
+	{
+		v1=rx.cap(1).toInt(&ok);
+		v2=rx.cap(2).toInt(&ok);
+		v3=rx.cap(3).toInt(&ok);
+	} else
+		qWarning (QString ("Warning: Checking version failed for v=%1").arg(v));
+
+	pos=rx.indexIn (d);
+	if (pos>-1)
+	{
+		d1=rx.cap(1).toInt(&ok);
+		d2=rx.cap(2).toInt(&ok);
+		d3=rx.cap(3).toInt(&ok);
+	} else
+		qWarning (QString ("Warning: Checking version failed for d=%1").arg(d));
+
+	
+	if (d1 > v1)
+		return true;
+	if (d1 < v1)
+		return false;
+	if (d2 > v2)
+		return true;
+	if (d2 < v2)
+		return false;
+	if (d3 > v3)
+		return true;
+	if (d3 < v3)
+		return false;
+	return true;	
+
+}
diff -r e47fe0d7b05b -r 79b0656dbe7d version.h
--- a/version.h	Mon Dec 01 16:44:35 2008 +0000
+++ b/version.h	Thu Dec 04 13:47:47 2008 +0000
@@ -4,10 +4,10 @@
 #include <QString>
 
 #define __VYM_NAME "VYM"
-#define __VYM_VERSION "1.12.2"
-#define __VYM_CODENAME "Maintenance Update a"
+#define __VYM_VERSION "1.12.2b"
+#define __VYM_CODENAME "Maintenance Update "
 //#define __VYM_CODENAME "Codename: development version"
-#define __VYM_BUILD_DATE "2008-12-01"
+#define __VYM_BUILD_DATE "2008-12-04"
 
 
 bool checkVersion(const QString &);