Commit ead77e11 authored by natalie's avatar natalie 💜
Browse files

Merge branch 'autogenerate_output_filename' into 'master'

Use filename like megagrrl_<hwver>_<type>_<version>.mgu if --outfile is unset

See merge request natalie/megagrrl!15
parents 32f1b7fa 75d38aca
......@@ -33,8 +33,8 @@ GetOptions(
(!(defined($app) && defined($updater) && $app eq $updater))
or help('--app and --updater must be different files');
(defined($outfile) && ($outfile =~ /.+\.mgu$/) && !(-e $outfile))
or help('--outfile must be set, end in .mgu, and not exist');
(!defined($outfile) || (($outfile =~ /.+\.mgu$/) && !(-e $outfile)))
or help('--outfile, if set, must end in .mgu and not exist');
if (defined($hw)) {
($hw =~ /^[a-z0-9]{1}$/i)
......@@ -71,9 +71,22 @@ else {
die('unable to extract version from firmware(s) and --version is not set');
}
# use the hw type, firmware type(s), and version as the basis for an output filename if one hasn't been explicitly specified
if (!defined($outfile)) {
my @type;
(defined($app))
and push(@type, 'app');
(defined($updater))
and push(@type, 'updater');
$outfile = sprintf('megagrrl_%s_%s_%s.mgu', $hw, join('+', @type), $mgu_version);
(-e $outfile)
and die('automatically generated output filename ' . $outfile . ' already exists, not overwriting')
}
print("writing packed firmware to $outfile...\n\n");
my $outfh = FileHandle->new($outfile, 'w')
my $outfh = FileHandle->new($outfile, O_WRONLY|O_CREAT|O_EXCL)
or die("failed to open $outfile: $!");
$outfh->binmode(); # if we're on windows for some reason
......@@ -240,7 +253,7 @@ sub help {
print STDERR ("--updater=<updater_file.bin> - (optional) the updater portion of the firmware (built with #define FWUPDATE)\n");
print STDERR ("--version=some-firmware-version - (optional) the firmware version. if not specified, it will be preferentially extracted from app_file.bin, or updater_file.bin\n");
print STDERR ("--hw=<d|p> - (optional) the hardware version, typically one of 'd' for desktop or 'p' for portable. defaults to desktop\n");
print STDERR ("--outfile=<output_file.mgu> (required) filename to write the packed (.mgu) firmware to\n");
print STDERR ("--outfile=<output_file.mgu> (optional) filename to write the packed (.mgu) firmware to. autogenerated if unset\n");
print STDERR ("--help - this message\n");
exit(defined($error));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment