Refactor: replace C-style code with modern C++ idioms

This commit is contained in:
Changhua 2025-01-29 18:32:20 +08:00
parent 554d62efcf
commit 15267632a1

View File

@ -8,13 +8,13 @@
#include "exec_sql.h"
#include "funcs.h"
#include "log.hpp"
#include "receive_msg.h"
#include "spy_types.h"
#include "util.h"
using namespace std;
namespace fs = std::filesystem;
extern bool gIsListeningPyq;
extern QWORD g_WeChatWinDllAddr;
#define HEADER_PNG1 0x89
@ -111,32 +111,25 @@ string DecryptImage(string src, string dir)
string dst = "";
try {
if (dir.empty()) {
dst = fs::path(src).replace_extension(ext).string();
} else {
dst = (dir.back() == '\\' || dir.back() == '/') ? dir : (dir + "/");
// 判断dir文件夹是否存在若不存在则创建否则将无法创建出文件
if (!fs::exists(dst)) {//判断该文件夹是否存在
bool success = fs::create_directories(dst); //Windows创建文件夹
if (!success) { //创建失败
LOG_ERROR("Failed to mkdir:{}", dst);
return "";
}
if (dir.empty()) {
dst = fs::path(src).replace_extension(ext).string();
} else {
dst = (dir.back() == '\\' || dir.back() == '/') ? dir : (dir + "/");
// 判断dir文件夹是否存在若不存在则创建否则将无法创建出文件
if (!fs::exists(dst)) { // 判断该文件夹是否存在
bool success = fs::create_directories(dst); // Windows创建文件夹
if (!success) { // 创建失败
LOG_ERROR("Failed to mkdir:{}", dst);
return "";
}
dst += fs::path(src).stem().string() + ext;
}
replace(dst.begin(), dst.end(), '\\', '/');
} catch (const std::exception &e) {
LOG_ERROR(GB2312ToUtf8(e.what()));
} catch (...) {
LOG_ERROR("Unknow exception.");
return "";
dst += fs::path(src).stem().string() + ext;
}
replace(dst.begin(), dst.end(), '\\', '/');
ofstream out(dst.c_str(), ios::binary);
if (!out.is_open()) {
LOG_ERROR("Failed to write file {}", dst);
@ -178,7 +171,8 @@ static int GetNextPage(QWORD id)
int RefreshPyq(QWORD id)
{
if (!gIsListeningPyq) {
auto &msgHandler = MessageHandler::getInstance();
if (!msgHandler.isPyqListening()) {
LOG_ERROR("没有启动朋友圈消息接收参考enable_receiving_msg");
return -1;
}
@ -319,7 +313,7 @@ string GetPCMAudio(uint64_t id, string dir, int32_t sr)
SilkDecode(silk, pcm, sr);
errno_t err;
FILE* fPCM;
FILE *fPCM;
err = fopen_s(&fPCM, pcmpath.c_str(), "wb");
if (err != 0) {
printf("Error: could not open input file %s\n", pcmpath.c_str());
@ -332,7 +326,6 @@ string GetPCMAudio(uint64_t id, string dir, int32_t sr)
return pcmpath;
}
OcrResult_t GetOcrResult(string path)
{
OcrResult_t ret = { -1, "" };