fssim_core.c
来自「最新MTK手机软件源码」· C语言 代码 · 共 1,826 行 · 第 1/5 页
C
1,826 行
/* */
/* INPUTS */
/* */
/* fullname - full name of found file/directory */
/* filename - file name of found file/directory */
/* param - no use */
/* order - FSSIM_BEFORE_RECURSIVE or FSSIM_AFTER_RECURSIVE */
/* */
/* OUTPUTS */
/* */
/* zero for success; non-zero for failure */
/* */
/*************************************************************************/
int fssim_del_dir(TCHAR *fullname, TCHAR *filename, void *param, int order)
{
DWORD attributes, error;
FSSIM_FORMAT_PARAM_T *format;
ASSERT(fullname != NULL && filename != NULL);
attributes = GetFileAttributes(fullname);
if (attributes & FILE_ATTRIBUTE_DIRECTORY) {
/* a directory is found in fssim_search_dir */
/* delete the directory */
if (order == FSSIM_AFTER_RECURSIVE) {
if (!RemoveDirectory(fullname)) {
error = GetLastError();
if (error == ERROR_DIR_NOT_EMPTY) {
return FS_ACCESS_DENIED;
} else {
#ifdef DEBUG_FSSIM
fssim_printf(("RemoveDirectory() failed in fssim_del_dir()\n"));
fssim_printf(("error code = %d\n", GetLastError()));
#endif /* DEBUG_FSSIM */
}
}
}
} else {
/* a file is found in fssim_search_dir */
/* delete the found file */
if (!DeleteFile(fullname)) {
#ifdef DEBUG_FSSIM
fssim_printf(("DeleteFile() failed in fssim_del_dir()\n"));
fssim_printf(("error code = %d\n", GetLastError()));
#endif /* DEBUG_FSSIM */
}
}
if (order == FSSIM_BEFORE_RECURSIVE && param != NULL) {
format = (FSSIM_FORMAT_PARAM_T *)param;
if (fssim_file[format->fh].formatprogress != NULL){
/* increase the complete counter */
format->completed++;
/* invoke the progress callback function */
fssim_file[format->fh].formatprogress((const char *)format->drive, format->level, format->total, format->completed);
}
}
return 0;
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* fssim_del_files */
/* */
/* DESCRIPTION */
/* */
/* This function is a callback function of fssim_search_dir and is */
/* used to delete found file only to avoid fail on non-empty dir */
/* */
/* INPUTS */
/* */
/* fullname - full name of found file/directory */
/* filename - file name of found file/directory */
/* param - no use */
/* order - FSSIM_BEFORE_RECURSIVE or FSSIM_AFTER_RECURSIVE */
/* but ignored */
/* OUTPUTS */
/* */
/* zero for success; non-zero for failure */
/* */
/*************************************************************************/
int fssim_del_files(TCHAR *fullname, TCHAR *filename, void *param, int order)
{
DWORD attributes;
ASSERT(fullname != NULL && filename != NULL);
attributes = GetFileAttributes(fullname);
if (attributes & FILE_ATTRIBUTE_DIRECTORY) {
} else {
/* a file is found in fssim_search_dir */
/* delete the found file */
if (!DeleteFile(fullname)) {
#ifdef DEBUG_FSSIM
fssim_printf(("DeleteFile() failed in fssim_del_dir()\n"));
fssim_printf(("error code = %d\n", GetLastError()));
#endif /* DEBUG_FSSIM */
}
}
return 0;
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* fssim_sum_allocated_clusters */
/* */
/* DESCRIPTION */
/* */
/* This function is a callback function of fssim_search_dir and is */
/* used to sum of all allocated clusters */
/* */
/* INPUTS */
/* */
/* fullname - full name of found file/directory */
/* filename - file name of found file/directory */
/* param - pointer to FSSIM_SUM_SIZE_PARAM_T */
/* order - FSSIM_BEFORE_RECURSIVE or FSSIM_AFTER_RECURSIVE */
/* */
/* OUTPUTS */
/* */
/* zero for success; non-zero for failure */
/* */
/*************************************************************************/
int fssim_sum_allocated_clusters(TCHAR *fullname, TCHAR *filename, void *param, int order)
{
FSSIM_SUM_SIZE_PARAM_T *this_sum, *sub_folder;
WIN32_FILE_ATTRIBUTE_DATA file_info;
int error;
ASSERT(fullname != NULL && filename != NULL && param != NULL);
this_sum = (FSSIM_SUM_SIZE_PARAM_T *)param;
if( GetFileAttributesEx(fullname, GetFileExInfoStandard, &file_info) == 0) {
error = GetLastError();
#ifdef DEBUG_FSSIM
fssim_printf(("GetFileAttributesEx() failed in fssim_sum_allocated_clusters()\n"));
fssim_printf(("error code = %d\n", error));
#endif /* DEBUG_FSSIM */
EXT_ASSERT( 0, error, 0, 0);
}
/* Dump Info For Debug
fssim_print_str(filename);
printf("TYPE: %c , This sum folder %d, alloc %d \n", (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? 'D' : 'F',
this_sum->directory_entry_cnt, this_sum->allocated_cluster_cnt);
*/
if (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
/* a directory is found in fssim_search_dir */
this_sum->directory_entry_cnt += (1 + (wcslen(filename) / 13) + 1);
if (order == FSSIM_BEFORE_RECURSIVE) {
/*
* malloc and push/copy curr sum into new structure,
* reset directory_entry_cnt, allocated_cluster_cnt
* link curr_sum next to new structure
*/
sub_folder = (FSSIM_SUM_SIZE_PARAM_T *) malloc(sizeof(FSSIM_SUM_SIZE_PARAM_T));
memcpy(sub_folder, this_sum, sizeof(FSSIM_SUM_SIZE_PARAM_T));
this_sum->directory_entry_cnt = 2;
this_sum->allocated_cluster_cnt = 0;
this_sum->next = sub_folder;
} else if (order == FSSIM_AFTER_RECURSIVE) {
/*
* NoteXXX: After recursive searching is done,
* we pick-up/pop next structure value,
* sum the cluster_cnt, re-link and cut, then free it.
*/
sub_folder = this_sum->next;
this_sum->allocated_cluster_cnt +=
((this_sum->directory_entry_cnt * sizeof(FS_DOSDirEntry) - 1) / this_sum->size_of_cluster_unit + 1);
this_sum->allocated_cluster_cnt += sub_folder->allocated_cluster_cnt;
this_sum->directory_entry_cnt = sub_folder->directory_entry_cnt;
this_sum->next = sub_folder->next;
free(sub_folder);
} else
ASSERT(0);
} else {
/* a file is found in fssim_search_dir */
this_sum->directory_entry_cnt += (1 + (wcslen(filename) / 13) + 1);
ASSERT(file_info.nFileSizeHigh == 0);
if (file_info.nFileSizeLow > 0)
this_sum->allocated_cluster_cnt += ((file_info.nFileSizeLow - 1) / this_sum->size_of_cluster_unit + 1);
}
return 0;
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* fssim_conv_attr */
/* */
/* DESCRIPTION */
/* */
/* This function is used convert file attributes from RTF to WIN32. */
/* */
/* INPUTS */
/* */
/* attr - file attributes to convert */
/* */
/* OUTPUTS */
/* */
/* converted file attribute */
/* */
/*************************************************************************/
DWORD fssim_conv_attr(BYTE attr)
{
DWORD ret_val = 0;
if (attr & FS_ATTR_READ_ONLY)
ret_val |= FILE_ATTRIBUTE_READONLY;
if (attr & FS_ATTR_HIDDEN)
ret_val |= FILE_ATTRIBUTE_HIDDEN;
if (attr & FS_ATTR_SYSTEM)
ret_val |= FILE_ATTRIBUTE_SYSTEM;
if (attr & FS_ATTR_DIR)
ret_val |= FILE_ATTRIBUTE_DIRECTORY;
if (attr & FS_ATTR_ARCHIVE)
ret_val |= FILE_ATTRIBUTE_ARCHIVE;
return ret_val;
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* fssim_rev_conv_attr */
/* */
/* DESCRIPTION */
/* */
/* This function is used convert file attributes from WIN32 to RTF. */
/* */
/* INPUTS */
/* */
/* attr - file attributes to convert */
/* */
/* OUTPUTS */
/* */
/* converted file attribute */
/* */
/*************************************************************************/
BYTE fssim_rev_conv_attr(DWORD attr)
{
BYTE ret_val = 0;
if (attr & FILE_ATTRIBUTE_READONLY)
ret_val |= FS_ATTR_READ_ONLY;
if (attr & FILE_ATTRIBUTE_HIDDEN)
ret_val |= FS_ATTR_HIDDEN;
if (attr & FILE_ATTRIBUTE_SYSTEM)
ret_val |= FS_ATTR_SYSTEM;
if (attr & FILE_ATTRIBUTE_DIRECTORY)
ret_val |= FS_ATTR_DIR;
if (attr & FILE_ATTRIBUTE_ARCHIVE)
ret_val |= FS_ATTR_ARCHIVE;
return ret_val;
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* fssim_match_pattern */
/* */
/* DESCRIPTION */
/* */
/* This function is used check whether a name matches a pattern */
/* or not. */
/* */
/* INPUTS */
/* */
/* pattern - pattern to compare */
/* name - name to compare */
/*
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?