⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmidc_storage.c

📁 手机Camera部分上层软件代码
💻 C
📖 第 1 页 / 共 5 页
字号:
		i_protect++;
		if (i_protect >= 10000)
		{
			*photo_name_ptr = '\0';
			return 0;
		}
	}

	SCI_TRACE_LOW("mmidc_storage.c: MMIDC_AssignPhotoDefaultName(), photo_name = %s", photo_name_ptr);

	return strlen((char*) photo_name_ptr);
}



/*****************************************************************************/
// 	Description : check whether the name of photo is valid
//	Global resource dependence : none
//  Author: bruce.chi
//	Note:
/*****************************************************************************/
BOOLEAN MMIDC_IsFileNameValid(
							  const uint8*	name_ptr,
							  const uint16	name_len,
							  const uint16	is_ucs2
							  )
{
	uint8						i = 0;
	BOOLEAN						result = TRUE;
	const MMIDC_PHOTO_INFO_T	*photo_info_ptr	= &s_mmidc_photo_info;

	uint16						ucs2_name[MMIDC_MAX_PHOTO_NAME_LEN + 2] = {0};
	uint16						ucs2_len = 0;

	if (name_ptr == PNULL || name_len == 0 || name_len > MMIDC_MAX_PHOTO_NAME_LEN)
	{
		return FALSE;
	}

	//change to ucs2
	if (is_ucs2)
	{
		SCI_MEMCPY(ucs2_name, name_ptr, name_len);
		ucs2_len = name_len;
	}
	else
	{
		ucs2_len = GUI_GB2UCS(ucs2_name, name_ptr, name_len);
	}
	
	result = TRUE;
	for(i = 0; i < photo_info_ptr->total_num; i++)
	{
        if(0 == GUI_StringCompare(
							(uint8 *)ucs2_name,
                            ucs2_len, 
                            (uint8 *)photo_info_ptr->photo_detail[i].name_ptr, 
                            photo_info_ptr->photo_detail[i].name_len
							)
			)
        {
        	SCI_TRACE_LOW("mmidc_storage.c : MMIDC_IsFileNameValid() the name is same as %d", i);
            result = FALSE;
            break;
        }
	}

	return result;
}



/*****************************************************************************/
// 	Description : check this file name whether exists in ffs
//	Global resource dependence : 
//  Author:	bruce.chi
//	Note: 
/*****************************************************************************/
PUBLIC BOOLEAN MMIDC_CheckNameExist(
							FILE_DEV_E_T e_file_dev,
                            uint8*  name_ptr,
                            uint16  name_len,
                            BOOLEAN is_ucs2
                            )
{
	uint8	name_arr[MMIDC_MAX_PHOTO_NAME_LEN + MMIDC_DEFAULT_SUBFIX_LEN * 2 + 2] = {0};

	uint16	ucs2_name_arr[(MMIDC_MAX_PHOTO_NAME_LEN + MMIDC_DEFAULT_SUBFIX_LEN * 2 + 4) / 2] = {0};
	uint16	ucs2_name_len = 0;

	//add subfix
	SCI_MEMSET(name_arr, 0, sizeof(name_arr));
	name_len = MIN(name_len, MMIDC_MAX_PHOTO_NAME_LEN);
	SCI_MEMCPY(name_arr, name_ptr, name_len);

	name_len = MMISTR_AddSubfix((uint8 *)name_arr, name_len, is_ucs2, (uint8 *)MMIDC_DEFAULT_SUBFIX, MMIDC_DEFAULT_SUBFIX_LEN);
	DC_ASSERT_LOW(name_len <= MMIDC_MAX_PHOTO_NAME_LEN + MMIDC_DEFAULT_SUBFIX_LEN * 2);

	//change to ucs2
	SCI_MEMSET(ucs2_name_arr, 0, sizeof(ucs2_name_arr));
	if (is_ucs2)
	{
		ucs2_name_len = name_len;
		SCI_MEMCPY(ucs2_name_arr, name_arr, ucs2_name_len);
	}
	else
	{
		ucs2_name_len = GUI_GB2UCS(ucs2_name_arr, name_arr, name_len);
	}

	//check
	if (FFS_NO_ERROR == FILE_CdDCPath(e_file_dev))
	{
		return (FFS_CheckExist(e_file_dev, (wchar *)ucs2_name_arr));
	}
	else
	{
		return FALSE;
	}
}

