From 04eead2fb96a07cf9e9d062ea2e10de1e5c65a94 Mon Sep 17 00:00:00 2001 From: Matthew <37573096+BlueMatthew@users.noreply.github.com> Date: Mon, 16 Nov 2020 23:06:04 +0800 Subject: [PATCH] Optmize code for debugging --- .../xcschemes/WechatExporter.xcscheme | 2 +- WechatExporter/ShellImpl.h | 9 +++++++++ WechatExporter/core/Shell.h | 1 + WechatExporter/core/WechatParser.cpp | 17 ++++++++++++----- WechatExporter/core/WechatParser.h | 2 +- vcproject/ShellImpl.h | 10 ++++++++++ 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/WechatExporter.xcodeproj/xcshareddata/xcschemes/WechatExporter.xcscheme b/WechatExporter.xcodeproj/xcshareddata/xcschemes/WechatExporter.xcscheme index f64a0a6..e896223 100644 --- a/WechatExporter.xcodeproj/xcshareddata/xcschemes/WechatExporter.xcscheme +++ b/WechatExporter.xcodeproj/xcshareddata/xcschemes/WechatExporter.xcscheme @@ -31,7 +31,7 @@ & subDirectories) const { struct dirent *entry; diff --git a/WechatExporter/core/Shell.h b/WechatExporter/core/Shell.h index acb8d8c..00b2e09 100644 --- a/WechatExporter/core/Shell.h +++ b/WechatExporter/core/Shell.h @@ -19,6 +19,7 @@ public: virtual bool existsDirectory(const std::string& path) const = 0; virtual bool makeDirectory(const std::string& path) const = 0; + virtual bool existsFile(const std::string& path) const = 0; virtual bool listSubDirectories(const std::string& path, std::vector& subDirectories) const = 0; virtual bool copyFile(const std::string& src, const std::string& dest, bool overwrite) const = 0; virtual bool openOutputFile(std::ofstream& ofs, const std::string& fileName, std::ios_base::openmode mode = std::ios::out) const = 0; diff --git a/WechatExporter/core/WechatParser.cpp b/WechatExporter/core/WechatParser.cpp index 8491d97..2ec6d42 100644 --- a/WechatExporter/core/WechatParser.cpp +++ b/WechatExporter/core/WechatParser.cpp @@ -861,8 +861,8 @@ bool SessionParser::parseRow(Record& record, const std::string& userBase, const } else if (record.type == 62 || record.type == 43) { - bool hasthum = requireResource(combinePath(userBase, "Video", session.Hash, msgIdStr + ".video_thum"), combinePath(assetsDir, msgIdStr + "_thum.jpg")); - bool hasvid = requireResource(combinePath(userBase, "Video", session.Hash, msgIdStr + ".mp4"), combinePath(assetsDir, msgIdStr + ".mp4")); + bool hasthum = requireFile(combinePath(userBase, "Video", session.Hash, msgIdStr + ".video_thum"), combinePath(assetsDir, msgIdStr + "_thum.jpg")); + bool hasvid = requireFile(combinePath(userBase, "Video", session.Hash, msgIdStr + ".mp4"), combinePath(assetsDir, msgIdStr + ".mp4")); std::string msgFile; if (hasthum || hasvid) @@ -908,8 +908,8 @@ bool SessionParser::parseRow(Record& record, const std::string& userBase, const { std::string vfile = combinePath(userBase, "Img", session.Hash, msgIdStr); - bool hasthum = requireResource(vfile + ".pic_thum", combinePath(assetsDir, msgIdStr + "_thum.jpg")); - bool haspic = requireResource(vfile + ".pic", combinePath(assetsDir, msgIdStr + ".jpg")); + bool hasthum = requireFile(vfile + ".pic_thum", combinePath(assetsDir, msgIdStr + "_thum.jpg")); + bool haspic = requireFile(vfile + ".pic", combinePath(assetsDir, msgIdStr + ".jpg")); std::string msgFile; if (hasthum || haspic) @@ -1053,11 +1053,18 @@ std::string SessionParser::getLocaleString(const std::string& key) const return it == m_localeStrings.cend() ? key : it->second; } -bool SessionParser::requireResource(const std::string& vpath, const std::string& dest) const +bool SessionParser::requireFile(const std::string& vpath, const std::string& dest) const { std::string srcPath = m_iTunesDb.findRealPath(vpath); if (!srcPath.empty()) { +#ifndef NDEBUG + // Make debug more effective + if (m_shell.existsFile(srcPath)) + { + return true; + } +#endif return m_shell.copyFile(srcPath, dest, true); } diff --git a/WechatExporter/core/WechatParser.h b/WechatExporter/core/WechatParser.h index f3a673d..f703f31 100644 --- a/WechatExporter/core/WechatParser.h +++ b/WechatExporter/core/WechatParser.h @@ -229,7 +229,7 @@ private: std::string getTemplate(const std::string& key) const; std::string getLocaleString(const std::string& key) const; std::string getDisplayTime(int ms) const; - bool requireResource(const std::string& vpath, const std::string& dest) const; + bool requireFile(const std::string& vpath, const std::string& dest) const; bool parseRow(Record& record, const std::string& userBase, const std::string& path, const Session& session, std::string& templateKey, std::map& templateValues) const; }; diff --git a/vcproject/ShellImpl.h b/vcproject/ShellImpl.h index 72e44ac..13ffc9f 100644 --- a/vcproject/ShellImpl.h +++ b/vcproject/ShellImpl.h @@ -27,6 +27,16 @@ public: return ::SHCreateDirectoryEx(NULL, (LPCTSTR)pszT, NULL) == ERROR_SUCCESS; } + bool existsFile(const std::string& path) const + { + CW2T pszT(CA2W(path.c_str(), CP_UTF8)); + + DWORD dwAttrib = ::GetFileAttributes((LPCTSTR)pszT); + + return (dwAttrib != INVALID_FILE_ATTRIBUTES && + (dwAttrib & FILE_ATTRIBUTE_DIRECTORY) == 0); + } + bool listSubDirectories(const std::string& path, std::vector& subDirectories) const { WIN32_FIND_DATA FindFileData;