forked from wingsummer/WingHexExplorer
工作区基本功能完成并通过测试(插件对应接口未实现)
This commit is contained in:
parent
a8ae116275
commit
5c21065fd4
|
@ -39,7 +39,7 @@ QString TestPlugin::comment() {
|
|||
|
||||
uint TestPlugin::pluginVersion() { return 1; }
|
||||
|
||||
QString TestPlugin::signature() { return sign; }
|
||||
QString TestPlugin::signature() { return WINGSUMMER; }
|
||||
|
||||
QList<QVariant> TestPlugin::optionalInfos() { return QList<QVariant>(); }
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef GENERICPLUGIN_H
|
||||
#define GENERICPLUGIN_H
|
||||
|
||||
#include "../WingHexExplorer/iwingplugin.h"
|
||||
#include "../WingHexExplorer/plugin/iwingplugin.h"
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
|
||||
|
|
|
@ -80,6 +80,12 @@ bool QHexDocument::existBookMark(int &index) {
|
|||
return false;
|
||||
}
|
||||
|
||||
QList<BookMarkStruct> QHexDocument::getAllBookMarks() { return bookmarks; }
|
||||
|
||||
void QHexDocument::applyBookMarks(QList<BookMarkStruct> books) {
|
||||
bookmarks.append(books);
|
||||
}
|
||||
|
||||
void QHexDocument::FindAllBytes(QByteArray b, QList<quint64> &results) {
|
||||
results.clear();
|
||||
qlonglong p = 0;
|
||||
|
|
|
@ -50,6 +50,8 @@ public:
|
|||
|
||||
void addBookMark(QString comment);
|
||||
BookMarkStruct bookMark(int index);
|
||||
QList<BookMarkStruct> getAllBookMarks();
|
||||
void applyBookMarks(QList<BookMarkStruct> books);
|
||||
void removeBookMark(int index);
|
||||
void clearBookMark();
|
||||
void getBookMarks(QList<BookMarkStruct> &bookmarks);
|
||||
|
|
|
@ -7,51 +7,12 @@ const QHexLineMetadata &QHexMetadata::get(quint64 line) const {
|
|||
return it.value();
|
||||
}
|
||||
|
||||
/*==================================*/
|
||||
// added by wingsummer
|
||||
QList<QHexMetadataItem> QHexMetadata::gets(qint64 offset) {
|
||||
QList<QHexMetadataItem> items;
|
||||
auto res = lldiv(offset, m_lineWidth);
|
||||
quint64 line = quint64(res.quot);
|
||||
auto m = res.quot;
|
||||
auto it = m_metadata.find(line);
|
||||
if (it != m_metadata.end()) {
|
||||
for (auto item : *it) {
|
||||
if (item.start <= m && m <= item.start + item.length) {
|
||||
items.push_back(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
QHash<quint64, QHexLineMetadata> QHexMetadata::getallMetas() {
|
||||
return m_metadata;
|
||||
}
|
||||
|
||||
QString QHexMetadata::comments(quint64 line, int column) const {
|
||||
if (!this->lineHasMetadata(line))
|
||||
return QString();
|
||||
|
||||
QString s;
|
||||
|
||||
const auto &linemetadata = this->get(line);
|
||||
|
||||
for (auto &mi : linemetadata) {
|
||||
if (!(mi.start <= column && column < mi.start + mi.length))
|
||||
continue;
|
||||
if (mi.comment.isEmpty())
|
||||
continue;
|
||||
|
||||
if (!s.isEmpty())
|
||||
s += "\n";
|
||||
|
||||
s += mi.comment;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool QHexMetadata::lineHasMetadata(quint64 line) const {
|
||||
return m_metadata.contains(line);
|
||||
}
|
||||
|
||||
// added by wingsummer
|
||||
bool QHexMetadata::removeMetadata(qint64 offset,
|
||||
QList<QHexMetadataItem> refer) {
|
||||
QList<QHexMetadataAbsoluteItem> delneeded;
|
||||
|
@ -87,6 +48,55 @@ bool QHexMetadata::removeMetadata(qint64 offset,
|
|||
return true;
|
||||
}
|
||||
|
||||
QList<QHexMetadataItem> QHexMetadata::gets(qint64 offset) {
|
||||
QList<QHexMetadataItem> items;
|
||||
auto res = lldiv(offset, m_lineWidth);
|
||||
quint64 line = quint64(res.quot);
|
||||
auto m = res.rem;
|
||||
auto it = m_metadata.find(line);
|
||||
if (it != m_metadata.end()) {
|
||||
for (auto item : *it) {
|
||||
if (item.start <= m && m <= item.start + item.length) {
|
||||
items.push_back(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
void QHexMetadata::applyMetas(QHash<quint64, QHexLineMetadata> metas) {
|
||||
m_metadata.insert(metas);
|
||||
}
|
||||
|
||||
/*==================================*/
|
||||
|
||||
QString QHexMetadata::comments(quint64 line, int column) const {
|
||||
if (!this->lineHasMetadata(line))
|
||||
return QString();
|
||||
|
||||
QString s;
|
||||
|
||||
const auto &linemetadata = this->get(line);
|
||||
|
||||
for (auto &mi : linemetadata) {
|
||||
if (!(mi.start <= column && column < mi.start + mi.length))
|
||||
continue;
|
||||
if (mi.comment.isEmpty())
|
||||
continue;
|
||||
|
||||
if (!s.isEmpty())
|
||||
s += "\n";
|
||||
|
||||
s += mi.comment;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool QHexMetadata::lineHasMetadata(quint64 line) const {
|
||||
return m_metadata.contains(line);
|
||||
}
|
||||
|
||||
void QHexMetadata::clear(quint64 line) {
|
||||
auto it = m_metadata.find(line);
|
||||
|
||||
|
|
|
@ -53,10 +53,16 @@ public:
|
|||
explicit QHexMetadata(QObject *parent = nullptr);
|
||||
const QHexLineMetadata &get(quint64 line) const;
|
||||
QString comments(quint64 line, int column) const;
|
||||
bool lineHasMetadata(quint64 line) const;
|
||||
bool removeMetadata(qint64 offset,
|
||||
QList<QHexMetadataItem> refer); // added by wingsummer
|
||||
QList<QHexMetadataItem> gets(qint64 offset); // added by wingsummer
|
||||
bool lineHasMetadata(quint64 line) const; // modified by wingsummer
|
||||
|
||||
/*============================*/
|
||||
// added by wingsummer
|
||||
|
||||
bool removeMetadata(qint64 offset, QList<QHexMetadataItem> refer);
|
||||
QList<QHexMetadataItem> gets(qint64 offset);
|
||||
void applyMetas(QHash<quint64, QHexLineMetadata> metas);
|
||||
|
||||
/*============================*/
|
||||
|
||||
void
|
||||
clear(quint64 line); // this is transient till next call to setLineWidth()
|
||||
|
@ -78,6 +84,9 @@ public:
|
|||
void background(quint64 line, int start, int length, const QColor &bgcolor);
|
||||
void comment(quint64 line, int start, int length, const QString &comment);
|
||||
|
||||
QHash<quint64, QHexLineMetadata>
|
||||
getallMetas(); // added by wingsummer to support workspace
|
||||
|
||||
private:
|
||||
void setMetadata(const QHexMetadataItem &mi);
|
||||
void setAbsoluteMetadata(const QHexMetadataAbsoluteItem &mi);
|
||||
|
|
|
@ -12,7 +12,10 @@ bool WorkSpaceManager::loadWorkSpace(QString filename, QString &file,
|
|||
QFile f(filename);
|
||||
if (f.exists()) {
|
||||
QJsonParseError err;
|
||||
if (!f.open(QFile::ReadOnly))
|
||||
return false;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(f.readAll(), &err);
|
||||
f.close();
|
||||
if (err.error == QJsonParseError::NoError) {
|
||||
auto jobj = doc.object();
|
||||
auto t = jobj.value("type");
|
||||
|
@ -36,7 +39,7 @@ bool WorkSpaceManager::loadWorkSpace(QString filename, QString &file,
|
|||
auto pos = ipos.toString().toULongLong(&b);
|
||||
if (!b)
|
||||
continue;
|
||||
auto ivalues = sitem.value("values");
|
||||
auto ivalues = sitem.value("value");
|
||||
if (!ivalues.isUndefined() && ivalues.isArray()) {
|
||||
QHexLineMetadata linemetas;
|
||||
for (auto v : ivalues.toArray()) {
|
||||
|
@ -127,6 +130,13 @@ bool WorkSpaceManager::saveWorkSpace(
|
|||
if (f.open(QFile::WriteOnly)) {
|
||||
QJsonObject jobj;
|
||||
jobj.insert("type", "workspace");
|
||||
|
||||
if (file[0] == '/') {
|
||||
QDir dir(QFileInfo(f).absoluteDir());
|
||||
QFileInfo fi(file);
|
||||
file = dir.relativeFilePath(fi.absoluteFilePath());
|
||||
}
|
||||
|
||||
jobj.insert("file", file);
|
||||
|
||||
QJsonArray metas;
|
||||
|
@ -140,8 +150,8 @@ bool WorkSpaceManager::saveWorkSpace(
|
|||
lineobj.insert("start", QString::number(line.start));
|
||||
lineobj.insert("length", QString::number(line.length));
|
||||
lineobj.insert("comment", line.comment);
|
||||
lineobj.insert("fgcolor", line.foreground.name(QColor::HexArgb));
|
||||
lineobj.insert("bgcolor", line.background.name(QColor::HexArgb));
|
||||
lineobj.insert("fgcolor", QString::number(line.foreground.rgba(), 16));
|
||||
lineobj.insert("bgcolor", QString::number(line.background.rgba(), 16));
|
||||
linemetas.append(lineobj);
|
||||
}
|
||||
i.insert("value", linemetas);
|
||||
|
|
|
@ -16,12 +16,12 @@ class WorkSpaceManager : public QObject {
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit WorkSpaceManager(QObject *parent = nullptr);
|
||||
bool saveWorkSpace(QString filename, QString file,
|
||||
QList<BookMarkStruct> bookmarks,
|
||||
QHash<quint64, QHexLineMetadata> metas);
|
||||
bool loadWorkSpace(QString filename, QString &file,
|
||||
QList<BookMarkStruct> &bookmarks,
|
||||
QHash<quint64, QHexLineMetadata> &metas);
|
||||
bool static saveWorkSpace(QString filename, QString file,
|
||||
QList<BookMarkStruct> bookmarks,
|
||||
QHash<quint64, QHexLineMetadata> metas);
|
||||
bool static loadWorkSpace(QString filename, QString &file,
|
||||
QList<BookMarkStruct> &bookmarks,
|
||||
QHash<quint64, QHexLineMetadata> &metas);
|
||||
|
||||
signals:
|
||||
|
||||
|
|
|
@ -189,7 +189,6 @@ MainWindow::MainWindow(DMainWindow *parent) {
|
|||
tm->addSeparator();
|
||||
AddToolSubMenuShortcutAction("workspace", tr("OpenWorkSpace"),
|
||||
MainWindow::on_openworkspace, keyopenws);
|
||||
AddMenuDB(ToolBoxIndex::OpenWorkSpace);
|
||||
AddToolSubMenuShortcutAction("workspacesave", tr("SaveWorkSpace"),
|
||||
MainWindow::on_saveworkspace, keysavews);
|
||||
AddMenuDB(ToolBoxIndex::SaveWorkSpace);
|
||||
|
@ -371,7 +370,6 @@ MainWindow::MainWindow(DMainWindow *parent) {
|
|||
toolbar->addSeparator();
|
||||
AddToolBarTool("workspace", MainWindow::on_openworkspace,
|
||||
tr("OpenWorkSpace"));
|
||||
AddToolsDB(ToolBoxIndex::OpenWorkSpace);
|
||||
AddToolBarTool("workspacesave", MainWindow::on_saveworkspace,
|
||||
tr("SaveWorkSpace"));
|
||||
AddToolsDB(ToolBoxIndex::SaveWorkSpace);
|
||||
|
@ -1183,7 +1181,9 @@ void MainWindow::connectShadowSlot(HexViewShadow *shadow) {
|
|||
});
|
||||
|
||||
ConnectShadows(HexViewShadow::newFile, MainWindow::newFile);
|
||||
ConnectShadows(HexViewShadow::openFile, MainWindow::openFile);
|
||||
ConnectShadowLamba(
|
||||
HexViewShadow::openFile,
|
||||
[=](QString filename, bool readonly) { openFile(filename, readonly); });
|
||||
ConnectShadows(HexViewShadow::openDriver, MainWindow::openDriver);
|
||||
ConnectShadows(HexViewShadow::closeFile, MainWindow::closeFile);
|
||||
ConnectShadows(HexViewShadow::saveFile, MainWindow::saveFile);
|
||||
|
@ -1281,6 +1281,7 @@ void MainWindow::newFile() {
|
|||
hf.render = hexeditor->renderer();
|
||||
hf.vBarValue = -1;
|
||||
hf.filename = ":" + title;
|
||||
hf.workspace = "";
|
||||
hf.isdriver = false;
|
||||
hexfiles.push_back(hf);
|
||||
tabs->addTab(QIcon::fromTheme("text-plain"), title);
|
||||
|
@ -1296,7 +1297,8 @@ void MainWindow::newFile() {
|
|||
}
|
||||
}
|
||||
|
||||
ErrFile MainWindow::openFile(QString filename, bool readonly) {
|
||||
ErrFile MainWindow::openFile(QString filename, bool readonly,
|
||||
QString workspace) {
|
||||
QList<QVariant> params;
|
||||
if (_enableplugin) {
|
||||
params << HookIndex::OpenFileBegin << filename << readonly;
|
||||
|
@ -1361,6 +1363,7 @@ ErrFile MainWindow::openFile(QString filename, bool readonly) {
|
|||
hf.render = hexeditor->renderer();
|
||||
hf.vBarValue = -1;
|
||||
hf.filename = filename;
|
||||
hf.workspace = workspace;
|
||||
hexfiles.push_back(hf);
|
||||
|
||||
QMimeDatabase db;
|
||||
|
@ -1921,7 +1924,7 @@ void MainWindow::on_metadata() {
|
|||
auto begin =
|
||||
qint64(hexeditor->document()->cursor()->selectionStart().offset());
|
||||
auto end =
|
||||
qint64(hexeditor->document()->cursor()->selectionEnd().offset());
|
||||
qint64(hexeditor->document()->cursor()->selectionEnd().offset()) + 1;
|
||||
hexeditor->document()->metadata()->metadata(
|
||||
begin, end, m.foreGroundColor(), m.backGroundColor(), m.comment());
|
||||
}
|
||||
|
@ -2105,8 +2108,66 @@ void MainWindow::on_about() {
|
|||
d.exec();
|
||||
}
|
||||
|
||||
void MainWindow::on_openworkspace() {}
|
||||
void MainWindow::on_openworkspace() {
|
||||
auto filename = QFileDialog::getOpenFileName(
|
||||
this, tr("ChooseFile"), QString(), tr("ProjectFile (*.wingpro)"));
|
||||
if (filename.isEmpty())
|
||||
return;
|
||||
QString file;
|
||||
QList<BookMarkStruct> bookmarks;
|
||||
QHash<quint64, QHexLineMetadata> metas;
|
||||
if (WorkSpaceManager::loadWorkSpace(filename, file, bookmarks, metas)) {
|
||||
openFile(file, false, filename);
|
||||
auto doc = hexeditor->document();
|
||||
doc->applyBookMarks(bookmarks);
|
||||
on_documentSwitched();
|
||||
doc->metadata()->applyMetas(metas);
|
||||
} else {
|
||||
DMessageManager::instance()->sendMessage(this, ICONRES("workspace"),
|
||||
tr("SaveUnSuccessfully"));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_saveworkspace() {}
|
||||
void MainWindow::on_saveworkspace() {
|
||||
CheckEnabled;
|
||||
auto f = hexfiles[_currentfile];
|
||||
if (f.workspace.length() == 0) {
|
||||
on_saveasworkspace();
|
||||
return;
|
||||
}
|
||||
if (WorkSpaceManager::saveWorkSpace(
|
||||
f.workspace, f.filename, hexeditor->document()->getAllBookMarks(),
|
||||
hexeditor->document()->metadata()->getallMetas())) {
|
||||
DMessageManager::instance()->sendMessage(this, ICONRES("workspacesave"),
|
||||
tr("SaveSuccessfully"));
|
||||
} else {
|
||||
DMessageManager::instance()->sendMessage(this, ICONRES("workspacesave"),
|
||||
tr("SaveUnSuccessfully"));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_saveasworkspace() {}
|
||||
void MainWindow::on_saveasworkspace() {
|
||||
CheckEnabled;
|
||||
auto f = hexfiles[_currentfile];
|
||||
if (f.filename[0] == ':') {
|
||||
QMessageBox::warning(this, tr("Warn"), tr("PleaseSaveNewFile"));
|
||||
return;
|
||||
}
|
||||
auto filename = QFileDialog::getSaveFileName(
|
||||
this, tr("ChooseSaveFile"), QString(), tr("ProjectFile (*.wingpro)"));
|
||||
if (filename.isEmpty())
|
||||
return;
|
||||
if (!filename.endsWith(".wingpro")) {
|
||||
filename += ".wingpro";
|
||||
}
|
||||
if (WorkSpaceManager::saveWorkSpace(
|
||||
filename, f.filename, hexeditor->document()->getAllBookMarks(),
|
||||
hexeditor->document()->metadata()->getallMetas())) {
|
||||
f.workspace = filename;
|
||||
DMessageManager::instance()->sendMessage(this, ICONRES("workspacesaveas"),
|
||||
tr("SaveSuccessfully"));
|
||||
} else {
|
||||
DMessageManager::instance()->sendMessage(this, ICONRES("workspacesaveas"),
|
||||
tr("SaveUnSuccessfully"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "QHexView/document/qhexdocument.h"
|
||||
#include "QHexView/qhexview.h"
|
||||
#include "class/logger.h"
|
||||
#include "class/workspacemanager.h"
|
||||
#include "control/gotobar.h"
|
||||
#include "plugin/pluginsystem.h"
|
||||
#include "settings.h"
|
||||
|
@ -110,7 +111,8 @@ private:
|
|||
void setTheme(DGuiApplicationHelper::ColorType theme);
|
||||
|
||||
public:
|
||||
ErrFile openFile(QString filename, bool readonly = false);
|
||||
ErrFile openFile(QString filename, bool readonly = false,
|
||||
QString workspace = "");
|
||||
|
||||
private:
|
||||
void newFile();
|
||||
|
|
|
@ -94,12 +94,12 @@ QColor MetaDialog::foreGroundColor() {
|
|||
if (cforeground->isChecked())
|
||||
return _foreground;
|
||||
else
|
||||
return QColor();
|
||||
return QColor::fromRgba(qRgba(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
QColor MetaDialog::backGroundColor() {
|
||||
if (cbackground->isChecked())
|
||||
return _background;
|
||||
else
|
||||
return QColor();
|
||||
return QColor::fromRgba(qRgba(0, 0, 0, 0));
|
||||
}
|
||||
|
|
|
@ -70,13 +70,13 @@ public slots:
|
|||
QList<QVariant> msg) = 0;
|
||||
};
|
||||
|
||||
const QString sign = "wingsummer";
|
||||
#define WINGSUMMER "wingsummer"
|
||||
|
||||
class PluginUtils {
|
||||
public:
|
||||
static QString GetPUID(IWingPlugin *plugin) {
|
||||
auto str = QString("%1%2%3%4%5")
|
||||
.arg(sign)
|
||||
.arg(WINGSUMMER)
|
||||
.arg(plugin->pluginName())
|
||||
.arg(plugin->pluginAuthor())
|
||||
.arg(plugin->comment())
|
||||
|
@ -88,7 +88,7 @@ public:
|
|||
static QString GetPuid(QString pluginName, QString author, QString comment,
|
||||
uint version) {
|
||||
auto str = QString("%1%2%3%4%5")
|
||||
.arg(sign)
|
||||
.arg(WINGSUMMER)
|
||||
.arg(pluginName)
|
||||
.arg(author)
|
||||
.arg(comment)
|
||||
|
|
|
@ -46,7 +46,7 @@ void PluginSystem::loadPlugin(QFileInfo fileinfo) {
|
|||
INFOLOG(QString(">> ") + tr("LoadingPlugin") + fileinfo.fileName()));
|
||||
auto p = qobject_cast<IWingPlugin *>(loader.instance());
|
||||
if (p) {
|
||||
if (p->signature() != sign) {
|
||||
if (p->signature() != WINGSUMMER) {
|
||||
logger->logMessage(ERRLOG(tr("ErrLoadPluginSign")));
|
||||
loader.unload();
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ struct HexFile {
|
|||
QHexDocument *doc;
|
||||
QHexRenderer *render;
|
||||
QString filename;
|
||||
QString workspace;
|
||||
int vBarValue;
|
||||
bool isdriver;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue