// // remove the file of the trashItem // bool TrashItem::removeFile() { if (this->fileExists()) { QFile file(fullFilePath()); qDebug() << __func__ << " - 'this->fileName': " << this->fileName; qDebug() << __func__ << " - 'file': " << file.fileName(); return file.remove(); } return false; }
void UIWizardNewVDPage3::onSelectLocationButtonClicked() { /* Get current folder and filename: */ QFileInfo fullFilePath(mediumPath()); QDir folder = fullFilePath.path(); QString strFileName = fullFilePath.fileName(); /* Set the first parent folder that exists as the current: */ while (!folder.exists() && !folder.isRoot()) { QFileInfo folderInfo(folder.absolutePath()); if (folder == QDir(folderInfo.absolutePath())) break; folder = folderInfo.absolutePath(); } /* But if it doesn't exists at all: */ if (!folder.exists() || folder.isRoot()) { /* Use recommended one folder: */ QFileInfo defaultFilePath(absoluteFilePath(strFileName, m_strDefaultPath)); folder = defaultFilePath.path(); } /* Prepare backends list: */ QVector<QString> fileExtensions; QVector<KDeviceType> deviceTypes; CMediumFormat mediumFormat = fieldImp("mediumFormat").value<CMediumFormat>(); mediumFormat.DescribeFileExtensions(fileExtensions, deviceTypes); QStringList validExtensionList; for (int i = 0; i < fileExtensions.size(); ++i) if (deviceTypes[i] == KDeviceType_HardDisk) validExtensionList << QString("*.%1").arg(fileExtensions[i]); /* Compose full filter list: */ QString strBackendsList = QString("%1 (%2)").arg(mediumFormat.GetName()).arg(validExtensionList.join(" ")); /* Open corresponding file-dialog: */ QString strChosenFilePath = QIFileDialog::getSaveFileName(folder.absoluteFilePath(strFileName), strBackendsList, thisImp(), VBoxGlobal::tr("Please choose a location for new virtual hard drive file")); /* If there was something really chosen: */ if (!strChosenFilePath.isEmpty()) { /* If valid file extension is missed, append it: */ if (QFileInfo(strChosenFilePath).suffix().isEmpty()) strChosenFilePath += QString(".%1").arg(m_strDefaultExtension); m_pLocationEditor->setText(QDir::toNativeSeparators(strChosenFilePath)); m_pLocationEditor->selectAll(); m_pLocationEditor->setFocus(); } }
void SmtpThread::moveToSentDir(void) { CkString strEmlPath; fullFilePath(m_queueDir.c_str(),m_filename.c_str(),strEmlPath); CkString strToPath; fullFilePath(m_sentDir.c_str(),m_filename.c_str(),strToPath); #if defined(TEST_SMTPQ) logNameValue("movingFile",strEmlPath.getString()); logNameValue("movingTo",strToPath.getString()); #endif if (!MoveFile(strEmlPath.getString(),strToPath.getString())) { CkString strWindowsError; strWindowsError.appendLastWindowsError(); logString("Failed to move file to sent directory.."); logNameValue("WindowsError",strWindowsError.getString()); logNameValue("EML file",m_filename); logNameValue("Sent directory",m_sentDir); #if defined(TEST_SMTPQ) logNameValue("deletingFile4",strEmlPath.getString()); #endif if (!DeleteFile(strEmlPath.getString())) { CkString strWindowsError; strWindowsError.appendLastWindowsError(); logNameValue("Failed to delete file",m_filename); logNameValue("WindowsError",strWindowsError.getString()); // This EML was abandoned in the queue directory.. m_emlAbandoned = true; } } return; }
/** * Fetches the content of the trashed file * * @return */ QString TrashItem::loadFileFromDisk() { QFile file(fullFilePath()); if (!file.open(QIODevice::ReadOnly)) { qDebug() << __func__ << " - 'file': " << file.fileName(); qDebug() << __func__ << " - " << file.errorString(); return ""; } QTextStream in(&file); in.setCodec("UTF-8"); QString text = in.readAll(); file.close(); return text; }
/** * Restores a trashed file and removes the trash item * * @return */ bool TrashItem::restoreFile() { if (!fileExists()) { return false; } QString newFilePath = restorationFilePath(); if (newFilePath.isEmpty()) { return false; } QFile file(fullFilePath()); if (file.rename(newFilePath)) { remove(); return true; } return false; }
//----------------------------------------------------------------------------- //static QString EdProject::ComposeFullFilePath(const QString& absolutePath, const QString& projectName) { QString fullFilePath( absolutePath ); if(!fullFilePath.endsWith('/')) { fullFilePath.append('/'); } fullFilePath.append( projectName ); if(!fullFilePath.endsWith(ED_PROJECT_FILE_EXTENSION)) { fullFilePath.append(ED_PROJECT_FILE_EXTENSION); } return fullFilePath; }
/** * Checks if file of trashItem exists in the filesystem and is readable * * @return bool */ bool TrashItem::fileExists() { QFile file(fullFilePath()); QFileInfo fileInfo(file); return file.exists() && fileInfo.isFile() && fileInfo.isReadable(); }
JSONObject* WriteVisitor::createJSONPagedLOD(osg::PagedLOD *plod) { if (!plod) { return 0; } if (_maps.find(plod) != _maps.end()) { return _maps[plod]->getShadowObject(); } osg::ref_ptr<JSONObject> jsonPlod = new JSONNode; _maps[plod] = jsonPlod; // Center Mode osg::ref_ptr<JSONValue<std::string> > centerMode = new JSONValue<std::string>("USE_BOUNDING_SPHERE_CENTER"); if (plod->getCenterMode() == osg::LOD::USER_DEFINED_CENTER) { centerMode = new JSONValue<std::string>("USER_DEFINED_CENTER"); } else if (plod->getCenterMode() == osg::LOD::UNION_OF_BOUNDING_SPHERE_AND_USER_DEFINED){ centerMode = new JSONValue<std::string>("UNION_OF_BOUNDING_SPHERE_AND_USER_DEFINED"); } jsonPlod->getMaps()["CenterMode"] = centerMode; // User defined center and radius jsonPlod->getMaps()["UserCenter"] = new JSONVec4Array(osg::Vec4(plod->getCenter().x(), plod->getCenter().y(),plod->getCenter().z(), plod->getRadius())); // Range Mode osg::ref_ptr<JSONValue<std::string> > rangeMode = new JSONValue<std::string>("DISTANCE_FROM_EYE_POINT"); if (plod->getRangeMode() == osg::LOD::PIXEL_SIZE_ON_SCREEN) { rangeMode = new JSONValue<std::string>("PIXEL_SIZE_ON_SCREEN"); } jsonPlod->getMaps()["RangeMode"] = rangeMode; // Range List osg::ref_ptr<JSONObject> rangeObject = new JSONObject; for (unsigned int i =0; i< plod->getRangeList().size(); i++) { std::stringstream ss; ss << "Range "; ss << i; std::string str = ss.str(); rangeObject->getMaps()[str] = new JSONVec2Array(osg::Vec2(plod->getRangeList()[i].first, plod->getRangeList()[i].second)); } jsonPlod->getMaps()["RangeList"] = rangeObject; // File List osg::ref_ptr<JSONObject> fileObject = new JSONObject; for (unsigned int i =0; i< plod->getNumFileNames(); i++) { std::stringstream ss; ss << "File "; ss << i; std::string str = ss.str(); // We need to convert first from osg format to osgjs format. osg::ref_ptr<osg::Node> n = osgDB::readNodeFile(plod->getDatabasePath() + plod->getFileName(i)+".gles"); if (n) { std::string filename(osgDB::getNameLessExtension(plod->getFileName(i))+".osgjs"); std::string fullFilePath(osgDB::getFilePath(_baseName) + osgDB::getNativePathSeparator() + filename); fileObject->getMaps()[str] = new JSONValue<std::string>(_baseLodURL + filename); osgDB::makeDirectoryForFile(fullFilePath); if (_baseLodURL.empty()) _baseLodURL = osgDB::getFilePath(filename) + osgDB::getNativePathSeparator() ; osg::ref_ptr<osgDB::Options> options = osgDB::Registry::instance()->getOptions()->cloneOptions(); options->setPluginStringData(std::string("baseLodURL"), _baseLodURL); osgDB::writeNodeFile(*n, fullFilePath, options.get()); } else fileObject->getMaps()[str] = new JSONValue<std::string>(""); } jsonPlod->getMaps()["RangeDataList"] = fileObject; return jsonPlod.release(); }
bool SmtpThread::sendEmail(bool &bFailureIsFinal) { // This must get set to false for a known case where it might be possible // to retry... bFailureIsFinal = true; CkString strEmlPath; fullFilePath(m_queueDir.c_str(),m_filename.c_str(),strEmlPath); // First load the email. CkByteData mimeData; bool success = mimeData.loadFile(strEmlPath.getString()); if (!success) { // Does the file exist? logNameValue("FailedToLoad",m_filename); CkFileAccess fac; if (fac.FileExists(strEmlPath.getString())) { logString("File may be locked by another process, will retry..."); bFailureIsFinal = false; } else { logString("File does not exist."); } return false; } // We pass 0 for the From and Recipients args because that info is embedded within the mimeData. // The special x-smtp* headers will be decoded and removed before sending. // All of the MailMan property settings (SMTP host, login, password, etc.) as well as the From/Recipient // information is contained in the x-smtp* headers. success = m_mailman->SendMimeBytes((const char *)0,(const char *)0,mimeData); if (!success) { string errText = m_mailman->lastErrorText(); logNameValue("SendMimeBytes",errText); // We can retry from some errors... string failReason = m_mailman->smtpFailReason(); logNameValue("SmtpFailReason",failReason); if (failReason == "Timeout" || failReason == "ConnectionLost" || failReason == "FromFailure" || failReason == "DataFailure" || failReason == "GreetingError" || failReason == "ConnectFailed") { bFailureIsFinal = false; } // Make sure the SMTP connection is closed after a failure. m_mailman->CloseSmtpConnection(); } return success; }
// Loads the file, sends the email, and logs the results. // Sets the m_running flag to false when done. void SmtpThread::runThread(void) { int tryCount = 0; CkString lastErrorText; tryAgain: if (!m_logErrorsOnly) { if (tryCount > 0) { logNameValue("Re-trying",m_filename); logNameValueInt("TryCount",tryCount + 1); } else { logNameValue("Sending",m_filename); } } bool success = false; bool bFailureIsFinal = true; success = sendEmail(bFailureIsFinal); m_mailman->get_LastErrorText(lastErrorText); if (success) { if (m_saveSent) { moveToSentDir(); } else { CkString strEmlPath; fullFilePath(m_queueDir.c_str(),m_filename.c_str(),strEmlPath); #if defined(TEST_SMTPQ) logNameValue("deletingFile3",strEmlPath.getString()); #endif BOOL b = DeleteFile(strEmlPath.getString()); if (!b) { CkString strWindowsError; strWindowsError.appendLastWindowsError(); logNameValue("Failed to delete file",m_filename); logNameValue("WindowsError",strWindowsError.getString()); // This EML was abandoned in the queue directory.. m_emlAbandoned = true; } } if (!m_logErrorsOnly) { logNameValue("Send successful",m_filename); } } else if (bFailureIsFinal || (!m_maxRetryCount) || (tryCount > m_maxRetryCount)) { if (bFailureIsFinal) { logNameValue("Send Failed, error is final and a retry won't succeed.",m_filename); } else { logNameValue("Send Failed, no more retries",m_filename); } CkString strEmlPath; fullFilePath(m_queueDir.c_str(),m_filename.c_str(),strEmlPath); CkString strToPath; fullFilePath(m_undeliverableDir.c_str(),m_filename.c_str(),strToPath); #if defined(TEST_SMTPQ) logNameValue("movingFile2",strEmlPath.getString()); logNameValue("movingTo2",strToPath.getString()); #endif if (!MoveFile(strEmlPath.getString(),strToPath.getString())) //if (!MoveFile(strEmlPath.getString(),m_undeliverableDir.c_str())) { #if defined(TEST_SMTPQ) logNameValue("deletingFile2",strEmlPath.getString()); #endif if (!DeleteFile(strEmlPath.getString())) { // This EML was abandoned in the queue directory.. m_emlAbandoned = true; } } } else { logString(lastErrorText.getString()); logNameValue("Send Failed, will try again",m_filename); tryCount++; int delayMs = 1000; /* tryCount delayTime -------- --------- 1 5 sec 2 10 sec 3 15 sec 4 1 min 5 1.5 minutes 6 2 minutes 7 5 minutes 8 10 minutes 9 15 minutes 10 20 minutes */ if (tryCount < 4) { // 5 seconds * tryCount delayMs = 5000 * tryCount; } else if (tryCount < 7) { delayMs = 30000 * (tryCount-2); } else // up to g_maxRetryCount (max 10) tries { delayMs = 300000 * (tryCount-6); } logNameValueInt("tryCount",tryCount); logNameValueInt("sleepMillisec",delayMs); // When waiting for the retry, continue updating the heartbeat so that the ThreadManager // knows the thread is not dead. while (delayMs) { int t = delayMs > 1000 ? 1000 : delayMs; ::Sleep(t); delayMs -= t; } goto tryAgain; } m_running = false; return; }