Database actions in the file menu, and recover database backup

This commit is contained in:
torusrxxx 2020-12-30 20:18:33 +08:00
parent 4a924d320a
commit 178482bf85
No known key found for this signature in database
GPG Key ID: A795C73A0F1CFADD
5 changed files with 75 additions and 3 deletions

View File

@ -35,6 +35,7 @@ bool cbInstrDbclear(int argc, char* argv[])
{
DebugRemoveBreakpoints();
DbClear();
dputs(QT_TRANSLATE_NOOP("DBG", "Database cleared!"));
GuiUpdateAllViews();
return true;
}

View File

@ -162,6 +162,14 @@ void DbLoad(DbLoadSaveType loadType, const char* dbfile)
EXCLUSIVE_ACQUIRE(LockDatabase);
auto file = dbfile ? dbfile : dbpath;
// If the file is "bak", load from database backup instead
if(stricmp(file, "bak") == 0)
{
String dbpath_backup(dbpath);
dbpath_backup.append(".bak");
DbLoad(loadType, dbpath_backup.c_str());
return;
}
// If the file doesn't exist, there is no DB to load
if(!FileExists(file))
return;

View File

@ -345,6 +345,10 @@ MainWindow::MainWindow(QWidget* parent)
connect(ui->actionSetInitializationScript, SIGNAL(triggered()), this, SLOT(setInitializationScript()));
connect(ui->actionCustomizeMenus, SIGNAL(triggered()), this, SLOT(customizeMenu()));
connect(ui->actionVariables, SIGNAL(triggered()), this, SLOT(displayVariables()));
makeCommandAction(ui->actionDbsave, "dbsave");
makeCommandAction(ui->actionDbload, "dbload");
makeCommandAction(ui->actionDbrecovery, "dbload bak");
makeCommandAction(ui->actionDbclear, "dbclear");
connect(mCpuWidget->getDisasmWidget(), SIGNAL(updateWindowTitle(QString)), this, SLOT(updateWindowTitleSlot(QString)));
connect(mCpuWidget->getDisasmWidget(), SIGNAL(displayReferencesWidget()), this, SLOT(displayReferencesWidget()));
@ -816,6 +820,10 @@ void MainWindow::refreshShortcuts()
setGlobalShortcut(ui->actionOpen, ConfigShortcut("FileOpen"));
setGlobalShortcut(ui->actionAttach, ConfigShortcut("FileAttach"));
setGlobalShortcut(ui->actionDetach, ConfigShortcut("FileDetach"));
setGlobalShortcut(ui->actionDbload, ConfigShortcut("FileDbload"));
setGlobalShortcut(ui->actionDbsave, ConfigShortcut("FileDbsave"));
setGlobalShortcut(ui->actionDbclear, ConfigShortcut("FileDbclear"));
setGlobalShortcut(ui->actionDbrecovery, ConfigShortcut("FileDbrecovery"));
setGlobalShortcut(ui->actionImportdatabase, ConfigShortcut("FileImportDatabase"));
setGlobalShortcut(ui->actionExportdatabase, ConfigShortcut("FileExportDatabase"));
setGlobalShortcut(ui->actionRestartAdmin, ConfigShortcut("FileRestartAdmin"));
@ -2193,7 +2201,7 @@ void MainWindow::on_actionImportdatabase_triggered()
{
if(!DbgIsDebugging())
return;
auto filename = QFileDialog::getOpenFileName(this, tr("Import database"), QString(), tr("Databases (%1);;All files (*.*)").arg(ArchValue("*.dd32", "*.dd64")));
auto filename = QFileDialog::getOpenFileName(this, tr("Import database"), QString(), tr("Databases (%1);;Database backup (%1.bak);;All files (*.*)").arg(ArchValue("*.dd32", "*.dd64")));
if(!filename.length())
return;
DbgCmdExec(QString("dbload \"%1\"").arg(QDir::toNativeSeparators(filename)));

View File

@ -40,12 +40,27 @@
</property>
<addaction name="separator"/>
</widget>
<widget class="QMenu" name="menuDatabase">
<property name="title">
<string>Database</string>
</property>
<property name="icon">
<iconset resource="../../resource.qrc">
<normaloff>:/icons/images/data-copy.png</normaloff>:/icons/images/data-copy.png</iconset>
</property>
<addaction name="actionDbsave"/>
<addaction name="actionDbload"/>
<addaction name="actionDbrecovery"/>
<addaction name="actionDbclear"/>
<addaction name="separator"/>
<addaction name="actionImportdatabase"/>
<addaction name="actionExportdatabase"/>
</widget>
<addaction name="actionOpen"/>
<addaction name="menuRecentFiles"/>
<addaction name="actionAttach"/>
<addaction name="actionDetach"/>
<addaction name="actionImportdatabase"/>
<addaction name="actionExportdatabase"/>
<addaction name="menuDatabase"/>
<addaction name="actionPatches"/>
<addaction name="actionChangeCommandLine"/>
<addaction name="actionRestartAdmin"/>
@ -1208,6 +1223,42 @@
<string>&amp;Default</string>
</property>
</action>
<action name="actionDbsave">
<property name="icon">
<iconset resource="../../resource.qrc">
<normaloff>:/icons/images/binary_save.png</normaloff>:/icons/images/binary_save.png</iconset>
</property>
<property name="text">
<string>&amp;Save database</string>
</property>
</action>
<action name="actionDbload">
<property name="icon">
<iconset resource="../../resource.qrc">
<normaloff>:/icons/images/arrow-restart.png</normaloff>:/icons/images/arrow-restart.png</iconset>
</property>
<property name="text">
<string>Re&amp;load database</string>
</property>
</action>
<action name="actionDbrecovery">
<property name="icon">
<iconset resource="../../resource.qrc">
<normaloff>:/icons/images/help.png</normaloff>:/icons/images/help.png</iconset>
</property>
<property name="text">
<string>&amp;Restore backup database</string>
</property>
</action>
<action name="actionDbclear">
<property name="icon">
<iconset resource="../../resource.qrc">
<normaloff>:/icons/images/crash_dump.png</normaloff>:/icons/images/crash_dump.png</iconset>
</property>
<property name="text">
<string>&amp;Clear database</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>

View File

@ -382,6 +382,10 @@ Configuration::Configuration() : QObject(), noMoreMsgbox(false)
defaultShortcuts.insert("FileOpen", Shortcut({tr("File"), tr("Open")}, "F3", true));
defaultShortcuts.insert("FileAttach", Shortcut({tr("File"), tr("Attach")}, "Alt+A", true));
defaultShortcuts.insert("FileDetach", Shortcut({tr("File"), tr("Detach")}, "Ctrl+Alt+F2", true));
defaultShortcuts.insert("FileDbsave", Shortcut({tr("File"), tr("Save database")}, "", true));
defaultShortcuts.insert("FileDbrecovery", Shortcut({tr("File"), tr("Restore backup database")}, "", true));
defaultShortcuts.insert("FileDbload", Shortcut({tr("File"), tr("Reload database")}, "", true));
defaultShortcuts.insert("FileDbclear", Shortcut({tr("File"), tr("Clear database")}, "", true));
defaultShortcuts.insert("FileImportDatabase", Shortcut({tr("File"), tr("Import database")}, "", true));
defaultShortcuts.insert("FileExportDatabase", Shortcut({tr("File"), tr("Export database")}, "", true));
defaultShortcuts.insert("FileRestartAdmin", Shortcut({tr("File"), tr("Restart as Admin")}, "", true));