本文整理匯總了Golang中github.com/uwedeportivo/romba/types.Dat.Games方法的典型用法代碼示例。如果您正苦於以下問題:Golang Dat.Games方法的具體用法?Golang Dat.Games怎麽用?Golang Dat.Games使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/uwedeportivo/romba/types.Dat
的用法示例。
在下文中一共展示了Dat.Games方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Dir2Dat
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)
}
示例2: Dedup
func Dedup(d *types.Dat, deduper Deduper) (*types.Dat, error) {
dc := new(types.Dat)
dc.CopyHeader(d)
for _, g := range d.Games {
gc := new(types.Game)
gc.CopyHeader(g)
for _, r := range g.Roms {
if !r.Valid() {
continue
}
seen, err := deduper.Seen(r)
if err != nil {
return nil, err
}
if !seen {
gc.Roms = append(gc.Roms, r)
err = deduper.Declare(r)
if err != nil {
return nil, err
}
}
}
if len(gc.Roms) > 0 {
dc.Games = append(dc.Games, gc)
}
}
if len(dc.Games) > 0 {
return dc, nil
}
return nil, nil
}
示例3: IndexRom
func (kvb *kvBatch) IndexRom(rom *types.Rom) error {
//glog.Infof("indexing rom %s", rom.Name)
dats, err := kvb.db.DatsForRom(rom)
if err != nil {
return err
}
if len(dats) > 0 {
if rom.Crc != nil && rom.Sha1 != nil {
//glog.Infof("declaring crc %s -> sha1 %s ampping", hex.EncodeToString(rom.Crc), hex.EncodeToString(rom.Sha1))
err = kvb.crcsha1Batch.Append(rom.Crc, rom.Sha1)
if err != nil {
return err
}
kvb.size += int64(sha1.Size)
}
if rom.Md5 != nil && rom.Sha1 != nil {
//glog.Infof("declaring md5 %s -> sha1 %s ampping", hex.EncodeToString(rom.Md5), hex.EncodeToString(rom.Sha1))
err = kvb.md5sha1Batch.Append(rom.Md5, rom.Sha1)
if err != nil {
return err
}
kvb.size += int64(sha1.Size)
}
return nil
}
if rom.Sha1 == nil {
glog.Warningf("indexing rom %s with missing SHA1", rom.Name)
}
dat := new(types.Dat)
dat.Artificial = true
dat.Generation = kvb.db.generation
dat.Name = fmt.Sprintf("Artificial Dat for %s", rom.Name)
dat.Path = rom.Path
game := new(types.Game)
game.Roms = []*types.Rom{rom}
dat.Games = []*types.Game{game}
var buf bytes.Buffer
gobEncoder := gob.NewEncoder(&buf)
err = gobEncoder.Encode(dat)
if err != nil {
return err
}
hh := sha1.New()
_, err = io.Copy(hh, &buf)
if err != nil {
return err
}
return kvb.IndexDat(dat, hh.Sum(nil))
}
示例4: BuildDat
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
}