Add try again option for write error dialog (#880)

* Add try again option for write error dialog
This commit is contained in:
Adam Zambrzycki 2018-10-27 17:55:22 +02:00 committed by xarkes
parent cf43ac9d90
commit ca1fb52bb7
2 changed files with 26 additions and 19 deletions

View File

@ -234,7 +234,7 @@ void DisassemblyContextMenu::aboutToShowSlot()
{ {
// check if set immediate base menu makes sense // check if set immediate base menu makes sense
QJsonObject instObject = Core()->cmdj("aoj @ " + QString::number( QJsonObject instObject = Core()->cmdj("aoj @ " + QString::number(
offset)).array().first().toObject(); offset)).array().first().toObject();
auto keys = instObject.keys(); auto keys = instObject.keys();
bool immBase = keys.contains("val") || keys.contains("ptr"); bool immBase = keys.contains("val") || keys.contains("ptr");
setBaseMenu->menuAction()->setVisible(immBase); setBaseMenu->menuAction()->setVisible(immBase);
@ -275,14 +275,11 @@ void DisassemblyContextMenu::aboutToShowSlot()
} }
//only show retype for local vars if in a function //only show retype for local vars if in a function
if(in_fcn) if (in_fcn) {
{
actionSetFunctionVarTypes.setVisible(true); actionSetFunctionVarTypes.setVisible(true);
actionEditFunction.setVisible(true); actionEditFunction.setVisible(true);
actionEditFunction.setText(tr("Edit function \"%1\"").arg(in_fcn->name)); actionEditFunction.setText(tr("Edit function \"%1\"").arg(in_fcn->name));
} } else {
else
{
actionSetFunctionVarTypes.setVisible(false); actionSetFunctionVarTypes.setVisible(false);
actionEditFunction.setVisible(false); actionEditFunction.setVisible(false);
} }
@ -391,7 +388,9 @@ void DisassemblyContextMenu::on_actionEditInstruction_triggered()
// check if the write failed // check if the write failed
auto newInstructionBytes = Core()->getInstructionBytes(offset); auto newInstructionBytes = Core()->getInstructionBytes(offset);
if (newInstructionBytes == oldInstructionBytes) { if (newInstructionBytes == oldInstructionBytes) {
writeFailed(); if (!writeFailed()) {
Core()->editInstruction(offset, userInstructionOpcode);
}
} }
} }
} }
@ -405,7 +404,9 @@ void DisassemblyContextMenu::on_actionNopInstruction_triggered()
QString newBytes = Core()->getInstructionBytes(offset); QString newBytes = Core()->getInstructionBytes(offset);
if (oldBytes == newBytes) { if (oldBytes == newBytes) {
writeFailed(); if (!writeFailed()) {
Core()->nopInstruction(offset);
}
} }
} }
@ -434,7 +435,9 @@ void DisassemblyContextMenu::on_actionJmpReverse_triggered()
QString newBytes = Core()->getInstructionBytes(offset); QString newBytes = Core()->getInstructionBytes(offset);
if (oldBytes == newBytes) { if (oldBytes == newBytes) {
writeFailed(); if (!writeFailed()) {
Core()->jmpReverse(offset);
}
} }
} }
@ -453,28 +456,33 @@ void DisassemblyContextMenu::on_actionEditBytes_triggered()
QString newBytes = Core()->getInstructionBytes(offset); QString newBytes = Core()->getInstructionBytes(offset);
if (oldBytes == newBytes) { if (oldBytes == newBytes) {
writeFailed(); if (!writeFailed()) {
Core()->editBytes(offset, bytes);
}
} }
} }
} }
} }
void DisassemblyContextMenu::writeFailed() bool DisassemblyContextMenu::writeFailed()
{ {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Icon::Critical); msgBox.setIcon(QMessageBox::Icon::Critical);
msgBox.setWindowTitle(tr("Write error")); msgBox.setWindowTitle(tr("Write error"));
msgBox.setText(tr("Unable to complete write operation. Consider opening in write mode.")); msgBox.setText(
tr("Unable to complete write operation. Consider opening in write mode. \n\nWARNING: In write mode any changes will be commited to disk"));
msgBox.addButton(tr("OK"), QMessageBox::NoRole); msgBox.addButton(tr("OK"), QMessageBox::NoRole);
QAbstractButton *reopenButton = msgBox.addButton(tr("Reopen in write mode"), QMessageBox::YesRole); QAbstractButton *reopenButton = msgBox.addButton(tr("Reopen in write mode and try again"),
QMessageBox::YesRole);
msgBox.exec(); msgBox.exec();
if (msgBox.clickedButton() == reopenButton) { if (msgBox.clickedButton() == reopenButton) {
QMessageBox::warning(this, "File reopened in write mode",
"WARNING: Any chages will now be commited to disk");
Core()->cmd("oo+"); Core()->cmd("oo+");
return false;
} }
return true;
} }
void DisassemblyContextMenu::on_actionCopy_triggered() void DisassemblyContextMenu::on_actionCopy_triggered()
@ -623,8 +631,7 @@ void DisassemblyContextMenu::on_actionSetFunctionVarTypes_triggered()
dialog = new SetFunctionVarTypes(this); dialog = new SetFunctionVarTypes(this);
if(fcn) if (fcn) {
{
dialog->setWindowTitle(tr("Set Variable Types for Function: %1").arg(fcn->name)); dialog->setWindowTitle(tr("Set Variable Types for Function: %1").arg(fcn->name));
} }
dialog->setFcn(fcn); dialog->setFcn(fcn);
@ -747,7 +754,7 @@ void DisassemblyContextMenu::setToData(int size, int repeat)
} }
QAction *DisassemblyContextMenu::addAnonymousAction(QString name, const char *slot, QAction *DisassemblyContextMenu::addAnonymousAction(QString name, const char *slot,
QKeySequence keySequence) QKeySequence keySequence)
{ {
auto action = new QAction(); auto action = new QAction();
addAction(action); addAction(action);

View File

@ -29,7 +29,7 @@ private slots:
void on_actionJmpReverse_triggered(); void on_actionJmpReverse_triggered();
void on_actionEditBytes_triggered(); void on_actionEditBytes_triggered();
void showReverseJmpQuery(); void showReverseJmpQuery();
void writeFailed(); bool writeFailed();
void on_actionCopy_triggered(); void on_actionCopy_triggered();
void on_actionCopyAddr_triggered(); void on_actionCopyAddr_triggered();