/*****************************************************************************/
// 	Description : add subfix to a string
//	Global resource dependence :
//  Author: bruce.chi
//	Note: subfix_ptr must be ascii code. and make sue that name_ptr is large enough to contain the name+subfix+2
/*****************************************************************************/
PUBLIC uint16 MMISTR_AddSubfix(
                uint8*  name_ptr,	//memory that is length is (MMIDC_MAX_PHOTO_NAME_LEN + MMIDC_DEFAULT_SUBFIX_LEN * 2 + 2)
                uint16  name_len,
                BOOLEAN is_ucs2,
				uint8	*subfix_ptr,
				uint16	subfix_len
			)
{
	uint16	ucs2_subfix_arr[MMIDC_DEFAULT_SUBFIX_LEN * 2 + 2] = {0};
	uint16	ucs2_subfix_len = 0;
	

	DC_ASSERT_LOW(name_ptr != PNULL);

	if (is_ucs2)
	{
		//get subfix
		SCI_MEMSET(ucs2_subfix_arr, 0, sizeof(ucs2_subfix_arr));
		ucs2_subfix_len = GUI_GB2UCS(ucs2_subfix_arr, (uint8 *)subfix_ptr, subfix_len);
		SCI_ASSERT(ucs2_subfix_len == subfix_len * 2);

		//add
		SCI_MEMCPY(name_ptr + name_len, ucs2_subfix_arr, ucs2_subfix_len);
		name_ptr[name_len + ucs2_subfix_len] = '\0';
		name_ptr[name_len + ucs2_subfix_len + 1] = '\0';

		return name_len + ucs2_subfix_len;
	}
	else
	{
		SCI_MEMCPY(name_ptr + name_len, subfix_ptr, subfix_len);
		name_ptr[name_len + subfix_len] = '\0';

		return name_len + subfix_len;
	}

}

