mirror of
https://github.com/Swordfish90/cool-retro-term.git
synced 2024-08-26 00:00:33 +02:00
38 lines
703 B
C++
38 lines
703 B
C++
#include "fileio.h"
|
|
|
|
FileIO::FileIO()
|
|
{
|
|
}
|
|
|
|
bool FileIO::write(const QString& sourceUrl, const QString& data) {
|
|
if (sourceUrl.isEmpty())
|
|
return false;
|
|
|
|
QUrl url(sourceUrl);
|
|
QFile file(url.toLocalFile());
|
|
if (!file.open(QFile::WriteOnly | QFile::Truncate))
|
|
return false;
|
|
|
|
QTextStream out(&file);
|
|
out << data;
|
|
file.close();
|
|
return true;
|
|
}
|
|
|
|
QString FileIO::read(const QString& sourceUrl) {
|
|
if (sourceUrl.isEmpty())
|
|
return "";
|
|
|
|
QUrl url(sourceUrl);
|
|
QFile file(url.toLocalFile());
|
|
if (!file.open(QFile::ReadOnly))
|
|
return "";
|
|
|
|
QTextStream in(&file);
|
|
QString result = in.readAll();
|
|
|
|
file.close();
|
|
|
|
return result;
|
|
}
|