Beispiel #1
0
static BOOL RemoveEmptyDirectory(WCHAR *dir)
{
    WIN32_FIND_DATA findData;
    BOOL success = TRUE;

    ScopedMem<WCHAR> dirPattern(path::Join(dir, L"*"));
    HANDLE h = FindFirstFile(dirPattern, &findData);
    if (h != INVALID_HANDLE_VALUE)
    {
        do {
            ScopedMem<WCHAR> path(path::Join(dir, findData.cFileName));
            DWORD attrs = findData.dwFileAttributes;
            // filter out directories. Even though there shouldn't be any
            // subdirectories, it also filters out the standard "." and ".."
            if ((attrs & FILE_ATTRIBUTE_DIRECTORY) &&
                !str::Eq(findData.cFileName, L".") &&
                !str::Eq(findData.cFileName, L"..")) {
                success &= RemoveEmptyDirectory(path);
            }
        } while (FindNextFile(h, &findData) != 0);
        FindClose(h);
    }

    if (!RemoveDirectory(dir)) {
        DWORD lastError = GetLastError();
        if (ERROR_DIR_NOT_EMPTY != lastError && ERROR_FILE_NOT_FOUND != lastError) {
            LogLastError(lastError);
            success = FALSE;
        }
    }

    return success;
}
void USetupDefinition::DoUninstallSteps( FInstallPoll* Poll )
{
	guard(USetupDefinition::DoInstallSteps);

	// Handle all uninstall steps.
	BeginSteps();
	UninstallTotal=0, UninstallCount=0;
	UninstallTree( TEXT("ProcessUninstallCountTotal"), Poll, ProcessUninstallCountTotal );
	UninstallTree( TEXT("ProcessUninstallRemove"),     Poll, ProcessUninstallRemove );
	TMultiMap<FString,FString>* Map = GConfig->GetSectionPrivate( TEXT("Setup"), 0, 0, *(DestPath * TEXT("System") * SETUP_INI) );
	for( TArray<USetupGroup*>::TIterator GroupIt(UninstallComponents); GroupIt; ++GroupIt )
	{
		(*GroupIt)->UninstallLog = TMultiMap<FString,FString>();
		if( Map )
			Map->RemovePair( TEXT("Group"), (*GroupIt)->GetName() );
	}
	EndSteps();

	// If reference counts exausted, delete unnecessary setup file so full directory can be removed.
	INT Refs=0;
	for( TMap<FString,FString>::TIterator It(RefCounts); It; ++It )
		Refs += appAtoi( *It.Value() );
	if( Refs==0 )
	{
		GFileManager->Delete( *SetupIniFile );
		RemoveEmptyDirectory( *BasePath(SetupIniFile) );
	}

	unguard;
}
void USetupDefinition::ProcessUninstallRemove( FString Key, FString Value, FInstallPoll* Poll )
{
	guard(USetupDefinition::ProcessUninstallRemove);
	Poll->Poll(*Value,0,1,UninstallCount++,UninstallTotal);
	if( (Key==TEXT("File") || Key==TEXT("Delete")) && UpdateRefCount(*Key,*Value,-1)==0 )
	{
		// Delete file; remove folder if empty.
		GFileManager->Delete( *(DestPath * Value) );
		RemoveEmptyDirectory( *BasePath(DestPath * Value) );
	}
	else if( Key==TEXT("Folder") && UpdateRefCount(*Key,*Value,-1)==0 )
	{
		// if folder is empty, remove it.
		RemoveEmptyDirectory( *(DestPath * Value) );
	}
	unguard;
}
Beispiel #4
0
static BOOL RemoveInstalledFiles()
{
    BOOL success = TRUE;

    for (int i = 0; NULL != gPayloadData[i].filepath; i++) {
        ScopedMem<WCHAR> relPath(str::conv::FromUtf8(gPayloadData[i].filepath));
        ScopedMem<WCHAR> path(path::Join(gGlobalData.installDir, relPath));

        if (file::Exists(path))
            success &= DeleteFile(path);
    }

    RemoveEmptyDirectory(gGlobalData.installDir);
    return success;
}