This commit is contained in:
寂静的羽夏 2022-09-03 22:59:40 +08:00
parent ddaa460c7c
commit cc10ca8416
21 changed files with 705 additions and 274 deletions

View File

@ -27,7 +27,8 @@ HEADERS += $$PWD/document/commands/hex/hexcommand.h \
$$PWD/QHexEdit2/chunks.h \ $$PWD/QHexEdit2/chunks.h \
$$PWD/document/commands/meta/metashowcommand.h \ $$PWD/document/commands/meta/metashowcommand.h \
$$PWD/document/commands/baseaddrcommand.h \ $$PWD/document/commands/baseaddrcommand.h \
$$PWD/document/commands/encodingchangecommand.h $$PWD/document/commands/encodingchangecommand.h \
$$PWD/document/buffer/qfileregionbuffer.h
SOURCES += $$PWD/document/commands/hex/hexcommand.cpp \ SOURCES += $$PWD/document/commands/hex/hexcommand.cpp \
$$PWD/document/commands/hex/insertcommand.cpp \ $$PWD/document/commands/hex/insertcommand.cpp \
@ -56,6 +57,7 @@ SOURCES += $$PWD/document/commands/hex/hexcommand.cpp \
$$PWD/QHexEdit2/chunks.cpp \ $$PWD/QHexEdit2/chunks.cpp \
$$PWD/document/commands/meta/metashowcommand.cpp \ $$PWD/document/commands/meta/metashowcommand.cpp \
$$PWD/document/commands/baseaddrcommand.cpp \ $$PWD/document/commands/baseaddrcommand.cpp \
$$PWD/document/commands/encodingchangecommand.cpp $$PWD/document/commands/encodingchangecommand.cpp \
$$PWD/document/buffer/qfileregionbuffer.cpp
INCLUDEPATH += $$PWD INCLUDEPATH += $$PWD

View File

@ -0,0 +1,64 @@
#include "qfileregionbuffer.h"
#include <QFile>
#include <QFileInfo>
#include <unistd.h>
QFileRegionBuffer::QFileRegionBuffer(QObject *parent) : QHexBuffer(parent) {}
qint64 QFileRegionBuffer::length() const { return buffer.length(); }
void QFileRegionBuffer::insert(qint64 offset, const QByteArray &data) {
Q_UNUSED(offset);
Q_UNUSED(data);
// 不支持插入,仅支持复写
return;
}
void QFileRegionBuffer::remove(qint64 offset, int length) {
// 在此模式下,删除视为按 0 填充
replace(offset, QByteArray(length, 0));
}
QByteArray QFileRegionBuffer::read(qint64 offset, int length) {
return buffer.mid(int(offset), length);
}
bool QFileRegionBuffer::read(QIODevice *iodevice) {
auto file = qobject_cast<QFile *>(iodevice);
if (file && file->open(QFile::ReadOnly)) {
lseek(file->handle(), offset,
SEEK_SET); // 有些特殊的文件 Qt 是不支持 seek 的,用原生函数
buffer = file->read(maxlength);
file->close();
return true;
}
return false;
}
void QFileRegionBuffer::write(QIODevice *iodevice) {
QFile file(iodevice);
if (file.open(QFile::WriteOnly)) {
lseek(file.handle(), offset, SEEK_SET);
file.write(buffer);
file.close();
}
}
qint64 QFileRegionBuffer::indexOf(const QByteArray &ba, qint64 from) {
return buffer.indexOf(ba, int(from));
}
qint64 QFileRegionBuffer::lastIndexOf(const QByteArray &ba, qint64 from) {
return buffer.lastIndexOf(ba, int(from));
}
void QFileRegionBuffer::setReadOffset(qint64 offset) { this->offset = offset; }
qint64 QFileRegionBuffer::readOffset() { return offset; }
qint64 QFileRegionBuffer::readMaxBytes() { return maxlength; }
void QFileRegionBuffer::setReadMaxBytes(qint64 maxlength) {
if (maxlength)
this->maxlength = maxlength;
}

View File

