Example #1
0
BOOL CFCacheImpl::DelDir(LPCWSTR lpDir)
{
    BOOL retval = FALSE;
    int nRetCode;
    char* szError = NULL;
    CStringA strSql;
    CStringW strDir;

    if (!m_pDbConnect)
        goto clean0;

    if (!lpDir)
        goto clean0;

    strDir = lpDir;
    strDir.MakeLower();

    strSql.Format("delete from files where path like '%s%s'", 
                  KUTF16_To_UTF8(strDir),
                  "%");
    nRetCode = sqlite3_exec(m_pDbConnect, strSql, NULL, NULL, &szError);
    if (nRetCode)
        goto clean0;

    retval = TRUE;

clean0:
    return retval;
}
Example #2
0
int CTWScriptEdit::IsConstant(LPCWSTR lpszSymbol)
{
	CStringW strSymbol; strSymbol.Format(L" %s ", lpszSymbol);
	if (!m_bCaseSensitive) 
		strSymbol.MakeLower();
				
	return m_strConstantsLower.Find(strSymbol);
}
  bool IsDefaultBrowser()
  {
    IApplicationAssociationRegistration* pAAR;
    HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration,
                                  NULL,
                                  CLSCTX_INPROC,
                                  IID_IApplicationAssociationRegistration,
                                  (void**)&pAAR);
    if (FAILED(hr))
      return false;

    BOOL res = FALSE;
    hr = pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE,
                                    APP_REG_NAME,
                                    &res);
    Log(L"QueryAppIsDefaultAll: %d", res);
    if (!res) {
      pAAR->Release();
      return false;
    }
    // Make sure the Prog ID matches what we have
    LPWSTR registeredApp;
    hr = pAAR->QueryCurrentDefault(L"http", AT_URLPROTOCOL, AL_EFFECTIVE,
                                    &registeredApp);
    pAAR->Release();
    Log(L"QueryCurrentDefault: %X", hr);
    if (FAILED(hr))
      return false;

    Log(L"registeredApp=%s", registeredApp);
    bool result = !wcsicmp(registeredApp, kDefaultMetroBrowserIDPathKey);
    CoTaskMemFree(registeredApp);
    if (!result)
      return false;

    // If the registry points another browser's path,
    // activating the Metro browser will fail. So fallback to the desktop.
    CStringW selfPath;
    GetDesktopBrowserPath(selfPath);
    selfPath.MakeLower();
    CStringW browserPath;
    GetDefaultBrowserPath(browserPath);
    browserPath.MakeLower();

    return selfPath == browserPath;
  }
