1
0
forked from 0ad/0ad

XMB cleanup program (to remove old unused .xmb files)

This was SVN commit r1487.
This commit is contained in:
Ykkrosh 2004-12-12 12:51:24 +00:00
parent 2e0bb04882
commit 61705f7caf
3 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,3 @@
@echo off
cd ..\..\build\bin
..\xmbcleanup\xmbcleanup.exe

Binary file not shown.

View File

@ -0,0 +1,52 @@
use strict;
use warnings;
use File::Find;
++$|;
# Relative to build/bin or build/xmbcleanup
my $dir = '../../binaries/data/mods/official';
my @xmlfiles;
find({
wanted => sub { push @xmlfiles, $File::Find::name if /\.xml$/; $File::Find::prune=1 if $_ eq '.svn' },
}, $dir);
my $count = 0;
# First, delete old-style XMB files
for (@xmlfiles) {
# Turn "etc.xml" into "etc.xmb"
(my $f = $_) =~ s/\.xml$/.xmb/ or die "Internal error: invalid filename '$_'";
# If it exists, delete it
if (-e $f) {
print "Deleting $f\n";
unlink $f;
++$count;
}
}
for (@xmlfiles) {
# Turn "etc.xml" into "etc_<'?' x 17>.xmb"
(my $f = $_) =~ s/\.xml$/_?????????????????.xmb/ or die "Internal error: invalid filename '$_'";
$f =~ s/ /\\ /g;
# Find all such files
my @xmbfiles = glob $f;
# If there are two or more, delete all but the newest
if (@xmbfiles > 1) {
@xmbfiles = sort @xmbfiles; # files are "etc_<TIMESTAMP><SIZE><VERSION>xmb", with TIMESTAMP
# hex-encoded, so sorting will put the oldest files first.
# Remove the newest
pop @xmbfiles;
# Delete the rest
print "DELETING @xmbfiles\n";
unlink @xmbfiles;
$count += @xmbfiles;
}
}
print "\n\nCompleted - $count ".($count==1?'file':'files')." deleted. Press enter to exit.";
<>