/*****************************************************************************/
// 	Description : rename a file 
//	Global resource dependence :
//  Author: bruce.chi
//	Note: 
/*****************************************************************************/
PUBLIC MMIDC_RESULT_E DCSaveInfo_RenamePhoto(
							FILE_DEV_E_T e_file_dev,
                            uint8*  name_ptr,   //file name
                            uint16  name_len,    //file name length
                            BOOLEAN is_ucs2, 
                            uint8   index
                            )
{
    MMIDC_RESULT_E	    result = MMIDC_RESULT_SUCCESS;
    MMIDC_PHOTO_INFO_T* photo_info_ptr = &s_mmidc_photo_info;
    
    uint16				old_file_name[(MMIDC_MAX_PHOTO_NAME_LEN + MMIDC_DEFAULT_SUBFIX_LEN * 2 + 4) / 2] = {0};
    uint16              old_name_len = 0;

    uint16				new_file_name[(MMIDC_MAX_PHOTO_NAME_LEN + MMIDC_DEFAULT_SUBFIX_LEN * 2 + 4) / 2] = {0};
    uint16              new_name_len = 0;

	uint16				new_file_ucs2_nosubfix[(MMIDC_MAX_PHOTO_NAME_LEN + MMIDC_DEFAULT_SUBFIX_LEN * 2 + 4) / 2] = {0};
	uint16				new_file_ucs2_len_nosubfix = 0;


    SCI_ASSERT(PNULL != photo_info_ptr);
	SCI_ASSERT(index < photo_info_ptr->total_num);
    SCI_ASSERT(PNULL != name_ptr);

    // 该函数用于给指定文件进行重新命名,具体分为以下几步:
    // 1. 进入DC子目录
    // 2. 转换新老文件名
    // 3. 给文件重新命名
    // 4. 在全局中设置新文件名

    // 进入DC子目录
    if (FFS_NO_ERROR == FILE_CdDCPath(e_file_dev))
    {
        //add subfix to old name
		SCI_MEMCPY(
			old_file_name, 
			photo_info_ptr->photo_detail[index].name_ptr, 
			photo_info_ptr->photo_detail[index].name_len
			);

		old_name_len = MMISTR_AddSubfix(
							(uint8 *)old_file_name, 
							photo_info_ptr->photo_detail[index].name_len, 
							TRUE,
							(uint8 *)MMIDC_DEFAULT_SUBFIX,
							MMIDC_DEFAULT_SUBFIX_LEN
							);
		
		// change to ucs2 then add subfix to new name
		if (is_ucs2)
		{
			SCI_MEMCPY(new_file_ucs2_nosubfix, name_ptr, name_len);
			new_file_ucs2_len_nosubfix = name_len;
		}
		else
		{
			new_file_ucs2_len_nosubfix = GUI_GB2UCS(new_file_ucs2_nosubfix, name_ptr, name_len);	//new_file_ucs2_name has no .jpg extension
		}

		SCI_MEMCPY(new_file_name, new_file_ucs2_nosubfix, new_file_ucs2_len_nosubfix);
		new_name_len = MMISTR_AddSubfix(
							(uint8 *)new_file_name,
							new_file_ucs2_len_nosubfix,
							TRUE,
							(uint8 *)MMIDC_DEFAULT_SUBFIX,
							MMIDC_DEFAULT_SUBFIX_LEN
							);
		
		

        // check whether the file name is ok
        if (FFS_CheckExist(e_file_dev, (wchar *)new_file_name))
        {
            SCI_TRACE_LOW("mmidc_storage.c : MMIDC_RenamePhoto: the file is exist!");
            return (MMIDC_RESULT_REPEAT);
        }

        // rename this file
        if (FFS_ERROR_NONE == FFS_Rename(
                                  e_file_dev, 
                                  (const wchar *)old_file_name, 
                                  (const wchar *)new_file_name
								  )
			)
        {
            //save in global
            photo_info_ptr->photo_detail[index].name_len = new_file_ucs2_len_nosubfix;
            SCI_MEMCPY(
                photo_info_ptr->photo_detail[index].name_ptr,
                new_file_ucs2_nosubfix,
                new_file_ucs2_len_nosubfix
				);

			//check whether we have renamed the wallpaper
			if (MMIMULTIM_CheckDCName(old_file_name, old_name_len, photo_info_ptr->photo_detail[index].location))
			{
				// Rename墙纸
				SCI_TRACE_LOW("MMIDC_RenamePhoto: rename the dc wallpaper!");
				MMIMULTIM_RenameDCWallpaper(new_file_name, new_name_len);
			}
        }
        else
        {
            SCI_TRACE_LOW("MMIDC_RenamePhoto: rename error!");
            result = MMIDC_RESULT_ERROR;
        }
    }
    else
    {
        SCI_TRACE_LOW("MMIDC_RenamePhoto: can't enter the DC dir!");
        result = MMIDC_RESULT_ERROR;
    }

    return (result);
}