@ -0,0 +1,34 @@
#ifndef QFILEREGIONBUFFER_H
#define QFILEREGIONBUFFER_H
#include "qhexbuffer.h"
class QFileRegionBuffer : public QHexBuffer {
Q_OBJECT
public:
explicit QFileRegionBuffer(QObject *parent = nullptr);
public:
qint64 length() const override;
void insert(qint64 offset, const QByteArray &data) override;
void remove(qint64 offset, int length) override;
QByteArray read(qint64 offset, int length) override;
bool read(QIODevice *iodevice) override;
void write(QIODevice *iodevice) override;
qint64 indexOf(const QByteArray &ba, qint64 from) override;
qint64 lastIndexOf(const QByteArray &ba, qint64 from) override;
void setReadOffset(qint64 offset);
qint64 readOffset();
qint64 readMaxBytes();
void setReadMaxBytes(qint64 maxlength);
private:
qint64 offset = 0;
qint64 maxlength = 1024;
QByteArray buffer;
};
#endif // QFILEREGIONBUFFER_H

View File

@ -1,5 +1,6 @@
#include "qhexdocument.h" #include "qhexdocument.h"
#include "buffer/qfilebuffer.h" #include "buffer/qfilebuffer.h"
#include "buffer/qfileregionbuffer.h"
#include "commands/baseaddrcommand.h" #include "commands/baseaddrcommand.h"
#include "commands/bookmark/bookmarkaddcommand.h" #include "commands/bookmark/bookmarkaddcommand.h"
#include "commands/bookmark/bookmarkclearcommand.h" #include "commands/bookmark/bookmarkclearcommand.h"
@ -94,9 +95,12 @@ void QHexDocument::setDocSaved(bool b) {
emit documentSaved(b); emit documentSaved(b);
} }
DocumentType QHexDocument::documentType() { return m_doctype; }
void QHexDocument::setDocumentType(DocumentType type) { m_doctype = type; }
bool QHexDocument::isReadOnly() { return m_readonly; } bool QHexDocument::isReadOnly() { return m_readonly; }
bool QHexDocument::isKeepSize() { return m_keepsize; } bool QHexDocument::isKeepSize() { return m_keepsize; }
bool QHexDocument::isLocked() { return m_islocked; } bool QHexDocument::isLocked() { return m_islocked; }
bool QHexDocument::setLockedFile(bool b) { bool QHexDocument::setLockedFile(bool b) {
if (m_readonly) if (m_readonly)
return false; return false;
@ -109,6 +113,9 @@ bool QHexDocument::setLockedFile(bool b) {
bool QHexDocument::setKeepSize(bool b) { bool QHexDocument::setKeepSize(bool b) {
if (m_readonly) if (m_readonly)
return false; return false;
if (!b && m_doctype == DocumentType::RegionFile)
return false;
m_keepsize = b; m_keepsize = b;
if (b) if (b)
m_cursor->setInsertionMode(QHexCursor::OverwriteMode); m_cursor->setInsertionMode(QHexCursor::OverwriteMode);
@ -335,6 +342,24 @@ bool QHexDocument::removeSelection() {
return res; return res;
} }
QHexDocument *QHexDocument::fromRegionFile(QString filename, qint64 start,
qint64 length, bool readonly,
QObject *parent) {
QFile iodevice(filename);
auto hexbuffer = new QFileRegionBuffer;
hexbuffer->setReadOffset(start);
hexbuffer->setReadMaxBytes(length);
if (hexbuffer->read(&iodevice)) {
return new QHexDocument(hexbuffer, readonly, parent);
} else {
delete hexbuffer;
}
return nullptr;
}
bool QHexDocument::cut(bool hex) { bool QHexDocument::cut(bool hex) {
if (!m_cursor->hasSelection() || m_keepsize) if (!m_cursor->hasSelection() || m_keepsize)
return false; return false;

View File

@ -18,6 +18,8 @@ struct BookMarkStruct {
enum class BookMarkModEnum { Insert, Modify, Remove, Apply, Clear }; enum class BookMarkModEnum { Insert, Modify, Remove, Apply, Clear };
enum class DocumentType { File, WorkSpace, RegionFile };
/*=========================*/ /*=========================*/
class QHexDocument : public QObject { class QHexDocument : public QObject {
@ -83,7 +85,8 @@ public:
bool isDocSaved(); bool isDocSaved();
void setDocSaved(bool b = true); void setDocSaved(bool b = true);
bool isWorkspace = false; DocumentType documentType();
void setDocumentType(DocumentType type);
void setMetafgVisible(bool b); void setMetafgVisible(bool b);
void setMetabgVisible(bool b); void setMetabgVisible(bool b);
@ -152,6 +155,11 @@ public:
template <typename T> template <typename T>
static QHexDocument *fromFile(QString filename, bool readonly = false, static QHexDocument *fromFile(QString filename, bool readonly = false,
QObject *parent = nullptr); QObject *parent = nullptr);
static QHexDocument *fromRegionFile(QString filename, qint64 start,
qint64 length, bool readonly = false,
QObject *parent = nullptr);
template <typename T> template <typename T>
static QHexDocument *fromMemory(char *data, int size, bool readonly = false, static QHexDocument *fromMemory(char *data, int size, bool readonly = false,
QObject *parent = nullptr); QObject *parent = nullptr);
@ -209,6 +217,8 @@ private:
bool m_metabg = true; bool m_metabg = true;
bool m_metacomment = true; bool m_metacomment = true;
DocumentType m_doctype = DocumentType::File;
/*======================*/ /*======================*/
}; };
@ -222,8 +232,7 @@ QHexDocument *QHexDocument::fromDevice(QIODevice *iodevice, bool readonly,
if (!iodevice->isOpen()) { if (!iodevice->isOpen()) {
needsclose = true; needsclose = true;
iodevice->open(readonly ? QIODevice::ReadOnly iodevice->open(QIODevice::ReadOnly);
: QIODevice::ReadWrite); // modifed by wingsummer
} }
QHexBuffer *hexbuffer = new T(); QHexBuffer *hexbuffer = new T();

View File

@ -18,17 +18,6 @@
QHexRenderer *QHexView::renderer() { return m_renderer; } QHexRenderer *QHexView::renderer() { return m_renderer; }
int QHexView::getWorkSpaceState(QHexDocument *doc, bool b) {
if (doc->isWorkspace) {
if (b)
return 1;
else
return 0;
} else {
return -1;
}
}
void QHexView::switchDocument(QHexDocument *document, QHexRenderer *renderer, void QHexView::switchDocument(QHexDocument *document, QHexRenderer *renderer,
int vBarValue) { int vBarValue) {
if (document && renderer) { if (document && renderer) {

View File

@ -46,7 +46,6 @@ public:
void setAddressBase(quint64 base); void setAddressBase(quint64 base);
bool isSaved(); bool isSaved();
int getWorkSpaceState(QHexDocument *doc, bool b);
static QFont getHexeditorFont(); static QFont getHexeditorFont();
void getStatus(); void getStatus();

View File

@ -19,7 +19,8 @@ SOURCES += \
$$PWD/class/logger.cpp \ $$PWD/class/logger.cpp \
$$PWD/dialog/settingwindow.cpp \ $$PWD/dialog/settingwindow.cpp \
$$PWD/mlicense/licensemanager.cpp \ $$PWD/mlicense/licensemanager.cpp \
$$PWD/mlicense/lincensedialog.cpp $$PWD/mlicense/lincensedialog.cpp \
$$PWD/dialog/openregiondialog.cpp
RESOURCES += resources.qrc RESOURCES += resources.qrc
@ -49,7 +50,8 @@ HEADERS += \
$$PWD/dialog/settingwindow.h \ $$PWD/dialog/settingwindow.h \
$$PWD/mlicense/licensemanager.h \ $$PWD/mlicense/licensemanager.h \
$$PWD/mlicense/lincensedialog.h \ $$PWD/mlicense/lincensedialog.h \
$$PWD/mlicense/qaesencryption.h $$PWD/mlicense/qaesencryption.h \
$$PWD/dialog/openregiondialog.h
LIBS += $$PWD/mlicense/libQtAES.a LIBS += $$PWD/mlicense/libQtAES.a

View File

@ -40,6 +40,8 @@ DriverSelectorDialog::DriverSelectorDialog(DMainWindow *parent)
connect(s, &QShortcut::activated, this, &DriverSelectorDialog::on_accepted); connect(s, &QShortcut::activated, this, &DriverSelectorDialog::on_accepted);
connect(drivers, &QListWidget::itemSelectionChanged, this, connect(drivers, &QListWidget::itemSelectionChanged, this,
&DriverSelectorDialog::on_list_selectionChanged); &DriverSelectorDialog::on_list_selectionChanged);
drivers->setCurrentRow(0); // 我不信你没有驱动器
} }
void DriverSelectorDialog::on_list_selectionChanged() { void DriverSelectorDialog::on_list_selectionChanged() {

View File

@ -6,8 +6,7 @@
#include <QListWidgetItem> #include <QListWidgetItem>
#include <QShortcut> #include <QShortcut>
EncodingDialog::EncodingDialog(DMainWindow *parent) { EncodingDialog::EncodingDialog(DMainWindow *parent) : DDialog(parent) {
Q_UNUSED(parent);
this->setWindowTitle(tr("Encoding")); this->setWindowTitle(tr("Encoding"));
this->setFixedSize(500, 600); this->setFixedSize(500, 600);
auto l = new DLabel(tr("ChooseEncoding"), this); auto l = new DLabel(tr("ChooseEncoding"), this);

View File

@ -1,11 +1,13 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "QHexView/document/buffer/qfilebuffer.h" #include "QHexView/document/buffer/qfilebuffer.h"
#include "QHexView/document/buffer/qfileregionbuffer.h"
#include "QHexView/document/buffer/qmemorybuffer.h" #include "QHexView/document/buffer/qmemorybuffer.h"
#include "QHexView/document/qhexcursor.h" #include "QHexView/document/qhexcursor.h"
#include "QHexView/document/qhexmetadata.h" #include "QHexView/document/qhexmetadata.h"
#include "aboutsoftwaredialog.h" #include "aboutsoftwaredialog.h"
#include "class/appmanager.h" #include "class/appmanager.h"
#include "class/recentfilemanager.h" #include "class/recentfilemanager.h"
#include "dialog/openregiondialog.h"
#include "driverselectordialog.h" #include "driverselectordialog.h"
#include "encodingdialog.h" #include "encodingdialog.h"
#include "finddialog.h" #include "finddialog.h"
@ -152,11 +154,15 @@ MainWindow::MainWindow(DMainWindow *parent) {
auto keynewb = QKeySequence(Qt::KeyboardModifier::ControlModifier | auto keynewb = QKeySequence(Qt::KeyboardModifier::ControlModifier |
Qt::KeyboardModifier::ShiftModifier | Qt::Key_N); Qt::KeyboardModifier::ShiftModifier | Qt::Key_N);
auto keyopenr = QKeySequence(Qt::KeyboardModifier::ControlModifier |
Qt::KeyboardModifier::ShiftModifier | Qt::Key_O);
AddToolSubMenuShortcutAction("newb", tr("NewBigFile"), AddToolSubMenuShortcutAction("newb", tr("NewBigFile"),
MainWindow::on_newbigfile, keynewb); MainWindow::on_newbigfile, keynewb);
AddToolSubMenuShortcutAction("open", tr("OpenF"), MainWindow::on_openfile, AddToolSubMenuShortcutAction("open", tr("OpenF"), MainWindow::on_openfile,
QKeySequence::Open); QKeySequence::Open);
AddToolSubMenuShortcutAction("openr", tr("OpenFR"), MainWindow::on_openregion,
keyopenr);
auto keysaveas = auto keysaveas =
QKeySequence(Qt::KeyboardModifier::ControlModifier | QKeySequence(Qt::KeyboardModifier::ControlModifier |
@ -513,7 +519,12 @@ MainWindow::MainWindow(DMainWindow *parent) {
} }
AddToolBtnEnd2(); AddToolBtnEnd2();
AddToolBarTool("open", MainWindow::on_openfile, tr("OpenF")); AddToolBtnBegin2("open") {
AddToolBtnBtn("open", tr("OpenF"), MainWindow::on_openfile);
AddToolBtnBtn("openr", tr("OpenFR"), MainWindow::on_openregion);
}
AddToolBtnEnd2();
AddToolBarTool("workspace", MainWindow::on_openworkspace, AddToolBarTool("workspace", MainWindow::on_openworkspace,
tr("OpenWorkSpace")); tr("OpenWorkSpace"));
AddToolBarTool("opendriver", MainWindow::on_opendriver, tr("OpenD")); AddToolBarTool("opendriver", MainWindow::on_opendriver, tr("OpenD"));
@ -2391,10 +2402,18 @@ void MainWindow::connectControl(IWingPlugin *plugin) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
newFile(); newFile();
}); });
ConnectControlLamba2(WingPlugin::Controller::openFile,
[=](QString filename, bool readonly, int *openedIndex) {
plgsys->resetTimeout(
qobject_cast<IWingPlugin *>(sender()));
return openFile(filename, readonly, openedIndex);
});
ConnectControlLamba2( ConnectControlLamba2(
WingPlugin::Controller::openFile, [=](QString filename, bool readonly) { WingPlugin::Controller::openRegionFile,
[=](QString filename, bool readonly, int *openedIndex, qint64 start,
qint64 length) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
return openFile(filename, readonly); return openRegionFile(filename, readonly, openedIndex, start, length);
}); });
ConnectControlLamba2(WingPlugin::Controller::openDriver, [=](QString driver) { ConnectControlLamba2(WingPlugin::Controller::openDriver, [=](QString driver) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
@ -2571,6 +2590,103 @@ void MainWindow::newFile(bool bigfile) {
} }
} }
ErrFile MainWindow::openRegionFile(QString filename, bool readonly,
int *openedindex, qint64 start,
qint64 length) {
QList<QVariant> params;
if (_enableplugin) {
params << filename << readonly;
plgsys->raiseDispatch(HookIndex::OpenFileBegin, params);
}
QFileInfo info(filename);
if (info.exists()) {
if (!info.permission(QFile::ReadUser)) {
if (_enableplugin) {
params << ErrFile::Permission;
plgsys->raiseDispatch(HookIndex::OpenFileEnd, params);
}
return ErrFile::Permission;
}
if (!readonly && !info.permission(QFile::WriteUser)) {
if (_enableplugin) {
params << ErrFile::Permission;
plgsys->raiseDispatch(HookIndex::OpenFileEnd, params);
}
return ErrFile::Permission;
}
int i = 0;
for (auto item : hexfiles) {
if (item.filename == filename) {
if (openedindex) {
*openedindex = i;
}
if (_enableplugin) {
params << ErrFile::AlreadyOpened;
plgsys->raiseDispatch(HookIndex::OpenFileEnd, params);
}
return ErrFile::AlreadyOpened;
}
i++;
}
HexFile hf;
auto *p =
QHexDocument::fromRegionFile(filename, start, length, readonly, this);
if (p == nullptr) {
if (_enableplugin) {
params << ErrFile::Permission;
plgsys->raiseDispatch(HookIndex::OpenFileEnd, params);
}
return ErrFile::Permission;
}
hexeditor->setVisible(true);
hf.doc = p;
hf.filename = filename;
hf.workspace.clear();
hf.vBarValue = -1;
p->setDocumentType(DocumentType::RegionFile);
hf.isdriver = false;
hexeditor->setDocument(p);
hexeditor->setLockedFile(readonly);
hexeditor->setKeepSize(true);
hexeditor->renderer()->setEncoding(_encoding);
hf.render = hexeditor->renderer();
hexfiles.push_back(hf);
p->setDocSaved();
hexeditor->getStatus();
QIcon qicon;
QMimeDatabase db;
auto t = db.mimeTypeForFile(filename);
auto ico = t.iconName();
qicon = QIcon::fromTheme(ico, QIcon(ico));
tabs->addTab(qicon, info.fileName());
auto index = hexfiles.count() - 1;
tabs->setCurrentIndex(index);
tabs->setTabToolTip(index, filename);
setEditModeEnabled(true);
_currentfile = index;
if (_enableplugin) {
params << ErrFile::Success;
plgsys->raiseDispatch(HookIndex::OpenFileEnd, params);
}
return ErrFile::Success;
}
if (_enableplugin) {
params << ErrFile::NotExist;
plgsys->raiseDispatch(HookIndex::OpenFileEnd, params);
}
return ErrFile::NotExist;
}
ErrFile MainWindow::openFile(QString filename, bool readonly, int *openedindex, ErrFile MainWindow::openFile(QString filename, bool readonly, int *openedindex,
QString workspace, bool *oldworkspace) { QString workspace, bool *oldworkspace) {
QList<QVariant> params; QList<QVariant> params;
@ -2615,8 +2731,6 @@ ErrFile MainWindow::openFile(QString filename, bool readonly, int *openedindex,
i++; i++;
} }
hexeditor->setVisible(true);
HexFile hf; HexFile hf;
auto *p = auto *p =
info.size() > FILEMAXBUFFER info.size() > FILEMAXBUFFER
@ -2625,17 +2739,19 @@ ErrFile MainWindow::openFile(QString filename, bool readonly, int *openedindex,
if (p == nullptr) { if (p == nullptr) {
if (_enableplugin) { if (_enableplugin) {
params << ErrFile::Error; params << ErrFile::Permission;
plgsys->raiseDispatch(HookIndex::OpenFileEnd, params); plgsys->raiseDispatch(HookIndex::OpenFileEnd, params);
} }
return ErrFile::Error; return ErrFile::Permission;
} }
hexeditor->setVisible(true);
hf.doc = p; hf.doc = p;
hf.filename = filename; hf.filename = filename;
hf.workspace = workspace; hf.workspace = workspace;
hf.vBarValue = -1; hf.vBarValue = -1;
p->isWorkspace = workspace.length() > 0; p->setDocumentType(workspace.length() > 0 ? DocumentType::WorkSpace
: DocumentType::File);
hf.isdriver = false; hf.isdriver = false;
hexeditor->setDocument(p); hexeditor->setDocument(p);
hexeditor->setLockedFile(readonly); hexeditor->setLockedFile(readonly);
@ -2648,7 +2764,7 @@ ErrFile MainWindow::openFile(QString filename, bool readonly, int *openedindex,
QIcon qicon; QIcon qicon;
if (p->isWorkspace) { if (p->documentType() == DocumentType::WorkSpace) {
qicon = ICONRES("pro"); qicon = ICONRES("pro");
} else { } else {
QMimeDatabase db; QMimeDatabase db;
@ -2856,16 +2972,40 @@ void MainWindow::on_openfile() {
QMessageBox::critical(this, tr("Error"), tr("FileNotExist")); QMessageBox::critical(this, tr("Error"), tr("FileNotExist"));
return; return;
} }
if (res == ErrFile::Permission &&
openFile(filename, true, &index) == ErrFile::Permission) {
QMessageBox::critical(this, tr("Error"), tr("FilePermission"));
return;
}
if (res == ErrFile::AlreadyOpened) { if (res == ErrFile::AlreadyOpened) {
setFilePage(index); setFilePage(index);
return; return;
} }
if (res == ErrFile::Permission && recentmanager->addRecentFile(filename);
openFile(filename, true) == ErrFile::Permission) { }
}
void MainWindow::on_openregion() {
OpenRegionDialog d;
if (d.exec()) {
auto res = d.getResult();
int index;
auto ret =
openRegionFile(res.filename, false, &index, res.start, res.length);
if (ret == ErrFile::NotExist) {
QMessageBox::critical(this, tr("Error"), tr("FileNotExist"));
return;
}
if (ret == ErrFile::Permission &&
openRegionFile(res.filename, true, &index, res.start, res.length) ==
ErrFile::Permission) {
QMessageBox::critical(this, tr("Error"), tr("FilePermission")); QMessageBox::critical(this, tr("Error"), tr("FilePermission"));
return; return;
} }
recentmanager->addRecentFile(filename); if (ret == ErrFile::AlreadyOpened) {
setFilePage(index);
return;
}
} }
} }
@ -3365,7 +3505,10 @@ void MainWindow::on_bookmarkChanged(BookMarkModEnum flag, int index, qint64 pos,
void MainWindow::on_documentSwitched() { void MainWindow::on_documentSwitched() {
iReadWrite->setPixmap(hexeditor->isReadOnly() ? infoReadonly : infoWriteable); iReadWrite->setPixmap(hexeditor->isReadOnly() ? infoReadonly : infoWriteable);
if (hexfiles.count()) { if (hexfiles.count()) {
iw->setPixmap(hexeditor->document()->isWorkspace ? infow : infouw); iw->setPixmap(hexeditor->document()->documentType() ==
DocumentType::WorkSpace
? infow
: infouw);
} else { } else {
iw->setPixmap(infouw); iw->setPixmap(infouw);
} }
@ -3394,7 +3537,7 @@ ErrFile MainWindow::save(int index) {
doc->metadata()->getallMetas(), infos); doc->metadata()->getallMetas(), infos);
if (!b) if (!b)
return ErrFile::WorkSpaceUnSaved; return ErrFile::WorkSpaceUnSaved;
f.doc->isWorkspace = true; f.doc->setDocumentType(DocumentType::WorkSpace);
iw->setPixmap(infow); iw->setPixmap(infow);
tabs->setTabIcon(index, ICONRES("pro")); tabs->setTabIcon(index, ICONRES("pro"));
f.doc->setDocSaved(); f.doc->setDocSaved();
@ -3409,7 +3552,7 @@ ErrFile MainWindow::save(int index) {
if (!b) if (!b)
return ErrFile::WorkSpaceUnSaved; return ErrFile::WorkSpaceUnSaved;
hexfiles[index].workspace = f.filename + PROEXT; hexfiles[index].workspace = f.filename + PROEXT;
f.doc->isWorkspace = true; f.doc->setDocumentType(DocumentType::WorkSpace);
iw->setPixmap(infow); iw->setPixmap(infow);
tabs->setTabIcon(index, ICONRES("pro")); tabs->setTabIcon(index, ICONRES("pro"));
f.doc->setDocSaved(); f.doc->setDocSaved();
@ -3473,7 +3616,7 @@ ErrFile MainWindow::saveAs(QString filename, int index) {
if (!b) if (!b)
return ErrFile::WorkSpaceUnSaved; return ErrFile::WorkSpaceUnSaved;
hexfiles[index].workspace = filename + PROEXT; hexfiles[index].workspace = filename + PROEXT;
f.doc->isWorkspace = true; f.doc->setDocumentType(DocumentType::WorkSpace);
iw->setPixmap(infow); iw->setPixmap(infow);
tabs->setTabIcon(index, ICONRES("pro")); tabs->setTabIcon(index, ICONRES("pro"));
f.doc->setDocSaved(); f.doc->setDocSaved();
@ -3690,7 +3833,7 @@ void MainWindow::setEditModeEnabled(bool b, bool isdriver) {
if (b) { if (b) {
enableDirverLimit(isdriver); enableDirverLimit(isdriver);
auto dm = hexeditor->document()->isWorkspace; auto dm = hexeditor->document()->documentType() == DocumentType::WorkSpace;
iw->setPixmap(dm ? infow : infouw); iw->setPixmap(dm ? infow : infouw);
auto doc = hexeditor->document(); auto doc = hexeditor->document();
doc->canRedoChanged(doc->canRedo()); doc->canRedoChanged(doc->canRedo());

View File

@ -137,6 +137,9 @@ public:
private: private:
void newFile(bool bigfile = false); void newFile(bool bigfile = false);
ErrFile openRegionFile(QString filename, bool readonly = false,
int *openedindex = nullptr, qint64 start = 0,
qint64 length = 1024);
ErrFile openDriver(QString driver); ErrFile openDriver(QString driver);
ErrFile closeFile(int index, bool force = false); ErrFile closeFile(int index, bool force = false);
ErrFile save(int index); ErrFile save(int index);
@ -165,6 +168,7 @@ private:
void on_newfile(); void on_newfile();
void on_newbigfile(); void on_newbigfile();
void on_openfile(); void on_openfile();
void on_openregion();
void on_redofile(); void on_redofile();
void on_undofile(); void on_undofile();
void on_copyfile(); void on_copyfile();

View File

@ -0,0 +1,70 @@
#include "openregiondialog.h"
#include "utilities.h"
#include <DDialogButtonBox>
#include <DLabel>
#include <DMessageManager>
#include <QShortcut>
OpenRegionDialog::OpenRegionDialog(DMainWindow *parent) : DDialog(parent) {
this->setWindowTitle(tr("OpenRegion"));
addContent(new DLabel(tr("ChooseFile"), this));
addSpacing(5);
filepath = new DFileChooserEdit(this);
filepath->initDialog();
addContent(filepath);
addSpacing(10);
addContent(new DLabel(tr("Start"), this));
addSpacing(5);
sbStart = new DSpinBox(this);
sbStart->setRange(0, INT_MAX);
sbStart->setPrefix("0x");
sbStart->setDisplayIntegerBase(16);
addContent(sbStart);
addSpacing(10);
addContent(new DLabel(tr("Len"), this));
addSpacing(5);
sbLength = new DSpinBox(this);
sbLength->setRange(1, INT_MAX);
addContent(sbLength);
addSpacing(20);
auto dbbox = new DDialogButtonBox(
DDialogButtonBox::Ok | DDialogButtonBox::Cancel, this);
connect(dbbox, &DDialogButtonBox::accepted, this,
&OpenRegionDialog::on_accept);
connect(dbbox, &DDialogButtonBox::rejected, this,
&OpenRegionDialog::on_reject);
auto key = QKeySequence(Qt::Key_Return);
auto s = new QShortcut(key, this);
connect(s, &QShortcut::activated, this, &OpenRegionDialog::on_accept);
addContent(dbbox);
}
RegionFileResult OpenRegionDialog::getResult() { return res; }
void OpenRegionDialog::on_accept() {
auto file = filepath->lineEdit()->text();
if (file.length()) {
if (!QFile::exists(file)) {
DMessageManager::instance()->sendMessage(this, ICONRES("open"),
tr("FileNotExist"));
}
} else {
DMessageManager::instance()->sendMessage(this, ICONRES("open"),
tr("NoFileSelected"));
return;
}
res.filename = file;
res.start = sbStart->value();
res.length = sbLength->value();
done(1);
}
void OpenRegionDialog::on_reject() { done(0); }
void OpenRegionDialog::closeEvent(QCloseEvent *event) {
Q_UNUSED(event);
done(0);
}

View File

@ -0,0 +1,37 @@
#ifndef OPENREGIONDIALOG_H
#define OPENREGIONDIALOG_H
#include <DDialog>
#include <DFileChooserEdit>
#include <DMainWindow>
#include <DSpinBox>
DWIDGET_USE_NAMESPACE
struct RegionFileResult {
QString filename;
qint64 start;
qint64 length;
};
class OpenRegionDialog : public DDialog {
Q_OBJECT
public:
OpenRegionDialog(DMainWindow *parent = nullptr);
RegionFileResult getResult();
private:
void on_accept();
void on_reject();
private:
DFileChooserEdit *filepath;
DSpinBox *sbStart, *sbLength;
RegionFileResult res;
protected:
void closeEvent(QCloseEvent *event) override;
};
#endif // OPENREGIONDIALOG_H

BIN
WingHexExplorer/images/openr.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -51,7 +51,8 @@ int main(int argc, char *argv[]) {
a.setOrganizationName("WingCloud"); a.setOrganizationName("WingCloud");
a.setApplicationName(QObject::tr("WingHexExplorer")); a.setApplicationName(QObject::tr("WingHexExplorer"));
a.setApplicationVersion("1.4.9"); a.setApplicationVersion("1.4.10");
a.setApplicationLicense("GPL-3.0");
a.setProductIcon(QIcon(":/images/icon.png")); a.setProductIcon(QIcon(":/images/icon.png"));
a.setProductName(QObject::tr("WingHexExplorer")); a.setProductName(QObject::tr("WingHexExplorer"));
a.setApplicationDescription(QObject::tr("AppDescription")); a.setApplicationDescription(QObject::tr("AppDescription"));
@ -81,14 +82,13 @@ int main(int argc, char *argv[]) {
// 保存程序的窗口主题设置 // 保存程序的窗口主题设置
DApplicationSettings as; DApplicationSettings as;
Q_UNUSED(as) Q_UNUSED(as);
auto manager = AppManager::instance(); auto manager = AppManager::instance();
MainWindow w; MainWindow w;
manager->mWindow = &w; manager->mWindow = &w;
manager->openFiles(urls); manager->openFiles(urls);
w.show(); w.show();
dbus.registerObject(com, manager, QDBusConnection::ExportScriptableSlots); dbus.registerObject(com, manager, QDBusConnection::ExportScriptableSlots);
Dtk::Widget::moveToCenter(&w); Dtk::Widget::moveToCenter(&w);
return a.exec(); return a.exec();

View File

@ -11,7 +11,7 @@
#include <QWidget> #include <QWidget>
#include <QtCore> #include <QtCore>
#define SDKVERSION 8 #define SDKVERSION 9
#define GETPLUGINQM(name) \ #define GETPLUGINQM(name) \
(QCoreApplication::applicationDirPath() + "/plglang/" + name) (QCoreApplication::applicationDirPath() + "/plglang/" + name)
#define PLUGINDIR (QCoreApplication::applicationDirPath() + "/plugin") #define PLUGINDIR (QCoreApplication::applicationDirPath() + "/plugin")
@ -309,7 +309,11 @@ signals:
// mainwindow // mainwindow
void newFile(bool bigfile = false); void newFile(bool bigfile = false);
ErrFile openFile(QString filename, bool readonly = false); ErrFile openFile(QString filename, bool readonly = false,
int *openedIndex = nullptr);
ErrFile openRegionFile(QString filename, bool readonly = false,
int *openedIndex = nullptr, qint64 start = 0,
qint64 length = 1024);
ErrFile openDriver(QString driver); ErrFile openDriver(QString driver);
ErrFile closeFile(int index, bool force = false); ErrFile closeFile(int index, bool force = false);
ErrFile saveFile(int index); ErrFile saveFile(int index);

View File

@ -81,6 +81,7 @@
<file>images/usr.jpg</file> <file>images/usr.jpg</file>
<file>images/fullscreen.png</file> <file>images/fullscreen.png</file>
<file>images/reload.png</file> <file>images/reload.png</file>
<file>images/openr.png</file>
</qresource> </qresource>
<qresource prefix="/resources"> <qresource prefix="/resources">
<file>settings.json</file> <file>settings.json</file>

View File

@ -1,5 +1,10 @@
更新日志(由寂静的羽夏编写): 更新日志(由寂静的羽夏编写):
1.4.10
1. 修复打开驱动器未选中直接点确定崩溃的 Bug
2. 更新打开相关接口
3. 修复文件打开失败但仍显示编辑区的 Bug
1.4.9 1.4.9
1. 增加“解码字符串”解码字节长度限制,防止卡死界面内存溢出 1. 增加“解码字符串”解码字节长度限制,防止卡死界面内存溢出
2. 修复最后选中行没有任何字节坐标溢出的 Bug 2. 修复最后选中行没有任何字节坐标溢出的 Bug