增加 Path::extractResource 方法,提取资源中的文件到 Temp 目录下
This commit is contained in:
parent
5f2583d4ba
commit
e7f0939030
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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.");
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<void()> _func;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue