Compare commits

...

2 Commits

25 changed files with 1334 additions and 923 deletions

3
.gitmodules vendored
View File

@ -8,3 +8,6 @@
path = 3rdparty/AngelScript
url = git@github.com:Wing-summer/AngelScript.git
branch=stable
[submodule "3rdparty/cpptrace"]
path = 3rdparty/cpptrace
url = git@github.com:Wing-summer/cpptrace.git

1
3rdparty/cpptrace vendored Submodule

@ -0,0 +1 @@
Subproject commit 6689d14c203eed390ae7bb64f56a983cfd7dff9c

View File

@ -2037,8 +2037,6 @@ void QEditor::createSimpleBasicContextMenu(bool shortcut, bool extTool) {
a->setObjectName("paste");
if (shortcut)
Q_SHORTCUT(a, "Ctrl+V", "Edit");
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this,
SLOT(checkClipboard()));
connect(a, SIGNAL(triggered()), this, SLOT(paste()));

View File

@ -17,6 +17,19 @@ find_package(
Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network Concurrent
PrintSupport Xml LinguistTools)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message("Build ${PROJECT_NAME} with ${CMAKE_BUILD_TYPE}.")
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
message("Build ${PROJECT_NAME} with ${CMAKE_BUILD_TYPE}.")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
message(
WARNING
"${PROJECT_NAME}'s stacktrace won't work built with ${CMAKE_BUILD_TYPE}."
)
else()
message(FATAL_ERROR "Unsupported build type!")
endif()
install(CODE "set(CMAKE_INSTALL_LOCAL_ONLY TRUE)" ALL_COMPONENTS)
option(BUILD_TEST_PLUGIN OFF)
@ -72,6 +85,7 @@ set(ADS_VERSION 4.3.1)
option(BUILD_EXAMPLES "Build the examples" FALSE)
option(BUILD_STATIC "Build the static library" TRUE)
add_subdirectory(3rdparty/cpptrace)
add_subdirectory(3rdparty/QHexView)
add_subdirectory(3rdparty/qcodeedit2)
add_subdirectory(3rdparty/Qt-Advanced-Docking-System)
@ -158,7 +172,10 @@ set(DIALOG_SRC
src/dialog/splashdialog.h
src/dialog/historydeldialog.h
src/dialog/historydeldialog.cpp
src/dialog/historydeldialog.ui)
src/dialog/historydeldialog.ui
src/dialog/crashreport.h
src/dialog/crashreport.cpp
src/dialog/crashreport.ui)
set(CONTROL_SRC
src/control/editorview.h
@ -195,7 +212,6 @@ set(CONTROL_SRC
set(CLASS_SRC
src/class/logger.cpp
src/class/logger.h
src/class/scopeguard.h
src/class/skinmanager.cpp
src/class/skinmanager.h
src/class/workspacemanager.cpp
@ -264,7 +280,9 @@ set(CLASS_SRC
src/class/dockcomponentsfactory.cpp
src/class/diffutil.h
src/class/diffutil.cpp
src/class/clickcallback.h)
src/class/clickcallback.h
src/class/crashhandler.h
src/class/crashhandler.cpp)
set(INTERNAL_PLG_SRC
src/class/wingangelapi.h src/class/wingangelapi.cpp
@ -502,6 +520,7 @@ target_link_libraries(
Qt${QT_VERSION_MAJOR}::GuiPrivate
Qt${QT_VERSION_MAJOR}::CorePrivate
Qt${QT_VERSION_MAJOR}::Xml
cpptrace::cpptrace
QtSingleApplication::QtSingleApplication
QHexView
QCodeEditor2

View File

@ -296,59 +296,60 @@
<context>
<name>TestPlugin</name>
<message>
<location filename="../testplugin.cpp" line="199"/>
<location filename="../testplugin.cpp" line="208"/>
<source>Test</source>
<translation></translation>
</message>
<message>
<location filename="../testplugin.cpp" line="211"/>
<location filename="../testplugin.cpp" line="220"/>
<location filename="../testplugin.cpp" line="225"/>
<location filename="../testplugin.cpp" line="306"/>
<location filename="../testplugin.cpp" line="229"/>
<location filename="../testplugin.cpp" line="234"/>
<location filename="../testplugin.cpp" line="315"/>
<source>TestPlugin</source>
<translation></translation>
</message>
<message>
<location filename="../testplugin.cpp" line="229"/>
<location filename="../testplugin.cpp" line="238"/>
<source>Button - </source>
<translation> - </translation>
</message>
<message>
<location filename="../testplugin.cpp" line="233"/>
<location filename="../testplugin.cpp" line="242"/>
<source>Click</source>
<translation></translation>
</message>
<message>
<location filename="../testplugin.cpp" line="309"/>
<location filename="../testplugin.cpp" line="318"/>
<source>A Test Plugin for WingHexExplorer2.</source>
<translation>2</translation>
</message>
<message>
<location filename="../testplugin.cpp" line="347"/>
<location filename="../testplugin.cpp" line="355"/>
<location filename="../testplugin.cpp" line="356"/>
<location filename="../testplugin.cpp" line="364"/>
<location filename="../testplugin.cpp" line="385"/>
<location filename="../testplugin.cpp" line="401"/>
<location filename="../testplugin.cpp" line="408"/>
<location filename="../testplugin.cpp" line="415"/>
<location filename="../testplugin.cpp" line="422"/>
<location filename="../testplugin.cpp" line="430"/>
<location filename="../testplugin.cpp" line="461"/>
<location filename="../testplugin.cpp" line="469"/>
<location filename="../testplugin.cpp" line="477"/>
<location filename="../testplugin.cpp" line="485"/>
<location filename="../testplugin.cpp" line="373"/>
<location filename="../testplugin.cpp" line="394"/>
<location filename="../testplugin.cpp" line="410"/>
<location filename="../testplugin.cpp" line="417"/>
<location filename="../testplugin.cpp" line="424"/>
<location filename="../testplugin.cpp" line="431"/>
<location filename="../testplugin.cpp" line="439"/>
<location filename="../testplugin.cpp" line="470"/>
<location filename="../testplugin.cpp" line="478"/>
<location filename="../testplugin.cpp" line="486"/>
<location filename="../testplugin.cpp" line="494"/>
<location filename="../testplugin.cpp" line="503"/>
<location filename="../testplugin.cpp" line="510"/>
<source>InvalidParamsCount</source>
<translation></translation>
</message>
<message>
<location filename="../testplugin.cpp" line="378"/>
<location filename="../testplugin.cpp" line="394"/>
<location filename="../testplugin.cpp" line="387"/>
<location filename="../testplugin.cpp" line="403"/>
<source>InvalidParam</source>
<translation></translation>
</message>
<message>
<location filename="../testplugin.cpp" line="452"/>
<location filename="../testplugin.cpp" line="461"/>
<source>AllocArrayFailed</source>
<translation></translation>
</message>

View File

@ -166,6 +166,15 @@ TestPlugin::TestPlugin() : WingHex::IWingPlugin() {
info.ret = MetaType::Bool;
_scriptInfo.insert(QStringLiteral("pluginMetaTestEnabled"), info);
}
{
WingHex::IWingPlugin::ScriptFnInfo info;
info.fn = std::bind(
QOverload<const QVariantList &>::of(&TestPlugin::testCrash), this,
std::placeholders::_1);
info.ret = MetaType::Void;
_scriptInfo.insert(QStringLiteral("testCrash"), info);
}
}
TestPlugin::~TestPlugin() { destoryTestShareMem(); }
@ -437,10 +446,10 @@ TestPlugin::colorTable(const QList<void *> &params) {
}
auto invoked =
emit invokeService(QStringLiteral("WingAngelAPI"), "vector2AsArray",
WINGAPI_RETURN_ARG(void *, array),
WINGAPI_ARG(MetaType, MetaType::Color),
WINGAPI_ARG(QVector<void *>, colors));
invokeService(QStringLiteral("WingAngelAPI"), "vector2AsArray",
WINGAPI_RETURN_ARG(void *, array),
WINGAPI_ARG(MetaType, MetaType::Color),
WINGAPI_ARG(QVector<void *>, colors));
if (invoked) {
if (array) {
qDeleteAll(colors);
@ -496,6 +505,14 @@ QVariant TestPlugin::pluginMetaTestEnabled(const QVariantList &params) {
return pluginMetaTestEnabled();
}
QVariant TestPlugin::testCrash(const QVariantList &params) {
if (!params.isEmpty()) {
return getScriptCallError(-1, tr("InvalidParamsCount"));
}
testCrash();
return {};
}
void TestPlugin::test_a() { emit debug(__FUNCTION__); }
void TestPlugin::test_b(const QString &b) {
@ -604,6 +621,15 @@ void TestPlugin::setPluginMetaTestEnabled(bool b) {
bool TestPlugin::pluginMetaTestEnabled() { return ENABLE_META; }
void TestPlugin::testCrash() {
// if you want to reproduce nullptr deferenced,
// you can use this example. 'volatile' is important in release mode
// volatile int *a = nullptr;
// (*a)++;
abort();
}
QHash<QString, WingHex::IWingPlugin::ScriptFnInfo>
TestPlugin::registeredScriptFns() const {
return _scriptInfo;

View File

@ -91,6 +91,8 @@ private:
QVariant setPluginMetaTestEnabled(const QVariantList &params);
QVariant pluginMetaTestEnabled(const QVariantList &params);
QVariant testCrash(const QVariantList &params);
private:
void test_a();
void test_b(const QString &b);
@ -110,6 +112,8 @@ private:
void setPluginMetaTestEnabled(bool b);
bool pluginMetaTestEnabled();
void testCrash();
private:
QDialog *_tform = nullptr;
QMenu *_tmenu = nullptr;

BIN
images/crashicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,7 @@
<file>images/convpro.png</file>
<file>images/copy.png</file>
<file>images/copyhex.png</file>
<file>images/crashicon.png</file>
<file>images/cut.png</file>
<file>images/cuthex.png</file>
<file>images/dbgcontinue.png</file>

View File

@ -24,6 +24,7 @@
#include "angelscript.h"
#include "clangformatmanager.h"
#include "control/toast.h"
#include "crashhandler.h"
#include "dbghelper.h"
#include "define.h"
#include "dialog/mainwindow.h"
@ -41,6 +42,8 @@ AppManager::AppManager(int &argc, char *argv[])
: QtSingleApplication(argc, argv) {
ASSERT_SINGLETON;
CrashHandler::instance().init();
auto args = arguments();
if (this->isRunning()) {
QByteArray buffer;

135
src/class/crashhandler.cpp Normal file
View File

@ -0,0 +1,135 @@
#include "crashhandler.h"
#include "angelscript.h"
#include "dialog/crashreport.h"
#include "plugin/pluginsystem.h"
#include <QApplication>
#include <QLibraryInfo>
#include <QTextStream>
#include <cpptrace/cpptrace.hpp>
#ifdef Q_OS_WIN
#include <Windows.h>
#include <cpptrace/from_current.hpp>
LONG WINAPI ExceptionFilter(EXCEPTION_POINTERS *) {
CrashHandler::reportCrashAndExit();
// Terminate the program
return EXCEPTION_EXECUTE_HANDLER;
}
#else
#include <csignal>
#include <execinfo.h>
#include <unistd.h>
void signalHandler(int) { CrashHandler::reportCrashAndExit(); }
#endif
CrashHandler &CrashHandler::instance() {
static CrashHandler ins;
return ins;
}
void CrashHandler::init() {
#ifdef Q_OS_WIN
::SetUnhandledExceptionFilter(ExceptionFilter);
#else
::signal(SIGSEGV, signalHandler);
::signal(SIGILL, signalHandler);
::signal(SIGABRT, signalHandler);
::signal(SIGFPE, signalHandler);
::signal(SIGBUS, signalHandler);
#endif
}
CrashHandler::CrashHandler() {}
void CrashHandler::reportCrashAndExit() {
QString buffer;
QTextStream ss(&buffer);
ss << QStringLiteral("Basic Infomation:") << Qt::endl;
ss << QStringLiteral("* Qt: ") << QLibraryInfo::build() << Qt::endl;
ss << QStringLiteral("* OS: ") << QSysInfo::prettyProductName() << Qt::endl;
ss << QStringLiteral("* Version: ") << WINGHEX_VERSION << Qt::endl;
ss << QStringLiteral("* ScriptEngine: ") << ANGELSCRIPT_VERSION_STRING
<< Qt::endl;
ss << Qt::endl;
// we should keep this exception free
auto &plgsys = PluginSystem::instance();
ss << QStringLiteral("Plugin System:") << Qt::endl;
ss << QStringLiteral("* Loading: ") << plgsys.currentLoadingPlugin()
<< Qt::endl;
size_t i = 1;
ss << QStringLiteral("* Plugins:") << Qt::endl;
for (auto &plg : plgsys.plugins()) {
auto info = plgsys.getPluginInfo(plg);
auto header = QStringLiteral(" ");
ss << header << QStringLiteral("#") << i << Qt::endl;
ss << header << QStringLiteral("- ID: ") << info.id << Qt::endl;
ss << header << QStringLiteral("- Name: ") << plg->pluginName()
<< Qt::endl;
ss << header << QStringLiteral("- License: ") << info.license
<< Qt::endl;
ss << header << QStringLiteral("- Author: ") << info.author << Qt::endl;
ss << header << QStringLiteral("- Vendor: ") << info.vendor << Qt::endl;
ss << header << QStringLiteral("- Version: ")
<< info.version.toString();
ss << header << QStringLiteral("- Comment: ") << plg->pluginComment()
<< Qt::endl;
ss << header << QStringLiteral("- URL: ") << info.url << Qt::endl;
i++;
ss << Qt::endl;
}
i = 1;
ss << QStringLiteral("* Devices:") << Qt::endl;
for (auto &plg : plgsys.devices()) {
auto info = plgsys.getPluginInfo(plg);
auto header = QStringLiteral(" ");
ss << header << QStringLiteral("#") << i << Qt::endl;
ss << header << QStringLiteral("- ID: ") << info.id << Qt::endl;
ss << header << QStringLiteral("- Name: ") << plg->pluginName()
<< Qt::endl;
ss << header << QStringLiteral("- License: ") << info.license
<< Qt::endl;
ss << header << QStringLiteral("- Author: ") << info.author << Qt::endl;
ss << header << QStringLiteral("- Vendor: ") << info.vendor << Qt::endl;
ss << header << QStringLiteral("- Version: ")
<< info.version.toString();
ss << header << QStringLiteral("- Comment: ") << plg->pluginComment()
<< Qt::endl;
ss << header << QStringLiteral("- URL: ") << info.url << Qt::endl;
i++;
ss << Qt::endl;
}
auto str = cpptrace::generate_trace().to_string();
ss << QString::fromStdString(str) << Qt::endl;
CrashReport r;
r.setInfomation(buffer);
r.exec();
#ifdef Q_OS_LINUX
// because abort() will also trigger it
::signal(SIGABRT, nullptr);
#endif
abort();
}

18
src/class/crashhandler.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef CRASHHANDLER_H
#define CRASHHANDLER_H
#include <QtGlobal>
class CrashHandler {
public:
static CrashHandler &instance();
void init();
static void reportCrashAndExit();
private:
CrashHandler();
};
#endif // CRASHHANDLER_H

View File

@ -1,19 +0,0 @@
#ifndef SCOPEGUARD_H
#define SCOPEGUARD_H
#include <QtGlobal>
template <typename CtorFn, typename DctorFn>
class ScopeGuard {
const DctorFn &dctorfn;
Q_DISABLE_COPY_MOVE(ScopeGuard)
public:
ScopeGuard(CtorFn &&ctorfn, DctorFn &&dctorfn) : dctorfn(dctorfn) {
ctorfn();
}
~ScopeGuard() { dctorfn(); }
};
#endif // SCOPEGUARD_H

View File

@ -213,7 +213,8 @@ void SettingManager::setLogCount(qsizetype newLogCount) {
void SettingManager::checkWriteableAndWarn() {
HANDLE_CONFIG;
if (!CONFIG.isWritable()) {
Logger::warning(tr("ConfigUnableSave"));
Logger::warning(QStringLiteral("<i><u>") % tr("ConfigUnableSave") %
QStringLiteral("</u></i>"));
}
}

View File

@ -32,7 +32,6 @@
#include <QVBoxLayout>
#ifdef Q_OS_LINUX
#include "class/scopeguard.h"
#include <unistd.h>
#endif

View File

@ -0,0 +1,40 @@
#include "crashreport.h"
#include "ui_crashreport.h"
#include <QClipboard>
#include <QPushButton>
#include "utilities.h"
#include "control/toast.h"
CrashReport::CrashReport(QWidget *parent)
: QWidget(parent), ui(new Ui::CrashReport) {
ui->setupUi(this);
_dialog = new FramelessDialogBase(parent);
_dialog->buildUpContent(this);
_dialog->setWindowTitle(this->windowTitle());
_dialog->setMinimumSize(600, 500);
Utilities::moveToCenter(_dialog);
}
CrashReport::~CrashReport() { delete ui; }
void CrashReport::setInfomation(const QString &info) {
ui->textBrowser->setText(info);
}
int CrashReport::exec() { return _dialog->exec(); }
void CrashReport::on_buttonBox_clicked(QAbstractButton *button) {
if (button == ui->buttonBox->button(QDialogButtonBox::Save)) {
auto clipboard = qApp->clipboard();
clipboard->setText(ui->textBrowser->toPlainText());
Toast::toast(_dialog, NAMEICONRES(QStringLiteral("copy")),
tr("CopyToClipBoard"));
} else {
_dialog->done(1);
}
}

33
src/dialog/crashreport.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef CRASHREPORT_H
#define CRASHREPORT_H
#include "dialog/framelessdialogbase.h"
#include <QAbstractButton>
#include <QWidget>
namespace Ui {
class CrashReport;
}
class CrashReport : public QWidget {
Q_OBJECT
public:
explicit CrashReport(QWidget *parent = nullptr);
~CrashReport();
public slots:
void setInfomation(const QString &info);
int exec();
private slots:
void on_buttonBox_clicked(QAbstractButton *button);
private:
Ui::CrashReport *ui;
FramelessDialogBase *_dialog = nullptr;
};
#endif // CRASHREPORT_H

90
src/dialog/crashreport.ui Normal file
View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CrashReport</class>
<widget class="QWidget" name="CrashReport">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>446</width>
<height>390</height>
</rect>
</property>
<property name="windowTitle">
<string>CrashReport</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>8</number>
</property>
<property name="leftMargin">
<number>12</number>
</property>
<property name="topMargin">
<number>12</number>
</property>
<property name="rightMargin">
<number>12</number>
</property>
<property name="bottomMargin">
<number>12</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>10</number>
</property>
<property name="leftMargin">
<number>15</number>
</property>
<property name="rightMargin">
<number>15</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="maximumSize">
<size>
<width>100</width>
<height>100</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../../resources.qrc">:/com.wingsummer.winghex/images/crashicon.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:12pt; font-weight:700;&quot;&gt;Opps! The software has crashed! Please send the information below to the dev:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTextBrowser" name="textBrowser"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Ok|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../resources.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -32,7 +32,6 @@
#include "class/logger.h"
#include "class/qkeysequences.h"
#include "class/richtextitemdelegate.h"
#include "class/scopeguard.h"
#include "class/scriptconsolemachine.h"
#include "class/settingmanager.h"
#include "class/wingfiledialog.h"
@ -1941,8 +1940,8 @@ EditorView *MainWindow::newfileGUI() {
void MainWindow::on_newfile() { newfileGUI(); }
void MainWindow::on_openfile() {
ScopeGuard g([this]() { showStatus(tr("Opening...")); },
[this]() { showStatus({}); });
showStatus(tr("Opening..."));
QScopeGuard g([this]() { showStatus({}); });
auto filename =
WingFileDialog::getOpenFileName(this, tr("ChooseFile"), m_lastusedpath);
@ -1972,8 +1971,8 @@ void MainWindow::on_openfile() {
}
void MainWindow::on_openworkspace() {
ScopeGuard g([this]() { showStatus(tr("WorkSpaceOpening...")); },
[this]() { showStatus({}); });
showStatus(tr("WorkSpaceOpening..."));
QScopeGuard g([this]() { showStatus({}); });
auto filename = WingFileDialog::getOpenFileName(
this, tr("ChooseFile"), m_lastusedpath, tr("ProjectFile (*.wingpro)"));
@ -2008,8 +2007,8 @@ void MainWindow::on_openworkspace() {
}
void MainWindow::on_reload() {
ScopeGuard g([this]() { showStatus(tr("Reloading...")); },
[this]() { showStatus({}); });
showStatus(tr("Reloading..."));
QScopeGuard g([this]() { showStatus({}); });
auto editor = currentEditor();
if (editor == nullptr) {
@ -2030,8 +2029,8 @@ void MainWindow::on_reload() {
}
void MainWindow::on_save() {
ScopeGuard g([this]() { showStatus(tr("Saving...")); },
[this]() { showStatus({}); });
showStatus(tr("Saving..."));
QScopeGuard g([this]() { showStatus({}); });
auto editor = currentEditor();
if (editor == nullptr) {
@ -2101,8 +2100,8 @@ void MainWindow::on_convpro() {
}
void MainWindow::on_saveas() {
ScopeGuard g([this]() { showStatus(tr("SavingAs...")); },
[this]() { showStatus({}); });
showStatus(tr("SavingAs..."));
QScopeGuard g([this]() { showStatus({}); });
auto editor = currentEditor();
if (editor == nullptr) {
@ -2147,8 +2146,8 @@ void MainWindow::on_saveas() {
}
void MainWindow::on_exportfile() {
ScopeGuard g([this]() { showStatus(tr("Exporting...")); },
[this]() { showStatus({}); });
showStatus(tr("Exporting..."));
QScopeGuard g([this]() { showStatus({}); });
auto editor = currentEditor();
if (editor == nullptr) {
@ -2177,8 +2176,8 @@ void MainWindow::on_exportfile() {
}
void MainWindow::on_savesel() {
ScopeGuard g([this]() { showStatus(tr("SavingSel...")); },
[this]() { showStatus({}); });
showStatus(tr("SavingSel..."));
QScopeGuard g([this]() { showStatus({}); });
auto hexeditor = currentHexView();
if (hexeditor == nullptr) {
@ -2745,8 +2744,8 @@ void MainWindow::on_clearfindresult() {
}
void MainWindow::on_exportfindresult() {
ScopeGuard g([this]() { showStatus(tr("FindResultExporting...")); },
[this]() { showStatus({}); });
showStatus(tr("FindResultExporting..."));
QScopeGuard g([this]() { showStatus({}); });
auto editor = currentEditor();
if (editor == nullptr) {
@ -3001,8 +3000,8 @@ void MainWindow::on_fullScreen() {
}
void MainWindow::on_saveLayout() {
ScopeGuard g([this]() { showStatus(tr("LayoutSaving...")); },
[this]() { showStatus({}); });
showStatus(tr("LayoutSaving..."));
QScopeGuard g([this]() { showStatus({}); });
static auto suffix = QStringLiteral(".wing-layout");
bool ok;
@ -3039,8 +3038,8 @@ void MainWindow::on_saveLayout() {
}
void MainWindow::on_exportlog() {
ScopeGuard g([this]() { showStatus(tr("LogExporting...")); },
[this]() { showStatus({}); });
showStatus(tr("LogExporting..."));
QScopeGuard g([this]() { showStatus({}); });
auto nfile = saveLog();
if (nfile.isEmpty()) {
Toast::toast(this, NAMEICONRES(QStringLiteral("log")),

View File

@ -1040,8 +1040,7 @@ void ScriptingDialog::startDebugScript(const QString &fileName) {
}
_DebugingScript = fileName;
PluginSystem::instance().dispatchEvent(
IWingPlugin::RegisteredEvent::ScriptPragmaInit, {});
PluginSystem::instance().scriptPragmaBegin();
m_consoleout->machine()->executeScript(fileName, true);
updateRunDebugMode();
@ -1393,8 +1392,7 @@ void ScriptingDialog::on_runscript() {
return;
}
m_consoleout->clear();
PluginSystem::instance().dispatchEvent(
IWingPlugin::RegisteredEvent::ScriptPragmaInit, {});
PluginSystem::instance().scriptPragmaBegin();
m_consoleout->machine()->executeScript(e->fileName());
updateRunDebugMode();
}

View File

@ -27,8 +27,8 @@ SplashDialog::SplashDialog(QWidget *parent)
QStringLiteral("<html><head/><body><p><span style=\" font-size:16pt; "
"font-weight:600;\">%1</span></p></body></html>")
.arg(qAppName()));
setWindowFlags(Qt::CustomizeWindowHint | Qt::SplashScreen |
Qt::WindowStaysOnTopHint);
setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint |
Qt::Window);
setAttribute(Qt::WA_DeleteOnClose);
setModal(true);
show();

View File

@ -38,14 +38,10 @@
#include <QFileInfoList>
#include <QMessageBox>
#include <QPluginLoader>
#include <QtCore>
PluginSystem::PluginSystem(QObject *parent) : QObject(parent) {}
PluginSystem::~PluginSystem() {
Q_ASSERT(_loadedplgs.isEmpty());
Q_ASSERT(_loadeddevs.isEmpty());
}
PluginSystem::~PluginSystem() {}
void PluginSystem::initCheckingEngine() {
_engine = dynamic_cast<asCScriptEngine *>(asCreateScriptEngine());
@ -58,8 +54,12 @@ void PluginSystem::initCheckingEngine() {
void PluginSystem::finalizeCheckingEngine() { _engine->ShutDownAndRelease(); }
QString PluginSystem::currentLoadingPlugin() const { return _curLoadingPlg; }
QStringList PluginSystem::scriptMarcos() const { return _scriptMarcos; }
void PluginSystem::scriptPragmaBegin() { _pragmaedPlg.clear(); }
const QList<IWingPlugin *> &PluginSystem::plugins() const {
return _loadedplgs;
}
@ -83,6 +83,10 @@ PluginSystem::loadPlugin(const QFileInfo &fileinfo, const QDir &setdir) {
if (fileinfo.exists()) {
auto fileName = fileinfo.absoluteFilePath();
_curLoadingPlg =
QDir(qApp->applicationDirPath()).relativeFilePath(fileName);
QScopeGuard g([this]() { _curLoadingPlg.clear(); });
QPluginLoader loader(fileName, this);
Logger::info(tr("LoadingPlugin") + fileinfo.fileName());
@ -493,13 +497,15 @@ bool PluginSystem::dispatchEvent(IWingPlugin::RegisteredEvent event,
if (r == es.constEnd()) {
return false;
}
return (*r)->eventOnScriptPragma(section, params.at(3).toStringList());
} break;
case WingHex::IWingPlugin::RegisteredEvent::ScriptPragmaInit: {
Q_ASSERT(params.isEmpty());
for (auto &plg : _evplgs[event]) {
auto plg = *r;
if (!_pragmaedPlg.contains(plg)) {
plg->eventOnScriptPragmaInit();
}
return plg->eventOnScriptPragma(section, params.at(3).toStringList());
} break;
case WingHex::IWingPlugin::RegisteredEvent::ScriptPragmaInit: {
Q_ASSERT(false);
// should not go there, lazy calling instead
} break;
case WingHex::IWingPlugin::RegisteredEvent::PluginFileOpened: {
Q_ASSERT(params.size() == 4);
@ -1281,6 +1287,7 @@ void PluginSystem::loadPlugin(IWingDevice *p, PluginInfo &meta,
registerPluginPages(p);
connectInterface(p);
registerMarcoDevice(p);
// ok register into menu open
auto menu =
@ -1417,6 +1424,12 @@ void PluginSystem::registerPluginPages(IWingPluginBase *p) {
}
}
void PluginSystem::registerMarcoDevice(IWingDevice *plg) {
auto id = getPUID(plg).toUpper();
auto sep = QStringLiteral("_");
_scriptMarcos.append(sep + id + sep);
}
bool PluginSystem::updateTextList_API(const QStringList &data,
const QString &title,
const ClickCallBack &click,

View File

@ -162,6 +162,9 @@ public:
QStringList scriptMarcos() const;
public:
void scriptPragmaBegin();
public:
PluginInfo getPluginInfo(IWingPluginBase *plg) const;
@ -256,6 +259,7 @@ private:
private:
void connectInterface(IWingDevice *plg);
void connectLoadingInterface(IWingDevice *plg);
void registerMarcoDevice(IWingDevice *plg);
private:
void connectBaseInterface(IWingPluginBase *plg);
@ -275,6 +279,10 @@ public:
const QString &title, const ClickCallBack &click,
const ClickCallBack &dblclick);
public:
// fpr crash checking
QString currentLoadingPlugin() const;
private:
template <typename T>
T readBasicTypeContent(IWingPlugin *plg, qsizetype offset) {
@ -396,8 +404,12 @@ private:
asCScriptEngine *_engine = nullptr;
QStringList _scriptMarcos;
QList<IWingPlugin *> _pragmaedPlg;
QReadWriteLock _rwlock;
private:
QString _curLoadingPlg;
};
#endif // PLUGINSYSTEM_H