BOOL CStubbornFiles::_LoadFromFile() { BOOL retval = FALSE; CDataFileLoader dataLoader; TiXmlDocument xmlDoc; const TiXmlElement* pXmlItems = NULL; const TiXmlElement* pXmlItem = NULL; const TiXmlElement* pXmlTime = NULL; TCHAR szConfPath[MAX_PATH] = { 0 }; CStringA strXmlAnsi; CStringW strPathUtf16; CStringA strPathAnsi; SYSTEMTIME sysTime = { 0 }; CStringA strTime; GetLocalTime(&sysTime); strTime.Format("%d.%d.%d", sysTime.wYear, sysTime.wMonth, sysTime.wDay); GetModuleFileName(NULL, szConfPath, MAX_PATH); PathRemoveFileSpec(szConfPath); PathAppend(szConfPath, _T("data\\strash.dat")); if (!dataLoader.LoadFile(szConfPath, strXmlAnsi)) goto clean0; if (!xmlDoc.LoadBuffer((LPSTR)(LPCSTR)strXmlAnsi, strXmlAnsi.GetLength(), TIXML_ENCODING_UTF8)) goto clean0; pXmlTime = xmlDoc.FirstChildElement("time"); if (!pXmlTime) goto clean0; if (strTime.Compare(pXmlTime->GetText())) goto clean0; pXmlItems = xmlDoc.FirstChildElement("items"); if (!pXmlItems) goto clean0; pXmlItem = pXmlItems->FirstChildElement("item"); while (pXmlItem) { strPathAnsi = pXmlItem->GetText(); if (strPathAnsi.GetLength()) { strPathUtf16 = KUTF8_To_UTF16(strPathAnsi); if (GetFileAttributes(strPathUtf16) != INVALID_FILE_ATTRIBUTES) { m_fileList.AddTail(strPathUtf16); m_fileMap[strPathUtf16] = TRUE; } } pXmlItem = pXmlItem->NextSiblingElement("item"); } retval = TRUE; clean0: return retval; }
BOOL SlimData::LoadDataSync() { BOOL retval = FALSE; KAutoLock lock(m_lock); CStringA strXml; TCHAR szModule[MAX_PATH] = { 0 }; TiXmlDocument xmlDoc; TiXmlElement* pXmlSlims = NULL; TiXmlElement* pXmlItem = NULL; CDataFileLoader datloader; GetModuleFileName(NULL, szModule, MAX_PATH); PathRemoveFileSpec(szModule); PathAppend(szModule, _T("data\\slimdata.dat")); if (!datloader.LoadFile(szModule, strXml)) goto clean0; xmlDoc.Parse(strXml); pXmlSlims = xmlDoc.FirstChildElement("slims"); if (!pXmlSlims) goto clean0; pXmlItem = pXmlSlims->FirstChildElement("slim"); while (pXmlItem) { TiXmlElement* pXmlId = pXmlItem->FirstChildElement("id"); TiXmlElement* pXmlName = pXmlItem->FirstChildElement("name"); TiXmlElement* pXmlDescription = pXmlItem->FirstChildElement("description"); TiXmlElement* pXmlWarning = pXmlItem->FirstChildElement("warning"); TiXmlElement* pXmlMethod = pXmlItem->FirstChildElement("method"); if (pXmlId && pXmlName && pXmlDescription && pXmlWarning && pXmlMethod) { SlimItem item; TiXmlElement* pXmlPath = NULL; item.SetLock(m_sharedLock); item.SetId(::StrToIntA(pXmlId->GetText())); item.SetName(KUTF8_To_UTF16(pXmlName->GetText())); item.SetDescription(KUTF8_To_UTF16(pXmlDescription->GetText())); item.SetWarning(KUTF8_To_UTF16(pXmlWarning->GetText())); if (!stricmp(pXmlMethod->GetText(), "delete")) { item.SetMethod(SLIM_DELETE_FILE); } else if (!stricmp(pXmlMethod->GetText(), "compress")) { item.SetMethod(SLIM_COMPRESS_FILE); } pXmlPath = pXmlItem->FirstChildElement("path"); while (pXmlPath) { CStringA strOsFlag = pXmlPath->Attribute("os"); item.InsertPath(KUTF8_To_UTF16(pXmlPath->GetText()), strOsFlag); pXmlPath = pXmlPath->NextSiblingElement("path"); } if (item.Valid() || (KGetWinVersion() < WINVERSION_VISTA && item.Id() == 10)) { m_slimItems.Add(item); } } pXmlItem = pXmlItem->NextSiblingElement("slim"); } retval = TRUE; clean0: if (m_hNotifyWnd) { ::PostMessage(m_hNotifyWnd, SLIM_WM_LOADCOMPLETE, 0, 0); } return retval; }