From 9c075563dbfbc3ba56906c6365365cc678ded27e Mon Sep 17 00:00:00 2001 From: "FWoltermann@gmail.com" Date: Mon, 28 May 2012 20:08:13 +0000 Subject: Updated datafile for compatibility to modern Windows, also changed MAX_FILES to 8192 --- Datafile/Archive.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'Datafile/Archive.cpp') diff --git a/Datafile/Archive.cpp b/Datafile/Archive.cpp index d9f9088..039fbb1 100644 --- a/Datafile/Archive.cpp +++ b/Datafile/Archive.cpp @@ -8,6 +8,7 @@ */ +#include #include #include #include @@ -384,6 +385,14 @@ void DataArchive::Insert(const char* name) // +--------------------------------------------------------------------+ +std::wstring ToWideString(const std::string& str) +{ + int stringLength = MultiByteToWideChar(CP_ACP, 0, str.data(), str.length(), 0, 0); + std::wstring wstr(stringLength, 0); + MultiByteToWideChar(CP_ACP, 0, str.data(), str.length(), &wstr[0], stringLength); + return wstr; +} + void DataArchive::Extract(const char* name) { int index = FindEntry(name); @@ -396,6 +405,17 @@ void DataArchive::Extract(const char* name) BYTE* buf; ExpandEntry(index, buf); + std::string dirname = directory[index].name; + std::wstring wdirname = ToWideString(dirname.substr(0, dirname.find_first_of('/'))); + CreateDirectory(wdirname.c_str(), NULL); + size_t offset = wdirname.length(); + while (dirname.find_first_of('/', offset + 1) != std::string::npos) { + wdirname.push_back('/'); + wdirname += ToWideString(dirname.substr(offset + 1, dirname.find_first_of('/', offset + 1) - offset - 1)); + CreateDirectory(wdirname.c_str(), NULL); + offset = wdirname.length(); + } + FILE* f = fopen(directory[index].name, "wb"); if (f) { fwrite(buf, directory[index].size_orig, 1, f); -- cgit v1.1