#!/usr/bin/perl # Migrate MGMaps cache from V1 to v2 or newer # script version 1.10 #Externals use POSIX; use File::Find; use Cwd; #OS Specific Variables $linuxDirDivider = "\/"; $linuxMoveCommand = "mv"; $linuxDeleteCommand = "rm"; $windowsDirDivider = "\\"; $windowsMoveCommand = "move"; $windowsDeleteCommand = "del"; print "Detected OS: $^O\n\n"; if($^O ge "linux" || $^O ge "cygwin" ) { $systemDirDivider = $linuxDirDivider; $systemMoveCommand = $linuxMoveCommand; $systemDeleteCommand = $linuxDeleteCommand; } elsif($^O ge "MSWin") { $systemDirDivider = $windowsDirDivider; $systemMoveCommand = $windowsMoveCommand; $systemDeleteCommand = $windowsDeleteCommand; } if($^O eq "darwin") { $systemDirDivider = $linuxDirDivider; $systemMoveCommand = $linuxMoveCommand; $systemDeleteCommand = $linuxDeleteCommand; } # check that the MGMapsCache directory does not exist if (-e "MGMapsCache") { print "The MGMapsCache directory already exists.\n"; exit; } # check that the MGMapsCacheV1 directory exists if (! -e "MGMapsCacheV1") { print "The MGMapsCacheV1 directory does not exist.\n"; exit; } # rename the files finddepth(\&recursiveRename, "MGMapsCacheV1"); # rename the main directory print "Renaming MGMapsCacheV1 to MGMapsCache\n"; my $cmd = $systemMoveCommand." MGMapsCacheV1 MGMapsCache"; system($cmd); print "Writing cache.conf\n"; my $file_CacheConf = "MGMapsCache".$systemDirDivider."cache.conf"; open(F, ">".$file_CacheConf) or die("Cannot write cache config file"); print F "version=2\n"; close(F); exit; sub recursiveRename { if (/\.png$/ || /\.jpg$/) { my $oldName = $_; s/\.[a-zA-Z]+$/.mgm/; print "Renaming ".$File::Find::name." to ".$_."\n"; my $cmd = $systemMoveCommand." ".$oldName." ".$_; system($cmd); } }