From dfbc2ad37abe67e0db6844e54d56bf0e423b1f26 Mon Sep 17 00:00:00 2001 From: Don HO Date: Fri, 21 Dec 2018 02:18:56 +0100 Subject: [PATCH] Fix/hack error directory/file detection while unzip It should be fixed once for all logically (except the leaf directory could still be treated as file). However, the logic doesn't exist in a nightmare, which is based on an unreliable unzip component. --- src/winmain.cpp | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/winmain.cpp b/src/winmain.cpp index 2cfa78ad..d93c5be2 100644 --- a/src/winmain.cpp +++ b/src/winmain.cpp @@ -329,13 +329,20 @@ bool decompress(const string& zipFullFilePath, const string& unzipDestTo) for (size_t k = 0; k < strArray.size(); ++k) { PathAppend(folderPath, strArray[k]); + if (!::PathFileExistsA(folderPath.c_str())) { - if (!::CreateDirectoryA(folderPath.c_str(), NULL)) - return false; + ::CreateDirectoryA(folderPath.c_str(), NULL); + } + else if (!::PathIsDirectoryA(folderPath.c_str())) // The unzip core component is not reliable for the file/directory detection + { // Hence such hack to make the result is as correct as possible + // if it's a file, remove it + deleteFileOrFolder(folderPath); + + // create it + ::CreateDirectoryA(folderPath.c_str(), NULL); } } - } } else // it's a file @@ -349,8 +356,15 @@ bool decompress(const string& zipFullFilePath, const string& unzipDestTo) PathAppend(folderPath, strArray[k]); if (!::PathFileExistsA(folderPath.c_str())) { - if (!::CreateDirectoryA(folderPath.c_str(), NULL)) - return false; + ::CreateDirectoryA(folderPath.c_str(), NULL); + } + else if (!::PathIsDirectoryA(folderPath.c_str())) // The unzip core component is not reliable for the file/directory detection + { // Hence such hack to make the result is as correct as possible + // if it's a file, remove it + deleteFileOrFolder(folderPath); + + // create it + ::CreateDirectoryA(folderPath.c_str(), NULL); } } @@ -806,6 +820,17 @@ void writeLog(const char *logFileName, const char *logSuffix, const char *log2wr int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, int) { + /* + { + string destPath = "C:\\tmp\\res\\TagsView"; + string dlDest = "C:\\tmp\\pb\\TagsView_Npp_03beta.zip"; + bool isSuccessful = decompress(dlDest, destPath); + if (isSuccessful) + { + return 0; + } + } + */ // Debug use - stop here so we can attach this process for debugging //::MessageBoxA(NULL, "And do something dirty to me ;)", "Attach me!", MB_OK);