int ReadBuild(int locale) { Log sLog; // include build info file also std::string filename = std::string("component.wow-")+langs[locale]+".txt"; //sLog.Write("Read %s file... ", filename.c_str()); CreateDir("./dbc/"); ExtractFileToHardDrive(localeMPQ[0], filename.c_str(), (std::string("./dbc/") + filename).c_str()); std::string text; std::string temp; std::ifstream fichier((std::string("./dbc/") + filename).c_str(), std::ios::in); if(!fichier) assert(false && "Error when loading component.wow-..."); while(fichier) { fichier >> temp; text += temp; } size_t pos = text.find("version=\""); size_t pos1 = pos + strlen("version=\""); size_t pos2 = text.find("\"",pos1); if (pos == text.npos || pos2 == text.npos || pos1 >= pos2) { sLog.Write("Fatal error: Invalid %s file format!", filename.c_str()); exit(1); } std::string build_str = text.substr(pos1,pos2-pos1); int build = atoi(build_str.c_str()); if (build <= 0) { sLog.Write("Fatal error: Invalid %s file format!", filename.c_str()); exit(1); } return build; }
void ExtractDBCFiles(int locale, bool basicLocale) { printf("Extracting dbc files...\n"); std::set<std::pair<int, std::string> > dbcfiles; int foundCount = 0; for (int i = 0; i < PATCH_REV_COUNT + 1; i++) { TMPQArchive * archive = (TMPQArchive *)localeMPQ[i]; TFileEntry * pFileEntry = archive->pFileTable; TFileEntry * pFileTableEnd = archive->pFileTable + archive->dwFileTableSize; // Parse the entire block table while (pFileEntry < pFileTableEnd) { // Only take existing files if ( pFileEntry->dwFlags & MPQ_FILE_EXISTS && (pFileEntry->dwFlags & MPQ_FILE_PATCH_FILE) == 0 && (pFileEntry->dwFlags & MPQ_FILE_DELETE_MARKER) == 0 && pFileEntry->szFileName != NULL) { std::string name = pFileEntry->szFileName; if (i != 0) { if (name.find(langs[locale]) == 0) name = name.substr(strlen(langs[locale]) + 1); else { pFileEntry++; continue; } } if (name.rfind(".dbc") == name.length() - strlen(".dbc") || name.rfind(".db2") == name.length() - strlen(".db2")) { //Verify if this dbc isn't in the list yet. StormLibs return some extra dbcs :P if (i != 0) { bool alreadyExist = false; for (std::set<std::pair<int, std::string> >::iterator itr = dbcfiles.begin(); itr != dbcfiles.end(); itr++) { if (itr->second == name) { alreadyExist = true; break; } } if (alreadyExist) { pFileEntry++; continue; } } dbcfiles.insert(std::pair<int, std::string>(i, name)); foundCount++; } } // Move to the next file entry pFileEntry++; } } printf("Found %i dbc files\n", foundCount); std::string path = "./dbc/"; if (!basicLocale) { path += langs[locale]; path += "/"; } CreateDir(path); // extract DBCs int count = 0; for (std::set<std::pair<int, std::string> >::iterator iter = dbcfiles.begin(); iter != dbcfiles.end(); ++iter) { std::string filename = path; filename += (iter->second.c_str() + strlen("DBFilesClient\\")); if (ExtractFileToHardDrive(localeMPQ[iter->first], iter->second.c_str(), filename.c_str()) == ERROR_SUCCESS) ++count; else { assert(false); } } printf("Extracted %u DBC files\n\n", count); }