forked from BASLQC/kc-vita-translation
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvita_copy.pl
64 lines (56 loc) · 1.72 KB
/
vita_copy.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use 5.020;
use strictures 2;
use IO::All -binary;
use Digest::SHA1 'sha1_base64';
$|++;
run();
sub run {
say "copying";
my $vita_dir = "e:/rePatch/PCSG00684/Media";
my $cand_dir = "../kc_translation_mod_candidate/rePatch/PCSG00684";
io($vita_dir)->mkpath;
my @vita_files = grep !/checksums/, io($vita_dir)->All_Files;
for my $file (@vita_files) {
my @file_parts = split /\/|\\/, $file;
shift @file_parts for 1 .. 3;
my $cand_file = join "/", $cand_dir, @file_parts;
next if -e $cand_file;
say "file '$file' on vita doesn't exist in candidate dir, deleting";
unlink $file;
}
my $sums_file = "$vita_dir/checksums";
my %known_sums = -e $sums_file ? split /\n|\t/, io($sums_file)->all : ();
my %sums;
say "checksumming files";
my @files = reverse sort { $a->size <=> $b->size } io($cand_dir)->All_Files;
my @to_copy;
for my $file (@files) {
print "$file ";
my @file_parts = split /\/|\\/, $file;
shift @file_parts for 1 .. 5;
my $path = join "/", @file_parts;
$sums{$path} = sha1_base64 $file->all;
if ( $known_sums{$path} and $sums{$path} eq $known_sums{$path} ) {
say " already on vita, skip";
next;
}
say " new!";
push @to_copy, [ $file, "$vita_dir/$path" ];
}
say "copying files";
for my $file (@to_copy) {
( $file, my $path ) = $file->@*;
say $file;
io( io->file($path)->filepath )->mkpath;
$file->copy($path);
}
io($sums_file)->print( join "\n", map "$_\t$sums{$_}", sort keys %sums );
say "done";
$|++;
print "\7";
sleep 1;
print "\7";
sleep 1;
print "\7";
return;
}