images perchance? 3
This commit is contained in:
parent
10174b1232
commit
6f9f80a190
@ -161,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)
|
||||||
@ -175,47 +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" {
|
||||||
conjPath := filepath.Join(gamePath, e.Name())
|
conjPath := filepath.Join(gamePath, e.Name())
|
||||||
r, err := zip.OpenReader(conjPath)
|
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", conjPath)
|
||||||
for _, f := range r.File {
|
for _, f := range entries {
|
||||||
printIndentedPath(f.Name)
|
if f.Name() == "metadata.txt" {
|
||||||
if f.Name == "metadata.txt" {
|
rc, err := os.Open(filepath.Join(conjBase, f.Name()))
|
||||||
rc, err := f.Open()
|
check(err)
|
||||||
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)
|
||||||
conjBase := strings.TrimSuffix(filepath.Base(conjPath), ".conj")
|
|
||||||
game.ThumbnailPath = filepath.Join(conjBase, game.ThumbnailPath)
|
game.ThumbnailPath = filepath.Join(conjBase, game.ThumbnailPath)
|
||||||
game.ImagePath = filepath.Join(conjBase, game.ImagePath)
|
game.ImagePath = filepath.Join(conjBase, game.ImagePath)
|
||||||
games = append(games, game)
|
games = append(games, game)
|
||||||
if err != nil {
|
check(err)
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user