1
0
Fork 0

Create/Open system breakpoint script

This commit is contained in:
torusrxxx 2020-12-30 17:27:28 +08:00
parent 4a924d320a
commit 83db837b66
No known key found for this signature in database
GPG Key ID: A795C73A0F1CFADD
3 changed files with 96 additions and 0 deletions

View File

@ -3,8 +3,11 @@
#include "Bridge.h" #include "Bridge.h"
#include "Configuration.h" #include "Configuration.h"
#include <QDirModel> #include <QDirModel>
#include <QFile>
#include <QFileDialog> #include <QFileDialog>
#include <QDesktopServices>
#include <QCompleter> #include <QCompleter>
#include <QMessageBox>
SystemBreakpointScriptDialog::SystemBreakpointScriptDialog(QWidget* parent) : SystemBreakpointScriptDialog::SystemBreakpointScriptDialog(QWidget* parent) :
QDialog(parent), QDialog(parent),
@ -43,6 +46,11 @@ SystemBreakpointScriptDialog::SystemBreakpointScriptDialog(QWidget* parent) :
ui->groupBoxDebuggee->setEnabled(false); ui->groupBoxDebuggee->setEnabled(false);
} }
if(ui->lineEditGlobal->text().isEmpty())
ui->openGlobal->setText(tr("Create"));
if(ui->lineEditDebuggee->text().isEmpty())
ui->openDebuggee->setText(tr("Create"));
Config()->setupWindowPos(this); Config()->setupWindowPos(this);
} }
@ -56,6 +64,10 @@ void SystemBreakpointScriptDialog::on_pushButtonGlobal_clicked()
QString file = QFileDialog::getOpenFileName(this, ui->groupBoxGlobal->title(), ui->lineEditGlobal->text(), tr("Script files (*.txt *.scr);;All files (*.*)")); QString file = QFileDialog::getOpenFileName(this, ui->groupBoxGlobal->title(), ui->lineEditGlobal->text(), tr("Script files (*.txt *.scr);;All files (*.*)"));
if(!file.isEmpty()) if(!file.isEmpty())
ui->lineEditGlobal->setText(QDir::toNativeSeparators(file)); ui->lineEditGlobal->setText(QDir::toNativeSeparators(file));
if(ui->lineEditGlobal->text().isEmpty())
ui->openGlobal->setText(tr("Create"));
else
ui->openGlobal->setText(tr("Open"));
} }
void SystemBreakpointScriptDialog::on_pushButtonDebuggee_clicked() void SystemBreakpointScriptDialog::on_pushButtonDebuggee_clicked()
@ -63,6 +75,74 @@ void SystemBreakpointScriptDialog::on_pushButtonDebuggee_clicked()
QString file = QFileDialog::getOpenFileName(this, ui->groupBoxDebuggee->title(), ui->lineEditDebuggee->text(), tr("Script files (*.txt *.scr);;All files (*.*)")); QString file = QFileDialog::getOpenFileName(this, ui->groupBoxDebuggee->title(), ui->lineEditDebuggee->text(), tr("Script files (*.txt *.scr);;All files (*.*)"));
if(!file.isEmpty()) if(!file.isEmpty())
ui->lineEditDebuggee->setText(QDir::toNativeSeparators(file)); ui->lineEditDebuggee->setText(QDir::toNativeSeparators(file));
if(ui->lineEditDebuggee->text().isEmpty())
ui->openDebuggee->setText(tr("Create"));
else
ui->openDebuggee->setText(tr("Open"));
}
void SystemBreakpointScriptDialog::on_openGlobal_clicked()
{
// First open the script if that is available
if(!ui->lineEditGlobal->text().isEmpty())
QDesktopServices::openUrl(QUrl(QDir::fromNativeSeparators(ui->lineEditGlobal->text())));
else
{
// Ask the user to create a new script
QMessageBox msgyn(QMessageBox::Question, tr("File not found"), tr("Would you like to create a new script?"), QMessageBox::Yes | QMessageBox::No, this);
if(msgyn.exec() == QMessageBox::Yes)
{
// The new script is at app dir
QString defaultFileName("autorun.txt");
defaultFileName = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + QDir::separator() + defaultFileName);
// Create it
if(!QFile::exists(defaultFileName))
{
QFile newScript(defaultFileName);
newScript.open(QFile::NewOnly);
newScript.close();
}
ui->lineEditGlobal->setText(defaultFileName);
ui->openGlobal->setText(tr("Open"));
// Open the file
QDesktopServices::openUrl(QUrl(QDir::fromNativeSeparators(ui->lineEditGlobal->text())));
}
}
}
void SystemBreakpointScriptDialog::on_openDebuggee_clicked()
{
// First open the script if that is available
if(!ui->lineEditDebuggee->text().isEmpty())
QDesktopServices::openUrl(QUrl(QDir::fromNativeSeparators(ui->lineEditDebuggee->text())));
else
{
// Ask the user to create a new script
QMessageBox msgyn(QMessageBox::Question, tr("File not found"), tr("Would you like to create a new script?"), QMessageBox::Yes | QMessageBox::No, this);
if(msgyn.exec() == QMessageBox::Yes)
{
// The new script is at db dir
QString defaultFileName;
char moduleName[MAX_MODULE_SIZE];
if(DbgFunctions()->ModNameFromAddr(DbgValFromString("mod.main()"), moduleName, false))
{
defaultFileName = QString::fromUtf8(moduleName);
}
defaultFileName = defaultFileName + ".autorun.txt";
defaultFileName = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + QDir::separator() + "db" + QDir::separator() + defaultFileName);
// Create it
if(!QFile::exists(defaultFileName))
{
QFile newScript(defaultFileName);
newScript.open(QFile::NewOnly);
newScript.close();
}
ui->lineEditDebuggee->setText(defaultFileName);
ui->openDebuggee->setText(tr("Open"));
// Open the file
QDesktopServices::openUrl(QUrl(QDir::fromNativeSeparators(ui->lineEditDebuggee->text())));
}
}
} }
void SystemBreakpointScriptDialog::on_SystemBreakpointScriptDialog_accepted() void SystemBreakpointScriptDialog::on_SystemBreakpointScriptDialog_accepted()

View File

@ -18,6 +18,8 @@ public:
private slots: private slots:
void on_pushButtonGlobal_clicked(); void on_pushButtonGlobal_clicked();
void on_pushButtonDebuggee_clicked(); void on_pushButtonDebuggee_clicked();
void on_openGlobal_clicked();
void on_openDebuggee_clicked();
void on_SystemBreakpointScriptDialog_accepted(); void on_SystemBreakpointScriptDialog_accepted();
private: private:

View File

@ -41,6 +41,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="openGlobal">
<property name="text">
<string>Open</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -67,6 +74,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="openDebuggee">
<property name="text">
<string>Open</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>