diff options
author | Shauren <shauren.trinity@gmail.com> | 2017-08-18 16:45:36 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2017-08-18 16:45:36 +0200 |
commit | 7eab6dbb9542118c14899452c7d0cb550e6263a6 (patch) | |
tree | 96fd38d6451e0bed7395f79e29fd2aa02458df5b /src | |
parent | 3f3991362848d80721dc8f4607518a9e451b60ad (diff) |
Tools/Extractors: Implement proper installed locale detection
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/extractor_common/CascHandles.cpp | 31 | ||||
-rw-r--r-- | src/tools/extractor_common/CascHandles.h | 1 | ||||
-rw-r--r-- | src/tools/map_extractor/System.cpp | 44 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/vmapexport.cpp | 25 |
4 files changed, 81 insertions, 20 deletions
diff --git a/src/tools/extractor_common/CascHandles.cpp b/src/tools/extractor_common/CascHandles.cpp index 45897c15617..031f6ae79a6 100644 --- a/src/tools/extractor_common/CascHandles.cpp +++ b/src/tools/extractor_common/CascHandles.cpp @@ -70,21 +70,34 @@ CASC::StorageHandle CASC::OpenStorage(boost::filesystem::path const& path, DWORD return StorageHandle(handle); } -DWORD CASC::GetBuildNumber(StorageHandle const& storage) +namespace CASC { - DWORD buildNumber = 0; - size_t infoDataSizeNeeded = 0; - if (!::CascGetStorageInfo(storage.get(), CascStorageGameBuild, &buildNumber, sizeof(buildNumber), &infoDataSizeNeeded)) + static DWORD GetStorageInfo(StorageHandle const& storage, CASC_STORAGE_INFO_CLASS storageInfoClass) { - if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) + DWORD value = 0; + size_t infoDataSizeNeeded = 0; + if (!::CascGetStorageInfo(storage.get(), storageInfoClass, &value, sizeof(value), &infoDataSizeNeeded)) { - std::unique_ptr<char> buf(new char[infoDataSizeNeeded]); - ::CascGetStorageInfo(storage.get(), CascStorageGameBuild, buf.get(), infoDataSizeNeeded, &infoDataSizeNeeded); - return *reinterpret_cast<DWORD*>(buf.get()); + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) + { + std::unique_ptr<char> buf(new char[infoDataSizeNeeded]); + ::CascGetStorageInfo(storage.get(), storageInfoClass, buf.get(), infoDataSizeNeeded, &infoDataSizeNeeded); + return *reinterpret_cast<DWORD*>(buf.get()); + } } + + return value; } +} + +DWORD CASC::GetBuildNumber(StorageHandle const& storage) +{ + return GetStorageInfo(storage, CascStorageGameBuild); +} - return buildNumber; +DWORD CASC::GetInstalledLocalesMask(StorageHandle const& storage) +{ + return GetStorageInfo(storage, CascStorageInstalledLocales); } CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors /*= false*/) diff --git a/src/tools/extractor_common/CascHandles.h b/src/tools/extractor_common/CascHandles.h index 583eecbf58f..ca51d1cbf11 100644 --- a/src/tools/extractor_common/CascHandles.h +++ b/src/tools/extractor_common/CascHandles.h @@ -50,6 +50,7 @@ namespace CASC StorageHandle OpenStorage(boost::filesystem::path const& path, DWORD localeMask); DWORD GetBuildNumber(StorageHandle const& storage); + DWORD GetInstalledLocalesMask(StorageHandle const& storage); FileHandle OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors = false); DWORD GetFileSize(FileHandle const& file, PDWORD fileSizeHigh); diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index b12f0cbe34e..f64ec3937b4 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -1337,6 +1337,25 @@ bool OpenCascStorage(int locale) } } +uint32 GetInstalledLocalesMask() +{ + try + { + boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data"); + CASC::StorageHandle storage = CASC::OpenStorage(storage_dir, 0); + if (!storage) + return false; + + return CASC::GetInstalledLocalesMask(storage); + } + catch (boost::filesystem::filesystem_error const& error) + { + printf("Unable to determine installed locales mask: %s\n", error.what()); + } + + return 0; +} + static bool RetardCheck() { try @@ -1375,12 +1394,14 @@ int main(int argc, char * arg[]) HandleArgs(argc, arg); - int FirstLocale = -1; - uint32 build = 0; - if (!RetardCheck()) return 1; + + uint32 installedLocalesMask = GetInstalledLocalesMask(); + int32 firstInstalledLocale = -1; + uint32 build = 0; + for (int i = 0; i < TOTAL_LOCALES; ++i) { if (CONF_Locale && !(CONF_Locale & (1 << i))) @@ -1389,12 +1410,15 @@ int main(int argc, char * arg[]) if (i == LOCALE_none) continue; + if (!(installedLocalesMask & WowLocaleToCascLocaleFlags[i])) + continue; + if (!OpenCascStorage(i)) continue; if ((CONF_extract & EXTRACT_DBC) == 0) { - FirstLocale = i; + firstInstalledLocale = i; build = CASC::GetBuildNumber(CascStorage); if (!build) { @@ -1418,14 +1442,14 @@ int main(int argc, char * arg[]) ExtractDBFilesClient(i); CascStorage.reset(); - if (FirstLocale < 0) + if (firstInstalledLocale < 0) { - FirstLocale = i; + firstInstalledLocale = i; build = tempBuild; } } - if (FirstLocale < 0) + if (firstInstalledLocale < 0) { printf("No locales detected\n"); return 0; @@ -1433,21 +1457,21 @@ int main(int argc, char * arg[]) if (CONF_extract & EXTRACT_CAMERA) { - OpenCascStorage(FirstLocale); + OpenCascStorage(firstInstalledLocale); ExtractCameraFiles(); CascStorage.reset(); } if (CONF_extract & EXTRACT_GT) { - OpenCascStorage(FirstLocale); + OpenCascStorage(firstInstalledLocale); ExtractGameTables(); CascStorage.reset(); } if (CONF_extract & EXTRACT_MAP) { - OpenCascStorage(FirstLocale); + OpenCascStorage(firstInstalledLocale); ExtractMaps(build); CascStorage.reset(); } diff --git a/src/tools/vmap4_extractor/vmapexport.cpp b/src/tools/vmap4_extractor/vmapexport.cpp index 35c6eb1f452..88765704954 100644 --- a/src/tools/vmap4_extractor/vmapexport.cpp +++ b/src/tools/vmap4_extractor/vmapexport.cpp @@ -162,6 +162,25 @@ bool OpenCascStorage(int locale) } } +uint32 GetInstalledLocalesMask() +{ + try + { + boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data"); + CASC::StorageHandle storage = CASC::OpenStorage(storage_dir, 0); + if (!storage) + return false; + + return CASC::GetInstalledLocalesMask(storage); + } + catch (boost::filesystem::filesystem_error const& error) + { + printf("Unable to determine installed locales mask: %s\n", error.what()); + } + + return 0; +} + // Local testing functions bool FileExists(const char* file) { @@ -414,12 +433,16 @@ int main(int argc, char ** argv) )) success = (errno == EEXIST); - int FirstLocale = -1; + uint32 installedLocalesMask = GetInstalledLocalesMask(); + int32 FirstLocale = -1; for (int i = 0; i < TOTAL_LOCALES; ++i) { if (i == LOCALE_none) continue; + if (!(installedLocalesMask & WowLocaleToCascLocaleFlags[i])) + continue; + if (!OpenCascStorage(i)) continue; |