Skip to content

Commit

Permalink
Optmize code for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueMatthew committed Nov 16, 2020
1 parent 7abf4f7 commit 9af9427
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand Down
9 changes: 9 additions & 0 deletions WechatExporter/ShellImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ class ShellImpl : public Shell
return existed == YES && isDir == YES;
}

bool existsFile(const std::string& path) const
{
BOOL isDir = NO;
NSString *ocPath = [NSString stringWithUTF8String: path.c_str()];

BOOL existed = [[NSFileManager defaultManager] fileExistsAtPath:ocPath isDirectory:&isDir];
return existed == YES;
}

bool listSubDirectories(const std::string& path, std::vector<std::string>& subDirectories) const
{
struct dirent *entry;
Expand Down
1 change: 1 addition & 0 deletions WechatExporter/core/Shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Shell

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<std::string>& 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;
Expand Down
17 changes: 12 additions & 5 deletions WechatExporter/core/WechatParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion WechatExporter/core/WechatParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class SessionParser
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<std::string, std::string>& templateValues) const;
};

Expand Down
10 changes: 10 additions & 0 deletions vcproject/ShellImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ class ShellImpl : public Shell
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<std::string>& subDirectories) const
{
WIN32_FIND_DATA FindFileData;
Expand Down

0 comments on commit 9af9427

Please sign in to comment.