forked from qt-creator/qt-creator
ProjectExplorer: Replace a use of FileReader by FilePath::fileContents()
Change-Id: I24914f666fbe84b7870fb24c591e0838d4957a8e Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -11,14 +11,12 @@
|
|||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
|
||||||
#include <utils/qtcassert.h>
|
|
||||||
#include <utils/macroexpander.h>
|
|
||||||
#include <utils/templateengine.h>
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/macroexpander.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/stringutils.h>
|
||||||
|
#include <utils/templateengine.h>
|
||||||
|
|
||||||
#include <QDir>
|
|
||||||
#include <QDirIterator>
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
@@ -111,9 +109,9 @@ Result<> JsonWizardFileGenerator::setup(const QVariant &data)
|
|||||||
Result<Core::GeneratedFile> JsonWizardFileGenerator::generateFile(const File &file, MacroExpander *expander)
|
Result<Core::GeneratedFile> JsonWizardFileGenerator::generateFile(const File &file, MacroExpander *expander)
|
||||||
{
|
{
|
||||||
// Read contents of source file
|
// Read contents of source file
|
||||||
FileReader reader;
|
const Result<QByteArray> contents = file.source.fileContents();
|
||||||
if (!reader.fetch(file.source))
|
if (!contents)
|
||||||
return ResultError(reader.errorString());
|
return ResultError(contents.error());
|
||||||
|
|
||||||
// Generate file information:
|
// Generate file information:
|
||||||
Core::GeneratedFile gf;
|
Core::GeneratedFile gf;
|
||||||
@@ -122,7 +120,7 @@ Result<Core::GeneratedFile> JsonWizardFileGenerator::generateFile(const File &fi
|
|||||||
if (!file.keepExisting) {
|
if (!file.keepExisting) {
|
||||||
if (file.isBinary.toBool()) {
|
if (file.isBinary.toBool()) {
|
||||||
gf.setBinary(true);
|
gf.setBinary(true);
|
||||||
gf.setBinaryContents(reader.data());
|
gf.setBinaryContents(contents.value());
|
||||||
} else {
|
} else {
|
||||||
// TODO: Document that input files are UTF8 encoded!
|
// TODO: Document that input files are UTF8 encoded!
|
||||||
gf.setBinary(false);
|
gf.setBinary(false);
|
||||||
@@ -146,7 +144,8 @@ Result<Core::GeneratedFile> JsonWizardFileGenerator::generateFile(const File &fi
|
|||||||
});
|
});
|
||||||
|
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
gf.setContents(TemplateEngine::processText(&nested, QString::fromUtf8(reader.text()),
|
gf.setContents(TemplateEngine::processText(&nested,
|
||||||
|
QString::fromUtf8(normalizeNewlines(contents.value())),
|
||||||
&errorMessage));
|
&errorMessage));
|
||||||
if (!errorMessage.isEmpty()) {
|
if (!errorMessage.isEmpty()) {
|
||||||
return ResultError(Tr::tr("When processing \"%1\":<br>%2")
|
return ResultError(Tr::tr("When processing \"%1\":<br>%2")
|
||||||
|
Reference in New Issue
Block a user