Skip to content

Commit

Permalink
go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
xypwn committed Apr 3, 2024
1 parent 43deb02 commit ce56232
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 81 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/jwalton/go-supportscolor v1.2.0
github.com/qmuntal/gltf v0.24.3
github.com/x448/float16 v0.8.4
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8
golang.org/x/sys v0.18.0
)

Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 h1:aAcj0Da7eBAtrTp03QXWvm88pSyOt+UgdZw2BFZ+lEw=
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
156 changes: 78 additions & 78 deletions update_hashes_txt/main.go
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
package main

import (
"bufio"
"fmt"
"net/http"
"os"
"slices"
"strings"
)

const prolog = `// Copied from Hellextractor by Xaymar (https://github.com/Xaymar/Hellextractor)
// as well as from hd2-name-db by DTZxPorter (https://github.com/dtzxporter/hd2-name-db)
// This is a list of all known file type and file path strings.
// Their respective hashes will be generated automatically.
`

func appendHTTPFile(strs *map[string]struct{}, url string, transform func(string) string) error {
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()

rd := bufio.NewScanner(resp.Body)
for rd.Scan() {
s := rd.Text()
if len(s) == 0 || strings.HasPrefix(s, "//") || strings.HasPrefix(s, "#") {
continue
}
if transform != nil {
s = transform(s)
}
(*strs)[s] = struct{}{}
}
return nil
}

func main() {
strs := make(map[string]struct{})
if err := appendHTTPFile(&strs, "https://raw.githubusercontent.com/Xaymar/Hellextractor/root/files.txt", nil); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if err := appendHTTPFile(&strs, "https://raw.githubusercontent.com/Xaymar/Hellextractor/root/types.txt", nil); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if err := appendHTTPFile(&strs, "https://raw.githubusercontent.com/dtzxporter/hd2-name-db/main/assets.txt", func(s string) string {
_, rhs, _ := strings.Cut(s, ",")
return rhs
}); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

out, err := os.Create("hashes.txt")
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if _, err := out.Write([]byte(prolog)); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

strsSorted := make([]string, 0, len(strs))
for k := range strs {
strsSorted = append(strsSorted, k)
}
slices.Sort(strsSorted)
for _, line := range strsSorted {
if _, err := fmt.Fprintln(out, line); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
}
package main

import (
"bufio"
"fmt"
"net/http"
"os"
"slices"
"strings"
)

const prolog = `// Copied from Hellextractor by Xaymar (https://github.com/Xaymar/Hellextractor)
// as well as from hd2-name-db by DTZxPorter (https://github.com/dtzxporter/hd2-name-db)
// This is a list of all known file type and file path strings.
// Their respective hashes will be generated automatically.
`

func appendHTTPFile(strs *map[string]struct{}, url string, transform func(string) string) error {
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()

rd := bufio.NewScanner(resp.Body)
for rd.Scan() {
s := rd.Text()
if len(s) == 0 || strings.HasPrefix(s, "//") || strings.HasPrefix(s, "#") {
continue
}
if transform != nil {
s = transform(s)
}
(*strs)[s] = struct{}{}
}
return nil
}

func main() {
strs := make(map[string]struct{})
if err := appendHTTPFile(&strs, "https://raw.githubusercontent.com/Xaymar/Hellextractor/root/files.txt", nil); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if err := appendHTTPFile(&strs, "https://raw.githubusercontent.com/Xaymar/Hellextractor/root/types.txt", nil); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if err := appendHTTPFile(&strs, "https://raw.githubusercontent.com/dtzxporter/hd2-name-db/main/assets.txt", func(s string) string {
_, rhs, _ := strings.Cut(s, ",")
return rhs
}); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

out, err := os.Create("hashes.txt")
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if _, err := out.Write([]byte(prolog)); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

strsSorted := make([]string, 0, len(strs))
for k := range strs {
strsSorted = append(strsSorted, k)
}
slices.Sort(strsSorted)
for _, line := range strsSorted {
if _, err := fmt.Fprintln(out, line); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
}

0 comments on commit ce56232

Please sign in to comment.