#!/usr/bin/perl
#############################################################################
# Xestia Address Book: Version Updater #
# (c) 2017 Xestia Address Book #
#############################################################################
# This file is part of Xestia Address Book. #
# #
# Xestia Address Book is free software: you can redistribute it and/or #
# modify it under the terms of the GNU General Public License as published #
# by the Free Software Foundation, version 3 of the license. #
# #
# Xestia Address Book is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with Xestia Address Book. If not, see #
#############################################################################
use strict;
use warnings;
use Tie::File;
# Get the version number.
if (!$ARGV[0]){
print "Error: No version specified!\n";
exit;
}
my $version = $ARGV[0];
my $filename;
my $file_handle;
my @file_data;
# Split the version information down.
my @version_split = split(/(\.)/, $version);
my $version_major = $version_split[0];
my $version_minor = $version_split[2];
# Update source/version.h
$filename = "../version.h";
tie(@file_data, 'Tie::File', $filename);
foreach my $file_data_line(@file_data) {
# Look for XSDAB_VERSION
if ($file_data_line =~ /^\#define\ XSDAB_VERSION/){
my $line_output = "#define XSDAB_VERSION \"";
$line_output .= $version;
$line_output .= "\"";
$file_data_line = $line_output;
}
# Look for XSDAB_USERAGENT
if ($file_data_line =~ /^\#define\ XSDAB_USERAGENT/){
my $line_output = "#define XSDAB_USERAGENT \"XestiaAddressBook/";
$line_output .= $version;
$line_output .= "\"";
$file_data_line = $line_output;
}
}
# Update source/os/msw/xestiaab.rc
$filename = "../os/msw/xestiaab.rc";
tie(@file_data, 'Tie::File', $filename);
foreach my $file_data_line(@file_data) {
# Look for FILEVERSION
if ($file_data_line =~ /^ FILEVERSION/){
my $line_output = " FILEVERSION ";
$line_output .= $version_major;
$line_output .= ",";
$line_output .= $version_minor;
$line_output .= ",0,0";
$file_data_line = $line_output;
}
# Look for PRODUCTVERSION
if ($file_data_line =~ /^ PRODUCTVERSION/){
my $line_output = " PRODUCTVERSION ";
$line_output .= $version_major;
$line_output .= ",";
$line_output .= $version_minor;
$line_output .= ",0,0";
$file_data_line = $line_output;
}
}
# Update source/os/osx/Info.plist
$filename = "../os/osx/Info.plist";
open($file_handle, '+<', $filename);
my $line_found = 0;
my $new_file = "";
while(<$file_handle>)
{
if ($line_found eq 1)
{
my $new_line = "\t" . $version_major . "." . $version_minor . "\n";
$new_file .= $new_line;
$line_found = 0;
next;
}
if (/.*CFBundleVersion<\/key>/)
{
$line_found = 1;
}
$new_file .= $_;
}
close($file_handle);
print $new_file;