/*****************************************************************************/
// 	Description : find photo file in ffs
//	Global resource dependence : 
//  Author:	bruce.chi
//	Note: 
/*****************************************************************************/
LOCAL void FindPhoto(FILE_DEV_E_T e_file_dev, MMIDC_PHOTO_INFO_T* photo_info_ptr)
{
    char                gb_file_name[MMIDC_DEFAULT_SUBFIX_LEN + 4]   = {0};

	uint16				ucs2_path_name[32] = {0};
	uint16				ucs2_path_len = 0;

    uint16              ucs2_file_name[MMIDC_DEFAULT_SUBFIX_LEN + 4] = {0};
	uint16				ucs2_file_len = 0;

    HFS                 handle_result;
    FFS_FIND_DATA_T     find_result;

    if (MMIDC_MAX_PHOTO_NUM <= photo_info_ptr->total_num)
    {
        return;
    }

    if (FFS_ERROR_NONE == FILE_CdDCPath(e_file_dev))
    {
		sprintf(gb_file_name, "*%s", MMIDC_DEFAULT_SUBFIX);
		DC_ASSERT_LOW(strlen(gb_file_name) < sizeof(gb_file_name));
		ucs2_file_len = GUI_GB2UCS(ucs2_file_name, (uint8 *)gb_file_name, (uint16)(sizeof(gb_file_name)));
		DC_ASSERT_LOW(ucs2_file_len < sizeof(ucs2_file_name) * sizeof(uint16));

        handle_result = FFS_FindFirst(
                            e_file_dev,
                            (const wchar*)ucs2_file_name,
                            &find_result
							);

        if (FFS_INVALID_HANDLE != handle_result)
        {
            // 初始化第一张图片信息
            if (InitPhotoDetail(&photo_info_ptr->photo_detail[photo_info_ptr->total_num], e_file_dev, &find_result))
			{
				photo_info_ptr->total_memory += CHUNK(photo_info_ptr->photo_detail[photo_info_ptr->total_num].memory_size);
				photo_info_ptr->total_num++;
			}

            while (FFS_ERROR_NONE == FFS_FindNext(e_file_dev, handle_result, (const wchar*)ucs2_file_name, &find_result))
            {
                if(photo_info_ptr->total_num < MMIDC_MAX_PHOTO_NUM)
                {
                    if (InitPhotoDetail(&photo_info_ptr->photo_detail[photo_info_ptr->total_num], e_file_dev, &find_result))
					{
						photo_info_ptr->total_memory += CHUNK(photo_info_ptr->photo_detail[photo_info_ptr->total_num].memory_size);
						photo_info_ptr->total_num++;
					}
                }
                else
                {
                    SCI_TRACE_LOW("mmidc_storage.c:DCSaveInfo_FindPhotoFileInFFS(): too much photo file, exceed MMIDC_MAX_PHOTO_NUM");
                    break;
                }
            }
        }
        else
        {
            SCI_TRACE_LOW("mmidc_storage.c:DCSaveInfo_FindPhotoFileInFFS: find first error!");
        }

        FFS_Close(e_file_dev, handle_result);
    }
    else
    {
        // 如果当前设备中不存在\DC这个目录,则创建该目录
        SCI_TRACE_LOW("mmidc_storage:DCSaveInfo_FindPhotoFileInFFS:no dc catalog!");

		FILE_CdRootPath(e_file_dev);
		ucs2_path_len = GUI_GB2UCS(ucs2_path_name, (uint8 *)MMIDC_DEFAULT_DIR, strlen(MMIDC_DEFAULT_DIR));
		if (FFS_NO_ERROR != FFS_CD(e_file_dev, (const wchar *)ucs2_path_name))
		{
			FFS_CreateDir(e_file_dev, (const wchar*)ucs2_path_name);
		}
    }

}


/*****************************************************************************/
// 	Description : find photo file in ffs
//	Global resource dependence : s_mmidc_photo_info
//  Author:	bruce.chi
//	Note: 
/*****************************************************************************/
PUBLIC void DCSaveInfo_FindPhotoFileInFFS(void)
{
    int32	i = 0;

    MMIDC_PHOTO_INFO_T* photo_info_ptr = &s_mmidc_photo_info;

    //this funciton will be call by MMIDC_Init() when udisk is plugged out, so I have to free the allcated name buffer
    for (i = 0; i < photo_info_ptr->total_num; i++)
    {
        if (photo_info_ptr->photo_detail[i].name_ptr != PNULL)
        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -