parent
331ec42523
commit
3ee2749b28
|
|
@ -22,6 +22,7 @@
|
||||||
#include "../base/logs.h"
|
#include "../base/logs.h"
|
||||||
#include "../renderer/render.h"
|
#include "../renderer/render.h"
|
||||||
#include "../platform/modules.h"
|
#include "../platform/modules.h"
|
||||||
|
#include "../utils/FileUtil.h"
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
@ -61,11 +62,13 @@ namespace kiwano
|
||||||
|
|
||||||
if (res.IsFileType())
|
if (res.IsFileType())
|
||||||
{
|
{
|
||||||
if (!modules::Shlwapi::Get().PathFileExistsW(res.GetFileName().c_str()))
|
#if defined(KGE_DEBUG)
|
||||||
|
if (!FileUtil::ExistsFile(res.GetFileName()))
|
||||||
{
|
{
|
||||||
KGE_WARNING_LOG(L"Image file '%s' not found!", res.GetFileName().c_str());
|
KGE_WARNING_LOG(L"Image file '%s' not found!", res.GetFileName().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
hr = Renderer::Instance().GetDeviceResources()->CreateBitmapFromFile(bitmap, res.GetFileName());
|
hr = Renderer::Instance().GetDeviceResources()->CreateBitmapFromFile(bitmap, res.GetFileName());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@
|
||||||
<ClInclude Include="ui\Button.h" />
|
<ClInclude Include="ui\Button.h" />
|
||||||
<ClInclude Include="ui\Menu.h" />
|
<ClInclude Include="ui\Menu.h" />
|
||||||
<ClInclude Include="utils\DataUtil.h" />
|
<ClInclude Include="utils\DataUtil.h" />
|
||||||
<ClInclude Include="utils\File.h" />
|
<ClInclude Include="utils\FileUtil.h" />
|
||||||
<ClInclude Include="utils\Path.h" />
|
<ClInclude Include="utils\Path.h" />
|
||||||
<ClInclude Include="utils\ResLoader.h" />
|
<ClInclude Include="utils\ResLoader.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
@ -158,7 +158,7 @@
|
||||||
<ClCompile Include="ui\Button.cpp" />
|
<ClCompile Include="ui\Button.cpp" />
|
||||||
<ClCompile Include="ui\Menu.cpp" />
|
<ClCompile Include="ui\Menu.cpp" />
|
||||||
<ClCompile Include="utils\DataUtil.cpp" />
|
<ClCompile Include="utils\DataUtil.cpp" />
|
||||||
<ClCompile Include="utils\File.cpp" />
|
<ClCompile Include="utils\FileUtil.cpp" />
|
||||||
<ClCompile Include="utils\Path.cpp" />
|
<ClCompile Include="utils\Path.cpp" />
|
||||||
<ClCompile Include="utils\ResLoader.cpp" />
|
<ClCompile Include="utils\ResLoader.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -219,9 +219,6 @@
|
||||||
<ClInclude Include="platform\modules.h">
|
<ClInclude Include="platform\modules.h">
|
||||||
<Filter>platform</Filter>
|
<Filter>platform</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="utils\File.h">
|
|
||||||
<Filter>utils</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="utils\Path.h">
|
<ClInclude Include="utils\Path.h">
|
||||||
<Filter>utils</Filter>
|
<Filter>utils</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
@ -333,6 +330,9 @@
|
||||||
<ClInclude Include="third-party\StackWalker\StackWalker.h">
|
<ClInclude Include="third-party\StackWalker\StackWalker.h">
|
||||||
<Filter>third-party\StackWalker</Filter>
|
<Filter>third-party\StackWalker</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="utils\FileUtil.h">
|
||||||
|
<Filter>utils</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="ui\Button.cpp">
|
<ClCompile Include="ui\Button.cpp">
|
||||||
|
|
@ -431,9 +431,6 @@
|
||||||
<ClCompile Include="platform\modules.cpp">
|
<ClCompile Include="platform\modules.cpp">
|
||||||
<Filter>platform</Filter>
|
<Filter>platform</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="utils\File.cpp">
|
|
||||||
<Filter>utils</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="utils\Path.cpp">
|
<ClCompile Include="utils\Path.cpp">
|
||||||
<Filter>utils</Filter>
|
<Filter>utils</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
@ -509,5 +506,8 @@
|
||||||
<ClCompile Include="third-party\StackWalker\StackWalker.cpp">
|
<ClCompile Include="third-party\StackWalker\StackWalker.cpp">
|
||||||
<Filter>third-party\StackWalker</Filter>
|
<Filter>third-party\StackWalker</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="utils\FileUtil.cpp">
|
||||||
|
<Filter>utils</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -56,11 +56,13 @@ namespace kiwano
|
||||||
|
|
||||||
if (res.IsFileType())
|
if (res.IsFileType())
|
||||||
{
|
{
|
||||||
if (!modules::Shlwapi::Get().PathFileExistsW(res.GetFileName().c_str()))
|
#if defined(KGE_DEBUG)
|
||||||
|
if (!FileUtil::ExistsFile(res.GetFileName()))
|
||||||
{
|
{
|
||||||
KGE_WARNING_LOG(L"Media file '%s' not found", res.GetFileName().c_str());
|
KGE_WARNING_LOG(L"Media file '%s' not found", res.GetFileName().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
hr = transcoder.LoadMediaFile(res.GetFileName(), &wave_data_, &size_);
|
hr = transcoder.LoadMediaFile(res.GetFileName(), &wave_data_, &size_);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@
|
||||||
|
|
||||||
#include "utils/Path.h"
|
#include "utils/Path.h"
|
||||||
#include "utils/DataUtil.h"
|
#include "utils/DataUtil.h"
|
||||||
#include "utils/File.h"
|
#include "utils/FileUtil.h"
|
||||||
#include "utils/ResLoader.h"
|
#include "utils/ResLoader.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,11 @@ namespace kiwano
|
||||||
return reinterpret_cast<D2D1_MATRIX_3X2_F const&>(matrix);
|
return reinterpret_cast<D2D1_MATRIX_3X2_F const&>(matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const D2D1_MATRIX_3X2_F* ConvertToMatrix3x2F(const Matrix* matrix)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<const D2D1_MATRIX_3X2_F*>(matrix);
|
||||||
|
}
|
||||||
|
|
||||||
// Converts a length in device-independent pixels (DIPs) to a length in physical pixels.
|
// Converts a length in device-independent pixels (DIPs) to a length in physical pixels.
|
||||||
inline float ConvertDipsToPixels(float dips, float dpi)
|
inline float ConvertDipsToPixels(float dips, float dpi)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -354,7 +354,7 @@ namespace kiwano
|
||||||
if (!device_context_)
|
if (!device_context_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
device_context_->SetTransform(DX::ConvertToMatrix3x2F(matrix));
|
device_context_->SetTransform(DX::ConvertToMatrix3x2F(&matrix));
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,67 +18,21 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#include "File.h"
|
#include "FileUtil.h"
|
||||||
#include "../platform/modules.h"
|
#include "../platform/modules.h"
|
||||||
#include <cwctype>
|
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
File::File()
|
|
||||||
: file_path_()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
File::File(String const& file_name)
|
bool FileUtil::Delete(String const& file_path)
|
||||||
: file_path_(file_name)
|
|
||||||
{
|
{
|
||||||
}
|
if (::DeleteFile(file_path.c_str()))
|
||||||
|
|
||||||
File::~File()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool File::Open(String const& file_name)
|
|
||||||
{
|
|
||||||
if (file_name.empty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
file_path_ = file_name;
|
|
||||||
return Exists();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool File::Exists() const
|
|
||||||
{
|
|
||||||
return !!modules::Shlwapi::Get().PathFileExistsW(file_path_.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
String const& File::GetPath() const
|
|
||||||
{
|
|
||||||
return file_path_;
|
|
||||||
}
|
|
||||||
|
|
||||||
String File::GetExtension() const
|
|
||||||
{
|
|
||||||
String file_ext;
|
|
||||||
size_t pos = file_path_.find_last_of(L'.');
|
|
||||||
if (pos != String::npos)
|
|
||||||
{
|
|
||||||
file_ext = file_path_.substr(pos);
|
|
||||||
std::transform(file_ext.begin(), file_ext.end(), file_ext.begin(), std::towlower);
|
|
||||||
}
|
|
||||||
return file_ext;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool File::Delete()
|
|
||||||
{
|
|
||||||
if (::DeleteFile(file_path_.c_str()))
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
File File::Extract(Resource const& res, String const& dest_file_name)
|
bool FileUtil::Extract(Resource const& res, String const& dest_file_name)
|
||||||
{
|
{
|
||||||
File file;
|
|
||||||
HANDLE file_handle = ::CreateFile(
|
HANDLE file_handle = ::CreateFile(
|
||||||
dest_file_name.c_str(),
|
dest_file_name.c_str(),
|
||||||
GENERIC_WRITE,
|
GENERIC_WRITE,
|
||||||
|
|
@ -90,7 +44,7 @@ namespace kiwano
|
||||||
);
|
);
|
||||||
|
|
||||||
if (file_handle == INVALID_HANDLE_VALUE)
|
if (file_handle == INVALID_HANDLE_VALUE)
|
||||||
return file;
|
return false;
|
||||||
|
|
||||||
LPVOID buffer;
|
LPVOID buffer;
|
||||||
DWORD buffer_size;
|
DWORD buffer_size;
|
||||||
|
|
@ -100,14 +54,29 @@ namespace kiwano
|
||||||
::WriteFile(file_handle, buffer, buffer_size, &written_bytes, NULL);
|
::WriteFile(file_handle, buffer, buffer_size, &written_bytes, NULL);
|
||||||
::CloseHandle(file_handle);
|
::CloseHandle(file_handle);
|
||||||
|
|
||||||
file.Open(dest_file_name);
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
::CloseHandle(file_handle);
|
::CloseHandle(file_handle);
|
||||||
::DeleteFile(dest_file_name.c_str());
|
::DeleteFile(dest_file_name.c_str());
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return file;
|
bool FileUtil::ExistsFile(String const& file_path)
|
||||||
|
{
|
||||||
|
DWORD dwAttrib = ::GetFileAttributesW(file_path.c_str());
|
||||||
|
|
||||||
|
return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
|
||||||
|
!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileUtil::ExistsDirectory(String const& dir_path)
|
||||||
|
{
|
||||||
|
DWORD dwAttrib = ::GetFileAttributesW(dir_path.c_str());
|
||||||
|
|
||||||
|
return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
|
||||||
|
(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,41 +26,22 @@
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
// 文件
|
// 文件
|
||||||
class KGE_API File
|
class KGE_API FileUtil
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
File();
|
|
||||||
|
|
||||||
File(
|
|
||||||
String const& file_name
|
|
||||||
);
|
|
||||||
|
|
||||||
virtual ~File();
|
|
||||||
|
|
||||||
// 打开文件
|
|
||||||
bool Open(
|
|
||||||
String const& file_name
|
|
||||||
);
|
|
||||||
|
|
||||||
// 文件是否存在
|
|
||||||
bool Exists() const;
|
|
||||||
|
|
||||||
// 删除文件
|
// 删除文件
|
||||||
bool Delete();
|
static bool Delete(String const& file_path);
|
||||||
|
|
||||||
// 获取文件路径
|
|
||||||
String const& GetPath() const;
|
|
||||||
|
|
||||||
// 获取文件扩展名
|
|
||||||
String GetExtension() const;
|
|
||||||
|
|
||||||
// 释放二进制资源到临时文件目录
|
// 释放二进制资源到临时文件目录
|
||||||
static File Extract(
|
static bool Extract(
|
||||||
Resource const& res, /* 资源 */
|
Resource const& res, /* 资源 */
|
||||||
String const& dest_file_name /* 目标文件名 */
|
String const& dest_file_name /* 目标文件名 */
|
||||||
);
|
);
|
||||||
|
|
||||||
protected:
|
// 文件是否存在
|
||||||
String file_path_;
|
static bool ExistsFile(String const& file_path);
|
||||||
|
|
||||||
|
// 文件夹是否存在
|
||||||
|
static bool ExistsDirectory(String const& dir_path);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue