1.1 --- a/version.cpp Mon Jul 23 12:42:02 2007 +0000
1.2 +++ b/version.cpp Tue Mar 02 13:59:19 2010 +0000
1.3 @@ -1,71 +1,56 @@
1.4 #include "version.h"
1.5
1.6 +#include <QRegExp>
1.7 +
1.8 bool checkVersion (const QString &v)
1.9 {
1.10 // returns true, if vym is able to read file regarding
1.11 // the version set with setVersion
1.12 return checkVersion (v,__VYM_VERSION);
1.13 - /*
1.14 - QString s1=v.section (".",0,0);
1.15 - QString s2=v.section (".",1,1);
1.16 - QString s3=v.section (".",2,2);
1.17 - bool ok;
1.18 - int vv1 =QString(__VYM_VERSION).section (".",0,0).toInt(&ok,10);
1.19 - int vv2 =QString(__VYM_VERSION).section (".",1,1).toInt(&ok,10);
1.20 - int vv3 =QString(__VYM_VERSION).section (".",2,2).toInt(&ok,10);
1.21 - int mv1=0;
1.22 - int mv2=0;
1.23 - int mv3=0;
1.24 - if (!s1.isEmpty() ) mv1=s1.toInt(&ok,10);
1.25 - if (!s2.isEmpty() ) mv2=s2.toInt(&ok,10);
1.26 - if (!s3.isEmpty() ) mv3=s3.toInt(&ok,10);
1.27 -
1.28 - if (vv1 > mv1)
1.29 - return true;
1.30 - if (vv1 < mv1)
1.31 - return false;
1.32 - if (vv2 > mv2)
1.33 - return true;
1.34 - if (vv2 < mv2)
1.35 - return false;
1.36 - if (vv3 > mv3)
1.37 - return true;
1.38 - if (vv3 < mv3)
1.39 - return false;
1.40 - return true;
1.41 -*/
1.42 }
1.43
1.44 +
1.45 bool checkVersion (const QString &v, const QString &d)
1.46 {
1.47 - QString v1=v.section (".",0,0);
1.48 - QString v2=v.section (".",1,1);
1.49 - QString v3=v.section (".",2,2);
1.50 - QString d1=d.section (".",0,0);
1.51 - QString d2=d.section (".",1,1);
1.52 - QString d3=d.section (".",2,2);
1.53 bool ok;
1.54 - int d1i=d1.toInt(&ok,10);
1.55 - int d2i=d2.toInt(&ok,10);
1.56 - int d3i=d3.toInt(&ok,10);
1.57 - int v1i=0;
1.58 - int v2i=0;
1.59 - int v3i=0;
1.60 - if (!v1.isEmpty() ) v1i=v1.toInt(&ok,10);
1.61 - if (!v2.isEmpty() ) v2i=v2.toInt(&ok,10);
1.62 - if (!v3.isEmpty() ) v3i=v3.toInt(&ok,10);
1.63 + int v1;
1.64 + int v2;
1.65 + int v3;
1.66 + int d1;
1.67 + int d2;
1.68 + int d3;
1.69 +
1.70 + QRegExp rx("(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})");
1.71 + int pos=rx.indexIn (v);
1.72 + if (pos>-1)
1.73 + {
1.74 + v1=rx.cap(1).toInt(&ok);
1.75 + v2=rx.cap(2).toInt(&ok);
1.76 + v3=rx.cap(3).toInt(&ok);
1.77 + } else
1.78 + qWarning (QString ("Warning: Checking version failed for v=%1").arg(v));
1.79 +
1.80 + pos=rx.indexIn (d);
1.81 + if (pos>-1)
1.82 + {
1.83 + d1=rx.cap(1).toInt(&ok);
1.84 + d2=rx.cap(2).toInt(&ok);
1.85 + d3=rx.cap(3).toInt(&ok);
1.86 + } else
1.87 + qWarning (QString ("Warning: Checking version failed for d=%1").arg(d));
1.88 +
1.89
1.90 - if (d1i > v1i)
1.91 + if (d1 > v1)
1.92 return true;
1.93 - if (d1i < v1i)
1.94 + if (d1 < v1)
1.95 return false;
1.96 - if (d2i > v2i)
1.97 + if (d2 > v2)
1.98 return true;
1.99 - if (d2i < v2i)
1.100 + if (d2 < v2)
1.101 return false;
1.102 - if (d3i > v3i)
1.103 + if (d3 > v3)
1.104 return true;
1.105 - if (d3i < v3i)
1.106 + if (d3 < v3)
1.107 return false;
1.108 return true;
1.109