#!/usr/bin/perl
binmode
(STDERR,
"encoding(UTF-8)"
);
(
@ARGV
>= 1) or
die
(
"No mcd provided"
);
my
$file
=
$ARGV
[0];
my
$mcfile
= PlayStation::MemoryCard->load(
$file
);
if
(!
$mcfile
) {
die
(
"Failed to open $file"
);
}
elsif
(
$mcfile
->{
'type'
} ne
'mcd'
) {
die
(
"Unsupported input format"
);
}
my
$searchfname
;
$searchfname
= decode(
'utf8'
,
$ARGV
[1])
if
(
@ARGV
>= 2);
$mcfile
->foreachDirEntry(
sub
{
my
(
$entry
,
$newsave
,
$entrydata
) =
@_
;
return
if
(!
$newsave
);
if
(PlayStation::MemoryCard::SaveNameAndTitleMatch(
$newsave
,
$searchfname
)) {
my
$mcs
= PlayStation::MemoryCard::FormatSaveAsMCS(
$newsave
);
print
$mcs
;
exit
0;
}
});
warn
"Failed to extract save"
;
exit
1;