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

📄 app_asyncfile.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 2 页
字号:


/*****************************************************************************
 * FUNCTION
 *  applib_async_file_task_stop
 * DESCRIPTION
 *  
 * PARAMETERS
 *  op      [?]     
 * RETURNS
 *  
 *****************************************************************************/
kal_bool applib_async_file_task_stop(applib_async_file_task_struct *op)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (op == NULL)
    {
        return KAL_FALSE;
    }
    if (op->isFSopen == KAL_TRUE)
    {
        FS_Close(op->fileHandle);
        op->isFSopen = KAL_FALSE;
    }

    if (op->es != NULL)
    {
        if (applib_callout_active(op->fs_timer))
        {
            op->fs_timer.c_flags &= ~APPLIB_CALLOUT_ACTIVE;
            ASSERT(op->fs_timer.event_id != NULL);
            evshed_cancel_event(op->es, &(op->fs_timer.event_id));
            op->fs_timer.event_id = NULL;
        }
        else
        {
            applib_callout_deactivate(op->fs_timer);
        }
        op->es = NULL;
    }
    kal_mem_set(op, 0, sizeof(applib_async_file_task_struct));
    return KAL_TRUE;
}


/*****************************************************************************
 * FUNCTION
 *  applib_async_file_task_write
 * DESCRIPTION
 *  
 * PARAMETERS
 *  op              [?]         
 *  start_pos       [IN]        
 *  buffer          [?]         
 *  buffer_size     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void applib_async_file_task_write(
        applib_async_file_task_struct *op,
        kal_uint32 start_pos,
        kal_uint8 *buffer,
        kal_uint32 buffer_size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (op == NULL || op->isFSopen == KAL_FALSE)
    {
        return;
    }
    op->totalLen = 0;
    op->buffer = buffer;
    op->pos = buffer;
    op->dataLen = buffer_size;

    if (start_pos == -1)
    {
        FS_Seek(op->fileHandle, 0, APPLIB_ASYNC_FILE_SEEK_END);
    }
    else
    {
        FS_Seek(op->fileHandle, start_pos, APPLIB_ASYNC_FILE_SEEK_SET);
    }

    applib_async_file_task_internal_write(op);
}


/*****************************************************************************
 * FUNCTION
 *  applib_async_file_task_read
 * DESCRIPTION
 *  
 * PARAMETERS
 *  op              [?]         
 *  start_pos       [IN]        
 *  buffer          [?]         
 *  datelen         [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void applib_async_file_task_read(
        applib_async_file_task_struct *op,
        kal_uint32 start_pos,
        kal_uint8 *buffer,
        kal_uint32 datelen)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (op == NULL || op->isFSopen == KAL_FALSE)
    {
        return;
    }
    op->totalLen = 0;
    op->buffer = buffer;
    op->pos = buffer;
    op->dataLen = datelen;

    if (start_pos == -1)
    {
        FS_Seek(op->fileHandle, 0, APPLIB_ASYNC_FILE_SEEK_END);
    }
    else
    {
        FS_Seek(op->fileHandle, start_pos, APPLIB_ASYNC_FILE_SEEK_SET);
    }

    applib_async_file_task_internal_read(op);
}


/*****************************************************************************
 * FUNCTION
 *  applib_async_file_task_write_continue
 * DESCRIPTION
 *  
 * PARAMETERS
 *  op      [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void applib_async_file_task_write_continue(applib_async_file_task_struct *op)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (op == NULL || op->isFSopen == KAL_FALSE)
    {
        ASSERT(0);
    }
    if (applib_callout_active(op->fs_timer))
    {
        op->fs_timer.c_flags &= ~APPLIB_CALLOUT_ACTIVE;
        ASSERT(op->fs_timer.event_id != NULL);
        op->fs_timer.event_id = NULL;
    }
    applib_async_file_task_internal_write(op);
}


/*****************************************************************************
 * FUNCTION
 *  applib_async_file_task_read_continue
 * DESCRIPTION
 *  
 * PARAMETERS
 *  op      [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void applib_async_file_task_read_continue(applib_async_file_task_struct *op)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (op == NULL || op->isFSopen == KAL_FALSE)
    {
        ASSERT(0);
    }
    if (applib_callout_active(op->fs_timer))
    {
        op->fs_timer.c_flags &= ~APPLIB_CALLOUT_ACTIVE;
        ASSERT(op->fs_timer.event_id != NULL);
        op->fs_timer.event_id = NULL;
    }
    applib_async_file_task_internal_read(op);
}


/*****************************************************************************
 * FUNCTION
 *  applib_file_read_line
 * DESCRIPTION
 *  This function is used to read one line from file.
 * PARAMETERS
 *  fileHandle          [IN]            
 *  buf                 [IN]            The buffer to store data
 *  buf_size            [IN]            The buffer size
 *  line_len            [IN/OUT]        The line length
 *  ret                 [IN/OUT]        The result
 *  filehandle(?)       [IN]            The filehandle
 * RETURNS
 *  void
 *****************************************************************************/