Example #4
0
BOOL CFCacheImpl::GetDirInfo(
    LPCWSTR lpDir,
    ULONGLONG& qwSize,
    ULONGLONG& qwCount
    )
{
    BOOL retval = FALSE;
    int nRetCode;
    char* szError = NULL;
    CStringA strSql;
    CStringW strDir;
    sqlite3_stmt* pStmt = NULL;

    if (!m_pDbConnect)
        goto clean0;

    if (!lpDir)
        goto clean0;

    strDir = lpDir;
    strDir.MakeLower();

    strSql.Format("select sum(size), count(size) from files where path like '%s\\%s'",
                  KUTF16_To_UTF8(strDir),
                  "%");
    nRetCode = sqlite3_prepare(m_pDbConnect, strSql, -1, &pStmt, 0);
    if (nRetCode)
        goto clean0;

    nRetCode = sqlite3_step(pStmt);
    if (SQLITE_ROW != nRetCode)
        goto clean0;

    qwSize = sqlite3_column_int64(pStmt, 0);
    qwCount = sqlite3_column_int64(pStmt, 1);

    retval = TRUE;

clean0:
    if (pStmt)
    {
        sqlite3_finalize(pStmt);
        pStmt = NULL;
    }

    return retval;
}
Example #5
0
BOOL CFCacheImpl::AddFile(
    LPCWSTR lpFilePath,
    ULONGLONG qwFileSize
    )
{
    BOOL retval = FALSE;
    int nRetCode;
    char* szError = NULL;
    CStringA strSql;
    CStringW strFilePath;
    CStringW strExt;
    int nExt;

    if (!m_pDbConnect)
        goto clean0;

    if (!lpFilePath)
        goto clean0;

    strFilePath = lpFilePath;
    strFilePath.MakeLower();

    nExt = strFilePath.ReverseFind(_T('.'));
    if (nExt != -1 && nExt > strFilePath.ReverseFind(_T('\\')))
    {
        strExt = strFilePath.Right(strFilePath.GetLength() - nExt);
    }

    if (strExt.IsEmpty())
    {
        strExt = _T(".n/a");
    }

    strSql.Format("insert into files values('%s', '%s', %I64d)",
                  KUTF16_To_UTF8(strFilePath),
                  KUTF16_To_UTF8(strExt),
                  qwFileSize);
    nRetCode = sqlite3_exec(m_pDbConnect, strSql, NULL, NULL, &szError);
    if (nRetCode)
        goto clean0;

    retval = TRUE;

clean0:
    return retval;
}
Example #6
0
BOOL CStubbornFiles::IsStubbornFile(const CStringW& strFilePath)
{
    BOOL retval = FALSE;

    CStringW strTempPath = strFilePath;
    CAtlMap<CStringW, BOOL>::CPair* pPair = NULL;
    KAutoLock lock(klock);


    if (strFilePath.IsEmpty())
        goto clean0;


    strTempPath.MakeLower();

//     static bool btest = FALSE;
//
//     if(!btest)
//     {
//         POSITION pos = m_fileList.GetHeadPosition();
//         while (pos)
//         {
//
//
//              ::OutputDebugString(m_fileList.GetNext(pos));
//
//         }
//
//         btest = true;
//
//     }




    pPair = m_fileMap.Lookup(strTempPath);
    if (!pPair)
        goto clean0;


    retval = TRUE;

clean0:
    return retval;
}
Example #7
0
BOOL CFCacheImpl::GetFileSize(
    LPCWSTR lpFilePath,
    ULONGLONG& qwSize
    )
{
    BOOL retval = FALSE;
    int nRetCode;
    char* szError = NULL;
    CStringA strSql;
    CStringW strFilePath;
    sqlite3_stmt* pStmt = NULL;

    if (!m_pDbConnect)
        goto clean0;

    if (!lpFilePath)
        goto clean0;

    strFilePath = lpFilePath;
    strFilePath.MakeLower();

    strSql.Format("select size from files where path = '%s'",
                   KUTF16_To_UTF8(strFilePath));
    nRetCode = sqlite3_prepare(m_pDbConnect, strSql, -1, &pStmt, 0);
    if (nRetCode)
        goto clean0;

    nRetCode = sqlite3_step(pStmt);
    if (SQLITE_ROW != nRetCode)
        goto clean0;

    qwSize = sqlite3_column_int64(pStmt, 0);

    retval = TRUE;

clean0:
    if (pStmt)
    {
        sqlite3_finalize(pStmt);
        pStmt = NULL;
    }

    return retval;
}   
Example #8
0
void CStubbornFiles::AddFile(const CStringW& strFilePath)
{
    CStringW strTempPath = strFilePath;
    CAtlMap<CStringW, BOOL>::CPair* pPair = NULL;
    KAutoLock lock(klock);

    if (strFilePath.IsEmpty())
        goto clean0;

    strTempPath.MakeLower();


    pPair = m_fileMap.Lookup(strTempPath);
    if (pPair)
        goto clean0;

    m_fileMap[strTempPath] = TRUE;
    m_fileList.AddTail(strTempPath);

clean0:
    return;
}
Example #9
0
BOOL CStubbornRegs::IsStubbornReg(const CStringW& strRegPath)
{
    BOOL retval = FALSE;

    CStringW strTempPath = strRegPath;
    CAtlMap<CStringW, BOOL>::CPair* pPair = NULL;
    KAutoLock lock(klock);


    if (strRegPath.IsEmpty())
        goto clean0;


    strTempPath.MakeLower();
   
    pPair = m_regMap.Lookup(strTempPath);
    if (!pPair)
        goto clean0;

    retval = TRUE;

clean0:
    return retval;
}
Example #10
0
void CIISConfigHelper::PopulateTreeFromFileSystem(CTreeCtrl& cTree, HTREEITEM htParent, const std::set<CStringW>& IgnoreDirNames, int nMaxDepth)
{
	if (htParent == NULL)
		return;	

	// get the item data from the tree item
	IISURIItem* pParentItem = (IISURIItem*) cTree.GetItemData(htParent);
	if (pParentItem == NULL)
	{
		ASSERT(pParentItem != NULL);
		return;
	}

	// if the item is incomplete then we need to get it's file system path
	if (pParentItem->Type == IISURIItem::IncompleteFileSystemPath && pParentItem->sFileSystemPath.GetLength() <= 0)
	{
		// get the grand parent item
		HTREEITEM htGrandParent = cTree.GetParentItem(htParent);
		if (htGrandParent == NULL)
		{
			ASSERT(htGrandParent != NULL);
			return;
		}		

		// get the grand parent item data
		IISURIItem* pGrandParentItem = (IISURIItem*) cTree.GetItemData(htGrandParent);
		if (pGrandParentItem == NULL)
		{
			ASSERT(pGrandParentItem != NULL);
			return;
		}

		// the grand parent MUST not be incomplete
		if (pGrandParentItem->Type == IISURIItem::IncompleteFileSystemPath)
		{
			ASSERT(pGrandParentItem->Type != IISURIItem::IncompleteFileSystemPath);
			return;
		}

		// get the item name
		CStringW sName = CStringW(cTree.GetItemText(htParent));
		if (sName.GetLength() <= 0)
		{
			ASSERT(sName.GetLength() > 0);
			return;
		}

		// make the path to the parent item
		CPathT<CStringW> ItemFileSystemPath(pGrandParentItem->sFileSystemPath);
		ItemFileSystemPath.Append(sName);

		// assign the new file system path and set the type
		pParentItem->sFileSystemPath = (LPCWSTR) ItemFileSystemPath;
		pParentItem->Type = IISURIItem::FileSystem;
	}

	// if the item already has children then we need to build up a list of their names
	std::set<CStringW> KnownDirs;
	if (cTree.ItemHasChildren(htParent) == TRUE)
	{
		// loop through all the children
		HTREEITEM htChild = cTree.GetChildItem(htParent);
		while (htChild != NULL)
		{
			// get the child name
			CStringW sName = CStringW(cTree.GetItemText(htChild));

			// we need lower case so we can compare easier
			sName.MakeLower();

			// add the name to the known list
			KnownDirs.insert(sName);

			// move on to the next child item
			htChild = cTree.GetNextSiblingItem(htChild);
		}
	}

#ifdef _DEBUG
	ATLTRACE2(L"CIISConfigHelper::PopulateTreeFromFileSystem() : searching '%s'\n", pParentItem->sFileSystemPath);
#endif

	// create a search string
	CPathT<CStringW> FileSystemPath(pParentItem->sFileSystemPath);
	FileSystemPath.Append(L"*.*");
	CStringW sSearchPath = (LPCWSTR) FileSystemPath;	

	// start the search
	WIN32_FIND_DATAW FindData;	
	HANDLE hFind = ::FindFirstFileW(sSearchPath, &FindData);
	if (hFind == INVALID_HANDLE_VALUE)
	{
		// TODO: empty
		return;
	}

	CArray<CStringW, LPCWSTR> saDirs;	

	// guess that we will have 32 sub dirs (the array will grow if we have more)
	saDirs.SetSize(32);

	// keep track of the number of dirs we have actually found
	int nDirsFound = 0;

	do
	{		
		if ((FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
			continue;		

		// eliminate . and .. from the search
		if (FindData.cFileName[0] == '.')
		{
			if (FindData.cFileName[1] == '\0')
			{
				continue;
			}
			else if (FindData.cFileName[1] == '.' && FindData.cFileName[2] == '\0')
			{
				continue;
			}
		}		
			
		// convert to lower case
		CStringW sTempFileName = FindData.cFileName;
		sTempFileName.MakeLower();

		// only add to the collection if we don't already know about it
		if (KnownDirs.find(sTempFileName) != KnownDirs.end())
			continue;

		// if it's a known ignore dir name - then ignore it
		if (IgnoreDirNames.find(sTempFileName) != IgnoreDirNames.end())
			continue;
		
#ifdef _DEBUG
		ATLTRACE2(L"CIISConfigHelper::PopulateTreeFromFileSystem() : found '%s'\n", FindData.cFileName);
#endif

		saDirs.SetAtGrow(nDirsFound, FindData.cFileName);		

		// we have found one
		nDirsFound++;
	}
	while (::FindNextFileW(hFind, &FindData) == TRUE);	

	// get rid of the find handle
	::FindClose(hFind);
	hFind = NULL;	
	
	if (nDirsFound <= 0)
	{		
		return;
	}

	if (nMaxDepth <= 0)
	{
		cTree.InsertItem(EmptyNodeString, htParent);
		return;
	}

	for (int i = 0; i < nDirsFound; i++)
	{
		CString sDir(saDirs[i]);
		HTREEITEM htChild = cTree.InsertItem(sDir, htParent);		

		// create the child file system path
		CPathT<CStringW> FileSystemPath(pParentItem->sFileSystemPath);
		FileSystemPath.Append(saDirs[i]);

		// we need an item data for this tree item
		IISURIItem* pChildItem = new IISURIItem;
		pChildItem->Type = IISURIItem::FileSystem;
		pChildItem->sFileSystemPath = (LPCWSTR) FileSystemPath;

		// make the child URI
		CStringW sChildURI = pParentItem->sURI;
		int nChildURILength = sChildURI.GetLength();
		if (nChildURILength > 0 && sChildURI[nChildURILength - 1] != '/')
			sChildURI += '/';

		// append the dir name
		sChildURI += saDirs[i];

		// assign the URI to the item data
		pChildItem->sURI = sChildURI;

		// store the item data
		cTree.SetItemData(htChild, (DWORD_PTR) pChildItem);

		PopulateTreeFromFileSystem(cTree, htChild, IgnoreDirNames, nMaxDepth - 1);
	}
}
Example #11
0
BOOL CFCacheImpl::DelFile(LPCWSTR lpFilePath)
{
    BOOL retval = FALSE;
    int nRetCode;
    char* szError = NULL;
    CStringA strSql;
    CStringW strFilePath;
    int nExt;
    CStringW strExt;
    sqlite3_stmt* pStmt = NULL;
    ULONGLONG qwSize;

    if (!m_pDbConnect)
        goto clean0;

    if (!lpFilePath)
        goto clean0;

    strFilePath = lpFilePath;
    strFilePath.MakeLower();

    nExt = strFilePath.ReverseFind(_T('.'));
    if (nExt != -1 && nExt > strFilePath.ReverseFind(_T('\\')))
    {
        strExt = strFilePath.Right(strFilePath.GetLength() - nExt);
    }

    if (strExt.IsEmpty())
    {
        strExt = _T(".n/a");
    }

    // 获得大小
    strSql.Format("select size from files where path = '%s'", KUTF16_To_UTF8(strFilePath));
    nRetCode = sqlite3_prepare(m_pDbConnect, strSql, -1, &pStmt, 0);
    if (nRetCode)
        goto clean0;

    nRetCode = sqlite3_step(pStmt);
    if (SQLITE_ROW != nRetCode)
        goto clean0;

    qwSize = sqlite3_column_int64(pStmt, 0);

    // 删除文件
    strSql.Format("delete from files where path = '%s'", KUTF16_To_UTF8(strFilePath));
    nRetCode = sqlite3_exec(m_pDbConnect, strSql, NULL, NULL, &szError);
    if (nRetCode)
        goto clean0;

    // 从Top100中删除
    strSql.Format("delete from top100 where path = '%s'", KUTF16_To_UTF8(strFilePath));
    nRetCode = sqlite3_exec(m_pDbConnect, strSql, NULL, NULL, &szError);

    // 从Exts中去除大小
    strSql.Format("insert into exts values('%s', -%I64d, -1)", KUTF16_To_UTF8(strExt), qwSize);
    nRetCode = sqlite3_exec(m_pDbConnect, strSql, NULL, NULL, &szError);

    // 从总大小中去除大小
    strSql.Format("insert into info values(-%I64d, -1)", qwSize);
    nRetCode = sqlite3_exec(m_pDbConnect, strSql, NULL, NULL, &szError);

    retval = TRUE;

clean0:
    if (pStmt)
    {
        sqlite3_finalize(pStmt);
        pStmt = NULL;
    }

    return retval;
}