diff --git a/Kiwano/2d/Image.cpp b/Kiwano/2d/Image.cpp
index 843abb0b..ef6b2538 100644
--- a/Kiwano/2d/Image.cpp
+++ b/Kiwano/2d/Image.cpp
@@ -22,6 +22,7 @@
#include "../base/logs.h"
#include "../renderer/render.h"
#include "../platform/modules.h"
+#include "../utils/FileUtil.h"
namespace kiwano
{
@@ -61,11 +62,13 @@ namespace kiwano
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());
return false;
}
+#endif
hr = Renderer::Instance().GetDeviceResources()->CreateBitmapFromFile(bitmap, res.GetFileName());
}
else
diff --git a/Kiwano/Kiwano.vcxproj b/Kiwano/Kiwano.vcxproj
index 1c7853cd..7d863634 100644
--- a/Kiwano/Kiwano.vcxproj
+++ b/Kiwano/Kiwano.vcxproj
@@ -98,7 +98,7 @@
-
+
@@ -158,7 +158,7 @@
-
+
diff --git a/Kiwano/Kiwano.vcxproj.filters b/Kiwano/Kiwano.vcxproj.filters
index 785c106f..dbf82b8b 100644
--- a/Kiwano/Kiwano.vcxproj.filters
+++ b/Kiwano/Kiwano.vcxproj.filters
@@ -219,9 +219,6 @@
platform
-
- utils
-
utils
@@ -333,6 +330,9 @@
third-party\StackWalker
+
+ utils
+
@@ -431,9 +431,6 @@
platform
-
- utils
-
utils
@@ -509,5 +506,8 @@
third-party\StackWalker
+
+ utils
+
\ No newline at end of file
diff --git a/Kiwano/audio/Sound.cpp b/Kiwano/audio/Sound.cpp
index 903b49a7..70c0f676 100644
--- a/Kiwano/audio/Sound.cpp
+++ b/Kiwano/audio/Sound.cpp
@@ -56,11 +56,13 @@ namespace kiwano
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());
return false;
}
+#endif
hr = transcoder.LoadMediaFile(res.GetFileName(), &wave_data_, &size_);
}
else
diff --git a/Kiwano/kiwano.h b/Kiwano/kiwano.h
index 08a7ed74..8fdc2866 100644
--- a/Kiwano/kiwano.h
+++ b/Kiwano/kiwano.h
@@ -110,7 +110,7 @@
#include "utils/Path.h"
#include "utils/DataUtil.h"
-#include "utils/File.h"
+#include "utils/FileUtil.h"
#include "utils/ResLoader.h"
diff --git a/Kiwano/renderer/helper.hpp b/Kiwano/renderer/helper.hpp
index 47097db3..47098a76 100644
--- a/Kiwano/renderer/helper.hpp
+++ b/Kiwano/renderer/helper.hpp
@@ -63,6 +63,11 @@ namespace kiwano
return reinterpret_cast(matrix);
}
+ inline const D2D1_MATRIX_3X2_F* ConvertToMatrix3x2F(const Matrix* matrix)
+ {
+ return reinterpret_cast(matrix);
+ }
+
// Converts a length in device-independent pixels (DIPs) to a length in physical pixels.
inline float ConvertDipsToPixels(float dips, float dpi)
{
diff --git a/Kiwano/renderer/render.cpp b/Kiwano/renderer/render.cpp
index abd7501e..89dbafbd 100644
--- a/Kiwano/renderer/render.cpp
+++ b/Kiwano/renderer/render.cpp
@@ -354,7 +354,7 @@ namespace kiwano
if (!device_context_)
return E_UNEXPECTED;
- device_context_->SetTransform(DX::ConvertToMatrix3x2F(matrix));
+ device_context_->SetTransform(DX::ConvertToMatrix3x2F(&matrix));
return S_OK;
}
diff --git a/Kiwano/utils/File.cpp b/Kiwano/utils/FileUtil.cpp
similarity index 65%
rename from Kiwano/utils/File.cpp
rename to Kiwano/utils/FileUtil.cpp
index 52f1f33a..25d3974c 100644
--- a/Kiwano/utils/File.cpp
+++ b/Kiwano/utils/FileUtil.cpp
@@ -18,67 +18,21 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#include "File.h"
+#include "FileUtil.h"
#include "../platform/modules.h"
-#include
namespace kiwano
{
- File::File()
- : file_path_()
- {
- }
- File::File(String const& file_name)
- : file_path_(file_name)
+ bool FileUtil::Delete(String const& file_path)
{
- }
-
- 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()))
+ if (::DeleteFile(file_path.c_str()))
return true;
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(
dest_file_name.c_str(),
GENERIC_WRITE,
@@ -90,7 +44,7 @@ namespace kiwano
);
if (file_handle == INVALID_HANDLE_VALUE)
- return file;
+ return false;
LPVOID buffer;
DWORD buffer_size;
@@ -100,14 +54,29 @@ namespace kiwano
::WriteFile(file_handle, buffer, buffer_size, &written_bytes, NULL);
::CloseHandle(file_handle);
- file.Open(dest_file_name);
+ return true;
}
else
{
::CloseHandle(file_handle);
::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));
}
}
\ No newline at end of file
diff --git a/Kiwano/utils/File.h b/Kiwano/utils/FileUtil.h
similarity index 80%
rename from Kiwano/utils/File.h
rename to Kiwano/utils/FileUtil.h
index 8842977b..4d03f777 100644
--- a/Kiwano/utils/File.h
+++ b/Kiwano/utils/FileUtil.h
@@ -26,41 +26,22 @@
namespace kiwano
{
// 文件
- class KGE_API File
+ class KGE_API FileUtil
{
public:
- File();
-
- File(
- String const& file_name
- );
-
- virtual ~File();
-
- // 打开文件
- bool Open(
- String const& file_name
- );
-
- // 文件是否存在
- bool Exists() const;
-
// 删除文件
- bool Delete();
-
- // 获取文件路径
- String const& GetPath() const;
-
- // 获取文件扩展名
- String GetExtension() const;
+ static bool Delete(String const& file_path);
// 释放二进制资源到临时文件目录
- static File Extract(
+ static bool Extract(
Resource const& res, /* 资源 */
String const& dest_file_name /* 目标文件名 */
);
- protected:
- String file_path_;
+ // 文件是否存在
+ static bool ExistsFile(String const& file_path);
+
+ // 文件夹是否存在
+ static bool ExistsDirectory(String const& dir_path);
};
}