aboutsummaryrefslogtreecommitdiff
path: root/src/tools/extractor_common
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2017-03-08 18:10:02 +0100
committerShauren <shauren.trinity@gmail.com>2017-03-08 18:10:02 +0100
commit7b235ce6e4da0e9c19fa9c6306bc7a71c7fb905d (patch)
tree28611e02e44e55d28f60a9b1b3433831ed6772b8 /src/tools/extractor_common
parentf585c831248f24c93697b0c314dd015897febe39 (diff)
Core/DataStores: Refactor DB2 loaders to be reusable by extractors
Diffstat (limited to 'src/tools/extractor_common')
-rw-r--r--src/tools/extractor_common/CMakeLists.txt5
-rw-r--r--src/tools/extractor_common/CascHandles.cpp46
-rw-r--r--src/tools/extractor_common/CascHandles.h5
-rw-r--r--src/tools/extractor_common/DB2CascFileSource.cpp46
-rw-r--r--src/tools/extractor_common/DB2CascFileSource.h38
5 files changed, 116 insertions, 24 deletions
diff --git a/src/tools/extractor_common/CMakeLists.txt b/src/tools/extractor_common/CMakeLists.txt
index 50cc20c9682..a982ce6ad1b 100644
--- a/src/tools/extractor_common/CMakeLists.txt
+++ b/src/tools/extractor_common/CMakeLists.txt
@@ -14,7 +14,10 @@ CollectSourceFiles(
add_library(extractor_common STATIC ${PRIVATE_SOURCES})
-target_link_libraries(extractor_common boost casc)
+target_link_libraries(extractor_common
+ PUBLIC
+ casc
+ common)
target_include_directories(extractor_common
PUBLIC
diff --git a/src/tools/extractor_common/CascHandles.cpp b/src/tools/extractor_common/CascHandles.cpp
index 9624a1ca149..46f90d8233f 100644
--- a/src/tools/extractor_common/CascHandles.cpp
+++ b/src/tools/extractor_common/CascHandles.cpp
@@ -16,32 +16,29 @@
*/
#include "CascHandles.h"
-#include "CascLib.h"
+#include <CascLib.h>
#include <boost/filesystem/operations.hpp>
-namespace
+char const* CASC::HumanReadableCASCError(DWORD error)
{
- const char* HumanReadableCASCError(int error)
+ switch (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";
- }
+ 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";
}
}
@@ -95,6 +92,11 @@ DWORD CASC::GetFileSize(FileHandle const& file, PDWORD fileSizeHigh)
return ::CascGetFileSize(file.get(), fileSizeHigh);
}
+DWORD CASC::GetFilePointer(FileHandle const& file)
+{
+ return ::CascSetFilePointer(file.get(), 0, nullptr, FILE_CURRENT);
+}
+
bool CASC::ReadFile(FileHandle const& file, void* buffer, DWORD bytes, PDWORD bytesRead)
{
return ::CascReadFile(file.get(), buffer, bytes, bytesRead);
diff --git a/src/tools/extractor_common/CascHandles.h b/src/tools/extractor_common/CascHandles.h
index 455306ad5e0..ebfd04466ab 100644
--- a/src/tools/extractor_common/CascHandles.h
+++ b/src/tools/extractor_common/CascHandles.h
@@ -18,7 +18,7 @@
#ifndef CascHandles_h__
#define CascHandles_h__
-#include "CascPort.h"
+#include <CascPort.h>
#include <memory>
namespace boost
@@ -46,10 +46,13 @@ namespace CASC
typedef std::unique_ptr<HANDLE, StorageDeleter> StorageHandle;
typedef std::unique_ptr<HANDLE, FileDeleter> FileHandle;
+ char const* HumanReadableCASCError(DWORD error);
+
StorageHandle OpenStorage(boost::filesystem::path const& path, DWORD localeMask);
FileHandle OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors = false);
DWORD GetFileSize(FileHandle const& file, PDWORD fileSizeHigh);
+ DWORD GetFilePointer(FileHandle const& file);
bool ReadFile(FileHandle const& file, void* buffer, DWORD bytes, PDWORD bytesRead);
}
diff --git a/src/tools/extractor_common/DB2CascFileSource.cpp b/src/tools/extractor_common/DB2CascFileSource.cpp
new file mode 100644
index 00000000000..24bf47491dd
--- /dev/null
+++ b/src/tools/extractor_common/DB2CascFileSource.cpp
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "DB2CascFileSource.h"
+#include <CascLib.h>
+
+DB2CascFileSource::DB2CascFileSource(CASC::StorageHandle const& storage, std::string fileName)
+{
+ _fileHandle = CASC::OpenFile(storage, fileName.c_str(), CASC_LOCALE_NONE, true);
+ _fileName = std::move(fileName);
+}
+
+bool DB2CascFileSource::IsOpen() const
+{
+ return _fileHandle != nullptr;
+}
+
+bool DB2CascFileSource::Read(void* buffer, std::size_t numBytes)
+{
+ DWORD bytesRead = 0;
+ return CASC::ReadFile(_fileHandle, buffer, numBytes, &bytesRead) && numBytes == bytesRead;
+}
+
+std::size_t DB2CascFileSource::GetPosition() const
+{
+ return CASC::GetFilePointer(_fileHandle);
+}
+
+char const* DB2CascFileSource::GetFileName() const
+{
+ return _fileName.c_str();
+}
diff --git a/src/tools/extractor_common/DB2CascFileSource.h b/src/tools/extractor_common/DB2CascFileSource.h
new file mode 100644
index 00000000000..b8876fdcdd1
--- /dev/null
+++ b/src/tools/extractor_common/DB2CascFileSource.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef DB2CascFileSource_h__
+#define DB2CascFileSource_h__
+
+#include "DB2FileLoader.h"
+#include "CascHandles.h"
+#include <string>
+
+struct DB2CascFileSource : public DB2FileSource
+{
+ DB2CascFileSource(CASC::StorageHandle const& storage, std::string fileName);
+ bool IsOpen() const override;
+ bool Read(void* buffer, std::size_t numBytes) override;
+ std::size_t GetPosition() const override;
+ char const* GetFileName() const override;
+
+private:
+ CASC::FileHandle _fileHandle;
+ std::string _fileName;
+};
+
+#endif // DB2CascFile_h__