Console::Console(QString _name, CommandInterpreter *_interpreter) : stopping(false), name(_name), interpreter(_interpreter) { QObject::connect(this, SIGNAL(read(QString)), interpreter, SLOT(handleString(QString))); QObject::connect(interpreter, SIGNAL(write(QString)), this, SLOT(write(QString))); QObject::connect(interpreter, SIGNAL(writeAsync(QString)), this, SLOT(writeAsync(QString))); QObject::connect(interpreter, SIGNAL(exit()), this, SLOT(quit())); /** allow conditional parsing of the inputrc file */ rl_readline_name = name.toAscii(); /** tell the completer that we want a crack first. */ rl_console = this; rl_attempted_completion_function = &Console::ConsoleCompletion; rl_event_hook = poll; rl_catch_signals = 0; // rl_set_keyboard_input_timeout(100000); using_history(); historyFile = QDir::homePath() + QString("/.%1_history").arg(name); QFile file(historyFile); if (!file.exists()) { // create file file.open(QIODevice::ReadWrite); file.close(); } read_history(historyFile.toAscii().constData()); // rl_bind_key('\t', readline_completion); }
bool FileWriter::writeToFile(char *buf, size_t size) { if (init == true) { fs.open(outPath.c_str(), std::fstream::out); if (!(fs)) { std::cerr << "ERROR FileWriter::FileWriter - Couldnt open file: " << outPath << std::endl; exit(EXIT_FAILURE); } init = false; } size_t counter = 0; while (counter < size) { if (pos == bufferSize) { if (writeAsync() == false) { std::cerr << "Something went terribly wrong! " << std::endl; return false; } pos = 0; continue; } workBuffer[pos] = buf[counter]; ++pos; ++counter; } //fs.write(buf, size); return true; }
bool FileWriter::closeFile() { if (fs.is_open()) { writeAsync(); localMtx.lock(); fs.close(); localMtx.unlock(); #ifndef WINDOWS std::string sys = "md5sum "; sys += outPath; std::cout << std::endl; std::cout << "Hash5 for " << outPath << ":" << std::endl; if (system(sys.c_str())) {} std::cout << std::endl; #endif } return true; }