string:统一非二进制的字符串数据统一使用wstring。

This commit is contained in:
taynpg 2025-05-12 22:38:23 +08:00
parent de46e40e0c
commit d0d1c2b36a
9 changed files with 20 additions and 18 deletions

View File

@ -128,7 +128,7 @@ void ClientCore::UseFrame(FrameBuffer* buf)
InfoCommunicate info; InfoCommunicate info;
ZeroCopyInput input(buf->dataMut, buf->len); ZeroCopyInput input(buf->dataMut, buf->len);
input.archive() >> info; input.archive() >> info;
id_ = wxString::FromUTF8(info.data); id_ = wxString(info.msg.c_str());
logCall_(wxString::Format(_("Your id is %s."), id_)); logCall_(wxString::Format(_("Your id is %s."), id_));
break; break;
} }
@ -139,7 +139,7 @@ void ClientCore::UseFrame(FrameBuffer* buf)
case FBT_CLI_ASK_HOME: { case FBT_CLI_ASK_HOME: {
InfoCommunicate info; InfoCommunicate info;
wxString home = wxGetHomeDir(); wxString home = wxGetHomeDir();
info.data = home.ToStdString(); info.msg = home.ToStdWstring();
Send<InfoCommunicate>(info, FBT_CLI_ANS_HOME, buf->fid); Send<InfoCommunicate>(info, FBT_CLI_ANS_HOME, buf->fid);
break; break;
} }
@ -148,7 +148,7 @@ void ClientCore::UseFrame(FrameBuffer* buf)
ZeroCopyInput input(buf->dataMut, buf->len); ZeroCopyInput input(buf->dataMut, buf->len);
input.archive() >> info; input.archive() >> info;
if (homeCall_) { if (homeCall_) {
homeCall_(info.data); homeCall_(wxString(info.msg.c_str()));
} }
break; break;
} }
@ -157,7 +157,7 @@ void ClientCore::UseFrame(FrameBuffer* buf)
ZeroCopyInput input(buf->dataMut, buf->len); ZeroCopyInput input(buf->dataMut, buf->len);
input.archive() >> info; input.archive() >> info;
DirFileInfoVec vec; DirFileInfoVec vec;
if (!cf_.GetDirFiles(info.data, vec)) { if (!cf_.GetDirFiles(info.msg, vec)) {
break; break;
} }
Send<DirFileInfoVec>(vec, FBT_CLI_ANS_DIRFILE, buf->fid); Send<DirFileInfoVec>(vec, FBT_CLI_ANS_DIRFILE, buf->fid);

View File

