in src/main/cpp/launcher/windows/src/FileUtils.c [415:466]
void deleteDirectory(LauncherProperties * props, WCHAR * dir) {
DWORD attrs = GetFileAttributesW(dir);
DWORD dwError;
DWORD count = 0 ;
if(attrs==INVALID_FILE_ATTRIBUTES) {
writeErrorA(props, OUTPUT_LEVEL_DEBUG, 1, "Error! Can`t get attributes of the dir : ", dir, GetLastError());
return;
}
if(!SetFileAttributesW(dir, attrs & FILE_ATTRIBUTE_NORMAL)) {
writeErrorA(props, OUTPUT_LEVEL_DEBUG, 1, "Error! Can`t set attributes of the dir : ", dir, GetLastError());
}
if(attrs & FILE_ATTRIBUTE_DIRECTORY) {
WIN32_FIND_DATAW FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
WCHAR * DirSpec = appendStringW(appendStringW(NULL, dir), L"\\*" );
// Find the first file in the directory.
hFind = FindFirstFileW(DirSpec, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) {
writeErrorA(props, OUTPUT_LEVEL_DEBUG, 1, "Error! Can`t file with pattern ", DirSpec, GetLastError());
}
else {
// List all the other files in the directory.
while (FindNextFileW(hFind, &FindFileData) != 0) {
if(lstrcmpW(FindFileData.cFileName, L".")!=0 &&
lstrcmpW(FindFileData.cFileName, L"..")!=0 ) {
WCHAR * child = appendStringW(appendStringW(appendStringW(NULL, dir), FILE_SEP), FindFileData.cFileName);
deleteDirectory(props, child);
FREE(child);
}
}
dwError = GetLastError();
FindClose(hFind);
if (dwError != ERROR_NO_MORE_FILES) {
writeErrorA(props, OUTPUT_LEVEL_DEBUG, 1, "Error! Can`t find file with pattern : ", DirSpec, dwError);
}
}
// 20 tries in 2 seconds to delete the directory
while(!RemoveDirectoryW(dir) && count++ < 20) Sleep(100);
FREE(DirSpec);
}
else {
// 20 tries in 2 seconds to delete the file
while(!DeleteFileW(dir) && count++ < 20) Sleep(100);
}
}