From d0d1c2b36a30592993c0ae43b052041887e28095 Mon Sep 17 00:00:00 2001 From: taynpg Date: Mon, 12 May 2025 22:38:23 +0800 Subject: [PATCH] =?UTF-8?q?string=EF=BC=9A=E7=BB=9F=E4=B8=80=E9=9D=9E?= =?UTF-8?q?=E4=BA=8C=E8=BF=9B=E5=88=B6=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A8wstring?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ClientCore/ClientCore.cxx | 8 ++++---- ClientCore/ClientFile.cxx | 6 +++--- ClientCore/ClientFile.h | 2 +- Information/InfoCommunicate.hpp | 3 ++- Information/InfoDirFile.hpp | 4 ++-- RelayServer/RelayServer.cxx | 2 +- Test/main.cxx | 8 ++++---- UserInterface/RemoteControl.cxx | 4 ++-- UserInterface/RemoteControl.h | 1 + 9 files changed, 20 insertions(+), 18 deletions(-) diff --git a/ClientCore/ClientCore.cxx b/ClientCore/ClientCore.cxx index 65aa968..35efb6e 100644 --- a/ClientCore/ClientCore.cxx +++ b/ClientCore/ClientCore.cxx @@ -128,7 +128,7 @@ void ClientCore::UseFrame(FrameBuffer* buf) InfoCommunicate info; ZeroCopyInput input(buf->dataMut, buf->len); input.archive() >> info; - id_ = wxString::FromUTF8(info.data); + id_ = wxString(info.msg.c_str()); logCall_(wxString::Format(_("Your id is %s."), id_)); break; } @@ -139,7 +139,7 @@ void ClientCore::UseFrame(FrameBuffer* buf) case FBT_CLI_ASK_HOME: { InfoCommunicate info; wxString home = wxGetHomeDir(); - info.data = home.ToStdString(); + info.msg = home.ToStdWstring(); Send(info, FBT_CLI_ANS_HOME, buf->fid); break; } @@ -148,7 +148,7 @@ void ClientCore::UseFrame(FrameBuffer* buf) ZeroCopyInput input(buf->dataMut, buf->len); input.archive() >> info; if (homeCall_) { - homeCall_(info.data); + homeCall_(wxString(info.msg.c_str())); } break; } @@ -157,7 +157,7 @@ void ClientCore::UseFrame(FrameBuffer* buf) ZeroCopyInput input(buf->dataMut, buf->len); input.archive() >> info; DirFileInfoVec vec; - if (!cf_.GetDirFiles(info.data, vec)) { + if (!cf_.GetDirFiles(info.msg, vec)) { break; } Send(vec, FBT_CLI_ANS_DIRFILE, buf->fid); diff --git a/ClientCore/ClientFile.cxx b/ClientCore/ClientFile.cxx index 85c5221..aeecd72 100644 --- a/ClientCore/ClientFile.cxx +++ b/ClientCore/ClientFile.cxx @@ -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)) { 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(); // 设置基本信息 - info.fullPath = path.string(); - info.name = path.filename().string(); + info.fullPath = path.wstring(); + info.name = path.filename().wstring(); // 设置类型 if (entry.is_directory()) { diff --git a/ClientCore/ClientFile.h b/ClientCore/ClientFile.h index c50f00d..85aa35d 100644 --- a/ClientCore/ClientFile.h +++ b/ClientCore/ClientFile.h @@ -11,7 +11,7 @@ public: ClientFile(); public: - bool GetDirFiles(const std::string& path, DirFileInfoVec& vec); + bool GetDirFiles(const std::wstring& path, DirFileInfoVec& vec); wxString GetLastErr() const; private: diff --git a/Information/InfoCommunicate.hpp b/Information/InfoCommunicate.hpp index d961083..81a7dc8 100644 --- a/Information/InfoCommunicate.hpp +++ b/Information/InfoCommunicate.hpp @@ -11,10 +11,11 @@ constexpr int GBUFFER_SIZE = 256; struct InfoCommunicate { std::string UUID; std::string data; + std::wstring msg; uint8_t mark{}; template 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)); } }; diff --git a/Information/InfoDirFile.hpp b/Information/InfoDirFile.hpp index dcc6c11..35471f3 100644 --- a/Information/InfoDirFile.hpp +++ b/Information/InfoDirFile.hpp @@ -58,10 +58,10 @@ struct DirFileInfo { } } - std::string name; + std::wstring name; uint64_t size = 0; FileType type = None; - std::string fullPath; + std::wstring fullPath; uint16_t permission = 0; uint64_t lastModifyTime = 0; diff --git a/RelayServer/RelayServer.cxx b/RelayServer/RelayServer.cxx index 9449ff1..8487ca4 100644 --- a/RelayServer/RelayServer.cxx +++ b/RelayServer/RelayServer.cxx @@ -96,7 +96,7 @@ void RelayServer::thClientThread(const std::shared_ptr& wxSock, co // 初次链接,告知对方的ID InfoCommunicate info; - info.data = id.ToStdString(); + info.msg = id.ToStdWstring(); Send(client->wxSock, info, FBT_SER_MSG_YOURID, id.ToStdString(), strID_); client->wxSock->SetFlags(wxSOCKET_BLOCK); diff --git a/Test/main.cxx b/Test/main.cxx index 9fef3f1..4c89cba 100644 --- a/Test/main.cxx +++ b/Test/main.cxx @@ -6,7 +6,7 @@ void test1() { DirFileInfo info; 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[0] = 'a'; @@ -41,9 +41,9 @@ void test2() DirFileInfoVec v; DirFileInfoVec v2; DirFileInfo d1; - d1.fullPath = "Java"; + d1.fullPath = L"Java"; DirFileInfo d2; - d2.fullPath = "CPP"; + d2.fullPath = L"CPP"; v.vec.push_back(d1); v.vec.push_back(d2); @@ -89,6 +89,6 @@ void test3() int main() { - test3(); + test1(); return 0; } \ No newline at end of file diff --git a/UserInterface/RemoteControl.cxx b/UserInterface/RemoteControl.cxx index 5f7272f..4df05d4 100644 --- a/UserInterface/RemoteControl.cxx +++ b/UserInterface/RemoteControl.cxx @@ -63,7 +63,7 @@ void RemoteControl::BindEvent() } for (auto& dirInfo : dirInfoVec.vec) { 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, 1, DirFileInfo::GetFileSize(dirInfo.size)); grid_->SetCellValue(grid_->GetNumberRows() - 1, 2, DirFileInfo::GetFileTypeName(dirInfo.type)); @@ -101,7 +101,7 @@ void RemoteControl::GetDirContent(wxCommandEvent& event) return; } InfoCommunicate info; - info.data = home.ToStdString(); + info.msg = home.ToStdWstring(); if (!clientCore_->Send(info, FBT_CLI_ASK_DIRFILE, remoteId)) { logControl_->AddLog(_("Request get %s's DirFile Failed"), home); } else { diff --git a/UserInterface/RemoteControl.h b/UserInterface/RemoteControl.h index 4759f8b..7441c6e 100644 --- a/UserInterface/RemoteControl.h +++ b/UserInterface/RemoteControl.h @@ -3,6 +3,7 @@ #include "InterfaceDefine.hpp" #include +#include class LogControl; class ClientCore;