From 035a4bac2fb50fa554f73283408cc40a1e910ad2 Mon Sep 17 00:00:00 2001 From: fangyunzhong Date: Thu, 20 Apr 2023 09:14:22 +0000 Subject: [PATCH] =?UTF-8?q?=E8=B6=85=E9=95=BF=E8=B7=AF=E5=BE=84json?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=A7=A3=E6=9E=90=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangyunzhong --- include/file_entry.h | 2 +- src/file_entry.cpp | 4 ++-- src/resource_util.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/file_entry.h b/include/file_entry.h index daac485..5419d9d 100644 --- a/include/file_entry.h +++ b/include/file_entry.h @@ -57,12 +57,12 @@ public: static bool CopyFileInner(const std::string &src, const std::string &dst); static bool IsDirectory(const std::string &path); static std::string RealPath(const std::string &path); + static std::string AdapateLongPath(const std::string &path); private: bool IsIgnore(const std::string &filename) const; static bool RemoveAllDirInner(const FileEntry &entry); static bool CreateDirsInner(const std::string &path, std::string::size_type offset); - static std::string AdapateLongPath(const std::string &path); FilePath filePath_; bool isFile_; static const std::string SEPARATE; diff --git a/src/file_entry.cpp b/src/file_entry.cpp index e9d1a01..260b2bc 100644 --- a/src/file_entry.cpp +++ b/src/file_entry.cpp @@ -360,15 +360,15 @@ void FileEntry::FilePath::Init() } } -#ifdef _WIN32 string FileEntry::AdapateLongPath(const string &path) { +#ifdef _WIN32 if (path.size() >= MAX_PATH -12) { //the max file path can not exceed 260 - 12 return LONG_PATH_HEAD + path; } +#endif return path; } -#endif } } } diff --git a/src/resource_util.cpp b/src/resource_util.cpp index 5cd8976..bb69a6e 100644 --- a/src/resource_util.cpp +++ b/src/resource_util.cpp @@ -72,7 +72,7 @@ bool ResourceUtil::RmoveAllDir(const string &path) bool ResourceUtil::OpenJsonFile(const string &path, Json::Value &root) { - ifstream ifs(path, ios::binary); + ifstream ifs(FileEntry::AdapateLongPath(path), ios::binary); if (!ifs.is_open()) { cerr << "Error: open json failed '" << path << "', reason: " << strerror(errno) << endl; return false; @@ -98,7 +98,7 @@ bool ResourceUtil::SaveToJsonFile(const string &path, const Json::Value &root) writerBuilder["indentation"] = " "; writerBuilder["emitUTF8"] = true; unique_ptr writer(writerBuilder.newStreamWriter()); - ofstream out(path, ofstream::out | ofstream::binary); + ofstream out(FileEntry::AdapateLongPath(path), ofstream::out | ofstream::binary); if (!out.is_open()) { cerr << "Error: open failed '" << path <<"', reason: " << strerror(errno) << endl; return false;