commit 115ae83c0ec5ee72c2def523a9fd4d47dc6afc30
parent 2fa5eb2efd4d76fa0a4a8ef0a1de3f413689ceac
Author: cfillion <cfillion@users.noreply.github.com>
Date: Mon, 4 Jan 2016 10:00:06 -0800
fix reading database from unicode path on windows
Diffstat:
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/database.cpp b/src/database.cpp
@@ -17,17 +17,36 @@
#include "database.hpp"
+#include "encoding.hpp"
#include "errors.hpp"
#include <WDL/tinyxml/tinyxml.h>
using namespace std;
-Database *Database::load(const string &name, const char *file)
+static FILE *OpenFile(const char *path)
{
- TiXmlDocument doc(file);
+ #ifdef _WIN32
+ FILE *file = nullptr;
+ _wfopen_s(&file, make_autostring(path).c_str(), L"rb");
+ return file;
+ #else
+ return fopen(path, "rb");
+ #endif
+}
+
+Database *Database::load(const string &name, const char *path)
+{
+ TiXmlDocument doc;
+
+ FILE *file = OpenFile(path);
+
+ const bool success = doc.LoadFile(file);
+
+ if(file)
+ fclose(file);
- if(!doc.LoadFile())
+ if(!success)
throw reapack_error("failed to read database");
TiXmlHandle docHandle(&doc);