Not sure what type of files you mean, but if it's exe or dll files on Windows this might be of use:
http://www.purebasic.fr/english/viewtopic.php?t=13910
Also, you need to decide how to treat the version info.
x1.x2.x3.x4
Now, normally x4 is usually a build (some may put the build in x3 instead though), it's for information purposes and usually internal, if the version is unchanged the only ones seeing a change in build would be the developer(s) of the software as a new release would change the version as well.
x3 is usually the update or patch, so if it's 0 then it's the first release a 1 could indicate a bugfix, patch, or Release Candidate etc.
x2 is the revision or minor version, usually this indicate there are changes or additions but that it is still compatible within the same major version.
x1 if this changes then it usually means is not compatible with other major versions.
These are not absolute rules, but they are good guidelines as most do it this way or close to it so it helps reduce confusion (which is bad enough)
Also note that leading 0's are ignored, in other words each "x" number are seperate and not fractions. So 1.001.0.14 is the same as 1.1.0.14
A higher number is thus a more recent one, this allows easy and fast integer comparisons.
Again this is a guideline, in the world of string based version info there is a lot of weird stuff like letters or even floating point like fractions O.o
I prefer to stay clos to how windows does it which is also how PureBasic ads version info to the dll and exe manifests.
If you want to cry....read this:
http://en.wikipedia.org/wiki/Software_versioning
Not the most elegant solution but it's simple, works, and give you a place to start and modify from
Code: Select all
EnableExplicit
Procedure.i CompareVersion(ver.l,rev.l,subver.l,subrev.l,oldver.l,oldrev.l,oldsubver.l,oldsubrev.l,flag.l=4)
Protected result.i=0
If flag>0
If ver<oldver
result=-1
ElseIf ver>oldver
result=1
Else
If flag>1
If rev<oldrev
result=-1
ElseIf rev>oldrev
result=1
Else
If flag>2
If subver<oldsubver
result=-1
ElseIf subver>oldsubver
result=1
Else
If flag>3
If subrev<oldsubrev
result=-1
ElseIf subrev>oldsubrev
result=1
Else
result=0
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
ProcedureReturn result
EndProcedure
Debug CompareVersion(1,2,3,4,1,2,3,4) ;0 if they are the same
Debug CompareVersion(2,2,3,4,1,2,3,4) ;1 if the first 4 params are higher than the last 4
Debug CompareVersion(0,2,3,4,1,2,3,4) ;-1 if the first 4 params are lower than the last 4
;Use the flag param to indicate how many params should be compared.
Debug CompareVersion(1,2,4,0,1,2,3,4,2) ;compare only the two first of the params