show dumps only if not using --write
[perl-Mifare-MAD.git] / nfc-card-dumper.pl
index b1e780a..5397f06 100755 (executable)
@@ -96,7 +96,7 @@ if ($r->init()) {
        }
 
        my $md5 = md5_hex($card);
-       my $out_file = "cards/$uid.$md5";
+       my $out_file = "cards/$uid.$md5.mfd";
        if ( -e $out_file ) {
                warn "$out_file allready exists, not overwriting\n";
        } else {
@@ -118,10 +118,12 @@ if ($r->init()) {
                        print STDERR "$block ";
                }
                print STDERR "done\n";
+       } else {
+               # view dump
+               my $txt_file = $out_file;
+               $txt_file =~ s/\.mfd/.txt/ || die "can't change extension to txt";
+               system "./mifare-mad.pl $out_file > $txt_file";
+               $ENV{MAD} && system "vi $txt_file";
        }
-
-       # view dump
-       system "./mifare-mad.pl $out_file > $out_file.txt";
-       $ENV{MAD} && system "vi $out_file.txt";
 }