You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
2.9 KiB
114 lines
2.9 KiB
/*++
|
|
|
|
Copyright (c) 1991 Microsoft Corporation
|
|
|
|
Module Name:
|
|
|
|
delnode.c
|
|
|
|
Abstract:
|
|
|
|
Delnode routine for Setup.
|
|
|
|
WARNING: the delnode routine in here is not multi-thread safe!
|
|
|
|
Author:
|
|
|
|
Ted Miller (tedm) August 1992
|
|
|
|
--*/
|
|
|
|
#include "precomp.h"
|
|
#pragma hdrstop
|
|
|
|
//
|
|
// Put these out here so we don't consume huge stack space as we recurse.
|
|
//
|
|
TCHAR DelnodePattern[MAX_PATH];
|
|
WIN32_FIND_DATA DelnodeFindData;
|
|
|
|
VOID
|
|
DelnodeRoutine(
|
|
VOID
|
|
)
|
|
{
|
|
LPTSTR PatternEnd;
|
|
HANDLE FindHandle;
|
|
|
|
//
|
|
// Delete each file in the directory, then remove the directory itself.
|
|
// If any directories are encountered along the way recurse to delete
|
|
// them as they are encountered.
|
|
//
|
|
PatternEnd = DelnodePattern+lstrlen(DelnodePattern);
|
|
|
|
//This is safe, since we accounted for these two chars in the higher level MyDelnode()
|
|
lstrcat(DelnodePattern,TEXT("\\*"));
|
|
FindHandle = FindFirstFile(DelnodePattern,&DelnodeFindData);
|
|
|
|
if(FindHandle != INVALID_HANDLE_VALUE) {
|
|
|
|
do {
|
|
|
|
//
|
|
// Form the full name of the file we just found.
|
|
//
|
|
if (SUCCEEDED(StringCchCopy(PatternEnd+1,
|
|
(DelnodePattern + ARRAYSIZE(DelnodePattern)) - (PatternEnd+1),
|
|
DelnodeFindData.cFileName)))
|
|
{
|
|
if(DelnodeFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
|
|
|
//
|
|
// The current match is a directory. Recurse into it unless
|
|
// it's . or ...
|
|
//
|
|
if(lstrcmp(DelnodeFindData.cFileName,TEXT("." ))
|
|
&& lstrcmp(DelnodeFindData.cFileName,TEXT("..")))
|
|
{
|
|
DelnodeRoutine();
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
// The current match is not a directory -- so delete it.
|
|
//
|
|
SetFileAttributes(DelnodePattern,FILE_ATTRIBUTE_NORMAL);
|
|
DeleteFile(DelnodePattern);
|
|
}
|
|
}
|
|
|
|
*(PatternEnd+1) = 0;
|
|
|
|
} while(FindNextFile(FindHandle,&DelnodeFindData));
|
|
|
|
FindClose(FindHandle);
|
|
}
|
|
|
|
//
|
|
// Remove the directory we just emptied out.
|
|
//
|
|
*PatternEnd = 0;
|
|
SetFileAttributes(DelnodePattern,FILE_ATTRIBUTE_NORMAL);
|
|
RemoveDirectory(DelnodePattern);
|
|
|
|
//
|
|
// Note that the 'directory' might actually be a file.
|
|
// Catch that case here.
|
|
//
|
|
DeleteFile(DelnodePattern);
|
|
}
|
|
|
|
|
|
VOID
|
|
MyDelnode(
|
|
IN LPCTSTR Directory
|
|
)
|
|
{
|
|
if (SUCCEEDED(StringCchCopy(DelnodePattern, ARRAYSIZE(DelnodePattern) - 2, Directory)))
|
|
//Use ArraySize - 2, since we will always append a wack, then a * to DelnodePattern.
|
|
{
|
|
DelnodeRoutine();
|
|
}
|
|
}
|