feat(api)!: 增加新的 API ;完善程序细节功能;

This commit is contained in:
寂静的羽夏 2024-09-21 12:28:18 +08:00
parent 598c20ac1a
commit 276787df09
19 changed files with 806 additions and 381 deletions

View File

@ -23,6 +23,15 @@ void QHexMetadata::ModifyMetadata(QHexMetadataAbsoluteItem newmeta,
m_undo->push(new MetaReplaceCommand(this, newmeta, oldmeta)); m_undo->push(new MetaReplaceCommand(this, newmeta, oldmeta));
} }
void QHexMetadata::RemoveMetadatas(
const QList<QHexMetadataAbsoluteItem> &items) {
m_undo->beginMacro("RemoveMetadatas");
for (auto &item : items) {
RemoveMetadata(item);
}
m_undo->endMacro();
}
void QHexMetadata::RemoveMetadata(QHexMetadataAbsoluteItem item) { void QHexMetadata::RemoveMetadata(QHexMetadataAbsoluteItem item) {
m_undo->push(new MetaRemoveCommand(this, item)); m_undo->push(new MetaRemoveCommand(this, item));
} }

View File

@ -61,6 +61,7 @@ public:
void ModifyMetadata(QHexMetadataAbsoluteItem newmeta, void ModifyMetadata(QHexMetadataAbsoluteItem newmeta,
QHexMetadataAbsoluteItem oldmeta); QHexMetadataAbsoluteItem oldmeta);
void RemoveMetadatas(const QList<QHexMetadataAbsoluteItem> &items);
void RemoveMetadata(QHexMetadataAbsoluteItem item); void RemoveMetadata(QHexMetadataAbsoluteItem item);
void RemoveMetadata(qsizetype offset); void RemoveMetadata(qsizetype offset);
void Metadata(qsizetype begin, qsizetype end, const QColor &fgcolor, void Metadata(qsizetype begin, qsizetype end, const QColor &fgcolor,

View File

@ -338,6 +338,10 @@ bool QHexView::atEnd() const {
return m_cursor->position().offset() >= m_document->length(); return m_cursor->position().offset() >= m_document->length();
} }
void QHexView::gotoMetaData(qsizetype index) {
m_cursor->moveTo(m_document->metadata()->getallMetasPtr().at(index).begin);
}
QByteArray QHexView::selectedBytes() const { QByteArray QHexView::selectedBytes() const {
if (!m_cursor->hasSelection()) if (!m_cursor->hasSelection())
return QByteArray(); return QByteArray();

View File

@ -103,6 +103,8 @@ public:
bool removeSelection(); bool removeSelection();
bool atEnd() const; bool atEnd() const;
void gotoMetaData(qsizetype index);
QByteArray selectedBytes() const; QByteArray selectedBytes() const;
bool cut(bool hex); bool cut(bool hex);

View File

@ -130,7 +130,7 @@
3. 打包后的二进制安装包不得含有侵犯他人合法权益的内容,比如向其加入未经授权的付费内容或计算机病毒等。 3. 打包后的二进制安装包不得含有侵犯他人合法权益的内容,比如向其加入未经授权的付费内容或计算机病毒等。
4. 包内最好含有主程序的校验和,但不强求。 4. 包内最好含有主程序的校验和,但不强求。
5. 无论是哪种打包形式,都一定要声明其开源协议和自由属性,不得隐藏而借机收费。虽然收费我并不反感,下载服务器还是需要资金维护的,但借着信息差骗人收费,这是我极其深恶痛绝的。 5. 无论是哪种打包形式,都一定要声明其开源协议和自由属性,不得隐藏而借机收费。虽然收费我并不反感,下载服务器还是需要资金维护的,但借着信息差骗人收费,这是我极其深恶痛绝的。
6. 无论以任何为目的,如未获得我作者的授权,不得修改任意程序内指向的网络链接,比如赞助和关于软件部分的内容等。 6. 无论以任何为目的,如未获得我作者的授权,不得修改任意程序内指向的网络链接和软件关于信息,比如赞助和关于软件部分的内容等。
7. 不得在安装程序内插入任何含有商业推广的插件,并且严格遵守第二条内容。 7. 不得在安装程序内插入任何含有商业推广的插件,并且严格遵守第二条内容。
### issue 前必读 ### issue 前必读

View File

@ -130,7 +130,7 @@ First of all, I would like to express my sincere tanks for your enthusiastic hel
3. The package must not contain content that infringes on the legitimate rights and interests of others, such as adding unauthorized paid content or computer viruses to it. 3. The package must not contain content that infringes on the legitimate rights and interests of others, such as adding unauthorized paid content or computer viruses to it.
4. It is best to contain the checksum of the main program in the package, but it is not mandatory. 4. It is best to contain the checksum of the main program in the package, but it is not mandatory.
5. Regardless of the packaging format, its open source agreement and free attributes must be stated, and it is not allowed to hide and charge for it. Although I don't mind charging, the download server still needs money to maintain, but I hate charging by taking advantage of the information gap. 5. Regardless of the packaging format, its open source agreement and free attributes must be stated, and it is not allowed to hide and charge for it. Although I don't mind charging, the download server still needs money to maintain, but I hate charging by taking advantage of the information gap.
6. Regardless of the purpose, if you do not obtain the authorization of me, you may not modify any network links pointed to in the program, such as sponsorship and content about the software. 6. Regardless of the purpose, if you do not obtain the authorization of me, you may not modify any network links pointed to and the ABOUT contents in the program, such as sponsorship and content about the software.
7. You may not insert any plug-in containing commercial promotion in the installation program, and strictly abide by the content of the second article. 7. You may not insert any plug-in containing commercial promotion in the installation program, and strictly abide by the content of the second article.
### Issue ### Issue

View File

@ -1,15 +1,11 @@
v2.0.0 版本规划(不知道啥时候会完成,很可能会鸽): v2.0.0 版本规划(不知道啥时候会完成,很可能会鸽):
1. 增加脚本的 Json 支持和正则表达式支持。 1. 增加 AngelScript 脚本编辑器的词法相关支持,比如更好的语法高亮以及增加智能提示等。
2. 对编辑器提供更加细节的设置:比如日志显示级别以及开发者模式等等。 2. 增加对内置的 AngelScript 脚本编辑器设置功能,增加语法片段管理器和支持。
3. 完成内置的 AngelScript 脚本的开发和调试的编辑器。 3. 对程序的操作细节优化,增加更多的提醒。
4. 实现在 Win 和 Linux 的基于 GitAction 自动化编译,在本地编译后只需输入一个命令或程序即可完成对当前平台支持的安装程序打包。 4. 完善 AngelScript 脚本模块标准库。
5. 对程序的操作细节优化,增加更多的提醒,完成剩余的细节功能(比如最近打开功能、打开文件等)。 5. 为 AngelScript 增加宏的条件编译,拓展宏的功能。
6. 尝试增加 AngelScript 脚本模块调用支持(类似标准库)。 6. 使用文档和开发文档。
7. 增加使用通用文件对话框按钮和标题栏是否使用系统提供的切换。
8. 使用文档和开发文档。
等 v2.0.0 前 7 项完成之后我会考虑多平台的支持和安装包的发布rpm、linglong、flatpak、 Win 安装包(考虑 InnoSetup以及其他硬件平台arm64 、RISC-V 和 LoongArch 实验性支持。
v3.0.0 版本规划: v3.0.0 版本规划:

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,7 @@ class SettingManager : public QObject {
public: public:
enum SETTING { enum SETTING {
NONE = 0,
APP = 1, APP = 1,
PLUGIN = 2, PLUGIN = 2,
EDITOR = 4, EDITOR = 4,

View File

@ -585,11 +585,11 @@ void WingAngelAPI::installHexReaderAPI(asIScriptEngine *engine) {
engine, std::bind(&WingHex::WingPlugin::Reader::addressBase, reader), engine, std::bind(&WingHex::WingPlugin::Reader::addressBase, reader),
QPTR_WRAP("addressBase()")); QPTR_WRAP("addressBase()"));
registerAPI<bool(void *ref, int typeId)>( registerAPI<bool(qsizetype, void *, int)>(
engine, engine,
std::bind(&WingAngelAPI::_HexReader_read, this, std::placeholders::_1, std::bind(&WingAngelAPI::_HexReader_read, this, std::placeholders::_1,
std::placeholders::_2), std::placeholders::_2, std::placeholders::_3),
"bool read(? &in)"); "bool read(" QSIZETYPE ", ? &out)");
registerAPI<CScriptArray *(qsizetype, qsizetype)>( registerAPI<CScriptArray *(qsizetype, qsizetype)>(
engine, engine,
@ -621,6 +621,18 @@ void WingAngelAPI::installHexReaderAPI(asIScriptEngine *engine) {
std::placeholders::_1), std::placeholders::_1),
"int64 readInt64(" QSIZETYPE ")"); "int64 readInt64(" QSIZETYPE ")");
registerAPI<float(qsizetype)>(
engine,
std::bind(&WingHex::WingPlugin::Reader::readFloat, reader,
std::placeholders::_1),
"float readFloat(" QSIZETYPE ")");
registerAPI<double(qsizetype)>(
engine,
std::bind(&WingHex::WingPlugin::Reader::readDouble, reader,
std::placeholders::_1),
"double readDouble(" QSIZETYPE ")");
registerAPI<QString(qsizetype, QString)>( registerAPI<QString(qsizetype, QString)>(
engine, engine,
std::bind(&WingHex::WingPlugin::Reader::readString, reader, std::bind(&WingHex::WingPlugin::Reader::readString, reader,
@ -770,6 +782,24 @@ void WingAngelAPI::installHexControllerAPI(asIScriptEngine *engine) {
std::placeholders::_1), std::placeholders::_1),
"bool setAddressBase(" QPTR ")"); "bool setAddressBase(" QPTR ")");
registerAPI<bool(qsizetype, void *, int)>(
engine,
std::bind(&WingAngelAPI::_HexReader_write, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3),
"bool write(" QSIZETYPE ", ? &out)");
registerAPI<bool(qsizetype, void *, int)>(
engine,
std::bind(&WingAngelAPI::_HexReader_insert, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3),
"bool insert(" QSIZETYPE ", ? &out)");
registerAPI<bool(qsizetype, void *, int)>(
engine,
std::bind(&WingAngelAPI::_HexReader_append, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3),
"bool append(" QSIZETYPE ", ? &out)");
registerAPI<bool()>(engine, registerAPI<bool()>(engine,
std::bind(&WingHex::WingPlugin::Controller::undo, ctl), std::bind(&WingHex::WingPlugin::Controller::undo, ctl),
"bool undo()"); "bool undo()");
@ -812,6 +842,18 @@ void WingAngelAPI::installHexControllerAPI(asIScriptEngine *engine) {
std::placeholders::_1, std::placeholders::_2), std::placeholders::_1, std::placeholders::_2),
"bool writeInt64(" QSIZETYPE ", int64)"); "bool writeInt64(" QSIZETYPE ", int64)");
registerAPI<bool(qsizetype, float)>(
engine,
std::bind(&WingHex::WingPlugin::Controller::writeFloat, ctl,
std::placeholders::_1, std::placeholders::_2),
"bool writeFloat(" QSIZETYPE ", float)");
registerAPI<bool(qsizetype, double)>(
engine,
std::bind(&WingHex::WingPlugin::Controller::writeDouble, ctl,
std::placeholders::_1, std::placeholders::_2),
"bool writeDouble(" QSIZETYPE ", double)");
registerAPI<bool(qsizetype, const CScriptArray &)>( registerAPI<bool(qsizetype, const CScriptArray &)>(
engine, engine,
std::bind(&WingAngelAPI::_HexController_writeBytes, this, std::bind(&WingAngelAPI::_HexController_writeBytes, this,
@ -849,6 +891,18 @@ void WingAngelAPI::installHexControllerAPI(asIScriptEngine *engine) {
std::placeholders::_1, std::placeholders::_2), std::placeholders::_1, std::placeholders::_2),
"bool insertInt64(" QSIZETYPE ", int64)"); "bool insertInt64(" QSIZETYPE ", int64)");
registerAPI<bool(qsizetype, float)>(
engine,
std::bind(&WingHex::WingPlugin::Controller::insertFloat, ctl,
std::placeholders::_1, std::placeholders::_2),
"bool insertFloat(" QSIZETYPE ", float)");
registerAPI<bool(qsizetype, double)>(
engine,
std::bind(&WingHex::WingPlugin::Controller::insertDouble, ctl,
std::placeholders::_1, std::placeholders::_2),
"bool insertDouble(" QSIZETYPE ", double)");
registerAPI<bool(qsizetype, const CScriptArray &)>( registerAPI<bool(qsizetype, const CScriptArray &)>(
engine, engine,
std::bind(&WingAngelAPI::_HexController_insertBytes, this, std::bind(&WingAngelAPI::_HexController_insertBytes, this,
@ -886,6 +940,18 @@ void WingAngelAPI::installHexControllerAPI(asIScriptEngine *engine) {
std::placeholders::_1), std::placeholders::_1),
"bool appendInt64(int64)"); "bool appendInt64(int64)");
registerAPI<bool(float)>(
engine,
std::bind(&WingHex::WingPlugin::Controller::appendFloat, ctl,
std::placeholders::_1),
"bool appendFloat(float)");
registerAPI<bool(double)>(
engine,
std::bind(&WingHex::WingPlugin::Controller::appendDouble, ctl,
std::placeholders::_1),
"bool appendDouble(double)");
registerAPI<bool(const CScriptArray &)>( registerAPI<bool(const CScriptArray &)>(
engine, engine,
std::bind(&WingAngelAPI::_HexController_appendBytes, this, std::bind(&WingAngelAPI::_HexController_appendBytes, this,
@ -1231,6 +1297,139 @@ QByteArray WingAngelAPI::cArray2ByteArray(const CScriptArray &array, int byteID,
return buffer; return buffer;
} }
bool WingAngelAPI::read2Ref(qsizetype offset, void *ref, int typeId) {
asIScriptContext *ctx = asGetActiveContext();
if (ctx) {
asIScriptEngine *engine = ctx->GetEngine();
if (typeId == asTYPEID_VOID)
return false;
else if (typeId == asTYPEID_BOOL)
*reinterpret_cast<bool *>(ref) = (reader.readInt8(offset) != 0);
else if (typeId == asTYPEID_INT8)
*reinterpret_cast<qint8 *>(ref) = reader.readInt8(offset);
else if (typeId == asTYPEID_INT16)
*reinterpret_cast<qint16 *>(ref) = reader.readInt16(offset);
else if (typeId == asTYPEID_INT32)
*reinterpret_cast<qint32 *>(ref) = reader.readInt32(offset);
else if (typeId == asTYPEID_INT64)
*reinterpret_cast<qint64 *>(ref) = reader.readInt64(offset);
else if (typeId == asTYPEID_UINT8)
*reinterpret_cast<quint8 *>(ref) = quint8(reader.readInt8(offset));
else if (typeId == asTYPEID_UINT16)
*reinterpret_cast<quint16 *>(ref) =
quint16(reader.readInt16(offset));
else if (typeId == asTYPEID_UINT32)
*reinterpret_cast<quint32 *>(ref) =
quint32(reader.readInt32(offset));
else if (typeId == asTYPEID_UINT64)
*reinterpret_cast<quint64 *>(ref) =
quint64(reader.readInt64(offset));
else if (typeId == asTYPEID_FLOAT)
*reinterpret_cast<float *>(ref) = reader.readFloat(offset);
else if (typeId == asTYPEID_DOUBLE)
*reinterpret_cast<double *>(ref) = reader.readDouble(offset);
else if ((typeId & asTYPEID_MASK_OBJECT) == 0) {
bool ok = false;
// Check if the value matches one of the defined enums
if (engine) {
asITypeInfo *t = engine->GetTypeInfoById(typeId);
for (int n = t->GetEnumValueCount(); n-- > 0;) {
int enumVal;
t->GetEnumValueByIndex(n, &enumVal);
if (enumVal == *(int *)ref) {
*reinterpret_cast<int *>(ref) = enumVal;
ok = true;
break;
}
}
}
if (!ok) {
return false;
}
} else if (typeId & asTYPEID_SCRIPTOBJECT) {
void *value = ref;
// Dereference handles, so we can see what it points to
if (typeId & asTYPEID_OBJHANDLE)
value = *(void **)value;
asIScriptObject *obj = (asIScriptObject *)value;
if (obj) {
for (asUINT n = 0; n < obj->GetPropertyCount(); n++) {
auto id = obj->GetPropertyTypeId(n);
auto data = obj->GetAddressOfProperty(n);
auto size = getAsTypeSize(id, data);
read2Ref(offset, data, id);
if (size > 0) {
offset += size;
}
}
}
} else {
// Dereference handles, so we can see what it points to
void *value = ref;
if (typeId & asTYPEID_OBJHANDLE)
value = *(void **)value;
if (engine) {
asITypeInfo *type = engine->GetTypeInfoByName("string");
if (value) {
// TODO support other type, now only string
if (type->GetTypeId() == (typeId & ~asTYPEID_OBJHANDLE)) {
*reinterpret_cast<QString *>(value) =
reader.readString(offset);
}
}
}
}
return true;
} else {
return false;
}
}
qsizetype WingAngelAPI::getAsTypeSize(int typeId, void *data) {
if (typeId == asTYPEID_VOID)
return false;
else if (typeId == asTYPEID_BOOL)
return 1;
else if (typeId == asTYPEID_INT8)
return sizeof(qint8);
else if (typeId == asTYPEID_INT16)
return sizeof(qint16);
else if (typeId == asTYPEID_INT32)
return sizeof(qint32);
else if (typeId == asTYPEID_INT64)
return sizeof(qint64);
else if (typeId == asTYPEID_UINT8)
return sizeof(quint8);
else if (typeId == asTYPEID_UINT16)
return sizeof(quint16);
else if (typeId == asTYPEID_UINT32)
return sizeof(quint32);
else if (typeId == asTYPEID_UINT64)
return sizeof(quint64);
else if (typeId == asTYPEID_FLOAT)
return sizeof(float);
else if (typeId == asTYPEID_DOUBLE)
return sizeof(double);
else {
typeId &= ~asTYPEID_OBJHANDLE;
asIScriptContext *ctx = asGetActiveContext();
auto engine = ctx->GetEngine();
asITypeInfo *type = engine->GetTypeInfoByName("string");
// TODO support other type, now only string
if (type->GetTypeId() == (typeId & ~asTYPEID_OBJHANDLE)) {
return reinterpret_cast<QString *>(data)->length() + 1;
}
}
return -1;
}
QString WingAngelAPI::_InputBox_getItem(int stringID, const QString &title, QString WingAngelAPI::_InputBox_getItem(int stringID, const QString &title,
const QString &label, const QString &label,
const CScriptArray &items, int current, const CScriptArray &items, int current,
@ -1270,7 +1469,203 @@ CScriptArray *WingAngelAPI::_HexReader_readBytes(qsizetype offset,
}); });
} }
bool WingAngelAPI::_HexReader_read(void *ref, int typeId) { return false; } bool WingAngelAPI::_HexReader_read(qsizetype offset, void *ref, int typeId) {
return read2Ref(offset, ref, typeId);
}
bool WingAngelAPI::_HexReader_write(qsizetype offset, void *ref, int typeId) {
asIScriptContext *ctx = asGetActiveContext();
if (ctx) {
asIScriptEngine *engine = ctx->GetEngine();
if (typeId == asTYPEID_VOID)
return false;
else if (typeId == asTYPEID_BOOL)
controller.writeInt8(offset,
*reinterpret_cast<bool *>(ref) ? 1 : 0);
else if (typeId == asTYPEID_INT8 || typeId == asTYPEID_UINT8)
controller.writeInt8(offset, *reinterpret_cast<qint8 *>(ref));
else if (typeId == asTYPEID_INT16 || typeId == asTYPEID_UINT16)
controller.writeInt16(offset, *reinterpret_cast<qint16 *>(ref));
else if (typeId == asTYPEID_INT32 || typeId == asTYPEID_UINT32)
controller.writeInt32(offset, *reinterpret_cast<qint32 *>(ref));
else if (typeId == asTYPEID_INT64 || typeId == asTYPEID_UINT64)
controller.writeInt64(offset, *reinterpret_cast<qint64 *>(ref));
else if (typeId == asTYPEID_FLOAT)
controller.writeFloat(offset, *reinterpret_cast<float *>(ref));
else if (typeId == asTYPEID_DOUBLE)
controller.writeDouble(offset, *reinterpret_cast<double *>(ref));
else if ((typeId & asTYPEID_MASK_OBJECT) == 0)
controller.writeInt32(offset, *reinterpret_cast<int *>(ref));
else if (typeId & asTYPEID_SCRIPTOBJECT) {
// Dereference handles, so we can see what it points to
void *value = ref;
if (typeId & asTYPEID_OBJHANDLE)
value = *(void **)value;
if (engine) {
asITypeInfo *t = engine->GetTypeInfoById(typeId);
for (int n = t->GetEnumValueCount(); n-- > 0;) {
int enumVal;
t->GetEnumValueByIndex(n, &enumVal);
if (enumVal == *(int *)value) {
controller.writeInt32(offset, enumVal);
break;
}
}
}
} else {
// Dereference handles, so we can see what it points to
void *value = ref;
if (typeId & asTYPEID_OBJHANDLE)
value = *(void **)value;
if (engine) {
asITypeInfo *type = engine->GetTypeInfoById(typeId);
if (value) {
// TODO support other type, now only string
if (type->GetTypeId() == (typeId & ~asTYPEID_OBJHANDLE)) {
controller.writeString(
offset, *reinterpret_cast<QString *>(value));
}
}
}
}
return true;
} else {
return false;
}
}
bool WingAngelAPI::_HexReader_insert(qsizetype offset, void *ref, int typeId) {
asIScriptContext *ctx = asGetActiveContext();
if (ctx) {
asIScriptEngine *engine = ctx->GetEngine();
if (typeId == asTYPEID_VOID)
return false;
else if (typeId == asTYPEID_BOOL)
controller.insertInt8(offset,
*reinterpret_cast<bool *>(ref) ? 1 : 0);
else if (typeId == asTYPEID_INT8 || typeId == asTYPEID_UINT8)
controller.insertInt8(offset, *reinterpret_cast<qint8 *>(ref));
else if (typeId == asTYPEID_INT16 || typeId == asTYPEID_UINT16)
controller.insertInt16(offset, *reinterpret_cast<qint16 *>(ref));
else if (typeId == asTYPEID_INT32 || typeId == asTYPEID_UINT32)
controller.insertInt32(offset, *reinterpret_cast<qint32 *>(ref));
else if (typeId == asTYPEID_INT64 || typeId == asTYPEID_UINT64)
controller.insertInt64(offset, *reinterpret_cast<qint64 *>(ref));
else if (typeId == asTYPEID_FLOAT)
controller.insertFloat(offset, *reinterpret_cast<float *>(ref));
else if (typeId == asTYPEID_DOUBLE)
controller.insertDouble(offset, *reinterpret_cast<double *>(ref));
else if ((typeId & asTYPEID_MASK_OBJECT) == 0)
controller.insertInt32(offset, *reinterpret_cast<int *>(ref));
else if (typeId & asTYPEID_SCRIPTOBJECT) {
// Dereference handles, so we can see what it points to
void *value = ref;
if (typeId & asTYPEID_OBJHANDLE)
value = *(void **)value;
if (engine) {
asITypeInfo *t = engine->GetTypeInfoById(typeId);
for (int n = t->GetEnumValueCount(); n-- > 0;) {
int enumVal;
t->GetEnumValueByIndex(n, &enumVal);
if (enumVal == *(int *)value) {
controller.insertInt32(offset, enumVal);
break;
}
}
}
} else {
// Dereference handles, so we can see what it points to
void *value = ref;
if (typeId & asTYPEID_OBJHANDLE)
value = *(void **)value;
if (engine) {
asITypeInfo *type = engine->GetTypeInfoById(typeId);
if (value) {
// TODO support other type, now only string
if (type->GetTypeId() == (typeId & ~asTYPEID_OBJHANDLE)) {
controller.insertString(
offset, *reinterpret_cast<QString *>(value));
}
}
}
}
return true;
} else {
return false;
}
}
bool WingAngelAPI::_HexReader_append(qsizetype offset, void *ref, int typeId) {
asIScriptContext *ctx = asGetActiveContext();
if (ctx) {
asIScriptEngine *engine = ctx->GetEngine();
if (typeId == asTYPEID_VOID)
return false;
else if (typeId == asTYPEID_BOOL)
controller.appendInt8(*reinterpret_cast<bool *>(ref) ? 1 : 0);
else if (typeId == asTYPEID_INT8 || typeId == asTYPEID_UINT8)
controller.appendInt8(*reinterpret_cast<qint8 *>(ref));
else if (typeId == asTYPEID_INT16 || typeId == asTYPEID_UINT16)
controller.appendInt16(*reinterpret_cast<qint16 *>(ref));
else if (typeId == asTYPEID_INT32 || typeId == asTYPEID_UINT32)
controller.appendInt32(*reinterpret_cast<qint32 *>(ref));
else if (typeId == asTYPEID_INT64 || typeId == asTYPEID_UINT64)
controller.appendInt64(*reinterpret_cast<qint64 *>(ref));
else if (typeId == asTYPEID_FLOAT)
controller.appendFloat(*reinterpret_cast<float *>(ref));
else if (typeId == asTYPEID_DOUBLE)
controller.appendDouble(*reinterpret_cast<double *>(ref));
else if ((typeId & asTYPEID_MASK_OBJECT) == 0)
controller.appendInt32(*reinterpret_cast<int *>(ref));
else if (typeId & asTYPEID_SCRIPTOBJECT) {
// Dereference handles, so we can see what it points to
void *value = ref;
if (typeId & asTYPEID_OBJHANDLE)
value = *(void **)value;
if (engine) {
asITypeInfo *t = engine->GetTypeInfoById(typeId);
for (int n = t->GetEnumValueCount(); n-- > 0;) {
int enumVal;
t->GetEnumValueByIndex(n, &enumVal);
if (enumVal == *(int *)value) {
controller.appendInt32(enumVal);
break;
}
}
}
} else {
// Dereference handles, so we can see what it points to
void *value = ref;
if (typeId & asTYPEID_OBJHANDLE)
value = *(void **)value;
if (engine) {
asITypeInfo *type = engine->GetTypeInfoById(typeId);
if (value) {
// TODO support other type, now only string
if (type->GetTypeId() == (typeId & ~asTYPEID_OBJHANDLE)) {
controller.appendString(
*reinterpret_cast<QString *>(value));
}
}
}
}
return true;
} else {
return false;
}
}
qsizetype WingAngelAPI::_HexReader_searchForward(qsizetype begin, qsizetype WingAngelAPI::_HexReader_searchForward(qsizetype begin,
const CScriptArray &ba) { const CScriptArray &ba) {

View File

@ -59,6 +59,10 @@ private:
QByteArray cArray2ByteArray(const CScriptArray &array, int byteID, QByteArray cArray2ByteArray(const CScriptArray &array, int byteID,
bool *ok = nullptr); bool *ok = nullptr);
bool read2Ref(qsizetype offset, void *ref, int typeId);
qsizetype getAsTypeSize(int typeId, void *data);
private: private:
QString _InputBox_getItem(int stringID, const QString &title, QString _InputBox_getItem(int stringID, const QString &title,
const QString &label, const CScriptArray &items, const QString &label, const CScriptArray &items,
@ -75,7 +79,13 @@ private:
CScriptArray *_HexReader_readBytes(qsizetype offset, qsizetype len); CScriptArray *_HexReader_readBytes(qsizetype offset, qsizetype len);
bool _HexReader_read(void *ref, int typeId); bool _HexReader_read(qsizetype offset, void *ref, int typeId);
bool _HexReader_write(qsizetype offset, void *ref, int typeId);
bool _HexReader_insert(qsizetype offset, void *ref, int typeId);
bool _HexReader_append(qsizetype offset, void *ref, int typeId);
qsizetype _HexReader_searchForward(qsizetype begin, const CScriptArray &ba); qsizetype _HexReader_searchForward(qsizetype begin, const CScriptArray &ba);

View File

@ -548,7 +548,7 @@ MainWindow::buildUpHexMetaDataDock(ads::CDockManager *dock,
return; return;
} }
hexeditor->renderer()->enableCursor(true); hexeditor->renderer()->enableCursor(true);
// hexeditor->gotoBookMark(index.row()); hexeditor->gotoBookMark(index.row());
}); });
m_aDelMetaData = new QAction(ICONRES(QStringLiteral("metadatadel")), m_aDelMetaData = new QAction(ICONRES(QStringLiteral("metadatadel")),
@ -558,16 +558,17 @@ MainWindow::buildUpHexMetaDataDock(ads::CDockManager *dock,
if (hexeditor == nullptr) { if (hexeditor == nullptr) {
return; return;
} }
auto s = m_bookmarks->selectionModel()->selectedRows(); auto s = m_metadatas->selectionModel()->selectedRows();
auto doc = hexeditor->document(); auto doc = hexeditor->document();
// const auto &bms = doc->bookMarks();
// QList<qsizetype> pos; const auto &mds = doc->metadata()->getallMetasPtr();
// for (auto &item : s) {
// pos.push_back(bms.at(item.row()).pos);
// }
// doc->RemoveBookMarks(pos); QList<QHexMetadataAbsoluteItem> pmetas;
for (auto &item : s) {
pmetas.push_back(mds.at(item.row()));
}
hexeditor->document()->metadata()->RemoveMetadatas(pmetas);
}); });
m_aDelMetaData->setEnabled(false); m_aDelMetaData->setEnabled(false);
m_metadatas->addAction(m_aDelMetaData); m_metadatas->addAction(m_aDelMetaData);

View File

@ -139,7 +139,8 @@ void ScriptingDialog::initConsole() {
connect(dbg, &asDebugger::onPullVariables, this, connect(dbg, &asDebugger::onPullVariables, this,
[=](const QVector<asDebugger::VariablesInfo> &globalvars, [=](const QVector<asDebugger::VariablesInfo> &globalvars,
const QVector<asDebugger::VariablesInfo> &localvars) { const QVector<asDebugger::VariablesInfo> &localvars) {
m_varshow->updateData(localvars);
m_gvarshow->updateData(globalvars);
}); });
connect(dbg, &asDebugger::onPullCallStack, m_callstack, connect(dbg, &asDebugger::onPullCallStack, m_callstack,
&DbgCallStackModel::updateData); &DbgCallStackModel::updateData);
@ -157,7 +158,7 @@ void ScriptingDialog::initConsole() {
e->setFocus(); e->setFocus();
e->raise(); e->raise();
} else { } else {
// error permission // TODO error permission
} }
} }
@ -194,6 +195,12 @@ void ScriptingDialog::initConsole() {
}); });
} }
void ScriptingDialog::saveDockLayout() {
auto &set = SettingManager::instance();
set.setScriptDockLayout(m_dock->saveState());
set.save(SettingManager::NONE);
}
void ScriptingDialog::buildUpRibbonBar() { void ScriptingDialog::buildUpRibbonBar() {
m_ribbon = new Ribbon(this); m_ribbon = new Ribbon(this);
buildFilePage(m_ribbon->addTab(tr("File"))); buildFilePage(m_ribbon->addTab(tr("File")));
@ -575,7 +582,6 @@ void ScriptingDialog::buildUpDockSystem(QWidget *container) {
m_editorViewArea = m_dock->setCentralWidget(CentralDockWidget); m_editorViewArea = m_dock->setCentralWidget(CentralDockWidget);
// build up basic docking widgets // build up basic docking widgets
// TODO
auto bottomArea = buildUpOutputShowDock(m_dock, ads::BottomDockWidgetArea); auto bottomArea = buildUpOutputShowDock(m_dock, ads::BottomDockWidgetArea);
auto splitter = auto splitter =
@ -587,6 +593,11 @@ void ScriptingDialog::buildUpDockSystem(QWidget *container) {
buildUpStackShowDock(m_dock, ads::CenterDockWidgetArea, bottomArea); buildUpStackShowDock(m_dock, ads::CenterDockWidgetArea, bottomArea);
// TODO
buildUpBreakpointShowDock(m_dock, ads::RightDockWidgetArea);
buildUpVarShowDock(m_dock, ads::RightDockWidgetArea);
buildUpWatchDock(m_dock, ads::CenterDockWidgetArea);
// set the first tab visible // set the first tab visible
for (auto &item : m_dock->openedDockAreas()) { for (auto &item : m_dock->openedDockAreas()) {
for (int i = 0; i < item->dockWidgetsCount(); ++i) { for (int i = 0; i < item->dockWidgetsCount(); ++i) {
@ -628,15 +639,19 @@ ads::CDockWidget *ScriptingDialog::buildDockWidget(ads::CDockManager *dock,
} }
void ScriptingDialog::registerEditorView(ScriptEditor *editor) { void ScriptingDialog::registerEditorView(ScriptEditor *editor) {
// TODO
connect(editor, &ScriptEditor::closeRequested, this, [this] { connect(editor, &ScriptEditor::closeRequested, this, [this] {
auto editor = qobject_cast<ScriptEditor *>(sender()); auto editor = qobject_cast<ScriptEditor *>(sender());
Q_ASSERT(editor); Q_ASSERT(editor);
Q_ASSERT(m_views.contains(editor)); Q_ASSERT(m_views.contains(editor));
auto m = m_consoleout->machine(); auto m = m_consoleout->machine();
if (m->isInDebugMode()) { if (m->isInDebugMode() && _DebugingScript == editor->fileName()) {
// TODO if (WingMessageBox::warning(
this, this->windowTitle(), tr("ScriptStillRunning"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
return;
}
on_stopscript();
} }
m_views.removeOne(editor); m_views.removeOne(editor);
@ -902,18 +917,22 @@ void ScriptingDialog::on_newfile() {
m_lastusedpath = QFileInfo(filename).absoluteDir().absolutePath(); m_lastusedpath = QFileInfo(filename).absoluteDir().absolutePath();
auto e = findEditorView(filename); auto e = findEditorView(filename);
if (e) {
e->raise();
e->setFocus();
// TODO
return;
}
// create an empty file // create an empty file
QFile f(filename); QFile f(filename);
f.open(QFile::WriteOnly | QFile::Text); f.open(QFile::WriteOnly | QFile::Text);
f.close(); f.close();
if (e) {
if (_DebugingScript == e->fileName()) {
on_stopscript();
}
e->reload();
e->raise();
e->setFocus();
return;
}
auto editor = new ScriptEditor(this); auto editor = new ScriptEditor(this);
auto res = editor->openFile(filename); auto res = editor->openFile(filename);
if (!res) { if (!res) {
@ -1239,10 +1258,8 @@ void ScriptingDialog::closeEvent(QCloseEvent *event) {
} }
auto &set = SettingManager::instance(); auto &set = SettingManager::instance();
set.setScriptDockLayout(m_dock->saveState());
set.setRecentScriptFiles(m_recentmanager->saveRecent()); set.setRecentScriptFiles(m_recentmanager->saveRecent());
set.save(); set.save(SettingManager::NONE);
FramelessMainWindow::closeEvent(event); FramelessMainWindow::closeEvent(event);
} }

View File

@ -56,6 +56,8 @@ public:
void initConsole(); void initConsole();
void saveDockLayout();
private: private:
void buildUpRibbonBar(); void buildUpRibbonBar();
RibbonTabContent *buildFilePage(RibbonTabContent *tab); RibbonTabContent *buildFilePage(RibbonTabContent *tab);

View File

@ -44,3 +44,9 @@ QVariant DbgVarShowModel::headerData(int section, Qt::Orientation orientation,
} }
return QVariant(); return QVariant();
} }
void DbgVarShowModel::updateData(
const QVector<asDebugger::VariablesInfo> &varinfos) {
_vars = varinfos;
emit layoutChanged();
}

View File

@ -18,8 +18,11 @@ public:
virtual QVariant headerData(int section, Qt::Orientation orientation, virtual QVariant headerData(int section, Qt::Orientation orientation,
int role) const override; int role) const override;
public slots:
void updateData(const QVector<asDebugger::VariablesInfo> &varinfos);
private: private:
QList<asDebugger::VariablesInfo> _vars; QVector<asDebugger::VariablesInfo> _vars;
}; };
#endif // DBGVARSHOWMODEL_H #endif // DBGVARSHOWMODEL_H

View File

@ -184,6 +184,8 @@ signals:
qint16 readInt16(qsizetype offset); qint16 readInt16(qsizetype offset);
qint32 readInt32(qsizetype offset); qint32 readInt32(qsizetype offset);
qint64 readInt64(qsizetype offset); qint64 readInt64(qsizetype offset);
float readFloat(qsizetype offset);
double readDouble(qsizetype offset);
QString readString(qsizetype offset, const QString &encoding = QString()); QString readString(qsizetype offset, const QString &encoding = QString());
QByteArray readBytes(qsizetype offset, qsizetype count); QByteArray readBytes(qsizetype offset, qsizetype count);
@ -243,6 +245,8 @@ signals:
bool writeInt16(qsizetype offset, qint16 value); bool writeInt16(qsizetype offset, qint16 value);
bool writeInt32(qsizetype offset, qint32 value); bool writeInt32(qsizetype offset, qint32 value);
bool writeInt64(qsizetype offset, qint64 value); bool writeInt64(qsizetype offset, qint64 value);
bool writeFloat(qsizetype offset, float value);
bool writeDouble(qsizetype offset, double value);
bool writeString(qsizetype offset, const QString &value, bool writeString(qsizetype offset, const QString &value,
const QString &encoding = QString()); const QString &encoding = QString());
bool writeBytes(qsizetype offset, const QByteArray &data); bool writeBytes(qsizetype offset, const QByteArray &data);
@ -251,6 +255,8 @@ signals:
bool insertInt16(qsizetype offset, qint16 value); bool insertInt16(qsizetype offset, qint16 value);
bool insertInt32(qsizetype offset, qint32 value); bool insertInt32(qsizetype offset, qint32 value);
bool insertInt64(qsizetype offset, qint64 value); bool insertInt64(qsizetype offset, qint64 value);
bool insertFloat(qsizetype offset, float value);
bool insertDouble(qsizetype offset, double value);
bool insertString(qsizetype offset, const QString &value, bool insertString(qsizetype offset, const QString &value,
const QString &encoding = QString()); const QString &encoding = QString());
bool insertBytes(qsizetype offset, const QByteArray &data); bool insertBytes(qsizetype offset, const QByteArray &data);
@ -259,6 +265,8 @@ signals:
bool appendInt16(qint16 value); bool appendInt16(qint16 value);
bool appendInt32(qint32 value); bool appendInt32(qint32 value);
bool appendInt64(qint64 value); bool appendInt64(qint64 value);
bool appendFloat(float value);
bool appendDouble(double value);
bool appendString(const QString &value, bool appendString(const QString &value,
const QString &encoding = QString()); const QString &encoding = QString());
bool appendBytes(const QByteArray &data); bool appendBytes(const QByteArray &data);

View File

@ -467,52 +467,29 @@ void PluginSystem::connectReaderInterface(IWingPlugin *plg) {
}); });
connect(preader, &WingPlugin::Reader::readInt8, _win, connect(preader, &WingPlugin::Reader::readInt8, _win,
[=](qsizetype offset) -> qint8 { [=](qsizetype offset) -> qint8 {
auto e = pluginCurrentEditor(plg); return readBasicTypeContent<qint8>(plg, offset);
if (e) {
auto buffer =
e->hexEditor()->document()->read(offset, sizeof(qint8));
auto pb =
reinterpret_cast<const qint8 *>(buffer.constData());
return *pb;
}
return qint8(-1);
}); });
connect(preader, &WingPlugin::Reader::readInt16, _win, connect(preader, &WingPlugin::Reader::readInt16, _win,
[=](qsizetype offset) -> qint16 { [=](qsizetype offset) -> qint16 {
auto e = pluginCurrentEditor(plg); return readBasicTypeContent<qint16>(plg, offset);
if (e) {
auto buffer = e->hexEditor()->document()->read(
offset, sizeof(qint16));
auto pb =
reinterpret_cast<const qint16 *>(buffer.constData());
return *pb;
}
return qint16(-1);
}); });
connect(preader, &WingPlugin::Reader::readInt32, _win, connect(preader, &WingPlugin::Reader::readInt32, _win,
[=](qsizetype offset) -> qint32 { [=](qsizetype offset) -> qint32 {
auto e = pluginCurrentEditor(plg); return readBasicTypeContent<qint32>(plg, offset);
if (e) {
auto buffer = e->hexEditor()->document()->read(
offset, sizeof(qint32));
auto pb =
reinterpret_cast<const qint32 *>(buffer.constData());
return *pb;
}
return qint32(-1);
}); });
connect(preader, &WingPlugin::Reader::readInt64, _win, connect(preader, &WingPlugin::Reader::readInt64, _win,
[=](qsizetype offset) -> qint64 { [=](qsizetype offset) -> qint64 {
auto e = pluginCurrentEditor(plg); return readBasicTypeContent<qint64>(plg, offset);
if (e) {
auto buffer = e->hexEditor()->document()->read(
offset, sizeof(qint64));
auto pb =
reinterpret_cast<const qint64 *>(buffer.constData());
return *pb;
}
return qint64(-1);
}); });
connect(preader, &WingPlugin::Reader::readFloat, _win,
[=](qsizetype offset) -> float {
return readBasicTypeContent<float>(plg, offset);
});
connect(preader, &WingPlugin::Reader::readDouble, _win,
[=](qsizetype offset) -> double {
return readBasicTypeContent<double>(plg, offset);
});
connect(preader, &WingPlugin::Reader::readString, _win, connect(preader, &WingPlugin::Reader::readString, _win,
[=](qsizetype offset, const QString &encoding) -> QString { [=](qsizetype offset, const QString &encoding) -> QString {
auto e = pluginCurrentEditor(plg); auto e = pluginCurrentEditor(plg);
@ -834,48 +811,28 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
connect(pctl, &WingPlugin::Controller::insertInt8, _win, connect(pctl, &WingPlugin::Controller::insertInt8, _win,
[=](qsizetype offset, qint8 value) -> bool { [=](qsizetype offset, qint8 value) -> bool {
auto e = pluginCurrentEditor(plg); return insertBasicTypeContent(plg, offset, value);
if (e) {
auto doc = e->hexEditor()->document();
auto buffer = reinterpret_cast<char *>(&value);
return doc->insert(offset,
QByteArray(buffer, sizeof(qint8)));
}
return false;
}); });
connect(pctl, &WingPlugin::Controller::insertInt16, _win, connect(pctl, &WingPlugin::Controller::insertInt16, _win,
[=](qsizetype offset, qint16 value) -> bool { [=](qsizetype offset, qint16 value) -> bool {
auto e = pluginCurrentEditor(plg); return insertBasicTypeContent(plg, offset, value);
if (e) {
auto doc = e->hexEditor()->document();
auto buffer = reinterpret_cast<char *>(&value);
return doc->insert(offset,
QByteArray(buffer, sizeof(qint16)));
}
return false;
}); });
connect(pctl, &WingPlugin::Controller::insertInt32, _win, connect(pctl, &WingPlugin::Controller::insertInt32, _win,
[=](qsizetype offset, qint32 value) -> bool { [=](qsizetype offset, qint32 value) -> bool {
auto e = pluginCurrentEditor(plg); return insertBasicTypeContent(plg, offset, value);
if (e) {
auto doc = e->hexEditor()->document();
auto buffer = reinterpret_cast<char *>(&value);
return doc->insert(offset,
QByteArray(buffer, sizeof(qint32)));
}
return false;
}); });
connect(pctl, &WingPlugin::Controller::insertInt64, _win, connect(pctl, &WingPlugin::Controller::insertInt64, _win,
[=](qsizetype offset, qint64 value) -> bool { [=](qsizetype offset, qint64 value) -> bool {
auto e = pluginCurrentEditor(plg); return insertBasicTypeContent(plg, offset, value);
if (e) { });
auto doc = e->hexEditor()->document(); connect(pctl, &WingPlugin::Controller::insertFloat, _win,
auto buffer = reinterpret_cast<char *>(&value); [=](qsizetype offset, float value) -> bool {
return doc->insert(offset, return insertBasicTypeContent(plg, offset, value);
QByteArray(buffer, sizeof(qint64))); });
} connect(pctl, &WingPlugin::Controller::insertDouble, _win,
return false; [=](qsizetype offset, double value) -> bool {
return insertBasicTypeContent(plg, offset, value);
}); });
connect(pctl, &WingPlugin::Controller::insertString, _win, connect(pctl, &WingPlugin::Controller::insertString, _win,
[=](qsizetype offset, const QString &value, [=](qsizetype offset, const QString &value,
@ -910,48 +867,28 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
connect(pctl, &WingPlugin::Controller::writeInt8, _win, connect(pctl, &WingPlugin::Controller::writeInt8, _win,
[=](qsizetype offset, qint8 value) -> bool { [=](qsizetype offset, qint8 value) -> bool {
auto e = pluginCurrentEditor(plg); return writeBasicTypeContent(plg, offset, value);
if (e) {
auto doc = e->hexEditor()->document();
auto buffer = reinterpret_cast<char *>(&value);
return doc->replace(offset,
QByteArray(buffer, sizeof(qint8)));
}
return false;
}); });
connect(pctl, &WingPlugin::Controller::writeInt16, _win, connect(pctl, &WingPlugin::Controller::writeInt16, _win,
[=](qsizetype offset, qint16 value) -> bool { [=](qsizetype offset, qint16 value) -> bool {
auto e = pluginCurrentEditor(plg); return writeBasicTypeContent(plg, offset, value);
if (e) {
auto doc = e->hexEditor()->document();
auto buffer = reinterpret_cast<char *>(&value);
return doc->replace(offset,
QByteArray(buffer, sizeof(qint16)));
}
return false;
}); });
connect(pctl, &WingPlugin::Controller::writeInt32, _win, connect(pctl, &WingPlugin::Controller::writeInt32, _win,
[=](qsizetype offset, qint32 value) -> bool { [=](qsizetype offset, qint32 value) -> bool {
auto e = pluginCurrentEditor(plg); return writeBasicTypeContent(plg, offset, value);
if (e) {
auto doc = e->hexEditor()->document();
auto buffer = reinterpret_cast<char *>(&value);
return doc->replace(offset,
QByteArray(buffer, sizeof(qint32)));
}
return false;
}); });
connect(pctl, &WingPlugin::Controller::writeInt64, _win, connect(pctl, &WingPlugin::Controller::writeInt64, _win,
[=](qsizetype offset, qint64 value) -> bool { [=](qsizetype offset, qint64 value) -> bool {
auto e = pluginCurrentEditor(plg); return writeBasicTypeContent(plg, offset, value);
if (e) { });
auto doc = e->hexEditor()->document(); connect(pctl, &WingPlugin::Controller::writeFloat, _win,
auto buffer = reinterpret_cast<char *>(&value); [=](qsizetype offset, float value) -> bool {
return doc->replace(offset, return writeBasicTypeContent(plg, offset, value);
QByteArray(buffer, sizeof(qint64))); });
} connect(pctl, &WingPlugin::Controller::writeDouble, _win,
return false; [=](qsizetype offset, double value) -> bool {
return writeBasicTypeContent(plg, offset, value);
}); });
connect(pctl, &WingPlugin::Controller::writeString, _win, connect(pctl, &WingPlugin::Controller::writeString, _win,
[=](qsizetype offset, const QString &value, [=](qsizetype offset, const QString &value,
@ -986,51 +923,27 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
connect(pctl, &WingPlugin::Controller::appendInt8, _win, connect(pctl, &WingPlugin::Controller::appendInt8, _win,
[=](qint8 value) -> bool { [=](qint8 value) -> bool {
auto e = pluginCurrentEditor(plg); return appendBasicTypeContent(plg, value);
if (e) {
auto doc = e->hexEditor()->document();
auto offset = doc->length();
auto buffer = reinterpret_cast<char *>(&value);
QByteArray data(buffer, sizeof(qint8));
return doc->insert(offset, data);
}
return false;
}); });
connect(pctl, &WingPlugin::Controller::appendInt16, _win, connect(pctl, &WingPlugin::Controller::appendInt16, _win,
[=](qint16 value) -> bool { [=](qint16 value) -> bool {
auto e = pluginCurrentEditor(plg); return appendBasicTypeContent(plg, value);
if (e) {
auto doc = e->hexEditor()->document();
auto offset = doc->length();
auto buffer = reinterpret_cast<char *>(&value);
QByteArray data(buffer, sizeof(qint16));
return doc->insert(offset, data);
}
return false;
}); });
connect(pctl, &WingPlugin::Controller::appendInt32, _win, connect(pctl, &WingPlugin::Controller::appendInt32, _win,
[=](qint32 value) -> bool { [=](qint32 value) -> bool {
auto e = pluginCurrentEditor(plg); return appendBasicTypeContent(plg, value);
if (e) {
auto doc = e->hexEditor()->document();
auto offset = doc->length();
auto buffer = reinterpret_cast<char *>(&value);
QByteArray data(buffer, sizeof(qint32));
return doc->insert(offset, data);
}
return false;
}); });
connect(pctl, &WingPlugin::Controller::appendInt64, _win, connect(pctl, &WingPlugin::Controller::appendInt64, _win,
[=](qint64 value) -> bool { [=](qint64 value) -> bool {
auto e = pluginCurrentEditor(plg); return appendBasicTypeContent(plg, value);
if (e) { });
auto doc = e->hexEditor()->document(); connect(pctl, &WingPlugin::Controller::appendFloat, _win,
auto offset = doc->length(); [=](qint64 value) -> bool {
auto buffer = reinterpret_cast<char *>(&value); return appendBasicTypeContent(plg, value);
QByteArray data(buffer, sizeof(qint64)); });
return doc->insert(offset, data); connect(pctl, &WingPlugin::Controller::appendDouble, _win,
} [=](qint64 value) -> bool {
return false; return appendBasicTypeContent(plg, value);
}); });
connect(pctl, &WingPlugin::Controller::appendString, _win, connect(pctl, &WingPlugin::Controller::appendString, _win,
[=](const QString &value, const QString &encoding) -> bool { [=](const QString &value, const QString &encoding) -> bool {

View File

@ -13,11 +13,11 @@
#include <QVariant> #include <QVariant>
#include "class/wingangelapi.h" #include "class/wingangelapi.h"
#include "control/editorview.h"
using namespace WingHex; using namespace WingHex;
class MainWindow; class MainWindow;
class EditorView;
class PluginSystem : public QObject { class PluginSystem : public QObject {
Q_OBJECT Q_OBJECT
@ -52,6 +52,63 @@ private:
EditorView *pluginCurrentEditor(IWingPlugin *sender) const; EditorView *pluginCurrentEditor(IWingPlugin *sender) const;
private:
template <typename T>
T readBasicTypeContent(IWingPlugin *plg, qsizetype offset) {
Q_STATIC_ASSERT(std::is_integral_v<T> || std::is_floating_point_v<T>);
auto e = pluginCurrentEditor(plg);
if (e) {
auto buffer = e->hexEditor()->document()->read(offset, sizeof(T));
auto pb = reinterpret_cast<const T *>(buffer.constData());
return *pb;
}
if constexpr (std::is_floating_point_v<T>) {
return qQNaN();
} else {
return T(0);
}
}
template <typename T>
bool insertBasicTypeContent(IWingPlugin *plg, qsizetype offset,
const T &value) {
Q_STATIC_ASSERT(std::is_integral_v<T> || std::is_floating_point_v<T>);
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
auto buffer = reinterpret_cast<const char *>(&value);
return doc->insert(offset, QByteArray(buffer, sizeof(T)));
}
return false;
}
template <typename T>
bool writeBasicTypeContent(IWingPlugin *plg, qsizetype offset,
const T &value) {
Q_STATIC_ASSERT(std::is_integral_v<T> || std::is_floating_point_v<T>);
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
auto buffer = reinterpret_cast<const char *>(&value);
return doc->replace(offset, QByteArray(buffer, sizeof(T)));
}
return false;
}
template <typename T>
bool appendBasicTypeContent(IWingPlugin *plg, const T &value) {
Q_STATIC_ASSERT(std::is_integral_v<T> || std::is_floating_point_v<T>);
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
auto offset = doc->length();
auto buffer = reinterpret_cast<const char *>(&value);
QByteArray data(buffer, sizeof(T));
return doc->insert(offset, data);
}
return false;
}
private: private:
PluginSystem(QObject *parent = nullptr); PluginSystem(QObject *parent = nullptr);
~PluginSystem(); ~PluginSystem();