-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsx_mc_cli
executable file
·78 lines (75 loc) · 2.67 KB
/
psx_mc_cli
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/perl
use strict; use warnings;
use File::Copy "copy";
use PlayStation::MemoryCard;
my $usage = <<'END_USAGE';
psx_mc_cli <command> [...]
List of commands
install | Extract the psx_mc_cli utilities. psx_mc_cli.com is copied
| and turned into a native executable. Symlinks to the
| utilities are created, or binaries are created as a
| fallback. On Windows < 11, Admin privileges are needed to
| create symlinks.
perldoc | Open the PlayStation::MemoryCard perldoc
help | Display this message
version | Display version
lsmc | Run the lsmc script
mciconextract | Run the mciconextract script
mcs2raw | Run the mcs2raw script
mcsaveextract | Run the mcsaveextract script
mkmcd | Run the mkmcd script
raw2mcs | Run the raw2mcs script
This is psx_mc_cli packaged into APPerl. Rename this executable to perl.com
to use perl.
END_USAGE
my $command = shift @ARGV or die($usage);
my @scripts = qw(lsmc mciconextract mcs2raw mcsaveextract mkmcd raw2mcs);
if(grep(/^$command$/, @scripts)) {
do "/zip/bin/$command" or die;
}
elsif($command =~ /^(\-)*(halp|help|h)$/i) {
print $usage;
}
elsif($command =~ /^(\-)*(version|v)$/i) {
my $message = <<"END_USAGE";
psx_mc_cli $PlayStation::MemoryCard::VERSION
Copyright (C) 2022 Gavin Arthur Hayes
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
END_USAGE
print $message;
}
elsif($command eq 'perldoc') {
@ARGV = ('PlayStation::MemoryCard');
do "/zip/bin/$command" or die;
}
elsif($command eq 'install') {
my $IsWindows = -f '/C/Windows/System32/cmd.exe';
my $ext = $IsWindows ? '.exe' : '';
my $srcbin = "./psx_mc_cli$ext";
copy($^X, $srcbin) or die "Failed to make copy";
chmod((stat $^X)[2], $srcbin) or die("Failed to set file permissions");
if(!$IsWindows) {
# for now we need to force this through a shell to run an APE binary
# and prevent the cosmopolitan runtime from handling it seperately
my $escapedcmd = join(' ', ('"'.$srcbin.'"', '--assimilate'));
system($escapedcmd) == 0 or die 'Failed to assimilate';
}
my @commands = (
sub { return eval { symlink($srcbin, $_[0]); }; },
sub { return copy($srcbin, $_[0])},
);
my $success;
OUTER:
foreach my $command (@commands) {
foreach my $tocreate (@scripts) {
$command->($tocreate.$ext) or next OUTER;
}
$success = 1;
last;
}
$success or die 'Error installing';
}
else {
die($usage);
}