From 4aa6a24d95219ceffd9efdc74e360633c65a9577 Mon Sep 17 00:00:00 2001
From: rubidium <rubidium@openttd.org>
Date: Mon, 29 Nov 2010 12:49:27 +0000
Subject: [PATCH] (svn r21351) -Change: read some metadata from (official)
 source tarballs so you'll more likely get the right version/revision
 out-of-the-box

---
 config.lib                    |  3 +++
 findversion.sh                |  4 ++++
 projects/determineversion.vbs | 33 +++++++++++++++++++++------------
 3 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/config.lib b/config.lib
index c75c558119..84db18ef6d 100644
--- a/config.lib
+++ b/config.lib
@@ -1020,6 +1020,9 @@ check_params() {
 		elif [ -d "$ROOT_DIR/.hg" ] && [ -n "`hg help 2>/dev/null`" ]; then
 			revision=""
 			log 1 "checking revision... hg detection"
+		elif [ -f "$ROOT_DIR/.rev" ]; then
+			revision=""
+			log 1 "checking revision... source tarball"
 		else
 			revision=""
 			log 1 "checking revision... no detection"
diff --git a/findversion.sh b/findversion.sh
index f20dc828b8..89fc44b3cb 100755
--- a/findversion.sh
+++ b/findversion.sh
@@ -108,6 +108,10 @@ elif [ -d "$ROOT_DIR/.hg" ]; then
 	REV="h`echo $HASH | cut -c1-8`"
 	BRANCH=`hg branch | sed 's@^default$@@'`
 	REV_NR=`LC_ALL=C hg log -f -k "(svn r" -l 1 --template "{desc}\n" | head -n 1 | sed "s@.*(svn r\([0-9]*\)).*@\1@"`
+elif [ -f "$ROOT_DIR/.ottdrev" ]; then
+	# We are an exported source bundle
+	cat $ROOT_DIR/.ottdrev
+	exit
 else
 	# We don't know
 	MODIFIED="1"
diff --git a/projects/determineversion.vbs b/projects/determineversion.vbs
index 98e4e8322f..1670882fb2 100755
--- a/projects/determineversion.vbs
+++ b/projects/determineversion.vbs
@@ -35,8 +35,9 @@ Sub UpdateFiles(version)
 
 	If InStr(version, Chr(9)) Then
 		revision = Mid(version, InStr(version, Chr(9)) + 1)
+		modified = Mid(revision, InStr(revision, Chr(9)) + 1)
 		revision = Mid(revision, 1, InStr(revision, Chr(9)) - 1)
-		modified = Mid(version, InStrRev(version, Chr(9)) + 1)
+		modified = Mid(modified, 1, InStr(modified, Chr(9)) - 1)
 		version  = Mid(version, 1, InStr(version, Chr(9)) - 1)
 	Else
 		revision = 0
@@ -260,19 +261,27 @@ Function DetermineSVNVersion()
 		End If ' version = "norev000"
 	End If ' version <> "norev000"
 
-	If modified = 2 Then
-		version = version & "M"
-	End If
-
-	If branch <> "" Then
-		version = version & "-" & branch
-	End If
-
-	If version <> "norev000" Then
-		DetermineSVNVersion = version & Chr(9) & revision & Chr(9) & modified
+	Dim rev_file
+	Set rev_file = FSO.OpenTextFile("../.ottdrev", 1, True, 0)
+	If Not rev_file.atEndOfStream Then
+		DetermineSVNVersion = rev_file.ReadLine()
 	Else
-		DetermineSVNVersion = version
+		If modified = 2 Then
+			version = version & "M"
+		End If
+
+		clean_rev = version
+		If branch <> "" Then
+			version = version & "-" & branch
+		End If
+
+		If version <> "norev000" Then
+			DetermineSVNVersion = version & Chr(9) & revision & Chr(9) & modified & Chr(9) & clean_rev
+		Else
+			DetermineSVNVersion = version
+		End If
 	End If
+	rev_file.close
 End Function
 
 Function IsCachedVersion(ByVal version)