diff --git a/core/Common/Image.cpp b/core/Common/Image.cpp index 7235386e..6a5b60e4 100644 --- a/core/Common/Image.cpp +++ b/core/Common/Image.cpp @@ -161,7 +161,7 @@ bool e2d::Image::preload(const String& filePath) return true; } - String actualFilePath = Path::checkFilePath(filePath); + String actualFilePath = Path::searchForFile(filePath); if (actualFilePath.isEmpty()) { return false; diff --git a/core/Tool/Music.cpp b/core/Tool/Music.cpp index 5118e831..e57d581a 100644 --- a/core/Tool/Music.cpp +++ b/core/Tool/Music.cpp @@ -85,7 +85,7 @@ bool e2d::Music::open(const e2d::String& filePath) return false; } - String actualFilePath = Path::checkFilePath(filePath); + String actualFilePath = Path::searchForFile(filePath); if (actualFilePath.isEmpty()) { WARN("MusicInfo::open File not found."); diff --git a/core/Tool/Path.cpp b/core/Tool/Path.cpp index cc74da3b..b36bdc70 100644 --- a/core/Tool/Path.cpp +++ b/core/Tool/Path.cpp @@ -104,7 +104,7 @@ e2d::String e2d::Path::getExecutableFilePath() return String(); } -e2d::String e2d::Path::checkFilePath(const String& path) +e2d::String e2d::Path::searchForFile(const String& path) { if (Path::exists(path)) { @@ -123,6 +123,26 @@ e2d::String e2d::Path::checkFilePath(const String& path) return String(); } +e2d::String e2d::Path::extractResource(int resNameId, const String & resType, const String & destFileName) +{ + String destFilePath = s_sTempPath + destFileName; + // 创建文件 + HANDLE hFile = ::CreateFile((LPCWSTR)destFilePath, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL); + if (hFile == INVALID_HANDLE_VALUE) + return String(); + + // 查找资源文件中、加载资源到内存、得到资源大小 + HRSRC hRes = ::FindResource(NULL, MAKEINTRESOURCE(resNameId), (LPCWSTR)resType); + HGLOBAL hMem = ::LoadResource(NULL, hRes); + DWORD dwSize = ::SizeofResource(NULL, hRes); + + // 写入文件 + DWORD dwWrite = 0; + ::WriteFile(hFile, hMem, dwSize, &dwWrite, NULL); + ::CloseHandle(hFile); + return destFilePath; +} + e2d::String e2d::Path::getDataSavePath() { return s_sDataSavePath; diff --git a/core/e2dcommon.h b/core/e2dcommon.h index fec59d01..643b2d44 100644 --- a/core/e2dcommon.h +++ b/core/e2dcommon.h @@ -236,8 +236,8 @@ public: friend String operator+ (const wchar_t*, const String &); // 类型转换操作符 - E2D_EXPLICIT operator const wchar_t* () const; - E2D_EXPLICIT operator wchar_t* () const; + E2D_OP_EXPLICIT operator const wchar_t* () const; + E2D_OP_EXPLICIT operator wchar_t* () const; // 比较运算符 bool operator== (const String &) const; @@ -392,7 +392,7 @@ public: void operator() (void) const; - operator bool() const; + E2D_OP_EXPLICIT operator bool() const; protected: std::function _func; diff --git a/core/e2dmacros.h b/core/e2dmacros.h index 7755a0b4..f2c0bf82 100644 --- a/core/e2dmacros.h +++ b/core/e2dmacros.h @@ -79,7 +79,7 @@ #endif #if _MSC_VER >= 1800 -# define E2D_EXPLICIT explicit +# define E2D_OP_EXPLICIT explicit #else -# define E2D_EXPLICIT +# define E2D_OP_EXPLICIT #endif \ No newline at end of file diff --git a/core/e2dtool.h b/core/e2dtool.h index ef4884a5..e73010a5 100644 --- a/core/e2dtool.h +++ b/core/e2dtool.h @@ -447,11 +447,18 @@ public: String path ); - // 检查文件路径 - static String checkFilePath( + // 检索文件路径 + static String searchForFile( const String& path ); + // 提取资源文件,返回提取后的文件路径 + static String extractResource( + int resNameId, /* 资源名称 */ + const String& resType, /* 资源类型 */ + const String& destFileName /* 目标文件名 */ + ); + // 获取数据的默认保存路径 static String getDataSavePath();