/* This file is part of cpp-ethereum. cpp-ethereum is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. cpp-ethereum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ /** @file FileIo.cpp * @author Arkadiy Paronyan arkadiy@ethdev.com * @date 2015 * Ethereum IDE client. */ #include #include #include #include #include #include "FileIo.h" using namespace dev::mix; void FileIo::makeDir(QString const& _path) { QDir dirPath(_path); if (!dirPath.exists()) dirPath.mkpath(dirPath.path()); } QString FileIo::readFile(QString const& _path) { QFile file(_path); if(file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream stream(&file); QString data = stream.readAll(); return data; } else throw std::runtime_error(tr("Error reading file %1").arg(_path).toStdString()); } void FileIo::writeFile(QString const& _path, QString const& _data) { QFile file(_path); if(file.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream stream(&file); stream << _data; } else throw std::runtime_error(tr("Error writing file %1").arg(_path).toStdString()); } void FileIo::copyFile(QString const& _sourcePath, QString const& _destPath) { if (!QFile::copy(_sourcePath, _destPath)) throw std::runtime_error(tr("Error copying file %1 to %2").arg(_sourcePath).arg(_destPath).toStdString()); }