@ -5,7 +5,7 @@ ClientFile::ClientFile()
{ {
} }
bool ClientFile::GetDirFiles(const std::string& path, DirFileInfoVec& vec) bool ClientFile::GetDirFiles(const std::wstring& path, DirFileInfoVec& vec)
{ {
if (!fs::exists(path)) { if (!fs::exists(path)) {
lastErr_ = wxString::Format(_("Path does not exist: %s"), path); lastErr_ = wxString::Format(_("Path does not exist: %s"), path);
@ -26,8 +26,8 @@ bool ClientFile::GetDirFiles(const std::string& path, DirFileInfoVec& vec)
const auto& path = entry.path(); const auto& path = entry.path();
// 设置基本信息 // 设置基本信息
info.fullPath = path.string(); info.fullPath = path.wstring();
info.name = path.filename().string(); info.name = path.filename().wstring();
// 设置类型 // 设置类型
if (entry.is_directory()) { if (entry.is_directory()) {

View File

@ -11,7 +11,7 @@ public:
ClientFile(); ClientFile();
public: public:
bool GetDirFiles(const std::string& path, DirFileInfoVec& vec); bool GetDirFiles(const std::wstring& path, DirFileInfoVec& vec);
wxString GetLastErr() const; wxString GetLastErr() const;
private: private:

View File

@ -11,10 +11,11 @@ constexpr int GBUFFER_SIZE = 256;
struct InfoCommunicate { struct InfoCommunicate {
std::string UUID; std::string UUID;
std::string data; std::string data;
std::wstring msg;
uint8_t mark{}; uint8_t mark{};
template <class Archive> void serialize(Archive& archive) template <class Archive> void serialize(Archive& archive)
{ {
archive(CEREAL_NVP(UUID), CEREAL_NVP(data), CEREAL_NVP(mark)); archive(CEREAL_NVP(UUID), CEREAL_NVP(data), CEREAL_NVP(msg), CEREAL_NVP(mark));
} }
}; };

View File

@ -58,10 +58,10 @@ struct DirFileInfo {
} }
} }
std::string name; std::wstring name;
uint64_t size = 0; uint64_t size = 0;
FileType type = None; FileType type = None;
std::string fullPath; std::wstring fullPath;
uint16_t permission = 0; uint16_t permission = 0;
uint64_t lastModifyTime = 0; uint64_t lastModifyTime = 0;

View File

@ -96,7 +96,7 @@ void RelayServer::thClientThread(const std::shared_ptr<wxSocketBase>& wxSock, co
// 初次链接,告知对方的ID // 初次链接,告知对方的ID
InfoCommunicate info; InfoCommunicate info;
info.data = id.ToStdString(); info.msg = id.ToStdWstring();
Send<InfoCommunicate>(client->wxSock, info, FBT_SER_MSG_YOURID, id.ToStdString(), strID_); Send<InfoCommunicate>(client->wxSock, info, FBT_SER_MSG_YOURID, id.ToStdString(), strID_);
client->wxSock->SetFlags(wxSOCKET_BLOCK); client->wxSock->SetFlags(wxSOCKET_BLOCK);

View File

@ -6,7 +6,7 @@ void test1()
{ {
DirFileInfo info; DirFileInfo info;
DirFileInfo info2; DirFileInfo info2;
info.fullPath = "C:\\Users\\Administrator\\Desktop\\test.txt"; info.fullPath = L"C:\\Users\\Administrator\\Desktop\\test.txt";
info.name.resize(1024); info.name.resize(1024);
info.name[0] = 'a'; info.name[0] = 'a';
@ -41,9 +41,9 @@ void test2()
DirFileInfoVec v; DirFileInfoVec v;
DirFileInfoVec v2; DirFileInfoVec v2;
DirFileInfo d1; DirFileInfo d1;
d1.fullPath = "Java"; d1.fullPath = L"Java";
DirFileInfo d2; DirFileInfo d2;
d2.fullPath = "CPP"; d2.fullPath = L"CPP";
v.vec.push_back(d1); v.vec.push_back(d1);
v.vec.push_back(d2); v.vec.push_back(d2);
@ -89,6 +89,6 @@ void test3()
int main() int main()
{ {
test3(); test1();
return 0; return 0;
} }

View File

@ -63,7 +63,7 @@ void RemoteControl::BindEvent()
} }
for (auto& dirInfo : dirInfoVec.vec) { for (auto& dirInfo : dirInfoVec.vec) {
grid_->AppendRows(); grid_->AppendRows();
auto wxPath = wxString::FromUTF8(dirInfo.fullPath); auto wxPath = wxString(dirInfo.fullPath.c_str());
grid_->SetCellValue(grid_->GetNumberRows() - 1, 0, wxPath); grid_->SetCellValue(grid_->GetNumberRows() - 1, 0, wxPath);
grid_->SetCellValue(grid_->GetNumberRows() - 1, 1, DirFileInfo::GetFileSize(dirInfo.size)); grid_->SetCellValue(grid_->GetNumberRows() - 1, 1, DirFileInfo::GetFileSize(dirInfo.size));
grid_->SetCellValue(grid_->GetNumberRows() - 1, 2, DirFileInfo::GetFileTypeName(dirInfo.type)); grid_->SetCellValue(grid_->GetNumberRows() - 1, 2, DirFileInfo::GetFileTypeName(dirInfo.type));
@ -101,7 +101,7 @@ void RemoteControl::GetDirContent(wxCommandEvent& event)
return; return;
} }
InfoCommunicate info; InfoCommunicate info;
info.data = home.ToStdString(); info.msg = home.ToStdWstring();
if (!clientCore_->Send<InfoCommunicate>(info, FBT_CLI_ASK_DIRFILE, remoteId)) { if (!clientCore_->Send<InfoCommunicate>(info, FBT_CLI_ASK_DIRFILE, remoteId)) {
logControl_->AddLog(_("Request get %s's DirFile Failed"), home); logControl_->AddLog(_("Request get %s's DirFile Failed"), home);
} else { } else {

View File

@ -3,6 +3,7 @@
#include "InterfaceDefine.hpp" #include "InterfaceDefine.hpp"
#include <wx/grid.h> #include <wx/grid.h>
#include <memory>
class LogControl; class LogControl;
class ClientCore; class ClientCore;