Skip to content

Commit

Permalink
Fix/hack error directory/file detection while unzip
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
donho committed Dec 21, 2018
1 parent a4f12fd commit dfbc2ad
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/winmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit dfbc2ad

Please sign in to comment.