|
|
@@ -3,7 +3,10 @@
|
|
|
#ifdef RVC_OS_WIN
|
|
|
#include "stdafx.h"
|
|
|
#else
|
|
|
-#include <sys/stat.h>
|
|
|
+#include<sys/stat.h>
|
|
|
+#include<sys/types.h>
|
|
|
+#include<dirent.h>
|
|
|
+#include<unistd.h>
|
|
|
#endif // RVC_OS_WIN
|
|
|
#include "Event.h"
|
|
|
#include "y2k_time.h"
|
|
|
@@ -773,8 +776,10 @@ int CRecorderEntity::HandleEncryptVideoRecord(const char* videofilename)
|
|
|
int iresult = encryption_file(strOutFile, MAX_PATH, videofilename, &cb, eVerB);
|
|
|
if (0 != iresult){
|
|
|
LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORDER_ENCRYPT_FAILED, CSimpleStringA::Format("encryption file %s failed, delete out temp file %s!", videofilename, strOutFile).GetData());
|
|
|
- if (!RvcDeleteFile(strOutFile)){
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DeleteFile file %s failed!", strOutFile);
|
|
|
+ if (ExistsFile(strOutFile)) {
|
|
|
+ if (!RvcDeleteFile(strOutFile)) {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DeleteFile file %s failed!", strOutFile);
|
|
|
+ }
|
|
|
}
|
|
|
return iRet;
|
|
|
}
|
|
|
@@ -793,7 +798,7 @@ int CRecorderEntity::HandleEncryptVideoRecord(const char* videofilename)
|
|
|
}
|
|
|
else{
|
|
|
if (rvcMoveFile(strOutFile, videofilename)){
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("rename %s to %s Success!",strOutFile, videofilename);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after encryption rename %s to %s Success!",strOutFile, videofilename);
|
|
|
iRet = 0;
|
|
|
}
|
|
|
else{
|
|
|
@@ -990,6 +995,53 @@ on_next:
|
|
|
FindClose(hFind);
|
|
|
}
|
|
|
#else
|
|
|
+ struct dirent* ptr;
|
|
|
+ DIR* dir = opendir(m_TempDir.GetData());
|
|
|
+ while ((ptr = readdir(dir)) != NULL)
|
|
|
+ {
|
|
|
+ if (ptr->d_type & DT_DIR) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (0 == memcmp(ptr->d_name, RVC_TRANSATCION_RECORD_SUFFIX, strlen(RVC_TRANSATCION_RECORD_SUFFIX)) ||
|
|
|
+ 0 == memcmp(ptr->d_name, RVC_ENCRYPT_TRANSATCION_RECORD_SUFFIX, strlen(RVC_ENCRYPT_TRANSATCION_RECORD_SUFFIX))) {
|
|
|
+ CSimpleStringA srcfile = CSimpleStringA::Format("%s%s", m_TempDir.GetData(), ptr->d_name);
|
|
|
+ if (m_bEncFlag) {
|
|
|
+ filecryption_callback_t cb = { 0 };
|
|
|
+ cb.dbg = &rvcDbg;
|
|
|
+ if (false == is_file_encrypted(srcfile.GetData(), &cb)) {
|
|
|
+ HandleEncryptVideoRecord(srcfile.GetData());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ char* pIndex = NULL;
|
|
|
+ if (pIndex = strstr(ptr->d_name, RVC_FILEENC_STR)) {
|
|
|
+ char strname[MAX_PATH] = { 0 };
|
|
|
+ memcpy(strname, pIndex + strlen(RVC_FILEENC_STR), strlen(pIndex + strlen(RVC_FILEENC_STR)));
|
|
|
+ CSimpleStringA tempsrcfile = CSimpleStringA::Format("%s%s", m_TempDir.GetData(), strname);
|
|
|
+ if (rvcMoveFile(srcfile.GetData(), tempsrcfile.GetData())) {
|
|
|
+ srcfile = tempsrcfile;
|
|
|
+ memset(ptr->d_name, 0, MAX_PATH);
|
|
|
+ memcpy(ptr->d_name, strname, strlen(strname));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_RENAME_FAILED, CSimpleStringA::Format("%s(%d) while rename %s.", strerror(errno), errno, srcfile.GetData()).GetData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ CSimpleStringA dstfile = CSimpleStringA::Format("%s%s", m_RecordSaveDir.GetData(), ptr->d_name);
|
|
|
+ bool bRet = rvcMoveFile(srcfile.GetData(), dstfile.GetData());
|
|
|
+ if (!bRet) {
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s -> %s", GetLastError(), srcfile.GetData(), dstfile.GetData()).GetData());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ AddToVideoRecordList(dstfile.GetData());
|
|
|
+ iRet = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ closedir(dir);
|
|
|
|
|
|
#endif // RVC_OS_WIN
|
|
|
|