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
import (
"archive/zip"
"conjure-os/lib/config"
"conjure-os/lib/models"
"encoding/json"
"fmt"
"io"
"io/fs"
"log"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
"gopkg.in/yaml.v3"
@ -71,17 +74,42 @@ func GetConjureGameInfo() []models.Game {
gamePath := config.GetDefaultConjureGamesDirectory()
entries, err := os.ReadDir(gamePath)
entrie, err := os.ReadDir(gamePath)
if err != nil {
log.Fatal(err)
}
var games []models.Game
for _, e := range entries {
for _, e := range entrie {
if e.IsDir() {
newGames := readFolder(e, gamePath)
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
}
// 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 {
newPath := path + "/" + entry.Name()
entries, err := os.ReadDir(newPath)