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 ++++++++++++++++++++ Datafile/Archive.h | 5 ++++- Datafile/Datafile.vcxproj | 5 +++++ Datafile/Main.cpp | 38 ++++++++++++++++++++------------------ 4 files changed, 49 insertions(+), 19 deletions(-) (limited to 'Datafile') 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); diff --git a/Datafile/Archive.h b/Datafile/Archive.h index f3ec099..eac284f 100644 --- a/Datafile/Archive.h +++ b/Datafile/Archive.h @@ -15,7 +15,7 @@ #define VERSION 0x0010 #define BLOCK_SIZE 1024 -#define MAX_FILES 4096 +#define MAX_FILES 8192 #define FILE_BLOCK 1024 #define NAMELEN 64 @@ -80,4 +80,7 @@ private: DWORD nblocks; }; +extern std::wstring ToWideString(const std::string& str); + + #endif diff --git a/Datafile/Datafile.vcxproj b/Datafile/Datafile.vcxproj index 8a1d557..964bca1 100644 --- a/Datafile/Datafile.vcxproj +++ b/Datafile/Datafile.vcxproj @@ -46,6 +46,7 @@ true + $(ProjectName)_D false @@ -58,6 +59,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) ../zlib; + true Console @@ -75,12 +77,15 @@ true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../zlib; Console true true true + ..\zlib\release\zlib.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + LIBCMT diff --git a/Datafile/Main.cpp b/Datafile/Main.cpp index 5920300..23ac306 100644 --- a/Datafile/Main.cpp +++ b/Datafile/Main.cpp @@ -25,19 +25,23 @@ void insertFile(DataArchive& a, const char* sPath, WIN32_FIND_DATA* find) { char sFile[256]; char sFlat[256]; - char sTemp[256]; + std::string sTemp; DWORD find_attrib_forbidden = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_OFFLINE; - if (sPath && *sPath) - sprintf(sFile, "%s/%s", sPath, find->cFileName); - else { - sprintf(sTemp, "%s", find->cFileName); - strcpy(sFile, sTemp); - } + if (sPath && *sPath) { + sTemp = sPath; + sTemp += '/'; + WideCharToMultiByte(CP_ACP,0,find->cFileName,-1, sFile,260, NULL, NULL); + sTemp += sFile; + strcpy(sFile, sTemp.c_str()); + } else { + WideCharToMultiByte(CP_ACP,0,find->cFileName,-1, sFile,260, NULL, NULL); + } + if (find->dwFileAttributes & find_attrib_forbidden) { printf(" Skipping: %-48s \n", sFile); @@ -132,10 +136,16 @@ void buildFile(DataArchive& a, const char* sPath, WIN32_FIND_DATA& find) if (find.cFileName[0] == '.') { } else if (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { char subdir[256]; - if (sPath && *sPath) - sprintf(subdir, "%s/%s", sPath, find.cFileName); + std::string sTemp; + if (sPath && *sPath) { + sTemp = sPath; + sTemp += '/'; + WideCharToMultiByte(CP_ACP,0,find.cFileName,-1, subdir,260, NULL, NULL); + sTemp += subdir; + strcpy(subdir, sTemp.c_str()); + } else - sprintf(subdir, "%s", find.cFileName); + WideCharToMultiByte(CP_ACP,0,find.cFileName,-1, subdir,256, NULL, NULL); build(a, subdir); } else { @@ -143,14 +153,6 @@ void buildFile(DataArchive& a, const char* sPath, WIN32_FIND_DATA& find) } } -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 build(DataArchive& a, const char* sBasePath) { char sPath[256]; -- cgit v1.1