DeckMetaData* DeckManager::getDeckMetaDataById( int deckId, bool isAI ) { DeckMetaData* deck = NULL; std::vector<DeckMetaData *>& deckList = isAI ? aiDeckOrderList : playerDeckOrderList; std::vector<DeckMetaData *>::iterator pos = find_if(deckList.begin(), deckList.end(), DeckIDMatch(deckId)); if (pos != deckList.end()) { deck = *pos; } else { ostringstream deckFilename; string filepath; if ( isAI ) filepath = options.profileFile( "ai/baka/"); else filepath = options.profileFile( "" ); deckFilename << filepath << "/deck" << deckId << ".txt"; AddMetaData( deckFilename.str(), isAI ); deck = deckList.back(); } return deck; }
static void _MonUpload(const char *file, const char *metafile) { DBG_Struct *dbg; char *id,*buf; size_t size; if (!g_file_get_contents(file, &buf, &size, NULL)) { g_warning("cannot read file:%s",file); exit(1); } dbg = GetDBG_monsys(); dbg->dbt = NewNameHash(); if (OpenDB(dbg) != MCP_OK) { g_warning("OpenDB failure"); exit(1); } monblob_setup(dbg, FALSE); TransactionStart(dbg); id = monblob_import_mem(dbg, NULL, 0, "monupload.bin", NULL, 0, buf, size); g_free(buf); TransactionEnd(dbg); CloseDB(dbg); AddMetaData(id, metafile); xfree(id); }
DeckMetaData* DeckManager::getDeckMetaDataByFilename(const string& filename, bool isAI) { DeckMetaData* deck = NULL; std::vector<DeckMetaData *>& deckList = isAI ? aiDeckOrderList : playerDeckOrderList; std::vector<DeckMetaData *>::iterator pos = find_if(deckList.begin(), deckList.end(), DeckFilenameMatch(filename)); if (pos != deckList.end()) { deck = *pos; } else { if ( FileExists( filename) ) { AddMetaData( filename, isAI ); deck = deckList.back(); } } return deck; }