use strict;
use Cwd;
use Win32;
require 'cmn.pl';
use File::Basename;
sub Main;
sub PathSetupOut;
sub PathSvn;
sub SetVerSvnIss;
sub SetVersion;
sub SvnVersion;
my $g_AutoRun='';
Main;
sub Main
{
my $Arg=$ARGV[0];
if ($Arg eq "-a")
{
$g_AutoRun="y";
}
my ($SvnVersion, $SvnRevision) = &SetVersion;
my $PathSetupOut = &PathSetupOut;
if (! $g_AutoRun)
{
print "Setting version $SvnVersion and revision $SvnRevision on...\n";
}
&SetVerSvnIss($SvnVersion, $SvnRevision);
}
sub PathSvn
{
my $RetVal = '';
my $path_svn = '';
my $path_svnclient = '';
my $ErrMsg = '';
my @paths;
$path_svn = &cmn_ValuePathfile('path_svn');
$path_svnclient = &cmn_ValuePathfile('path_svnclient');
if (-e "$path_svn\\bin\\svn.exe")
{
$path_svnclient = "$path_svn\\bin";
}
else
{
$path_svnclient = &cmn_ValuePathfile('path_svnclient');
}
unless (-e "$path_svnclient\\svn.exe")
{
@paths = ($path_svnclient =~ /(\w+)/g);
$path_svn = &cmn_ValuePathfile($paths[0]);
$path_svnclient = "$path_svn\\$paths[1]";
$path_svnclient =~ s/\\\\/\\/g;
}
$ErrMsg="ERROR: File not found: Could not find svn.exe in:\n $path_svnclient\n";
$ErrMsg=$ErrMsg . "Please, check that the path_svnclient variable in the ";
$ErrMsg=$ErrMsg . "..\\svn_dynamics.iss\n";
$ErrMsg=$ErrMsg . "file is correct and try again\n";
if (-e "$path_svnclient\\svn.exe")
{
$RetVal="$path_svnclient\\svn.exe";
}
else
{
die $ErrMsg;
}
return $RetVal;
}
sub SetVersion
{
my ($SvnVersion, $SvnRevision) = &SvnVersion;
my ($InputVersion, $InputRevision)='';
$SvnRevision = "unset" if (! $SvnRevision);
if (! $g_AutoRun)
{
print "\nsvn.exe that's mentioned in your svn_dynamics.iss file have ",
"told me that the\n",
"version you want to make a distro from is $SvnVersion and that the ",
"revision is\n",
"$SvnRevision. You can confirm this by hitting the ENTER button ",
"(wich then sets the numbers\n",
"inside the brackets) or write some new data followed by the ENTER",
" button.\n\n",
"Please, make sure that svn.iss is not opened by another ",
"applications before you continue:\n\n";
print " Version [$SvnVersion]: ";
chomp ($InputVersion = <STDIN>);
if ($InputVersion)
{
$SvnVersion = $InputVersion;
}
$SvnRevision = "" if ($SvnRevision eq "unset");
print " Revision [$SvnRevision]: ";
chomp ($InputRevision = <STDIN>);
if ($InputRevision)
{
$SvnRevision = $InputRevision;
}
}
return ($SvnVersion, $SvnRevision);
}
sub SetVerSvnIss
{
my ($SvnVersion, $SvnRevision) = @_;
my $SvnPreTxtRevision='';
my $IssFileCnt='';
$SvnPreTxtRevision='-r' if ($SvnRevision);
if (! -e '../svn_version.iss')
{
system ("copy ..\\templates\\svn_version.iss ..");
}
print " svn_version.iss in the Inno Setup directory.\n" if (! $g_AutoRun);
open (FH_ISSFILE, '../svn_version.iss') || die "ERROR: Could not open ..\\svn_version.iss";
while (<FH_ISSFILE>)
{
chomp($_);
if ($IssFileCnt)
{
$IssFileCnt="$IssFileCnt\n";
}
if (/^ {
$IssFileCnt= $IssFileCnt . "#define svn_version \"$SvnVersion\"";
}
elsif (/^ {
$IssFileCnt= $IssFileCnt . "#define svn_revision \"$SvnRevision\"";
}
elsif (/^ {
$IssFileCnt= $IssFileCnt . "#define svn_pretxtrevision \"$SvnPreTxtRevision\"";
}
else
{
$IssFileCnt= $IssFileCnt . $_;
}
}
close (FH_ISSFILE);
$IssFileCnt="$IssFileCnt\n";
open (FH_ISSFILE, ">" . '../svn_version.iss')
|| die "ERROR: Could not open ..\\svn_version.iss";
print FH_ISSFILE $IssFileCnt;
close (FH_ISSFILE);
}
sub SvnVersion
{
my $Svn = &PathSvn;
my @SvnVerOut;
my $SvnRetVal='';
my ($SvnVersion, $SvnRevision) ='';
$Svn = "\"$Svn\"";
$SvnRetVal = `$Svn --version`;
@SvnVerOut = split(/\n/, $SvnRetVal);
for (@SvnVerOut)
{
if (/svn, version /)
{
$SvnRetVal = $_;
last;
}
}
$SvnRetVal =~ s/svn, version //s;
if ($SvnRetVal =~ /.+\(r.+\)/)
{
$SvnRetVal =~ s/(^.*)\).*/$1/;
($SvnVersion, $SvnRevision) = split (/\(/, $1);
}
else
{
$SvnRetVal =~ s/([\d]?\.[\d]{1,2}\.[\d]{1,2})/$1/;
$SvnVersion = $SvnRetVal;
}
$SvnVersion =~ s/^\s+//;
$SvnVersion =~ s/\s+$//;
$SvnRevision =~ s/r//;
$SvnRevision =~ s/dev build/_dev-build/;
return ($SvnVersion, $SvnRevision);
}