void DBMaintenance::Do1DayMaintenance() { DateTime yesterday; DateTime tendaysago; yesterday.Add(0,0,0,-1); tendaysago.Add(0,0,0,-10); m_db->Execute("BEGIN;"); SQLite3DB::Statement st=m_db->Prepare("DELETE FROM tblIdentity WHERE (DateAdded<? AND LastSeen IS NULL) OR LastSeen<? AND Ignored=0;"); st.Bind(0,tendaysago.Format("%Y-%m-%d")); st.Bind(1,tendaysago.Format("%Y-%m-%d")); st.Step(); st=m_db->Prepare("DELETE FROM tblAnnounceIndex WHERE Date<?;"); st.Bind(0,yesterday.Format("%Y-%m-%d")); st.Step(); st=m_db->Prepare("DELETE FROM tblIdentityEdition WHERE Date<?;"); st.Bind(0,yesterday.Format("%Y-%m-%d")); st.Step(); st=m_db->Prepare("DELETE FROM tblInsertedMessageIndex WHERE Date<?;"); st.Bind(0,yesterday.Format("%Y-%m-%d")); st.Step(); st=m_db->Prepare("DELETE FROM tblRetrievedMessageIndex WHERE Date<?;"); st.Bind(0,yesterday.Format("%Y-%m-%d")); st.Step(); m_db->Execute("COMMIT;"); m_log->Error("DBMaintenance::Do1DayMaintenance"); }
void FreenetMessageInserter::StartTopicInsert(const int localidentityid, const std::string &channel, const std::string &topic) { SQLite3DB::Statement st; std::string idstr(""); std::string data(""); std::string datalengthstr(""); DateTime now; FCPv2::Message mess("ClientPut"); LoadLocalIdentityPrivateKey(localidentityid); if(m_identitykeys[localidentityid]!="") { std::string indexstr("0"); FreenetMessage fm; fm["type"]="settopic"; fm["channel"]=channel; fm["sentdate"]=now.Format("%Y-%m-%d %H:%M:%S"); fm.Body()=topic; data=fm.GetMessageText(); StringFunctions::Convert(localidentityid,idstr); StringFunctions::Convert(data.size(),datalengthstr); StringFunctions::Convert(GetNextMessageIndex(localidentityid,now),indexstr); st=m_db->Prepare("INSERT INTO tblInsertedMessageIndex(LocalIdentityID,Date,MessageIndex) VALUES(?,?,?);"); st.Bind(0,localidentityid); st.Bind(1,now.Format("%Y-%m-%d")); st.Bind(2,indexstr); st.Step(); mess["URI"]="SSK@"+m_identitykeys[localidentityid].substr(4)+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|Message-"+indexstr; mess["Identifier"]=m_fcpuniqueidentifier+"|"+idstr+"|"+now.Format("%Y-%m-%d")+"|"+indexstr+"|"+mess["URI"]; mess["RealTimeFlag"]="true"; mess["UploadFrom"]="direct"; mess["PriorityClass"]=m_insertpriority; mess["ExtraInsertsSingleBlock"]="0"; mess["DataLength"]=datalengthstr; mess["Metadata.ContentType"]=""; m_fcp->Send(mess); m_fcp->Send(std::vector<char>(data.begin(),data.end())); m_log->Debug("FreenetMessageInserter::StartInsert started insert of channel topic "+mess["Identifier"]); } }
const int FreenetMessageInserter::GetNextMessageIndex(const int localidentityid, const DateTime &date) { int index=0; SQLite3DB::Statement st=m_db->Prepare("SELECT IFNULL(MAX(MessageIndex)+1,0) FROM tblInsertedMessageIndex WHERE LocalIdentityID=? AND Date=?;"); st.Bind(0,localidentityid); st.Bind(1,date.Format("%Y-%m-%d")); st.Step(); if(st.RowReturned()) { st.ResultInt(0,index); } return index; }
void LogFile::LogText(const CString& cszText, bool bLongDate) { if (m_spStream == NULL) return; DateTime dt = DateTime::Now(); CString cszTemp; cszTemp.Format(_T("[%s] %s"), dt.Format(bLongDate ? _T("%Y-%m-%d %H:%M:%S") : _T("%H:%M:%S")).GetString(), cszText.GetString()); m_spStream->Write(cszTemp); m_spStream->WriteEndline(); m_spStream->Flush(); }
void FreenetMessageInserter::StartPrivateInsert(const int localidentityid, const int recipientidentityid, const std::string &message) { RSAKeyPair rsa; std::string idstr(""); std::string publickey(""); std::string rsapublickey(""); std::string data(""); std::string datalengthstr(""); DateTime now; FCPv2::Message mess("ClientPut"); LoadLocalIdentityPrivateKey(localidentityid); SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, RSAPublicKey FROM tblIdentity WHERE IdentityID=?;"); st.Bind(0,recipientidentityid); st.Step(); if(st.RowReturned()) { st.ResultText(0,publickey); st.ResultText(1,rsapublickey); } if(publickey!="" && rsapublickey!="" && rsa.SetFromEncodedPublicKey(rsapublickey)) { if(m_identitykeys[localidentityid]!="") { std::string indexstr("0"); FreenetMessage fm; fm["type"]="privatemessage"; fm["recipient"]=publickey; fm["sentdate"]=now.Format("%Y-%m-%d %H:%M:%S"); rsa.Encrypt(message,fm.Body()); data=fm.GetMessageText(); StringFunctions::Convert(localidentityid,idstr); StringFunctions::Convert(data.size(),datalengthstr); StringFunctions::Convert(GetNextMessageIndex(localidentityid,now),indexstr); st=m_db->Prepare("INSERT INTO tblInsertedMessageIndex(LocalIdentityID,Date,MessageIndex) VALUES(?,?,?);"); st.Bind(0,localidentityid); st.Bind(1,now.Format("%Y-%m-%d")); st.Bind(2,indexstr); st.Step(); mess["URI"]="SSK@"+m_identitykeys[localidentityid].substr(4)+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|Message-"+indexstr; mess["Identifier"]=m_fcpuniqueidentifier+"|"+idstr+"|"+now.Format("%Y-%m-%d")+"|"+indexstr+"|"+mess["URI"]; mess["RealTimeFlag"]="true"; mess["UploadFrom"]="direct"; mess["PriorityClass"]=m_insertpriority; mess["ExtraInsertsSingleBlock"]="0"; mess["DataLength"]=datalengthstr; mess["Metadata.ContentType"]=""; m_fcp->Send(mess); m_fcp->Send(std::vector<char>(data.begin(),data.end())); m_log->Debug("FreenetMessageInserter::StartInsert started insert of private message "+mess["Identifier"]); } } }
bool BmpClipboardDumper::Dump(POEngine* pEngine) { m_strErr.Empty(); m_bAbort = false; chuwin32::DibBitmap dib; if( !PrepareDib(dib, m_strErr) ) { return false; } uint32* const pSrc = dib.m_pBits; const int32 nWidth = dib.GetWidth(); const int32 nHeight = dib.GetHeight(); const int32 nPixelCount = nWidth * nHeight; Buffer buf24; if( !buf24.SetSize(nPixelCount * 3) ) { m_strErr = k_szNotEnoughMemory; return false; } uint8* const pBuf24 = buf24.GetWritePtr(); uint8* pBufTmp24 = pBuf24; for(int32 i = 0; i < nPixelCount; ++i) { uint32 nSrc = pSrc[i]; uint8 r = uint8( (nSrc >> 16) & 0x000000ff); uint8 g = uint8( (nSrc >> 8) & 0x000000ff); uint8 b = uint8( (nSrc >> 0) & 0x000000ff); pBufTmp24[0] = r; pBufTmp24[1] = g; pBufTmp24[2] = b; pBufTmp24 += 3; } PngDumpData dd; dd.pixels = buf24; dd.width = nWidth; dd.height = nHeight; dd.pixelFormat = PF_24bppRgb; // Determine the file name DateTime date = DateTime::GetNow(); String strDate = date.FormatDate(); String strTime = date.FormatTime(); String strFileNameBase = L"shot-" + date.Format(DateFormat::Compact); String strDestDir; if( m_settings.useDefaultDir ) { strDestDir = GetTempDir(); if( strDestDir.IsEmpty() ) { // Cannot get the temp directory. I wonder when this can happen (maybe a bad registry settings ?) // Anyway, we inform the user m_strErr = k_szCannotRetrieveTempPath; return false; } } else { if( m_settings.customDir.IsEmpty() ) { m_strErr = k_szCustomDirIsEmpty; m_strErr = m_strErr + L"\n"; m_strErr = m_strErr + k_szCustomDirIsEmpty2; return false; } strDestDir = m_settings.customDir; } strDestDir = FilePath::AddSeparator(strDestDir); String strFileNameFinal = strFileNameBase + L".png"; String strTotalFinalPath = FilePath::Combine(strDestDir, strFileNameFinal); // Find a unique name // With the date/time in the name, there is very little chance to get twice the same name, // but when pasting very fast, one second of delay might be not enough if( File::Exists(strDestDir + strFileNameFinal) ) { // Oops String strCountW; // 100 tries max, oterwise er... 100 dump in less than one second ? int32 iCount = 1; const int32 nMaxCount = 100; for(; iCount <= nMaxCount; ++iCount) { strCountW = L"(" + String::FromInt(iCount) + L")"; strFileNameFinal = strFileNameBase + strCountW + L".png"; if( !File::Exists(strDestDir + strFileNameFinal) ) { // Found ! ^^ break; } } if( iCount == nMaxCount ) { // Warn the user anyway that him and his 8 THz computer are too fast m_strErr = k_szFileAlreadyExists; return false; } } m_strFileName = strFileNameFinal; if( m_settings.askForFileName ) { // Give the opportunity to the user to change the file name DumpStateChanged.Fire(DS_AskForFileName); if( m_bAbort ) { // Aborted return false; } strFileNameFinal = m_strFileName; } if( !Directory::Exists(strDestDir) ) { m_strErr = k_szDirectoryDoesNotExists + strDestDir; return false; } strTotalFinalPath = FilePath::Combine(strDestDir, strFileNameFinal); m_strFilePath = strTotalFinalPath; DumpStateChanged.Fire(DS_Creating); bool bResult = false; if( m_settings.maximizeCompression ) { bResult = pEngine->OptimizeExternalBuffer(dd, strTotalFinalPath); if( !bResult ) { m_strErr = pEngine->GetLastErrorString(); } } else { File fileOut; if( !fileOut.Open(strTotalFinalPath, File::modeWrite) ) { m_strErr = k_szCannotOpenOutput; } else { PngDumpSettings ds; ds.zlibCompressionLevel = 6; if( !PngDumper::Dump(fileOut, dd, ds) ) { m_strErr = k_szErrorWhileDumping; } else { bResult = true; } } } if( bResult ) { m_strPreviousFileName = m_strFileName; } return bResult; }