diff --git a/apply.sh b/apply.sh index 56dce35..8dfe396 100755 --- a/apply.sh +++ b/apply.sh @@ -1,4 +1,6 @@ #!/bin/bash +# applies the .ips patch to base.nes, generating working.nes +# Run with -f flag to replace existing working.nes _force=false flips="./flips/flips.exe" @@ -19,7 +21,8 @@ else then if [ "$_force" = false ] then - >&2 echo "working.nes already exists. Rerun with -f flag to force overwriting working.nes" + >&2 echo "Error: working.nes already exists." + >&2 echo "Rerun with -f flag to force overwriting working.nes" exit 1; else echo "Replacing existing working.nes" @@ -49,6 +52,13 @@ else chmod u+x $flips + chmod u+wr working.nes + $flips --apply patch.ips working.nes - exit $? + err=$? + + chmod a-x working.nes + chmod u+wr working.nes + + exit $err fi diff --git a/hooks/pre-commit b/hooks/pre-commit index cb49b3b..e61a738 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -7,5 +7,18 @@ cd $_rdir # make sure base.nes and working.nes exist: if [ ! -f ./base.nes ] then - echo "Base ROM (base.nes) is not found!" + >&2 echo "Base ROM (base.nes) is not found! Aborting commit." + exit 1; fi + +if [ ! -f ./base.nes ] +then + >&2 echo "Modified ROM (working.nes) is not found! Aborting commit." + >&2 echo "(Did you ever generate working.nes with apply.sh?)" + exit 2; +fi + +# generate patch +./make-patch.sh + +exit $? diff --git a/make-patch.sh b/make-patch.sh new file mode 100755 index 0000000..1ad3636 --- /dev/null +++ b/make-patch.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# creates a patch based on the difference between base.rom and working.rom + +# find flips patcher: +flips="./flips/flips.exe" + +if [ "$op" = "Linux" ] +then + flips="./flips/flips-linux" +fi + +if [ ! -f $flips ] +then + >&2 echo "flips not found; do you have the flips/ folder?" + exit 2; +fi + +echo "Generating patch.ips..." + +chmod u+w patch.ips + +rm patch.ips + +$flips --create --ips base.nes working.nes patch.ips +err=$? + +chmod u+r patch.ips +chmod a-wx patch.ips + +exit $? diff --git a/setup.sh b/setup.sh index 7723636..5528712 100755 --- a/setup.sh +++ b/setup.sh @@ -23,6 +23,9 @@ else then echo "Warning: working.nes but no base.nes file; you will not be able to generate patches." echo "(Perhaps you should delete working.nes and copy in a new base.nes?)" + else + echo "No changes made to base.nes or working.nes" + echo "(If you intended to apply the patch now, then run ./apply.sh)" fi fi