bool ResourceCache::VHasResource(CMResource& r) { std::vector<std::string> elems = util::split(r.m_name, '.'); if(elems.size() < 2) { return false; } std::string pattern = elems.back(); auto it = m_loader.find(pattern); std::string subFolder(""); if(it != m_loader.end()) { //return false; subFolder = it->second->VSubFolder(); } std::string fileName = m_pFile->VGetName() + "/" + subFolder + r.m_name; std::ifstream file(fileName, std::ios::in | std::ios::binary); bool good = file.good(); file.close(); return good; }
NS_IMETHODIMP nsPop3IncomingServer::GetDeferredToAccount(nsACString& aRetVal) { nsresult rv = GetCharValue("deferred_to_account", aRetVal); if (aRetVal.IsEmpty()) return rv; // We need to repair broken profiles that defer to hidden or invalid servers, // so find out if the deferred to account has a valid non-hidden server, and // if not, defer to the local folders inbox. nsCOMPtr<nsIMsgAccountManager> acctMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID); bool invalidAccount = true; if (acctMgr) { nsCOMPtr<nsIMsgAccount> account; nsCOMPtr<nsIMsgIncomingServer> server; rv = acctMgr->GetAccount(aRetVal, getter_AddRefs(account)); if (account) { account->GetIncomingServer(getter_AddRefs(server)); if (server) server->GetHidden(&invalidAccount); } if (invalidAccount) { nsCOMPtr<nsIMsgIncomingServer> localServer; nsCOMPtr<nsIMsgAccount> localAccount; rv = acctMgr->GetLocalFoldersServer(getter_AddRefs(localServer)); NS_ENSURE_SUCCESS(rv, rv); // Try to copy any folders that have been stranded in the hidden account // into the local folders account. if (server) { nsCOMPtr<nsIMsgFolder> hiddenRootFolder; nsCOMPtr<nsIMsgFolder> localFoldersRoot; server->GetRootFolder(getter_AddRefs(hiddenRootFolder)); localServer->GetRootFolder(getter_AddRefs(localFoldersRoot)); if (hiddenRootFolder && localFoldersRoot) { // We're going to iterate over the folders in Local Folders-1, // though I suspect only the Inbox will have messages. I don't // think Sent Mail could end up here, but if any folders have // messages, might as well copy them to the real Local Folders // account. nsCOMPtr<nsISimpleEnumerator> enumerator; rv = hiddenRootFolder->GetSubFolders(getter_AddRefs(enumerator)); if (NS_SUCCEEDED(rv)) { bool hasMore; while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore) { nsCOMPtr<nsISupports> item; enumerator->GetNext(getter_AddRefs(item)); nsCOMPtr<nsIMsgFolder> subFolder(do_QueryInterface(item)); if (subFolder) { nsCOMPtr<nsIMsgDatabase> subFolderDB; subFolder->GetMsgDatabase(getter_AddRefs(subFolderDB)); if (subFolderDB) { // Copy any messages in this sub-folder of the hidden // account to the corresponding folder in Local Folders. RefPtr<nsMsgKeyArray> keys = new nsMsgKeyArray; rv = subFolderDB->ListAllKeys(keys); nsCOMPtr<nsIMutableArray> hdrsToCopy(do_CreateInstance(NS_ARRAY_CONTRACTID)); MsgGetHeadersFromKeys(subFolderDB, keys->m_keys, hdrsToCopy); uint32_t numHdrs = 0; if (hdrsToCopy) hdrsToCopy->GetLength(&numHdrs); if (numHdrs) { // Look for a folder with the same name in Local Folders. nsCOMPtr<nsIMsgFolder> dest; nsString folderName; subFolder->GetName(folderName); localFoldersRoot->GetChildNamed(folderName, getter_AddRefs(dest)); if (dest) dest->CopyMessages(subFolder, hdrsToCopy, false, nullptr, nullptr, false,false); // Should we copy the folder if the dest doesn't exist? } } } } } } } rv = acctMgr->FindAccountForServer(localServer, getter_AddRefs(localAccount)); NS_ENSURE_SUCCESS(rv, rv); if (!localAccount) return NS_ERROR_NOT_AVAILABLE; localAccount->GetKey(aRetVal); // Can't call SetDeferredToAccount because it calls GetDeferredToAccount. return SetCharValue("deferred_to_account", aRetVal); } } return rv; }
void CFtpManager::SyncServerFolder(CConnection * con, CRealFtpClient * ftpClient, CString &folder) { //TRACE2(" Synch folder %s %s \n", con->name, folder); // Download directory information CFtpManager ftp; bool r = ftp.GetFtpDirectory(con, folder, ftpClient); if(!r){return;} CLocalStore localStore; bool local_store = false; CFileContainer dir; dir.host = CString(con->host); dir.path = CString(folder); dir.name = CString(_T("")); local_store = localStore.IsFolderStored(dir); //TRACE2(" folder: %s l: %d \n ", folder, local_store); // Read directory information, process subfolders. std::vector<CFileContainer> files; ftp.ReadLocalDirectory(con, folder, files); int i = 0; for(i = 0; i < files.size(); i++) { CFileContainer f; f = (CFileContainer)files[i]; bool descend = true; bool download = false; bool upload = false; //TRACE1(" name %s \n", f.name); // If store local, sync.... TODO if(f.dir == 0 && local_store) // is file and local store { CFileStatus status; if(CFile::GetStatus(f.localPath + f.name, status) == 0) // not found, not local { download = true; } else { // File exists ULONGLONG local_size = status.m_size; // is local file stale? CString fileDate = f.remoteDate; // 2012/11/23 15:00 COleDateTime myDtTime; CTime sysTime; if(myDtTime.ParseDateTime(fileDate)) { SYSTEMTIME st_remote; if(myDtTime.GetAsSystemTime(st_remote)) { sysTime = st_remote; } CTime ct_local = status.m_mtime; SYSTEMTIME st_local; ct_local.GetAsSystemTime(st_local); //DWORD x = ft_remote-> _int64 d = Delta(st_local, st_remote); // d = d / 10000000; //TRACE1(" d: %ld \n", d); // -200859136 // 105568 1 day - if(d > 86400) // remote file was updated a day later than the local. { download = true; } //TRACE2(" size: %d : %d \n", f.size, local_size); if(d < 86400 && f.size != local_size) // local file updated a day after the remote file. { upload = true; } } } } if(download) { CWaitDialog wait; ftp.ReceiveFile(con, f, wait); } // if file is local but not remote send it if(upload) { CWaitDialog wait; //ftp.SendFile(con, f, wait); } // If older than a year skip, unless local store long age = f.GetAge(); //TRACE2(" date %s age: %d \n", f.remoteDate, age); if(age > 1000){ // this only applies if not local store directory descend = false; } if(f.path.Compare(_T("/proc/")) == 0){ descend = false; } if(f.path.Compare(_T("/sys/")) == 0){ descend = false; } if(f.dir && descend) { CString subFolder(CString(f.path + f.name + _T("/"))); SyncServerFolder(con, ftpClient, subFolder); if(f.path.Find(_T("newsletter-form")) != -1){ int i = 0; } } } }