예제 #1
0
	void Hub::sendMessage(const Message *message, const Stream* sourceStream)
	{
		// dump if requested
		if (dump)
		{
			dumpTime(cout, rawTime);
			message->dump(wcout);
			cout << std::endl;
		}
		
		// Called from the dbus thread, not the Hub thread, need to lock	
		lock();

		// write on all connected streams
		for (StreamsSet::iterator it = dataStreams.begin(); it != dataStreams.end();++it)
		{
			Stream* destStream(*it);
			
			if ((forward) && (destStream == sourceStream))
				continue;
			
			try
			{
				message->serialize(destStream);
				destStream->flush();
			}
			catch (DashelException e)
			{
				// if this stream has a problem, ignore it for now, and let Hub call connectionClosed later.
				std::cerr << "error while writing message" << std::endl;
			}
		}

		unlock();
	}
예제 #2
0
bool
aService::copyFile(const QString& srcFileName, const QString& destFileName, bool replaceIfExists)
{
	
	QFile srcFile(srcFileName);
	QFile destFile(destFileName);
	
	if(!srcFile.exists())
	{
		aLog::print(aLog::MT_ERROR, QObject::tr("aService copy: source file %1 not exist").arg(srcFileName));
		return false;
	}
	if(destFile.exists() && !replaceIfExists)
	{
		aLog::print(aLog::MT_ERROR, QObject::tr("aService copy: replace destination file %1").arg(destFileName));
		return false;
	}

	if(!srcFile.open( IO_ReadOnly ))
	{
		aLog::print(aLog::MT_ERROR, QObject::tr("aService copy: source file %1 open for read error").arg(srcFileName));
		return false;
	}
	if(!destFile.open( IO_WriteOnly))
	{
		aLog::print(aLog::MT_ERROR, QObject::tr("aService copy: destination file %1 open for write error").arg(destFileName));
		return false;
	}
	
	const int BUFFER_SIZE = 1024;
	Q_INT8 buffer[BUFFER_SIZE];
	QDataStream srcStream(&srcFile);
	QDataStream destStream(&destFile);

	while(!srcStream.atEnd())
	{
		int i = 0;
		while(!srcStream.atEnd() && i < BUFFER_SIZE)
		{
			srcStream >> buffer[i];
			i++;
		}
		for(int k = 0; k < i; k++)
		{
			destStream << buffer[k];
		}
	}
	srcFile.close();
	destFile.close();

	aLog::print(aLog::MT_INFO, QObject::tr("aService copy file %1 to %2 ok").arg(srcFileName).arg(destFileName));
	return true;
}
예제 #3
0
static inline bool performCopy(const String &source, const String &dest) {
	if (stappler::filesystem::exists(dest)) {
		stappler::filesystem::remove(dest);
	}
#if SPDEFAULT
	if (!stappler::filesystem::exists(dest)) {
		std::ofstream destStream(dest, std::ios::binary);
		auto f = openForReading(source);
		if (f && destStream.is_open()) {
			if (io::read(f, destStream) > 0) {
				return true;
			}
		}
		destStream.close();
	}
	return false;
#else
	return apr_file_copy(source.c_str(), dest.c_str(), APR_FPROT_FILE_SOURCE_PERMS, apr::AllocStack::get().top()) == APR_SUCCESS;
#endif
}
예제 #4
0
// Copy, recursively if necessary, the source to the destination
bool Foam::cp(const fileName& src, const fileName& dest)
{
    // Make sure source exists.
    if (!exists(src))
    {
        return false;
    }

    fileName destFile(dest);

    // Check type of source file.
    if (src.type() == fileName::FILE)
    {
        // If dest is a directory, create the destination file name.
        if (destFile.type() == fileName::DIRECTORY)
        {
            destFile = destFile/src.name();
        }

        // Make sure the destination directory exists.
        if (!isDir(destFile.path()) && !mkDir(destFile.path()))
        {
            return false;
        }

        // Open and check streams.
        std::ifstream srcStream(src.c_str());
        if (!srcStream)
        {
            return false;
        }

        std::ofstream destStream(destFile.c_str());
        if (!destStream)
        {
            return false;
        }

        // Copy character data.
        char ch;
        while (srcStream.get(ch))
        {
            destStream.put(ch);
        }

        // Final check.
        if (!srcStream.eof() || !destStream)
        {
            return false;
        }
    }
    else if (src.type() == fileName::DIRECTORY)
    {
        // If dest is a directory, create the destination file name.
        if (destFile.type() == fileName::DIRECTORY)
        {
            destFile = destFile/src.component(src.components().size() -1);
        }

        // Make sure the destination directory exists.
        if (!isDir(destFile) && !mkDir(destFile))
        {
            return false;
        }

        // Copy files
        fileNameList contents = readDir(src, fileName::FILE, false);
        forAll(contents, i)
        {
            if (POSIX::debug)
            {
                Info<< "Copying : " << src/contents[i]
                    << " to " << destFile/contents[i] << endl;
            }

            // File to file.
            cp(src/contents[i], destFile/contents[i]);
        }

        // Copy sub directories.
        fileNameList subdirs = readDir(src, fileName::DIRECTORY);
        forAll(subdirs, i)
        {
            if (POSIX::debug)
            {
                Info<< "Copying : " << src/subdirs[i]
                    << " to " << destFile << endl;
            }

            // Dir to Dir.
            cp(src/subdirs[i], destFile);
        }
    }

    return true;
}
예제 #5
0
파일: config.cpp 프로젝트: hkoehler/cute
/** reads the configuration file .cuterc*/
void readConfig()
{
	QDir dir = QDir::home();
	
	if( !dir.cd(".cute") ){
	dir.cd(".cute");
		QFileInfo fi(dir, ".cute");
		if(fi.exists()){
				if(fi.isDir())
					QMessageBox::warning(qApp->mainWidget(), "CUTE", "Cannot cd into .cute");
				else
					QMessageBox::warning(qApp->mainWidget(), "CUTE", "Cannot create directory");
			}
		else{
			QMessageBox::information(qApp->mainWidget(), "CUTE", "Creating ~/.cute directory");
			if(!dir.mkdir(".cute"))
				QMessageBox::information(qApp->mainWidget(), "CUTE", "Could not create ~/.cute directory");
			else{
				dir.cd(".cute");
				if(!dir.mkdir("scripts"))
					QMessageBox::information(qApp->mainWidget(), "CUTE", "Could not create ~/.cute/scripts directory");
				if(!dir.mkdir("macros"))
					QMessageBox::information(qApp->mainWidget(), "CUTE", "Could not create ~/.cute/macros directory");
				if(!dir.mkdir("sessions"))
					QMessageBox::information(qApp->mainWidget(), "CUTE", "Could not create ~/.cute/sessions directory");
			}
		}
	}

	// if cute version >= 0.1.6 langs dir is required
	if( !QDir(QDir::homeDirPath()+QDir::separator()+".cute"+QDir::separator()+"langs").exists() ) {
		QDir destDir = QDir::home();
		destDir.cd(".cute");
		destDir.mkdir("langs");
		destDir.cd("langs");
		QDir srcDir(LANG_DIR);
	
		QString data;
		QStringList dirList = srcDir.entryList();
		for( int i = 2; i < dirList.count(); i++)
			if( QFileInfo(srcDir.absPath()+QDir::separator()+dirList[i]).isFile()) {
				QFile srcFile(srcDir.absPath()+QDir::separator()+dirList[i]);
				QFile destFile(destDir.absPath()+QDir::separator()+dirList[i]);
				if(destFile.exists())
					continue;
				QTextStream destStream(&destFile);
				QTextStream srcStream(&srcFile);
				srcFile.open(IO_ReadOnly);
				destFile.open(IO_WriteOnly);
				data = srcStream.read();
				destStream << data;
				srcFile.close();
				destFile.close();
			}
	}
	
	QFile file(QDir::homeDirPath()+"/.cuterc");
	if(!file.exists()){
		QMessageBox::information(qApp->mainWidget(), "CUTE", "Creating ~/.cuterc");
		file.open(IO_ReadOnly);
		file.close();
		return;
	}
	
	//FILE *c_file = fopen("/home/heiko/.cuterc", "r");
	//PyRun_SimpleFile(c_file, ".cuterc");
	QString const_cmd("execfile(\".cuterc\")\n");
	dir = QDir::current();
	QDir::setCurrent( QDir::homeDirPath() );
	char *cmd = new char[1024];
	strcpy(cmd, const_cmd.latin1());
	PyRun_SimpleString(cmd);

	// read language config files
	QDir langDir = QDir(QDir::homeDirPath()+QDir::separator()+".cute"+QDir::separator()+"langs");
	QStringList langEntryList = langDir.entryList();
	QString langFile;
	for( int i = 2; i < langEntryList.count(); i++ ){
		QString langFile = langDir.absPath()+QDir::separator()+langEntryList[i];
		QFileInfo fi(langDir, langFile);
		if(fi.isFile()){
			langFile = QString("execfile(\"")+langFile+QString("\")\n");
			char *cmd = strdup(langFile);
			PyRun_SimpleString( cmd );
		}
	}

	QDir::setCurrent( dir.absPath() );
}