Add coloring to progress output

This commit is contained in:
Spotlight 2021-12-31 01:35:25 -06:00
parent c597e8f17d
commit b15a4059bf
No known key found for this signature in database
GPG Key ID: 874AA355B3209BDC
4 changed files with 17 additions and 7 deletions

1
go.mod
View File

@ -3,6 +3,7 @@ module github.com/OpenShopChannel/WSC-Patcher
go 1.17 go 1.17
require ( require (
github.com/logrusorgru/aurora/v3 v3.0.0
github.com/wii-tools/GoNUSD v0.2.1 github.com/wii-tools/GoNUSD v0.2.1
github.com/wii-tools/arclib v1.0.0 github.com/wii-tools/arclib v1.0.0
github.com/wii-tools/wadlib v0.3.0 github.com/wii-tools/wadlib v0.3.0

2
go.sum
View File

@ -1,3 +1,5 @@
github.com/logrusorgru/aurora/v3 v3.0.0 h1:R6zcoZZbvVcGMvDCKo45A9U/lzYyzl5NfYIvznmDfE4=
github.com/logrusorgru/aurora/v3 v3.0.0/go.mod h1:vsR12bk5grlLvLXAYrBsb5Oc/N+LxAlxggSjiwMnCUc=
github.com/wii-tools/GoNUSD v0.2.1 h1:HW8vssrEiCdFjiugCx3cTTaPw9nlz1TWxzeCqXKqTnQ= github.com/wii-tools/GoNUSD v0.2.1 h1:HW8vssrEiCdFjiugCx3cTTaPw9nlz1TWxzeCqXKqTnQ=
github.com/wii-tools/GoNUSD v0.2.1/go.mod h1:jMYMU5X81Hp0R+bq6/0AxAOijGHXfexaG6dLRilgS2s= github.com/wii-tools/GoNUSD v0.2.1/go.mod h1:jMYMU5X81Hp0R+bq6/0AxAOijGHXfexaG6dLRilgS2s=
github.com/wii-tools/arclib v1.0.0 h1:OAmbL3NDUmlR0wa1VpJhxnKiIRFZz1CC40lTVPUm8Ms= github.com/wii-tools/arclib v1.0.0 h1:OAmbL3NDUmlR0wa1VpJhxnKiIRFZz1CC40lTVPUm8Ms=

14
main.go
View File

@ -3,10 +3,12 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/logrusorgru/aurora/v3"
"github.com/wii-tools/GoNUSD" "github.com/wii-tools/GoNUSD"
"github.com/wii-tools/arclib" "github.com/wii-tools/arclib"
"github.com/wii-tools/wadlib" "github.com/wii-tools/wadlib"
"io/fs" "io/fs"
"io/ioutil"
"log" "log"
"os" "os"
) )
@ -20,6 +22,8 @@ var mainDol []byte
// mainArc holds the main ARC - our content at index 2. // mainArc holds the main ARC - our content at index 2.
var mainArc *arclib.ARC var mainArc *arclib.ARC
// rootCertificate holds the public certificate, in DER form, to be patched in.
var rootCertificate []byte
// filePresent returns whether the specified path is present on disk. // filePresent returns whether the specified path is present on disk.
func filePresent(path string) bool { func filePresent(path string) bool {
@ -77,7 +81,7 @@ func main() {
// Determine whether a certificate authority was provided, or generated previously. // Determine whether a certificate authority was provided, or generated previously.
if !filePresent("./output/root.cer") { if !filePresent("./output/root.cer") {
log.Println("Generating root certificates...") fmt.Println(aurora.Green("Generating root certificates..."))
rootCertificate = createCertificates() rootCertificate = createCertificates()
} else { } else {
rootCertificate, err = ioutil.ReadFile("./output/root.cer") rootCertificate, err = ioutil.ReadFile("./output/root.cer")
@ -101,9 +105,11 @@ func main() {
originalWad.TMD.AccessRightsFlags = 0x3 originalWad.TMD.AccessRightsFlags = 0x3
// Apply all DOL patches // Apply all DOL patches
log.Println("Applying DOL patches...") fmt.Println(aurora.Green("Applying DOL patches..."))
applyDefaultPatches() applyDefaultPatches()
ioutil.WriteFile("/Users/spot/Desktop/patched.app", mainDol, 0755)
// Load main ARC // Load main ARC
arcData, err := originalWad.GetContent(2) arcData, err := originalWad.GetContent(2)
check(err) check(err)
@ -111,7 +117,7 @@ func main() {
check(err) check(err)
// Generate filter list and certificate store // Generate filter list and certificate store
log.Println("Applying Opera patches...") fmt.Println(aurora.Green("Applying Opera patches..."))
modifyAllowList() modifyAllowList()
generateOperaCertStore() generateOperaCertStore()
@ -125,7 +131,7 @@ func main() {
output, err := originalWad.GetWAD(wadlib.WADTypeCommon) output, err := originalWad.GetWAD(wadlib.WADTypeCommon)
check(err) check(err)
log.Println("Done! Install ./output/patched.wad, sit back, and enjoy.") fmt.Println(aurora.Green("Done! Install ./output/patched.wad, sit back, and enjoy."))
writeOut("patched.wad", output) writeOut("patched.wad", output)
} }

View File

@ -3,7 +3,8 @@ package main
import ( import (
"bytes" "bytes"
"errors" "errors"
"log" "fmt"
"github.com/logrusorgru/aurora/v3"
) )
var ( var (
@ -35,7 +36,7 @@ type PatchSet []Patch
func applyPatch(patch Patch) error { func applyPatch(patch Patch) error {
// Print name if present // Print name if present
if patch.Name != "" { if patch.Name != "" {
log.Println("Applying patch " + patch.Name) fmt.Println(" + Applying patch", aurora.Cyan(patch.Name))
} }
// Ensure consistency // Ensure consistency
@ -63,7 +64,7 @@ func applyPatch(patch Patch) error {
// applyPatchSet iterates through all possible patches, noting their name. // applyPatchSet iterates through all possible patches, noting their name.
func applyPatchSet(setName string, set PatchSet) { func applyPatchSet(setName string, set PatchSet) {
log.Printf("Handling patch set \"%s\":", setName) fmt.Printf("Handling patch set \"%s\":\n", aurora.Yellow(setName))
for _, patch := range set { for _, patch := range set {
err := applyPatch(patch) err := applyPatch(patch)