forked from qt-creator/qt-creator
BinEditor: Make it work with remote files
For testing, start Creator with bin/qtcreator docker://<imageid>/bin/ls Change-Id: I438dde457b6bfb860939ad928fb4e563a3766aa9 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -241,19 +241,26 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
OpenResult open(QString *errorString, const FilePath &filePath,
|
||||||
const Utils::FilePath &realFilePath) override
|
const FilePath &realFilePath) override
|
||||||
{
|
{
|
||||||
QTC_CHECK(filePath == realFilePath); // The bineditor can do no autosaving
|
QTC_CHECK(filePath == realFilePath); // The bineditor can do no autosaving
|
||||||
return openImpl(errorString, filePath);
|
return openImpl(errorString, filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenResult openImpl(QString *errorString, const Utils::FilePath &filePath, quint64 offset = 0)
|
OpenResult openImpl(QString *errorString, const FilePath &filePath, quint64 offset = 0)
|
||||||
{
|
{
|
||||||
QFile file(filePath.toString());
|
const qint64 size = filePath.fileSize();
|
||||||
if (file.open(QIODevice::ReadOnly)) {
|
if (size < 0) {
|
||||||
file.close();
|
QString msg = tr("Cannot open %1: %2").arg(filePath.toUserOutput(), tr("File Error"));
|
||||||
quint64 size = static_cast<quint64>(file.size());
|
// FIXME: Was: file.errorString(), but we don't have a file anymore.
|
||||||
|
if (errorString)
|
||||||
|
*errorString = msg;
|
||||||
|
else
|
||||||
|
QMessageBox::critical(ICore::dialogParent(), tr("File Error"), msg);
|
||||||
|
return OpenResult::ReadError;
|
||||||
|
}
|
||||||
|
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
QString msg = tr("The Binary Editor cannot open empty files.");
|
QString msg = tr("The Binary Editor cannot open empty files.");
|
||||||
if (errorString)
|
if (errorString)
|
||||||
@@ -262,6 +269,7 @@ public:
|
|||||||
QMessageBox::critical(ICore::dialogParent(), tr("File Error"), msg);
|
QMessageBox::critical(ICore::dialogParent(), tr("File Error"), msg);
|
||||||
return OpenResult::CannotHandle;
|
return OpenResult::CannotHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size / 16 >= qint64(1) << 31) {
|
if (size / 16 >= qint64(1) << 31) {
|
||||||
// The limit is 2^31 lines (due to QText* interfaces) * 16 bytes per line.
|
// The limit is 2^31 lines (due to QText* interfaces) * 16 bytes per line.
|
||||||
QString msg = tr("The file is too big for the Binary Editor (max. 32GB).");
|
QString msg = tr("The file is too big for the Binary Editor (max. 32GB).");
|
||||||
@@ -271,40 +279,29 @@ public:
|
|||||||
QMessageBox::critical(ICore::dialogParent(), tr("File Error"), msg);
|
QMessageBox::critical(ICore::dialogParent(), tr("File Error"), msg);
|
||||||
return OpenResult::CannotHandle;
|
return OpenResult::CannotHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset >= size)
|
if (offset >= size)
|
||||||
return OpenResult::CannotHandle;
|
return OpenResult::CannotHandle;
|
||||||
|
|
||||||
setFilePath(filePath);
|
setFilePath(filePath);
|
||||||
m_widget->setSizes(offset, file.size());
|
m_widget->setSizes(offset, size);
|
||||||
return OpenResult::Success;
|
return OpenResult::Success;
|
||||||
}
|
}
|
||||||
QString errStr = tr("Cannot open %1: %2").arg(filePath.toUserOutput(), file.errorString());
|
|
||||||
if (errorString)
|
|
||||||
*errorString = errStr;
|
|
||||||
else
|
|
||||||
QMessageBox::critical(ICore::dialogParent(), tr("File Error"), errStr);
|
|
||||||
return OpenResult::ReadError;
|
|
||||||
}
|
|
||||||
|
|
||||||
void provideData(quint64 address)
|
void provideData(quint64 address)
|
||||||
{
|
{
|
||||||
const FilePath fn = filePath();
|
const FilePath fn = filePath();
|
||||||
if (fn.isEmpty())
|
if (fn.isEmpty())
|
||||||
return;
|
return;
|
||||||
QFile file(fn.toString());
|
const int blockSize = m_widget->dataBlockSize();
|
||||||
if (file.open(QIODevice::ReadOnly)) {
|
QByteArray data = fn.fileContents(blockSize, address);
|
||||||
int blockSize = m_widget->dataBlockSize();
|
|
||||||
file.seek(address);
|
|
||||||
QByteArray data = file.read(blockSize);
|
|
||||||
file.close();
|
|
||||||
const int dataSize = data.size();
|
const int dataSize = data.size();
|
||||||
if (dataSize != blockSize)
|
if (dataSize != blockSize)
|
||||||
data += QByteArray(blockSize - dataSize, 0);
|
data += QByteArray(blockSize - dataSize, 0);
|
||||||
m_widget->addData(address, data);
|
m_widget->addData(address, data);
|
||||||
} else {
|
// QMessageBox::critical(ICore::dialogParent(), tr("File Error"),
|
||||||
QMessageBox::critical(ICore::dialogParent(), tr("File Error"),
|
// tr("Cannot open %1: %2").arg(
|
||||||
tr("Cannot open %1: %2").arg(
|
// fn.toUserOutput(), file.errorString()));
|
||||||
fn.toUserOutput(), file.errorString()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void provideNewRange(quint64 offset)
|
void provideNewRange(quint64 offset)
|
||||||
|
|||||||
Reference in New Issue
Block a user