|
@@ -204,54 +204,6 @@ static void PrintDiskStatus(LPCTSTR dir, const unsigned long long& uiDiskFreeSiz
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[Disk(%s)] total: %s, free: %s, rate: %.1lf%%.", dir, szResult2, szResult, dFreeRate * 100);
|
|
|
}
|
|
|
|
|
|
-struct TmpFileInfo
|
|
|
-{
|
|
|
-#if defined(_MSC_VER)
|
|
|
- string msFileName;
|
|
|
- FILETIME mftEditTime;
|
|
|
-
|
|
|
- DWORD mDwFileSizeHeight;
|
|
|
- DWORD mDwFileSizeLow;
|
|
|
-
|
|
|
- TmpFileInfo(LPCTSTR lpszFileName, const PFILETIME ftEditTime, DWORD dwFileSizeHeight, DWORD dwFileSizeLow)
|
|
|
- : msFileName(lpszFileName)
|
|
|
- , mftEditTime(*ftEditTime)
|
|
|
- , mDwFileSizeHeight(dwFileSizeHeight)
|
|
|
- , mDwFileSizeLow(dwFileSizeLow)
|
|
|
- {
|
|
|
- }
|
|
|
-#else
|
|
|
- string msFileName;
|
|
|
- time_t mftEditTime;
|
|
|
- off_t ftSize;
|
|
|
-
|
|
|
- TmpFileInfo() :msFileName(""), mftEditTime(0), ftSize(0){}
|
|
|
-
|
|
|
- TmpFileInfo(LPCTSTR lpszFileName, const time_t ftEditTime, off_t fileSize)
|
|
|
- : msFileName(lpszFileName)
|
|
|
- , mftEditTime(ftEditTime)
|
|
|
- , ftSize(fileSize)
|
|
|
- {
|
|
|
- }
|
|
|
- ~TmpFileInfo() {}
|
|
|
-
|
|
|
-#endif //_MSC_VER
|
|
|
-};
|
|
|
-
|
|
|
-struct Comparetor
|
|
|
-{
|
|
|
- bool operator () (const TmpFileInfo* lhs, const TmpFileInfo* rhs) const
|
|
|
- {
|
|
|
-#if defined(_MSC_VER)
|
|
|
- if (CompareFileTime(&(lhs->mftEditTime), &(rhs->mftEditTime)) > 0)
|
|
|
- return true;
|
|
|
- return false;
|
|
|
-#else
|
|
|
- return (lhs->mftEditTime > rhs->mftEditTime);
|
|
|
-#endif //_MSC_VER
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
struct DiskInfo
|
|
|
{
|
|
|
#if defined(_MSC_VER)
|
|
@@ -364,134 +316,6 @@ struct DiskInfo
|
|
|
mUiMaxFileSize = uiRhs;
|
|
|
}
|
|
|
|
|
|
- BOOL CalAverRequreSpaceEachDay(
|
|
|
- const ULARGE_INTEGER& uiAllVideoFileBytes,
|
|
|
- const UINT uVideoFileCount,
|
|
|
- const UINT uAvailDayCount,
|
|
|
- const UINT uRequredDays,
|
|
|
- ULARGE_INTEGER& uiRequireBytes)
|
|
|
- {
|
|
|
- mUiAllVideoFilesBytes = uiAllVideoFileBytes;
|
|
|
- mUVideoFileCount = uVideoFileCount;
|
|
|
- mUVideoCreateDayCount = uAvailDayCount;
|
|
|
-
|
|
|
- char szResult[DEFAULT_OUTPUT_FORMAT_SIZE];
|
|
|
- ByteSprintf(szResult, (double)mUiAllVideoFilesBytes.QuadPart);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("录像文件夹的大小 : %s", szResult);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("已上传录像文件数量 : %u", mUVideoFileCount);
|
|
|
-
|
|
|
- //平均每天的录像数目
|
|
|
- mUAverageFileCreated = DEFAULT_VIDEOFILE_CREATE_COUNT;
|
|
|
- if (mUVideoCreateDayCount != 0) {
|
|
|
- mUAverageFileCreated = mUVideoFileCount / mUVideoCreateDayCount;
|
|
|
- }
|
|
|
-
|
|
|
- //平均录像文件的大小 TODO:
|
|
|
- mUliAverageFileSize = mUiAllVideoFilesBytes;
|
|
|
- if (mUVideoFileCount != 0) {
|
|
|
- mUliAverageFileSize.QuadPart = mUiAllVideoFilesBytes.QuadPart / mUVideoFileCount;
|
|
|
- }
|
|
|
-
|
|
|
- ByteSprintf(szResult, (double)mUliAverageFileSize.QuadPart);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("平均录像文件的大小 : %s", szResult);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("平均每天录像的数目 : %u", mUAverageFileCreated);
|
|
|
-
|
|
|
- //预估每天需要提供的空间大小
|
|
|
- ULARGE_INTEGER uiForecastDailySpace;
|
|
|
- uiForecastDailySpace.QuadPart = mUliAverageFileSize.QuadPart * mUAverageFileCreated;
|
|
|
-
|
|
|
- //至少需预留的磁盘空间大小
|
|
|
- ULARGE_INTEGER uiForecastSpaceAvail;
|
|
|
- uiForecastSpaceAvail.QuadPart = uiForecastDailySpace.QuadPart * uRequredDays;
|
|
|
- ByteSprintf(szResult, (double)uiForecastSpaceAvail.QuadPart);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("需预留的磁盘空间大小 : %s", szResult);
|
|
|
-
|
|
|
- mUiFreeBytesRequired = uiForecastSpaceAvail;
|
|
|
- uiRequireBytes = uiForecastSpaceAvail;
|
|
|
-
|
|
|
- return (mBAverageAvailable = TRUE);
|
|
|
- }
|
|
|
-
|
|
|
- BOOL IsNeedToDoClearJobEx(LPCTSTR lpszDiskPath,
|
|
|
- const ULARGE_INTEGER& uiRequiredByts,
|
|
|
- const ULARGE_INTEGER& uiAdjustmentFactor, PULARGE_INTEGER pUiRealRequiredByts)
|
|
|
- {
|
|
|
- BOOL bRet = FALSE;
|
|
|
- if (lpszDiskPath == NULL || strlen(lpszDiskPath) == 0)
|
|
|
- return FALSE;
|
|
|
- if (pUiRealRequiredByts != NULL) {
|
|
|
- pUiRealRequiredByts->QuadPart = 0;
|
|
|
- }
|
|
|
- ULARGE_INTEGER uiDiskOverallSize;
|
|
|
- ULARGE_INTEGER uiDiskFreeSize;
|
|
|
- bRet = GetDiskSpace(lpszDiskPath, uiDiskOverallSize, uiDiskFreeSize);
|
|
|
- if (bRet) {
|
|
|
- assert(uiDiskOverallSize.QuadPart != 0);
|
|
|
- char szResult[DEFAULT_OUTPUT_FORMAT_SIZE];
|
|
|
- char szResult2[DEFAULT_OUTPUT_FORMAT_SIZE];
|
|
|
- ByteSprintf(szResult, (double)uiDiskFreeSize.QuadPart);
|
|
|
- ByteSprintf(szResult2, (double)uiDiskOverallSize.QuadPart);
|
|
|
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Current operated disk(%s) : %s / %s", lpszDiskPath, szResult, szResult2);
|
|
|
- ULARGE_INTEGER uiForecastSpaceAvail;
|
|
|
- uiForecastSpaceAvail.QuadPart = uiRequiredByts.QuadPart + uiAdjustmentFactor.QuadPart;
|
|
|
- if (uiForecastSpaceAvail.QuadPart > uiDiskFreeSize.QuadPart) {
|
|
|
- ULARGE_INTEGER uiTemp;
|
|
|
- uiTemp.QuadPart = uiForecastSpaceAvail.QuadPart - uiDiskFreeSize.QuadPart;
|
|
|
- ByteSprintf(szResult, (double)uiTemp.QuadPart);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("More space required : %s", szResult);
|
|
|
- if (pUiRealRequiredByts != NULL) {
|
|
|
- pUiRealRequiredByts->QuadPart = uiTemp.QuadPart;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return bRet;
|
|
|
- }
|
|
|
-
|
|
|
- BOOL IsNeedToDoClearJob(const ULARGE_INTEGER& uiAdjustmentFactor, PULARGE_INTEGER pUiRealRequiredByts)
|
|
|
- {
|
|
|
- BOOL bResult = FALSE;
|
|
|
-
|
|
|
- char szResult[DEFAULT_OUTPUT_FORMAT_SIZE];
|
|
|
- //ByteSprintf(szResult, ULONGLONG_ERROR);
|
|
|
- if (mUiUploadVideoFileBytes.QuadPart != ULONGLONG_ERROR) {
|
|
|
- ByteSprintf(szResult, (double)mUiUploadVideoFileBytes.QuadPart);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("未上传录像文件夹的大小 : %s", szResult);
|
|
|
- }
|
|
|
-
|
|
|
-#if JUS_A_TEST
|
|
|
- //uiAdjustmentFactor.QuadPart = 1024ui64 * 1024 * 1024 * 100 * 4;
|
|
|
-#endif
|
|
|
- if (pUiRealRequiredByts != NULL) {
|
|
|
- pUiRealRequiredByts->QuadPart = 0;
|
|
|
- }
|
|
|
-
|
|
|
- ULARGE_INTEGER uiForecastSpaceAvail;
|
|
|
-
|
|
|
- if (!mBAverageAvailable) {
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("mBAverageAvailable == FALSE");
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
-
|
|
|
- uiForecastSpaceAvail.QuadPart = mUiFreeBytesRequired.QuadPart + uiAdjustmentFactor.QuadPart;
|
|
|
-
|
|
|
- assert(mUliDiskOverallSize.QuadPart != 0);
|
|
|
-
|
|
|
- if (uiForecastSpaceAvail.QuadPart > mUliDiskFreeSize.QuadPart) {
|
|
|
- //TODO: Alert !!
|
|
|
- ULARGE_INTEGER uiTemp;
|
|
|
- uiTemp.QuadPart = uiForecastSpaceAvail.QuadPart - mUliDiskFreeSize.QuadPart;
|
|
|
- ByteSprintf(szResult, (double)uiTemp.QuadPart);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("需要待清理的空间大小 : %s", szResult);
|
|
|
- if (pUiRealRequiredByts != NULL) {
|
|
|
- pUiRealRequiredByts->QuadPart = uiTemp.QuadPart;
|
|
|
- }
|
|
|
- bResult = TRUE;
|
|
|
- } else {
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("当前无需对磁盘空间进行清理。");
|
|
|
- }
|
|
|
- return bResult;
|
|
|
- }
|
|
|
-
|
|
|
static BOOL GetDiskSpace(
|
|
|
LPCTSTR lpszVideoPath,
|
|
|
ULARGE_INTEGER& uiTotalByteNumber,
|
|
@@ -530,128 +354,6 @@ struct DiskInfo
|
|
|
mUiMaxFileSize = uiRhs;
|
|
|
}
|
|
|
|
|
|
- BOOL CalAverRequreSpaceEachDay(
|
|
|
- const unsigned long long& uiAllVideoFileBytes,
|
|
|
- const unsigned int uVideoFileCount,
|
|
|
- const unsigned int uAvailDayCount,
|
|
|
- const unsigned int uRequredDays,
|
|
|
- unsigned long long& uiRequireBytes)
|
|
|
- {
|
|
|
- mUiAllVideoFilesBytes = uiAllVideoFileBytes;
|
|
|
- mUVideoFileCount = uVideoFileCount;
|
|
|
- mUVideoCreateDayCount = uAvailDayCount;
|
|
|
-
|
|
|
- char szResult[DEFAULT_OUTPUT_FORMAT_SIZE];
|
|
|
- ByteSprintf(szResult, (double)mUiAllVideoFilesBytes);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("录像文件夹的大小 : %s", szResult);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("录像文件数量(已上传+未上传) : %u", mUVideoFileCount);
|
|
|
-
|
|
|
- //平均每天的录像数目
|
|
|
- mUAverageFileCreated = DEFAULT_VIDEOFILE_CREATE_COUNT;
|
|
|
- if (mUVideoCreateDayCount != 0) {
|
|
|
- mUAverageFileCreated = mUVideoFileCount / mUVideoCreateDayCount;
|
|
|
- }
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("平均每天录像的数目 : %u", mUAverageFileCreated);
|
|
|
-
|
|
|
- //平均录像文件的大小 TODO:
|
|
|
- if (mUVideoFileCount != 0) {
|
|
|
- mUliAverageFileSize = mUiAllVideoFilesBytes / mUVideoFileCount;
|
|
|
- } else {
|
|
|
- mUliAverageFileSize = mUiAllVideoFilesBytes;
|
|
|
- }
|
|
|
- ByteSprintf(szResult, (double)mUliAverageFileSize);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("平均录像文件的大小 : %s", szResult);
|
|
|
-
|
|
|
- //预估每天需要提供的空间大小 = 平均每个文件大小 * 平均每天文件数量
|
|
|
- const unsigned long long uiForecastDailySpace = mUliAverageFileSize * mUAverageFileCreated;
|
|
|
-
|
|
|
- //至少需预留的磁盘空间大小 = 平均每天需要的大小*要求留存的天数
|
|
|
- const unsigned long long uiForecastSpaceAvail = uiForecastDailySpace * uRequredDays;
|
|
|
- ByteSprintf(szResult, (double)uiForecastSpaceAvail);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("需预留的磁盘空间大小(平均每个文件大小 * 平均每天文件数量 * 要求留存的天数#%u) : %s", uRequredDays, szResult);
|
|
|
- mUiFreeBytesRequired = uiForecastSpaceAvail;
|
|
|
-
|
|
|
- uiRequireBytes = uiForecastSpaceAvail;
|
|
|
- return (mBAverageAvailable = TRUE);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- uiAdjustmentFactor: 增量调整因子
|
|
|
- */
|
|
|
- BOOL IsNeedToDoClearJobEx(LPCTSTR lpszDiskPath,
|
|
|
- const unsigned long long& uiRequiredByts,
|
|
|
- const unsigned long long& uiAdjustmentFactor,
|
|
|
- unsigned long long* pUiRealRequiredByts)
|
|
|
- {
|
|
|
- BOOL bRet = FALSE;
|
|
|
- if (lpszDiskPath == NULL || strlen(lpszDiskPath) == 0)
|
|
|
- return FALSE;
|
|
|
- if (pUiRealRequiredByts != NULL) {
|
|
|
- *pUiRealRequiredByts = 0;
|
|
|
- }
|
|
|
- unsigned long long uiDiskOverallSize;
|
|
|
- unsigned long long uiDiskFreeSize;
|
|
|
- bRet = GetDiskSpace(lpszDiskPath, uiDiskOverallSize, uiDiskFreeSize);
|
|
|
- if (bRet) {
|
|
|
- assert(uiDiskOverallSize != 0);
|
|
|
- PrintDiskStatus(lpszDiskPath, uiDiskFreeSize, uiDiskOverallSize);
|
|
|
- const unsigned long long uiForecastSpaceAvail = uiRequiredByts + uiAdjustmentFactor;
|
|
|
- if (uiForecastSpaceAvail > uiDiskFreeSize) {
|
|
|
- unsigned long long uiTemp;
|
|
|
- uiTemp = uiForecastSpaceAvail - uiDiskFreeSize;
|
|
|
- char szResult[DEFAULT_OUTPUT_FORMAT_SIZE];
|
|
|
- ByteSprintf(szResult, (double)uiTemp);
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("More space required : %s", szResult);
|
|
|
- if (pUiRealRequiredByts != NULL) {
|
|
|
- *pUiRealRequiredByts = uiTemp;
|
|
|
- }
|
|
|
- return TRUE;
|
|
|
- }
|
|
|
- }
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
-
|
|
|
- BOOL IsNeedToDoClearJob(const unsigned long long& uiAdjustmentFactor, unsigned long long* pUiRealRequiredByts)
|
|
|
- {
|
|
|
- BOOL bResult = FALSE;
|
|
|
-
|
|
|
- char szResult[DEFAULT_OUTPUT_FORMAT_SIZE];
|
|
|
- if (mUiUploadVideoFileBytes != ULONGLONG_ERROR) {
|
|
|
- ByteSprintf(szResult, (double)mUiUploadVideoFileBytes);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("未上传录像文件夹的大小 : %s", szResult);
|
|
|
- }
|
|
|
-
|
|
|
- if (pUiRealRequiredByts != NULL) {
|
|
|
- *pUiRealRequiredByts = 0;
|
|
|
- }
|
|
|
-
|
|
|
- unsigned long long uiForecastSpaceAvail;
|
|
|
-
|
|
|
- if (!mBAverageAvailable) {
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("mBAverageAvailable == FALSE");
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
-
|
|
|
- uiForecastSpaceAvail = mUiFreeBytesRequired + uiAdjustmentFactor;
|
|
|
-
|
|
|
- assert(mUliDiskOverallSize != 0);
|
|
|
-
|
|
|
- if (uiForecastSpaceAvail > mUliDiskFreeSize) {
|
|
|
- //TODO: Alert !!
|
|
|
- unsigned long long uiTemp;
|
|
|
- uiTemp = uiForecastSpaceAvail - mUliDiskFreeSize;
|
|
|
- ByteSprintf(szResult, (double)uiTemp);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("需要待清理的空间大小 : %s", szResult);
|
|
|
- if (pUiRealRequiredByts != NULL) {
|
|
|
- *pUiRealRequiredByts = uiTemp;
|
|
|
- }
|
|
|
- bResult = TRUE;
|
|
|
- } else {
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("当前无需对磁盘空间进行清理。");
|
|
|
- }
|
|
|
- return bResult;
|
|
|
- }
|
|
|
-
|
|
|
static BOOL GetDiskSpace(LPCTSTR lpszVideoPath,unsigned long long& uiTotalByteNumber, unsigned long long& uiTotalFreeByteNumber)
|
|
|
{
|
|
|
struct statfs buf;
|