Esempio n. 1
0
func Dir2Dat(dat *types.Dat, srcpath, outpath string) error {
	glog.Infof("composing DAT from source %s into output dir %s", srcpath, outpath)

	fis, err := ioutil.ReadDir(srcpath)
	if err != nil {
		return err
	}

	for _, fi := range fis {
		if fi.IsDir() {
			game, err := populateGame(srcpath, fi)
			if err != nil {
				return err
			}

			dat.Games = append(dat.Games, game)
		}
	}

	outfilename := filepath.Join(outpath, dat.Name+datSuffix)
	outf, err := os.Create(outfilename)
	if err != nil {
		return err
	}
	defer outf.Close()

	outbuf := bufio.NewWriter(outf)
	defer outbuf.Flush()

	return types.ComposeDat(dat, outbuf)
}
Esempio n. 2
0
func (depot *Depot) BuildDat(dat *types.Dat, outpath string) (bool, error) {
	datPath := filepath.Join(outpath, dat.Name)

	err := os.Mkdir(datPath, 0777)
	if err != nil {
		return false, err
	}

	var fixDat *types.Dat

	for _, game := range dat.Games {
		fixGame, err := depot.buildGame(game, datPath)
		if err != nil {
			return false, err
		}
		if fixGame != nil {
			if fixDat == nil {
				fixDat = new(types.Dat)
				fixDat.Name = dat.Name
				fixDat.Description = dat.Description
				fixDat.Path = dat.Path
			}
			fixDat.Games = append(fixDat.Games, fixGame)
		}
	}

	if fixDat != nil {
		fixDatPath := filepath.Join(outpath, fixPrefix+dat.Name+datSuffix)

		fixFile, err := os.Create(fixDatPath)
		if err != nil {
			return false, err
		}
		defer fixFile.Close()

		fixWriter := bufio.NewWriter(fixFile)
		defer fixWriter.Flush()

		err = types.ComposeDat(fixDat, fixWriter)
		if err != nil {
			return false, err
		}
	}

	return fixDat == nil, nil
}