2017-02-22 13:01:43 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
2017-02-22 13:08:14 +00:00
|
|
|
"github.com/icedream/go-bsdiff/patch"
|
2017-02-22 13:01:43 +00:00
|
|
|
"gopkg.in/alecthomas/kingpin.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-02-22 13:08:14 +00:00
|
|
|
cli = kingpin.New("go-bspatch", "Applies binary patches generated using the bsdiff algorithm.")
|
2017-02-22 13:01:43 +00:00
|
|
|
|
|
|
|
argOld = cli.Arg("old", "The old file.").Required().ExistingFile()
|
2017-02-22 13:08:14 +00:00
|
|
|
argNew = cli.Arg("new", "Where the new file will be written to.").Required().File()
|
|
|
|
argPatch = cli.Arg("patch", "The patch file.").Required().ExistingFile()
|
2017-02-22 13:01:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func must(err error) {
|
|
|
|
if err == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
kingpin.MustParse(cli.Parse(os.Args[1:]))
|
|
|
|
|
2017-02-22 13:08:14 +00:00
|
|
|
newFile := *argNew
|
|
|
|
defer newFile.Close()
|
2017-02-22 13:01:43 +00:00
|
|
|
|
|
|
|
oldFile, err := os.Open(*argOld)
|
|
|
|
must(err)
|
|
|
|
defer oldFile.Close()
|
|
|
|
|
2017-02-22 13:08:14 +00:00
|
|
|
patchFile, err := os.Open(*argPatch)
|
2017-02-22 13:01:43 +00:00
|
|
|
must(err)
|
2017-02-22 13:08:14 +00:00
|
|
|
defer patchFile.Close()
|
2017-02-22 13:01:43 +00:00
|
|
|
|
2017-02-22 13:08:14 +00:00
|
|
|
must(patch.Patch(oldFile, newFile, patchFile))
|
2017-02-22 13:01:43 +00:00
|
|
|
}
|