void applib_file_read_line(
        kal_int32 fileHandle,
        kal_uint8 *buf,
        kal_uint32 buf_size,
        kal_uint32 *line_len,
        kal_int32 *ret)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint8 *pos = buf;
    kal_uint32 rd_no = 0;
    kal_uint32 count = 0;
    kal_bool CR = KAL_FALSE;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_mem_set(buf, 0, buf_size);
    *line_len = 0;
    while (buf_size)
    {
        *ret = FS_Read(fileHandle, pos, 1, &rd_no);
        if (*ret < 0)
        {
            *line_len = count;
            return;
        }
        else if (rd_no != 1)
        {
            *line_len = count;
            return;
        }
        else
        {
            count++;
            if (*pos == '\r')
            {
                CR = KAL_TRUE;
            }
            else if (*pos == '\n')
            {
                if (CR == KAL_TRUE)
                {
                    *line_len = count;
                    return;
                }
                else
                {
                    CR = KAL_FALSE;
                }
            }
            else
            {
                CR = KAL_FALSE;
            }
        }
        buf_size--;
        pos++;
    }
    *ret = -1;
    *line_len = rd_no;
    return;
}


/*****************************************************************************
 * FUNCTION
 *  applib_get_file_size
 * DESCRIPTION
 *  This function is used to get the size of one file.
 * PARAMETERS
 *  filename        [IN]        The filename
 * RETURNS
 *  file size.
 *****************************************************************************/
kal_uint32 applib_get_file_size(kal_wchar *filename)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int32 fileHandle;
    kal_uint32 fileSize = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (filename == NULL)
    {
        return 0;
    }

    fileHandle = FS_Open(filename, APPLIB_ASYNC_FILE_READ | FS_NONBLOCK_MODE | FS_OPEN_SHARED);
    if (fileHandle < 0)
    {
        return 0;
    }
    FS_GetFileSize(fileHandle, &fileSize);
    FS_Close(fileHandle);
    return fileSize;
}


/*****************************************************************************
 * FUNCTION
 *  applib_file_delete_folder
 * DESCRIPTION
 *  This function is used to remove one folder.
 * PARAMETERS
 *  foldername      [IN]        The foldername
 * RETURNS
 *  void
 *****************************************************************************/
kal_bool applib_file_delete_folder(kal_wchar *foldername)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    int h = -1; /* save temp. file handle for find */
    FS_DOSDirEntry info;
    kal_wchar path[200];
    kal_wchar filename[100];
    kal_wchar wildcard[6];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (foldername == NULL)
    {
        return KAL_FALSE;
    }
    else if (app_ucs2_strlen((kal_int8*) foldername) > 97)
    {
        return KAL_FALSE;
    }
    else
    {

        kal_mem_set(path, 0, 400);
        app_ucs2_strcpy((kal_int8*) path, (kal_int8*) foldername);
        kal_wsprintf(wildcard, "\\*");
        app_ucs2_strcat((kal_int8*) path, (kal_int8*) wildcard);

        h = FS_FindFirst(path, 0, 0, &info, filename, 200);
        if (h < 0)
        {
            return KAL_FALSE;
        }
        do
        {
            /* filter out folder results */
            if (!(info.Attributes & FS_ATTR_DIR))
            {
                kal_mem_set(path, 0, 400);
                app_ucs2_strcpy((kal_int8*) path, (kal_int8*) foldername);
                kal_wsprintf(wildcard, "\\");
                app_ucs2_strcat((kal_int8*) path, (kal_int8*) wildcard);
                app_ucs2_strcat((kal_int8*) path, (kal_int8*) filename);
                FS_Delete(path);
                kal_mem_set(filename, 0x00, 200);
            }
        } while (FS_FindNext(h, &info, filename, 200) == FS_NO_ERROR);
        FS_FindClose(h);
    }
    return KAL_TRUE;
}

⌨️ 快捷键说明

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