#!/usr/bin/perl use strict; use warnings; use File::Find; use File::Copy; use File::Basename; use Win32::File qw(SetAttributes READONLY); use Cwd; my @fileArry; my $file; my $fullName; my $lastName; my $dirName; my $addString; my $location; my $hLogFile; my %options=(wanted=>\&wanted,postprocess => \&postFun); my $script_ver = "1.1"; exit &main(@ARGV); sub main { print "vsUpgrade $script_ver.\nfor help use vsUpgrade --help\n"; for my $arg (0 .. $#_) { if ($_[$arg] eq '--suffix') { $addString = $_[$arg+1]; } elsif ($_[$arg] eq '--location') { $location = $_[$arg+1]; } elsif ($_[$arg] eq '--help') { printHelp(); return 0; } } # for arg if (!defined $addString) { $addString = "_vs2008"; } print "sln and vcproj names will be suffixed with $addString\n\n"; if (!defined $location) { $location = getcwd; } print "Processing will start from directory $location\n\n"; open ($hLogFile, ">vsUpgrade.log") or die "can't open vsUpgrade.log\n"; print $hLogFile ("Starting to process from directory $location and down\n"); find(\%options, $location); foreach $file (@fileArry) { my @tempName; my $newName; my $newFullName; $lastName=basename($file); $dirName=dirname($file); @tempName=split (/\./,$lastName); $newName = $tempName[0].$addString.".".$tempName[1]; $newFullName = $dirName."/".$newName; print $hLogFile ("copying $file to $newFullName\n"); copy ($file,$newFullName) or print $hLogFile "cannot copy $file to $newFullName\n"; if ($tempName[1] =~ /sln$/) { # process sln content processSln($newFullName); } } print "finished. Check log vsUpgrade.log for full details\n"; print $hLogFile ("Finished\n"); close $hLogFile; return 0; } sub wanted { # do nothing. function must be defined. } sub postFun { if ($File::Find::dir !~ /lost|found|binaries|VTune|include|tools|\.svn/) { my $dirHandle; my @dirContents; my $fileName; opendir ($dirHandle,$File::Find::dir) or die "can't open dir $File::Find::dir\n"; @dirContents = readdir($dirHandle) or die "can't read dir $File::Find::dir\n"; foreach $fileName (@dirContents) { if ($fileName =~ /\.sln|\.vcproj$/) { if ($fileName =~ /\.WM\.vcproj|\.WM\.sln$/) { # do nothing, invalid files } else { if ($fileName =~ /$addString\.sln|$addString\.vcproj/) { # delete this file, just in case. We will re-create it later print $hLogFile ("deleting $fileName in $File::Find::dir\n"); unlink($fileName); } else { $fullName = "$File::Find::name"."/"."$fileName"; push @fileArry,$fullName; } } } } } } sub processSln ($) { my $hSrc; my $hDst; my ($srcName) = @_; my $dstName = $srcName.".temp"; print $hLogFile ("processing $srcName\n"); SetAttributes($srcName, !READONLY); SetAttributes($dstName, !READONLY); open ($hSrc, "<$srcName") or die "can't open $srcName\n"; open ($hDst, ">$dstName") or die "can't open $dstName\n"; for my $line (<$hSrc>) { if ($line =~ /\.vcproj/) { $line =~ s/\.vcproj/$addString\.vcproj/; } print $hDst $line; } close $hSrc; close $hDst; unlink $srcName or die; rename $dstName, $srcName or die "cannot rename\n"; } sub printHelp { print "\n"; print "vsUpgrade $script_ver help\n"; print "==================\n"; print "This script will upgrade your vcproj and sln files from vs2005 to vs2008 (for now).\n"; print "It will go over each directory, look for vcproj files and sln files without a suffix, and will\n"; print "create new ones, with the right suffix. For each created sln, it will also edit its internals,\n"; print "replacing references to xxx.vcproj with xxx_.vcproj\n\n"; print "usage: vsUpgrade --suffix suffix --location base_folder\n\n"; print " is the string that will be added to the file names before their extension.\n"; print " for exmaple: if is _vs2008, the original xxx.vcproj will be copied to xxx_vs2008.vcproj.\n"; print " If no suffix is given, the default _vs2008 will be used\n\n"; print " is the folder from which the script will start processing. If none is given, the current\n"; print " working directory will be used\n\n"; print "Once finished, results can be seen in the vsUpgrade.log file created in the same folder the script is saved\n\n"; print "To finalize the process, open the new sln file with visual-studio 2008. A wizard will tell you it is about to\n"; print "upgrade your sln and vcproj files to vs2008 format. Next Next Next, and you're done.\n\n"; print "Bug reports can be sent to oferg\@radvision.com (9658).\n"; }