From 7a3d5bb50ff9db72dc39b905476e983681f7ca86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernd=20L=C3=B6rwald?= Date: Wed, 29 Oct 2014 23:38:01 +0100 Subject: [PATCH 1/3] Tools/MapExtractor: give a nice error message on failing to CascOpenStorage() --- src/tools/map_extractor/CMakeLists.txt | 1 + src/tools/map_extractor/System.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/tools/map_extractor/CMakeLists.txt b/src/tools/map_extractor/CMakeLists.txt index 3d6849eee0..2fe5450ee2 100644 --- a/src/tools/map_extractor/CMakeLists.txt +++ b/src/tools/map_extractor/CMakeLists.txt @@ -27,6 +27,7 @@ add_executable(mapextractor target_link_libraries(mapextractor ${BZIP2_LIBRARIES} ${ZLIB_LIBRARIES} + ${Boost_LIBRARIES} casc ) diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index 2d5c21d151..e260f39338 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -33,6 +33,9 @@ #define ERROR_PATH_NOT_FOUND ERROR_FILE_NOT_FOUND #endif +#include +#include + #include "DBFilesClientList.h" #include "CascLib.h" #include "dbcfile.h" @@ -1134,13 +1137,13 @@ void ExtractDBFilesClient(int l) bool OpenCascStorage() { - if (!CascOpenStorage(".\\Data", 0, &CascStorage)) + boost::filesystem::path const storage_dir (boost::filesystem::canonical (input_path) / "Data"); + if (!CascOpenStorage(storage_dir.string().c_str(), 0, &CascStorage)) { - printf("Error %d\n", GetLastError()); + printf("error opening casc storage '%s': %d\n", storage_dir.string().c_str(), GetLastError()); return false; } - - printf("\n"); + printf("opened casc storage '%s'\n", storage_dir.string().c_str()); return true; } @@ -1156,8 +1159,6 @@ int main(int argc, char * arg[]) if (!OpenCascStorage()) { - if (GetLastError() != ERROR_PATH_NOT_FOUND) - printf("Unable to open storage!\n"); return 1; } From 5e33cb61a999649edf3654aeef4e268f23285494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernd=20L=C3=B6rwald?= Date: Wed, 29 Oct 2014 23:38:47 +0100 Subject: [PATCH 2/3] Tools/MapExtractor: print human readable casc errors --- src/tools/map_extractor/System.cpp | 36 +++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index e260f39338..bc282912d3 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -60,6 +60,32 @@ #define OPEN_FLAGS (O_RDONLY | O_BINARY) #endif +namespace +{ + const char* HumanReadableCASCError(int error) + { + switch (error) + { + case ERROR_SUCCESS: return "SUCCESS"; + case ERROR_FILE_CORRUPT: return "FILE_CORRUPT"; + case ERROR_CAN_NOT_COMPLETE: return "CAN_NOT_COMPLETE"; + case ERROR_HANDLE_EOF: return "HANDLE_EOF"; + case ERROR_NO_MORE_FILES: return "NO_MORE_FILES"; + case ERROR_BAD_FORMAT: return "BAD_FORMAT"; + case ERROR_INSUFFICIENT_BUFFER: return "INSUFFICIENT_BUFFER"; + case ERROR_ALREADY_EXISTS: return "ALREADY_EXISTS"; + case ERROR_DISK_FULL: return "DISK_FULL"; + case ERROR_INVALID_PARAMETER: return "INVALID_PARAMETER"; + case ERROR_NOT_SUPPORTED: return "NOT_SUPPORTED"; + case ERROR_NOT_ENOUGH_MEMORY: return "NOT_ENOUGH_MEMORY"; + case ERROR_INVALID_HANDLE: return "INVALID_HANDLE"; + case ERROR_ACCESS_DENIED: return "ACCESS_DENIED"; + case ERROR_FILE_NOT_FOUND: return "FILE_NOT_FOUND"; + default: return "UNKNOWN"; + } + } +} + HANDLE CascStorage = NULL; typedef struct @@ -268,7 +294,7 @@ uint32 ReadMapDBC() HANDLE dbcFile; if (!CascOpenFile(CascStorage, "DBFilesClient\\Map.dbc", CASC_LOCALE_NONE, 0, &dbcFile)) { - printf("Fatal error: Cannot find Map.dbc in archive!\n"); + printf("Fatal error: Cannot find Map.dbc in archive! %s\n", HumanReadableCASCError(GetLastError())); exit(1); } @@ -298,7 +324,7 @@ void ReadAreaTableDBC() HANDLE dbcFile; if (!CascOpenFile(CascStorage, "DBFilesClient\\AreaTable.dbc", CASC_LOCALE_NONE, 0, &dbcFile)) { - printf("Fatal error: Cannot find AreaTable.dbc in archive!\n"); + printf("Fatal error: Cannot find AreaTable.dbc in archive! %s\n", HumanReadableCASCError(GetLastError())); exit(1); } @@ -326,7 +352,7 @@ void ReadLiquidTypeTableDBC() HANDLE dbcFile; if (!CascOpenFile(CascStorage, "DBFilesClient\\LiquidType.dbc", CASC_LOCALE_NONE, 0, &dbcFile)) { - printf("Fatal error: Cannot find LiquidType.dbc in archive!\n"); + printf("Fatal error: Cannot find LiquidType.dbc in archive! %s\n", HumanReadableCASCError(GetLastError())); exit(1); } @@ -1127,7 +1153,7 @@ void ExtractDBFilesClient(int l) CascCloseFile(dbcFile); } else - printf("Unable to open file %s in the archive for locale %s.\n", fileName, Locales[l]); + printf("Unable to open file %s in the archive for locale %s: %s\n", fileName, Locales[l], HumanReadableCASCError(GetLastError())); fileName = DBFilesClientList[++index]; } @@ -1140,7 +1166,7 @@ bool OpenCascStorage() boost::filesystem::path const storage_dir (boost::filesystem::canonical (input_path) / "Data"); if (!CascOpenStorage(storage_dir.string().c_str(), 0, &CascStorage)) { - printf("error opening casc storage '%s': %d\n", storage_dir.string().c_str(), GetLastError()); + printf("error opening casc storage '%s': %s\n", storage_dir.string().c_str(), HumanReadableCASCError(GetLastError())); return false; } printf("opened casc storage '%s'\n", storage_dir.string().c_str()); From 7272e4201427682dea866146816925e4c75e42cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernd=20L=C3=B6rwald?= Date: Wed, 29 Oct 2014 23:39:03 +0100 Subject: [PATCH 3/3] Tools/MapExtractor: add -h and add missing newline --- src/tools/map_extractor/System.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index bc282912d3..5c5ff5f9a9 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -177,7 +177,7 @@ void Usage(char const* prg) "-o set output path\n"\ "-e extract only MAP(1)/DBC(2) - standard: both(3)\n"\ "-f height stored as int (less map size but lost some accuracy) 1 by default\n"\ - "Example: %s -f 0 -i \"c:\\games\\game\"", prg, prg); + "Example: %s -f 0 -i \"c:\\games\\game\"\n", prg, prg); exit(1); } @@ -235,6 +235,9 @@ void HandleArgs(int argc, char* arg[]) else Usage(arg[0]); break; + case 'h': + Usage(arg[0]); + break; default: break; }