INT64 GetFolderSize(LPCTSTR szFolder, BOOL bIncludeChild, FolderFilter fn)
{
	WIN32_FIND_DATA FindFileData;
	HANDLE hFind = INVALID_HANDLE_VALUE;

	CString strFolder(szFolder);
	strFolder.Append( _T("\\*") );

	INT64 folderSize = 0;
	hFind = FindFirstFile(strFolder, &FindFileData);
	if (hFind != INVALID_HANDLE_VALUE) 
	{
		printf ("First file name is %s\n", FindFileData.cFileName);
		do 
		{
			printf ("Next file name is %s\n", FindFileData.cFileName);

			if( _tcsicmp(_T("."), FindFileData.cFileName)==0 
				|| _tcsicmp(_T(".."), FindFileData.cFileName)==0 )
			{
				continue;
			}
			if( FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
			{
				if( bIncludeChild )
				{
					CString strResult = szFolder;
					LPCTSTR pszResult;
					LPCTSTR pchLast;
					pszResult = strResult;
					pchLast = _tcsdec( pszResult, pszResult+strResult.GetLength() );
					ATLASSERT(pchLast!=NULL);
					if ((*pchLast != _T('\\')) && (*pchLast != _T('/')))
						strResult += _T('\\');
					strResult += FindFileData.cFileName;
					folderSize += GetFolderSize( strResult, bIncludeChild );
				}
			}
			else
			{
				if( !fn || fn(szFolder, FindFileData.cFileName) )
				{
					ULARGE_INTEGER nFileSize;
					nFileSize.LowPart = FindFileData.nFileSizeLow;
					nFileSize.HighPart = FindFileData.nFileSizeHigh;
					folderSize += nFileSize.QuadPart;
				}
			}

		} while (FindNextFile(hFind, &FindFileData) != 0);
		FindClose(hFind);
	}
	return folderSize;
}
Beispiel #2
0
int GetSteamUsers(std::vector<gcString> &vUsers)
{
	std::string steampath = UTIL::OS::getConfigValue(STEAMPATH);

	if (steampath.size() == 0)
		return 0;

	gcString searchPath("{0}\\steamapps\\", steampath);

	std::vector<UTIL::FS::Path> fileList;
	UTIL::FS::getAllFolders(UTIL::FS::Path(searchPath, "", false), fileList);

	int num = 0;

	for (size_t x = 0; x < fileList.size(); x++)
	{
		gcString strFolder(fileList[x].getLastFolder());
		std::transform(strFolder.begin(), strFolder.end(), strFolder.begin(), ::tolower);

		int y = 0;

		while (g_szIgnoredFolders[y])
		{
			if (strFolder == g_szIgnoredFolders[y])
				break;

			++y;
		}

		if (g_szIgnoredFolders[y])
			continue;

		vUsers.push_back(fileList[x].getLastFolder());
		num++;
	}

	return num;
}
LPMAPIFOLDER CExMapi::GetContactFolderCount(LPMAPIFOLDER pFolder,ULONG& count,BOOL doLog)
{
	
	__recursionCount++;
	wchar_t buffer[5];
	_itow(__recursionCount,buffer,10);
	if(doLog)
	{
		if(__recursionCount > 1)
			m_logHelper.LogPAB(L"-------------------------------------");
		m_logHelper.LogPAB(L"Recursive Call No: "+CString(buffer));
		m_logHelper.LogPAB(L"-------------------------------------");
	}	
	LPMAPIFOLDER pSubFolder=NULL;
	LPMAPITABLE pHierarchy;
	CString strFolder(L"");
		
	try
	{
		if(doLog)
			m_logHelper.LogPAB(L"RELEASE(m_pHierarchy) 1 START");
		
		RELEASE(m_pHierarchy);		

		if(doLog)
			m_logHelper.LogPAB(L"RELEASE(m_pHierarchy) 1 END");
		
		if(doLog)
			m_logHelper.LogPAB(L"pHierarchy = GetHierarchy(pFolder) START");

		pHierarchy = GetHierarchy(pFolder);
		
		if(doLog)
			m_logHelper.LogPAB(L"pHierarchy = GetHierarchy(pFolder) END");
		if(pHierarchy) 
		{
			LPMAPIFOLDER pRecurse = NULL;
			do 
			{
				if(doLog)
					m_logHelper.LogPAB(L"RELEASE(pSubFolder) 1 START");
								
				RELEASE(pSubFolder);
				
				if(doLog)
					m_logHelper.LogPAB(L"RELEASE(pSubFolder) 1 END");

				m_pHierarchy = pHierarchy;				

				if(doLog)
					m_logHelper.LogPAB(L"pSubFolder = GetNextSubFolder(strFolder,pFolder) START");
				
				pSubFolder = GetNextSubFolder(strFolder,pFolder);
				//AfxMessageBox(strFolder);

				if(doLog)
				{
					m_logHelper.LogPAB(L"pSubFolder = GetNextSubFolder(strFolder,pFolder) END");
					m_logHelper.LogPAB(L"FolderName: "+strFolder);
				}
				
				if(pSubFolder) 
				{
					if(strFolder == L"Deleted Items")
						continue;

					if(doLog)
						m_logHelper.LogPAB(L"if(IsContactFolder(pSubFolder)) START");

					if(IsContactFolder(pSubFolder))
					{
						count++;
					}

					if(doLog)
						m_logHelper.LogPAB(L"if(IsContactFolder(pSubFolder)) END");

					m_pHierarchy = NULL; // so we don't release it in subsequent drilldown
										
					if(__recursionCount < m_pCtrl->GetSubFOlderLevel())
					{
						if(doLog)
							m_logHelper.LogPAB(L"pRecurse = GetContactFolderCount(pSubFolder,count) START");

						pRecurse = GetContactFolderCount(pSubFolder,count,doLog);

						if(doLog)
							m_logHelper.LogPAB(L"pRecurse = GetContactFolderCount(pSubFolder,count) END");
					}


					if(pRecurse) 
					{
						if(doLog)
							m_logHelper.LogPAB(L"RELEASE(pSubFolder) 2 START");

						RELEASE(pSubFolder);

						if(doLog)
							m_logHelper.LogPAB(L"RELEASE(pSubFolder) 2 END");

						pSubFolder = pRecurse;
						break;
					}
				}
				else
				{
					__recursionCount = 1;
				}
			} while(pSubFolder && !m_pCtrl->IsPABFolderCoutningAbort());
			if(doLog)
				m_logHelper.LogPAB(L"RELEASE(m_pHierarchy) 2 START");

			RELEASE(pHierarchy);

			if(doLog)
				m_logHelper.LogPAB(L"RELEASE(m_pHierarchy) 2 END");

			m_pHierarchy=NULL;
		}
		// this may occur many times depending on how deep the recursion is; make sure we haven't already assigned m_pFolder
		if(pSubFolder && m_pFolder!=pSubFolder) 
		{
			if(doLog)			
				m_logHelper.LogPAB(L"RELEASE(m_pFolder) START");

			RELEASE(m_pFolder);

			if(doLog)
				m_logHelper.LogPAB(L"RELEASE(m_pFolder) END");
			m_pFolder=pSubFolder;
		}
	}
	catch(_com_error &e)
	{
		if(doLog)
		{
			m_logHelper.LogPAB(L"GetContactFolderCount Exception Catch START:");
			m_logHelper.LogPAB(L"FolderName: " + strFolder );
			m_logHelper.LogPAB(e.ErrorMessage());
			m_logHelper.LogPAB(L"GetContactFolderCount Exception Catch END:");
		}
	}
	return pSubFolder;
}