This commit is contained in:
2025-10-24 17:25:57 +08:00
parent 7462b7aa93
commit e43078aa84
3 changed files with 32 additions and 5 deletions

View File

@@ -473,7 +473,7 @@ namespace QCL
ReadFile::~ReadFile()
{
std::lock_guard<std::mutex> lock(mtx_);
// std::lock_guard<std::mutex> lock(mtx_);
Close();
}

Binary file not shown.

View File

@@ -70,14 +70,14 @@ bool checkUUID()
bool flag = false;
// 读取文件
ReadFile *rf = new ReadFile(envPath);
if (rf->Open() == false)
ReadFile rf(envPath);
if (rf.Open() == false)
{
cerr << "文件打开失败" << endl;
}
// 读取文本每一行
auto lines = rf->ReadLines();
auto lines = rf.ReadLines();
for (auto &ii : lines)
{
if (ii.find("ServerPwd:null") != string::npos)
@@ -88,6 +88,8 @@ bool checkUUID()
else
flag = true;
}
rf.Close();
return flag;
}
@@ -109,6 +111,31 @@ void messageCallback(mqtt::const_message_ptr msg)
auto res = nlohmann::json::parse(buffer); // 准备解析接受到的秘钥
auto pwd = res["Data"];
cout << pwd << endl;
// 写入文件
ReadFile rf(envPath);
auto lines = rf.ReadLines();
for (auto &ii : lines)
{
if (ii.find("ServerPwd:null") != string::npos)
ii = format("ServerPwd:{}", pwd);
}
rf.Close();
thread([lines]()
{
WriteFile wf(envPath);
string out;
out.resize(1024);
for (size_t i = 0; i < lines.size(); ++i)
{
out += lines[i];
if (i + 1 < lines.size())
out += "\n";
}
wf.overwriteText(out); })
.detach();
}
}