Merge branch 'tristan-wip' of https://gitea.clubconjure.com/Conjure/conjure-os into tristan-wip

This commit is contained in:
club 2025-06-29 18:59:19 -04:00
commit 563070aeeb

View File

@ -73,6 +73,7 @@ func GetOrSetEnvKey(key string, defaultValue string) string {
func extractZipToSiblingFolder(zipPath string) error { func extractZipToSiblingFolder(zipPath string) error {
// Determine destination folder name (same name as zip file, without .zip) // Determine destination folder name (same name as zip file, without .zip)
zipBase := strings.TrimSuffix(filepath.Base(zipPath), ".conj") zipBase := strings.TrimSuffix(filepath.Base(zipPath), ".conj")
zipBase = strings.TrimSuffix(filepath.Base(zipBase), ".zip")
destDir := filepath.Join(filepath.Dir(zipPath), zipBase) destDir := filepath.Join(filepath.Dir(zipPath), zipBase)
// Delete destination folder if it exists // Delete destination folder if it exists
@ -147,7 +148,7 @@ func extractZipsInFolder(folder string) error {
if entry.IsDir() { if entry.IsDir() {
continue continue
} }
if strings.HasSuffix(strings.ToLower(entry.Name()), ".conj") { if strings.HasSuffix(strings.ToLower(entry.Name()), ".zip") {
zipPath := filepath.Join(folder, entry.Name()) zipPath := filepath.Join(folder, entry.Name())
fmt.Println("Extracting:", zipPath) fmt.Println("Extracting:", zipPath)
if err := extractZipToSiblingFolder(zipPath); err != nil { if err := extractZipToSiblingFolder(zipPath); err != nil {
@ -160,10 +161,13 @@ func extractZipsInFolder(folder string) error {
} }
func ExtractGame(game models.Game) string { func ExtractGame(game models.Game) string {
info, err := os.Stat(filepath.Join(config.GetDefaultConjureGamesDirectory(), game.Id))
if err != nil || !info.IsDir() {
gamePath := filepath.Join(config.GetDefaultConjureGamesDirectory(), fmt.Sprintf("%s.conj", game.Id)) gamePath := filepath.Join(config.GetDefaultConjureGamesDirectory(), fmt.Sprintf("%s.conj", game.Id))
err := extractZipToSiblingFolder(gamePath) err = extractZipToSiblingFolder(gamePath)
check(err) check(err)
gamePath = filepath.Join(config.GetDefaultConjureGamesDirectory(), game.Id) }
gamePath := filepath.Join(config.GetDefaultConjureGamesDirectory(), game.Id)
err = extractZipsInFolder(gamePath) err = extractZipsInFolder(gamePath)
check(err) check(err)
gamePath = filepath.Join(gamePath, game.Files) gamePath = filepath.Join(gamePath, game.Files)
@ -174,44 +178,40 @@ func GetConjureGameInfo() []models.Game {
gamePath := config.GetDefaultConjureGamesDirectory() gamePath := config.GetDefaultConjureGamesDirectory()
entrie, err := os.ReadDir(gamePath) entries, 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 entrie { for _, e := range entries {
if e.IsDir() { if e.IsDir() {
newGames := readFolder(e, gamePath) continue
games = append(newGames, games...)
} else if filepath.Ext(e.Name()) == ".conj" { } else if filepath.Ext(e.Name()) == ".conj" {
zipPath := filepath.Join(gamePath, e.Name()) conjPath := filepath.Join(gamePath, e.Name())
r, err := zip.OpenReader(zipPath) err = extractZipToSiblingFolder(conjPath)
if err != nil { check(err)
log.Fatal(err) conjBase := strings.TrimSuffix(conjPath, ".conj")
} entries, err := os.ReadDir(conjBase)
defer r.Close() check(err)
fmt.Println("Contents of", conjPath)
fmt.Println("Contents of", zipPath) for _, f := range entries {
for _, f := range r.File { if f.Name() == "metadata.txt" {
printIndentedPath(f.Name) rc, err := os.Open(filepath.Join(conjBase, f.Name()))
if f.Name == "metadata.txt" { check(err)
rc, err := f.Open()
if err != nil {
log.Fatal(err)
}
defer rc.Close() defer rc.Close()
fmt.Println("Contents of metadata.txt:") fmt.Println("Contents of metadata.txt:")
metadata, err := io.ReadAll(rc) metadata, err := io.ReadAll(rc)
game := parseGameInfo(metadata) game := parseGameInfo(metadata)
game.ThumbnailPath = filepath.Join(conjBase, game.ThumbnailPath)
game.ImagePath = filepath.Join(conjBase, game.ImagePath)
games = append(games, game) games = append(games, game)
if err != nil { check(err)
log.Fatal(err)
}
} }
} }
} }
} }