优化代码

heatbeat
Matthew 3 months ago
parent d9c1cbac2f
commit cd0a6befd6

@ -3594,8 +3594,17 @@ bool CPhoneDevice::OnImageReady(cv::Mat mat)
#endif #endif
#endif // OUTPUT_DBG_INFO #endif // OUTPUT_DBG_INFO
bool imgExisted = std::filesystem::exists(std::filesystem::path(fullPath));
if (imgExisted)
{
size_t imgFileSize = getFileSize(fullPath);
if (imgFileSize == 0 || imgFileSize == (size_t)-1)
{
imgExisted = false;
}
}
if (!std::filesystem::exists(std::filesystem::path(fullPath)) || getFileSize(fullPath) == 0) if (!imgExisted)
{ {
bool res = cv::imwrite(fullPath.c_str(), mat, params); bool res = cv::imwrite(fullPath.c_str(), mat, params);
if (!res) if (!res)
@ -3854,7 +3863,16 @@ bool CPhoneDevice::PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector<ID
bool res = false; bool res = false;
std::string fullPath = endsWith(path, ".jpg") ? path : (path + CTerminal::BuildPhotoFileName(photoInfo)); std::string fullPath = endsWith(path, ".jpg") ? path : (path + CTerminal::BuildPhotoFileName(photoInfo));
if (!std::filesystem::exists(std::filesystem::path(fullPath)) || getFileSize(fullPath) == 0) bool imgExisted = std::filesystem::exists(std::filesystem::path(fullPath));
if (imgExisted)
{
size_t imgFileSize = getFileSize(fullPath);
if (imgFileSize == 0 || imgFileSize == (size_t)-1)
{
imgExisted = false;
}
}
if (!imgExisted)
{ {
#ifdef _DEBUG #ifdef _DEBUG
char log[256] = { 0 }; char log[256] = { 0 };
@ -3877,7 +3895,7 @@ bool CPhoneDevice::PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector<ID
if (existsFile(tmpPath)) if (existsFile(tmpPath))
{ {
imgFileSize = getFileSize(tmpPath); imgFileSize = getFileSize(tmpPath);
if (imgFileSize == 0) if (imgFileSize == 0 || imgFileSize == -1)
{ {
XYLOG(XYLOG_SEVERITY_ERROR, "Empty File Written: %s errno=%d", tmpPath.c_str() + m_appPath.size(), errcode); XYLOG(XYLOG_SEVERITY_ERROR, "Empty File Written: %s errno=%d", tmpPath.c_str() + m_appPath.size(), errcode);
remove(tmpPath.c_str()); remove(tmpPath.c_str());
@ -3906,7 +3924,7 @@ bool CPhoneDevice::PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector<ID
if (res) if (res)
{ {
imgFileSize = getFileSize(tmpPath); imgFileSize = getFileSize(tmpPath);
if (imgFileSize == 0) if (imgFileSize == 0 || imgFileSize == -1)
{ {
XYLOG(XYLOG_SEVERITY_ERROR, "Empty File after rename %s", fullPath.c_str() + m_appPath.size()); XYLOG(XYLOG_SEVERITY_ERROR, "Empty File after rename %s", fullPath.c_str() + m_appPath.size());
res = false; res = false;

Loading…
Cancel
Save