1.sd卡循环
This commit is contained in:
parent
19ff0a250b
commit
2a260473a7
|
@ -27,7 +27,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#define SF_DCF_FILENAME_LEN_MAX 64
|
||||||
#define SDLOOP_REMAIN_SPACE 300 /*300MB*/
|
#define SDLOOP_REMAIN_SPACE 300 /*300MB*/
|
||||||
#define FILETXTCNT 300
|
#define FILETXTCNT 300
|
||||||
#define FILENAMELEN 128
|
#define FILENAMELEN 128
|
||||||
|
@ -71,6 +71,8 @@ SINT32 sf_sd_status_set(SF_SD_STATUS_E enStatus);
|
||||||
|
|
||||||
UINT32 sf_delete_send_flie_list(void);
|
UINT32 sf_delete_send_flie_list(void);
|
||||||
|
|
||||||
|
int sf_sd_loop(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -2417,7 +2417,11 @@ SINT32 sf_power_off_check_sd(void)
|
||||||
{
|
{
|
||||||
sf_sd_info_get(&storeattrs);
|
sf_sd_info_get(&storeattrs);
|
||||||
if((storeattrs.SDStatus == 0) & (storeattrs.SDFree < SDLOOP_REMAIN_SPACE))
|
if((storeattrs.SDStatus == 0) & (storeattrs.SDFree < SDLOOP_REMAIN_SPACE))
|
||||||
sf_sd_loopremove(SF_DCIM_DIR);
|
{
|
||||||
|
// sf_sd_loopremove(SF_DCIM_DIR);
|
||||||
|
sf_sd_loop();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sf_in_card_exist())
|
if(sf_in_card_exist())
|
||||||
|
|
|
@ -1071,7 +1071,8 @@ SINT32 app_debug_process(SINT32 argc, SF_CHAR **argv[])
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
sf_sd_loopremove("/mnt/mmc/DCIM");
|
// sf_sd_loopremove("/mnt/mmc/DCIM");
|
||||||
|
sf_sd_loop();
|
||||||
MLOGI("/* Added by MaxLi 2022/12/14--15:20:19*/\n");
|
MLOGI("/* Added by MaxLi 2022/12/14--15:20:19*/\n");
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
#include "DCF.h"
|
||||||
#include "sf_type.h"
|
#include "sf_type.h"
|
||||||
#include "sf_log.h"
|
#include "sf_log.h"
|
||||||
#include "sf_fileMng.h"
|
#include "sf_fileMng.h"
|
||||||
|
@ -22,6 +22,18 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
UINT32 gLastDirKey = 100;
|
||||||
|
UINT32 gLastFileKey = 1;
|
||||||
|
UINT32 gCurDirKey = 100;
|
||||||
|
UINT32 gCurFileKey = 1;
|
||||||
|
|
||||||
|
char gDirList[MAX_DCF_DIR_NUM][SF_DCF_FILENAME_LEN_MAX];
|
||||||
|
char gFileList[MAX_DCF_FILE_NUM][SF_DCF_FILENAME_LEN_MAX];
|
||||||
|
int gnDirList[MAX_DCF_DIR_NUM];
|
||||||
|
int gnFileList[MAX_DCF_FILE_NUM];
|
||||||
|
|
||||||
|
UINT32 gnFileIdx = 0;
|
||||||
|
UINT32 gnDirIdx = 0;
|
||||||
|
|
||||||
static SF_SD_STATUS_E SdStatus = SF_SD_BUTT;
|
static SF_SD_STATUS_E SdStatus = SF_SD_BUTT;
|
||||||
|
|
||||||
|
@ -410,6 +422,415 @@ UINT32 sf_delete_send_flie_list(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sf_find_maxval(int arr[],int narray_len)
|
||||||
|
{
|
||||||
|
int max = 0; //max value
|
||||||
|
for (int i=0; i<=narray_len; ++i)
|
||||||
|
{
|
||||||
|
if (arr[i] > max)
|
||||||
|
{
|
||||||
|
//update max value
|
||||||
|
max = arr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sf_find_minval(int arr[],int narray_len)
|
||||||
|
{
|
||||||
|
int min = MAX_DCF_FILE_NUM+1; //min value
|
||||||
|
for (int i=0; i<=narray_len; ++i)
|
||||||
|
{
|
||||||
|
if (arr[i] < min)
|
||||||
|
{
|
||||||
|
//update min value
|
||||||
|
min = arr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
SINT32 sf_dcf_is_dir_name(const char dirNamePrm[])
|
||||||
|
{
|
||||||
|
SINT32 index;
|
||||||
|
SINT32 num;
|
||||||
|
|
||||||
|
/* check parameter */
|
||||||
|
if(NULL == dirNamePrm)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// length check
|
||||||
|
if(8 > strlen(dirNamePrm))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check first charactor
|
||||||
|
if(('1' > dirNamePrm[0]) || ('9' < dirNamePrm[0]))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check charactor
|
||||||
|
for(index = 1; index < 3; index++)
|
||||||
|
{
|
||||||
|
if(!isdigit(dirNamePrm[index]))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(; index < 8; index++)
|
||||||
|
{
|
||||||
|
if((!isdigit(dirNamePrm[index]))
|
||||||
|
&& (!isalpha(dirNamePrm[index]))
|
||||||
|
&& ('_' != dirNamePrm[index]))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//check directory number
|
||||||
|
num = (dirNamePrm[0] - '0') * 100 + (dirNamePrm[1] - '0') * 10 + (dirNamePrm[2] - '0');
|
||||||
|
if(100 > num)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SINT32 sf_dcf_is_file_name(const char fileName[])
|
||||||
|
{
|
||||||
|
SINT32 index;
|
||||||
|
|
||||||
|
/* check parameter */
|
||||||
|
if(NULL == fileName)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// length check
|
||||||
|
//if(12 > strlen(fileName)) {return FALSE;}
|
||||||
|
if(8 > strlen(fileName))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check charactor
|
||||||
|
for(index = 0; index < 4; index++)
|
||||||
|
{
|
||||||
|
if((!isdigit(fileName[index]))
|
||||||
|
&& (!isalpha(fileName[index]))
|
||||||
|
&& ('_' != fileName[index]))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(; index < 8; index++)
|
||||||
|
{
|
||||||
|
if(!isdigit(fileName[index]))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void trave_dir(char* path,int nType)
|
||||||
|
{
|
||||||
|
DIR *d = NULL;
|
||||||
|
struct dirent *dp = NULL;
|
||||||
|
struct stat st;
|
||||||
|
char p[SF_DCF_FILENAME_LEN_MAX+256] = {0};
|
||||||
|
char sTmp[SF_DCF_FILENAME_LEN_MAX+1]= {0};
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
gnDirIdx = 0;
|
||||||
|
gnFileIdx = 0;
|
||||||
|
|
||||||
|
ret = stat(path, &st);
|
||||||
|
if(ret < 0 || !S_ISDIR(st.st_mode))
|
||||||
|
{
|
||||||
|
MLOGE("invalid path: %s,ret: %d\n", path,ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(d = opendir(path)))
|
||||||
|
{
|
||||||
|
MLOGE("opendir[%s] error: %m\n", path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while((dp = readdir(d)) != NULL)
|
||||||
|
{
|
||||||
|
if((!strncmp(dp->d_name, ".", 1)) || (!strncmp(dp->d_name, "..", 2)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
snprintf(p, sizeof(p) - 1, "%s/%s", path, dp->d_name);
|
||||||
|
stat(p, &st);
|
||||||
|
|
||||||
|
if(nType == 0)
|
||||||
|
{
|
||||||
|
if(S_ISDIR(st.st_mode))
|
||||||
|
{
|
||||||
|
MLOGD("%s/\n", dp->d_name);
|
||||||
|
if(sf_dcf_is_dir_name(dp->d_name) == 0)
|
||||||
|
{
|
||||||
|
strncpy(sTmp, dp->d_name,3);
|
||||||
|
|
||||||
|
gnDirList[gnDirIdx] = atoi(sTmp);
|
||||||
|
strcpy(gDirList[gnDirIdx++],dp->d_name);
|
||||||
|
MLOGD("%d\n", gnDirList[gnDirIdx-1]);
|
||||||
|
}
|
||||||
|
//trave_dir(p,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!S_ISDIR(st.st_mode))
|
||||||
|
{
|
||||||
|
MLOGD("--%s\n", dp->d_name);
|
||||||
|
if(sf_dcf_is_file_name(dp->d_name) == 0)
|
||||||
|
{
|
||||||
|
strncpy(sTmp, &dp->d_name[4],4);
|
||||||
|
|
||||||
|
gnFileList[gnFileIdx] = atoi(sTmp);
|
||||||
|
strcpy(gFileList[gnFileIdx++],dp->d_name) ;
|
||||||
|
MLOGD("%d\n", gnFileList[gnFileIdx-1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if(!S_ISDIR(st.st_mode))
|
||||||
|
{
|
||||||
|
printf("%s\n", dp->d_name);
|
||||||
|
|
||||||
|
strcpy(gFileList[gnFileIdx++], dp->d_name);
|
||||||
|
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
printf("%s/\n", dp->d_name);
|
||||||
|
|
||||||
|
strcpy(gDirList[gnDirIdx++], dp->d_name);
|
||||||
|
|
||||||
|
trave_dir(p);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(d);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void trave_file(char* path)
|
||||||
|
{
|
||||||
|
DIR *d = NULL;
|
||||||
|
struct dirent *dp = NULL;
|
||||||
|
struct stat st;
|
||||||
|
char sTmp[SF_DCF_FILENAME_LEN_MAX+1]= {0};
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
gnFileIdx = 0;
|
||||||
|
|
||||||
|
MLOGD("path: %s\n", path);
|
||||||
|
ret = stat(path, &st);
|
||||||
|
if(ret < 0 || !S_ISDIR(st.st_mode))
|
||||||
|
{
|
||||||
|
MLOGE("invalid path: %s,ret: %d\n", path,ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(d = opendir(path)))
|
||||||
|
{
|
||||||
|
MLOGE("opendir[%s] error: %m\n", path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while((dp = readdir(d)) != NULL)
|
||||||
|
{
|
||||||
|
if(sf_dcf_is_file_name(dp->d_name) == 0)
|
||||||
|
{
|
||||||
|
strncpy(sTmp, &dp->d_name[4],4);
|
||||||
|
|
||||||
|
gnFileList[gnFileIdx] = atoi(sTmp);
|
||||||
|
strcpy(gFileList[gnFileIdx++],dp->d_name);
|
||||||
|
//MLOGD("%d\n", gnFileList[gnFileIdx-1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(d);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sf_dcf_resort_min(void)
|
||||||
|
{
|
||||||
|
char sRootPath[SF_DCF_FILENAME_LEN_MAX] = {0};
|
||||||
|
char sTmp[SF_DCF_FILENAME_LEN_MAX] = {0};
|
||||||
|
int nmax_dirkey = 0;
|
||||||
|
int nmin_dirkey = 0;
|
||||||
|
|
||||||
|
strcpy(sRootPath, SF_SD_ROOT); // "/mnt/sd/"
|
||||||
|
strcat(sRootPath, SF_DCF_ROOT_DIR_NAME); // ""/mnt/sd/DCIM/"
|
||||||
|
|
||||||
|
trave_dir(sRootPath,0);
|
||||||
|
MLOGD("gnDirIdx:%d,gDirList:%d\n", gnDirIdx, gnDirList[gnDirIdx-1]);
|
||||||
|
|
||||||
|
gLastDirKey = sf_find_minval(gnDirList, gnDirIdx-1);
|
||||||
|
MLOGD("gCurDirKey:%d\n",gCurDirKey);
|
||||||
|
|
||||||
|
sprintf(sTmp,"%s/%d%s",sRootPath,gLastDirKey,DCF_DIR_NAME);
|
||||||
|
trave_file(sTmp);
|
||||||
|
MLOGD("gnFileIdx:%d,FileList:%d\n", gnFileIdx, gnFileList[gnFileIdx-1]);
|
||||||
|
|
||||||
|
gLastFileKey = sf_find_minval(gnFileList, gnFileIdx-1);
|
||||||
|
MLOGD("DirKey:%d,FileKey:%d\n", gLastDirKey, gLastFileKey); //ok
|
||||||
|
|
||||||
|
if(gLastFileKey > MAX_DCF_FILE_NUM)
|
||||||
|
{
|
||||||
|
nmin_dirkey = gLastDirKey;
|
||||||
|
nmax_dirkey = sf_find_maxval(gnDirList, gnDirIdx-1);
|
||||||
|
MLOGD("nmin_dirkey:%d , nmax_dirkey:%d\n",nmin_dirkey,nmax_dirkey);
|
||||||
|
for(int i=nmin_dirkey; i<=nmax_dirkey; i++)
|
||||||
|
{
|
||||||
|
sprintf(sTmp,"%s/%d%s", sRootPath, i, DCF_DIR_NAME);
|
||||||
|
trave_file(sTmp);
|
||||||
|
gLastFileKey = sf_find_minval(gnFileList, gnFileIdx-1);
|
||||||
|
MLOGD("DirKey:%d,FileKey:%d\n", gLastDirKey, gLastFileKey);
|
||||||
|
if(gLastFileKey <= MAX_DCF_FILE_NUM)
|
||||||
|
{
|
||||||
|
gLastDirKey = i;
|
||||||
|
MLOGD("DirKey:%d,FileKey:%d\n", gLastDirKey, gLastFileKey);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MLOGD("gCurFileKey:%d\n",gCurFileKey);
|
||||||
|
|
||||||
|
if((gLastFileKey < 1) || (gLastFileKey > MAX_DCF_FILE_NUM))
|
||||||
|
{
|
||||||
|
gLastFileKey = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
MLOGD("DirKey:%d,FileKey:%d\n", gLastDirKey, gLastFileKey); //ok
|
||||||
|
//sf_dcfkey_save();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sf_sd_loop(void)
|
||||||
|
{
|
||||||
|
char cPathTmp[512] = {0};
|
||||||
|
char cFileTmp[512] = {0};
|
||||||
|
int iFileCount = 0;
|
||||||
|
int nloop = 1;
|
||||||
|
int nDirKey = 0, nFileKey = 0;
|
||||||
|
SF_STORE_ATTR_S storeattrs = {0};
|
||||||
|
|
||||||
|
sf_dcf_resort_min();
|
||||||
|
nDirKey = gLastDirKey;
|
||||||
|
nFileKey = gLastFileKey;
|
||||||
|
|
||||||
|
MLOGD(" s\n");
|
||||||
|
|
||||||
|
while(nloop)
|
||||||
|
{
|
||||||
|
sprintf(cPathTmp,"%s%s/%03d%s/", SF_SD_ROOT, SF_DCF_ROOT_DIR_NAME, nDirKey, DCF_DIR_NAME); // ""/mnt/sd/DCIM/100MEDIA"
|
||||||
|
//Not Empty,Record File Name
|
||||||
|
sprintf(cFileTmp, "%s/%s%04d.%s",cPathTmp, DCF_FILE_NAME, nFileKey, SF_DCF_EXT_PHOTO);
|
||||||
|
|
||||||
|
if(access(cFileTmp,R_OK) == 0)
|
||||||
|
{
|
||||||
|
MLOGD("Will Delete File Name:%s\n", cFileTmp);
|
||||||
|
remove(cFileTmp);
|
||||||
|
iFileCount++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sprintf(cFileTmp, "%s/%s%04d.%s", cPathTmp, DCF_FILE_NAME, nFileKey, SF_DCF_EXT_MOV);
|
||||||
|
if(access(cFileTmp,R_OK) == 0)
|
||||||
|
{
|
||||||
|
MLOGD("Will Delete File Name:%s\n", cFileTmp);
|
||||||
|
remove(cFileTmp);
|
||||||
|
iFileCount++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//sleep(1);
|
||||||
|
system("sync");
|
||||||
|
sf_dcf_resort_min();
|
||||||
|
nDirKey = gLastDirKey;
|
||||||
|
nFileKey = gLastFileKey;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(cFileTmp,"%s%s/W%03d%04d.JPG", SF_SD_ROOT, SF_DCF_THM_DIR_NAME, nDirKey, nFileKey);
|
||||||
|
//MLOGD("Thumb Filename:%s\n", cFileTmp);
|
||||||
|
if(access(cFileTmp,R_OK) == 0)
|
||||||
|
{
|
||||||
|
MLOGD("Will Delete File Name:%s\n", cFileTmp);
|
||||||
|
remove(cFileTmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(cFileTmp,"%s%s/S%03d%04d.JPG", SF_SD_ROOT, SF_DCF_THM_DIR_NAME, nDirKey, nFileKey);
|
||||||
|
//MLOGD("Thumb Filename:%s\n", cFileTmp);
|
||||||
|
if(access(cFileTmp,R_OK) == 0)
|
||||||
|
{
|
||||||
|
MLOGD("Will Delete File Name:%s\n", cFileTmp);
|
||||||
|
remove(cFileTmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(iFileCount % 30 == 0)
|
||||||
|
{
|
||||||
|
//sf_get_sd_info(&sdStatus, &sdFree, &sdTotal);
|
||||||
|
sf_sd_info_get(&storeattrs);
|
||||||
|
|
||||||
|
if(storeattrs.SDFree > (SDLOOP_REMAIN_SPACE+50))
|
||||||
|
{
|
||||||
|
iFileCount = FILETXTCNT;
|
||||||
|
nloop = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//if del 300 files, sd free size < 350, del file
|
||||||
|
if(iFileCount >= FILETXTCNT)
|
||||||
|
{
|
||||||
|
nloop = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nFileKey++;
|
||||||
|
if(nFileKey > MAX_DCF_FILE_NUM)
|
||||||
|
{
|
||||||
|
if(access(cPathTmp,R_OK) == 0)
|
||||||
|
{
|
||||||
|
MLOGD("Will Delete Dir:%s\n", cPathTmp);
|
||||||
|
remove(cPathTmp);
|
||||||
|
}
|
||||||
|
nDirKey++;
|
||||||
|
nFileKey = 1;
|
||||||
|
if(nDirKey > MAX_DCF_DIR_NUM)
|
||||||
|
{
|
||||||
|
nDirKey = 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sync();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user