version.cpp
author insilmaril
Fri, 02 Oct 2009 13:24:55 +0000
changeset 802 f076fdec767d
parent 729 7ddbe3fa34a1
permissions -rw-r--r--
More fixes for using proxy
insilmaril@402
     1
#include "version.h"
insilmaril@402
     2
insilmaril@729
     3
#include <QRegExp>
insilmaril@729
     4
insilmaril@402
     5
bool checkVersion (const QString &v)
insilmaril@402
     6
{
insilmaril@402
     7
	// returns true, if vym is able to read file regarding 
insilmaril@402
     8
	// the version set with setVersion
insilmaril@565
     9
	return checkVersion (v,__VYM_VERSION);
insilmaril@565
    10
}
insilmaril@565
    11
insilmaril@729
    12
insilmaril@565
    13
bool checkVersion (const QString &v, const QString &d)
insilmaril@565
    14
{
insilmaril@565
    15
	bool ok;
insilmaril@729
    16
	int v1;
insilmaril@729
    17
	int v2;
insilmaril@729
    18
	int v3;
insilmaril@729
    19
	int d1;
insilmaril@729
    20
	int d2;
insilmaril@729
    21
	int d3;
insilmaril@729
    22
insilmaril@729
    23
	QRegExp rx("(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})");
insilmaril@729
    24
	int pos=rx.indexIn (v);
insilmaril@729
    25
	if (pos>-1)
insilmaril@729
    26
	{
insilmaril@729
    27
		v1=rx.cap(1).toInt(&ok);
insilmaril@729
    28
		v2=rx.cap(2).toInt(&ok);
insilmaril@729
    29
		v3=rx.cap(3).toInt(&ok);
insilmaril@729
    30
	} else
insilmaril@729
    31
		qWarning (QString ("Warning: Checking version failed for v=%1").arg(v));
insilmaril@729
    32
insilmaril@729
    33
	pos=rx.indexIn (d);
insilmaril@729
    34
	if (pos>-1)
insilmaril@729
    35
	{
insilmaril@729
    36
		d1=rx.cap(1).toInt(&ok);
insilmaril@729
    37
		d2=rx.cap(2).toInt(&ok);
insilmaril@729
    38
		d3=rx.cap(3).toInt(&ok);
insilmaril@729
    39
	} else
insilmaril@729
    40
		qWarning (QString ("Warning: Checking version failed for d=%1").arg(d));
insilmaril@729
    41
insilmaril@565
    42
	
insilmaril@729
    43
	if (d1 > v1)
insilmaril@565
    44
		return true;
insilmaril@729
    45
	if (d1 < v1)
insilmaril@565
    46
		return false;
insilmaril@729
    47
	if (d2 > v2)
insilmaril@565
    48
		return true;
insilmaril@729
    49
	if (d2 < v2)
insilmaril@565
    50
		return false;
insilmaril@729
    51
	if (d3 > v3)
insilmaril@565
    52
		return true;
insilmaril@729
    53
	if (d3 < v3)
insilmaril@565
    54
		return false;
insilmaril@565
    55
	return true;	
insilmaril@402
    56
insilmaril@404
    57
}