Tools/Extractors: Improved game build reported by extractors

This commit is contained in:
Shauren
2017-06-13 23:31:41 +02:00
parent 1ec8228d4a
commit ff1a71d6f7
4 changed files with 21 additions and 93 deletions

View File

@@ -70,6 +70,23 @@ CASC::StorageHandle CASC::OpenStorage(boost::filesystem::path const& path, DWORD
return StorageHandle(handle);
}
DWORD CASC::GetBuildNumber(StorageHandle const& storage)
{
DWORD buildNumber = 0;
size_t infoDataSizeNeeded = 0;
if (!::CascGetStorageInfo(storage.get(), CascStorageGameBuild, &buildNumber, sizeof(buildNumber), &infoDataSizeNeeded))
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
std::unique_ptr<char> buf(new char[infoDataSizeNeeded]);
::CascGetStorageInfo(storage.get(), CascStorageGameBuild, buf.get(), infoDataSizeNeeded, &infoDataSizeNeeded);
return *reinterpret_cast<DWORD*>(buf.get());
}
}
return buildNumber;
}
CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors /*= false*/)
{
HANDLE handle = nullptr;

View File

@@ -49,6 +49,7 @@ namespace CASC
char const* HumanReadableCASCError(DWORD error);
StorageHandle OpenStorage(boost::filesystem::path const& path, DWORD localeMask);
DWORD GetBuildNumber(StorageHandle const& storage);
FileHandle OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors = false);
DWORD GetFileSize(FileHandle const& file, PDWORD fileSizeHigh);

View File

@@ -325,51 +325,6 @@ void HandleArgs(int argc, char* arg[])
}
}
uint32 ReadBuild(int locale)
{
// include build info file also
std::string filename = Trinity::StringFormat("component.wow-%s.txt", localeNames[locale]);
//printf("Read %s file... ", filename.c_str());
CASC::FileHandle dbcFile = CASC::OpenFile(CascStorage, filename.c_str(), CASC_LOCALE_ALL);
if (!dbcFile)
{
printf("Locale %s not installed.\n", localeNames[locale]);
return 0;
}
char buff[512];
DWORD readBytes = 0;
CASC::ReadFile(dbcFile, buff, 512, &readBytes);
if (!readBytes)
{
printf("Fatal error: Not found %s file!\n", filename.c_str());
exit(1);
}
std::string text = std::string(buff, readBytes);
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)
{
printf("Fatal error: Invalid %s file format!\n", filename.c_str());
exit(1);
}
std::string build_str = text.substr(pos1,pos2-pos1);
int build = atoi(build_str.c_str());
if (build <= 0)
{
printf("Fatal error: Invalid %s file format!\n", filename.c_str());
exit(1);
}
return build;
}
void ReadMapDBC()
{
printf("Read Map.db2 file...\n");
@@ -1384,7 +1339,7 @@ int main(int argc, char * arg[])
if ((CONF_extract & EXTRACT_DBC) == 0)
{
FirstLocale = i;
build = ReadBuild(i);
build = CASC::GetBuildNumber(CascStorage);
if (!build)
{
CascStorage.reset();
@@ -1396,7 +1351,7 @@ int main(int argc, char * arg[])
}
//Extract DBC files
uint32 tempBuild = ReadBuild(i);
uint32 tempBuild = CASC::GetBuildNumber(CascStorage);
if (!tempBuild)
{
CascStorage.reset();

View File

@@ -141,51 +141,6 @@ uint32 WowLocaleToCascLocaleFlags[12] =
CASC_LOCALE_ITIT,
};
uint32 ReadBuild(int locale)
{
// include build info file also
std::string filename = std::string("component.wow-") + localeNames[locale] + ".txt";
//printf("Read %s file... ", filename.c_str());
CASC::FileHandle dbcFile = CASC::OpenFile(CascStorage, filename.c_str(), CASC_LOCALE_ALL);
if (!dbcFile)
{
printf("Locale %s not installed.\n", localeNames[locale]);
return 0;
}
char buff[512];
DWORD readBytes = 0;
CASC::ReadFile(dbcFile, buff, 512, &readBytes);
if (!readBytes)
{
printf("Fatal error: Not found %s file!\n", filename.c_str());
exit(1);
}
std::string text = std::string(buff, readBytes);
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)
{
printf("Fatal error: Invalid %s file format!\n", filename.c_str());
exit(1);
}
std::string build_str = text.substr(pos1, pos2 - pos1);
int build = atoi(build_str.c_str());
if (build <= 0)
{
printf("Fatal error: Invalid %s file format!\n", filename.c_str());
exit(1);
}
return build;
}
bool OpenCascStorage(int locale)
{
try
@@ -437,7 +392,7 @@ int main(int argc, char ** argv)
continue;
FirstLocale = i;
uint32 build = ReadBuild(i);
uint32 build = CASC::GetBuildNumber(CascStorage);
if (!build)
{
CascStorage.reset();