This commit is contained in:
Trit0 2025-06-29 17:27:12 -04:00
parent 2acc9b0133
commit 6e6ac9bce7

View File

@ -1,15 +1,18 @@
package provider package provider
import ( import (
"archive/zip"
"conjure-os/lib/config" "conjure-os/lib/config"
"conjure-os/lib/models" "conjure-os/lib/models"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"io/fs" "io/fs"
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"path/filepath"
"strings" "strings"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
@ -71,17 +74,42 @@ func GetConjureGameInfo() []models.Game {
gamePath := config.GetDefaultConjureGamesDirectory() gamePath := config.GetDefaultConjureGamesDirectory()
entries, err := os.ReadDir(gamePath) entrie, err := os.ReadDir(gamePath)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
var games []models.Game var games []models.Game
for _, e := range entries { for _, e := range entrie {
if e.IsDir() { if e.IsDir() {
newGames := readFolder(e, gamePath) newGames := readFolder(e, gamePath)
games = append(newGames, games...) games = append(newGames, games...)
} else if filepath.Ext(e.Name()) == ".conj" {
zipPath := filepath.Join(gamePath, e.Name())
r, err := zip.OpenReader(zipPath)
if err != nil {
log.Fatal(err)
}
defer r.Close()
fmt.Println("Contents of", zipPath)
for _, f := range r.File {
printIndentedPath(f.Name)
if f.Name == "metadata.txt" {
rc, err := f.Open()
if err != nil {
log.Fatal(err)
}
defer rc.Close()
fmt.Println("Contents of metadata.txt:")
_, err = io.Copy(os.Stdout, rc)
if err != nil {
log.Fatal(err)
}
}
}
} }
} }
@ -93,6 +121,18 @@ func GetConjureGameInfo() []models.Game {
return games return games
} }
// Helper to print tree-like structure
func printIndentedPath(path string) {
parts := strings.Split(path, "/")
for i, part := range parts {
if part == "" {
continue
}
fmt.Print(strings.Repeat(" ", i))
fmt.Println(part)
}
}
func readFolder(entry fs.DirEntry, path string) []models.Game { func readFolder(entry fs.DirEntry, path string) []models.Game {
newPath := path + "/" + entry.Name() newPath := path + "/" + entry.Name()
entries, err := os.ReadDir(newPath) entries, err := os.ReadDir(newPath)