EbookFramework.c
资源名称:mmi.rar [点击查看]
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:303k
源码类别:
MTK
开发平台:
C/C++
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*******************************************************************************
- * Filename:
- * ---------
- * EbookFramework.c
- *
- * Project:
- * --------MMI_CARD_DRV
- * MAUI
- *
- * Description:
- * ------------
- *
- *
- * Author:
- * -------
- * -------
- *
- *==============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * removed!
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *==============================================================================
- *******************************************************************************/
- /**
- * Copyright Notice
- * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
- * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
- * (It is illegal to remove this copyright notice from this software or any
- * portion of it)
- */
- /***************** Ebook Application implementation *********************/
- /**************************************************************
- FILENAME : EbookFramework.c
- PURPOSE : Framework Application Functions
- REMARKS : nil
- AUTHOR : Rajat Kumar
- DATE :
- **************************************************************/
- #include "StdC.h"
- #include "L4Dr1.h"
- #include "L4Dr.h"
- #include "MMI_features.h"
- #include "Conversions.h" //KP Jerry add for can use "g_chset_text_encoding" on 2007-3-7
- #ifdef __MMI_EBOOK_READER__
- #include "gpioInc.h"
- #include "TimerEvents.h"
- #include "EbookDefs.h"
- #include "NVRAMType.h"
- #include "NVRAMProt.h"
- #include "NVRAMEnum.h"
- #include "CommonScreens.h"
- #include "FileMgr.h"
- #include "EbookManager.h"
- #include "EbookProt.h"
- #include "FileManagerDef.h"
- #include "Conversions.h"
- #include "FileManagerGProt.h"
- #include "fmt_struct.h"
- #include "PhoneSetupGprots.h"
- #include "hf_rules.h"
- g_current_book_context g_curr_bk_cntx;
- g_current_book_context *g_curr_book_cntx_p = &g_curr_bk_cntx;
- S8 *HW_itoa(S32 value, S8 *s, S32 radix);
- S32 HW_atoi(const S8 *s);
- #define MAX_FAILURE_RETRIES 5
- #define MAX_RECORD_CONVERT_EACH_RECURSION 8
- #define WHITE_SPACE 0x20
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_open_book_create_nfo_file_pdb
- * DESCRIPTION
- * Create Nfo File for PDB
- * PARAMETERS
- * filename [IN]
- * RETURNS
- * void
- *****************************************************************************/
- ebr_frm_nfo_create_type_errors_enum ebr_frm_open_book_create_nfo_file_pdb(U8 *filename)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U32 size;
- FILE_HANDLE file_hnd, nfo_hnd;
- S32 write_result;
- U8 ebook_file_name[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH] = {0};
- ebr_frm_database_hdr_type file_header;
- S32 local_nfo_id, compare_type = 0, isValidNfo = 0;
- S32 offset;
- S32 create_nfo_file = 0;
- ebr_frm_nfo_create_type_errors_enum return_value = EBR_FRM_NFO_CREATE_SUCCESS;
- doc_record0 rec0;
- S32 attr = 0;
- U32 nfo_file_size;
- pBOOL is_read_only = FALSE;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- pfnUnicodeStrcpy(
- (S8*) ebook_file_name,
- (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
- pfnUnicodeStrcat((PS8) ebook_file_name, (PS8) filename);
- attr = FS_GetAttributes((const WCHAR*)ebook_file_name);
- if (attr & FS_ATTR_READ_ONLY)
- {
- is_read_only = TRUE;
- FS_SetAttributes((const WCHAR*)ebook_file_name, (U8) (attr & ~(FS_ATTR_READ_ONLY)));
- }
- file_hnd = FS_Open((const WCHAR*)ebook_file_name, FS_READ_WRITE);
- if (!file_hnd)
- {
- return EBR_FRM_NFO_CREATE_FAILURE;
- }
- if (FS_Read(file_hnd, &file_header, EBR_FRM_DATABASE_HEADER_SIZE, &size) == FS_NO_ERROR)
- {
- if (file_header.modification_date > 32768)
- {
- create_nfo_file = 1;
- }
- else
- { /* Check that the cerrseponding nfo file exists or not if not then change the header information */
- nfo_hnd = FS_Open((const WCHAR*)ebr_frm_get_nfo_file_name((S32) file_header.modification_date), FS_READ_ONLY);
- if (nfo_hnd <= 0)
- {
- create_nfo_file = 1;
- }
- else
- {
- FS_Read(
- nfo_hnd,
- &g_curr_book_cntx_p->g_nfo_book_struct,
- sizeof(g_curr_book_cntx_p->g_nfo_book_struct),
- &size);
- FS_GetFileSize(nfo_hnd, &nfo_file_size);
- isValidNfo = strncmp(
- (const S8*)g_curr_book_cntx_p->g_nfo_book_struct.checksum,
- (const S8*)EBR_TXT_FOOTER_START,
- TXT_FOOTER_START_SIZE);
- compare_type = pfnUnicodeStrcmp(
- (const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name,
- (const S8*)g_curr_book_cntx_p->nfo_name);
- if ((compare_type != 0) || (isValidNfo != 0) ||
- (nfo_file_size != sizeof(g_curr_book_cntx_p->g_nfo_book_struct)))
- {
- create_nfo_file = 1;
- }
- FS_Close(nfo_hnd);
- }
- }
- }
- if (create_nfo_file)
- {
- if (memcmp(file_header.type, DOC_TYPE, strlen((PS8) DOC_TYPE)) == 0)
- {
- if (FS_Read(file_hnd, &offset, 4, &size) == FS_NO_ERROR)
- {
- offset = ntohl(offset);
- }
- FS_Seek(file_hnd, offset, FS_FILE_BEGIN);
- if (FS_Read(file_hnd, &rec0, sizeof rec0, &size) == FS_NO_ERROR)
- {
- g_curr_book_cntx_p->num_records = ntohs(rec0.num_records);
- g_curr_book_cntx_p->g_nfo_book_struct.book_size = ntohl(rec0.doc_size);
- if (ebr_frm_is_empty_file(file_hnd, EBR_FRM_FILE_TYPE_PDB))
- {
- create_nfo_file = 1;
- return_value = EBR_FRM_EMPTY_BOOK;
- memset(g_curr_book_cntx_p->nfo_path, 0, sizeof(g_curr_book_cntx_p->nfo_path));
- FS_Close(file_hnd);
- return return_value;
- }
- }
- pfnUnicodeStrcpy(
- (S8*) ebook_file_name,
- (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
- local_nfo_id = ebr_frm_create_nfo_file(file_header.name, ebook_file_name, filename);
- if (local_nfo_id >= 0)
- {
- file_header.modification_date = local_nfo_id;
- if (g_curr_book_cntx_p->src_application == EBR_FRM_SRC_APP_FMGR)
- { /* Means it is from file manager */
- ebr_frm_fmgr_set_nfo_id(local_nfo_id);
- }
- FS_Seek(file_hnd, 0, FS_FILE_BEGIN);
- write_result = FS_Write(file_hnd, &file_header, EBR_FRM_DATABASE_HEADER_SIZE, (U32*) & size);
- return_value = EBR_FRM_NFO_CREATE_SUCCESS;
- }
- else
- {
- return_value = EBR_FRM_NFO_CREATE_FAILURE;
- }
- }
- else
- {
- return_value = EBR_FRM_NFO_CREATE_FILE_TYPE_NOT_SUPPORTED;
- }
- }
- FS_Close(file_hnd);
- pfnUnicodeStrcpy(
- (S8*) ebook_file_name,
- (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
- pfnUnicodeStrcat((PS8) ebook_file_name, (PS8) filename);
- attr = FS_GetAttributes((const WCHAR*)ebook_file_name);
- if(is_read_only)
- {
- FS_SetAttributes((const WCHAR*)ebook_file_name, (U8) (attr | (FS_ATTR_READ_ONLY)));
- }
- return return_value;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_open_book_create_nfo_file_txt
- * DESCRIPTION
- * Create Nfo File for TXT
- * PARAMETERS
- * filename [IN]
- * RETURNS
- * void
- *****************************************************************************/
- ebr_frm_nfo_create_type_errors_enum ebr_frm_open_book_create_nfo_file_txt(U8 *filename)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U32 size;
- FILE_HANDLE file_hnd, nfo_hnd;
- S8 tmp_str[MAX_EBOOK_NAME_LENGTH];
- U8 ebook_file_name[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH] = {0};
- U8 display_name[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH] = {0};
- S32 create_nfo_file = 0, compare_type = 0, isValidNfo = 0;
- S32 local_nfo_id;
- U32 strlength = 0;
- ebr_frm_nfo_create_type_errors_enum return_value = EBR_FRM_NFO_CREATE_SUCCESS;
- S32 attr = 0;
- U32 nfo_file_size;
- pBOOL is_read_only = FALSE;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- pfnUnicodeStrcpy(
- (S8*) ebook_file_name,
- (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
- pfnUnicodeStrcat((S8*) ebook_file_name, (S8*) filename);
- attr = FS_GetAttributes((const WCHAR*)ebook_file_name);
- if (attr & FS_ATTR_READ_ONLY)
- {
- is_read_only = TRUE;
- FS_SetAttributes((const WCHAR*)ebook_file_name, (U8) (attr & ~(FS_ATTR_READ_ONLY)));
- }
- file_hnd = FS_Open((const WCHAR*)ebook_file_name, FS_READ_WRITE);
- if (file_hnd > 0)
- {
- FS_GetFileSize(file_hnd, &g_curr_book_cntx_p->g_nfo_book_struct.book_size);
- /* g_curr_book_cntx_p->g_nfo_book_struct.book_size=g_curr_book_cntx_p->g_nfo_book_struct.book_size-TXT_FOOTER_END_SIZE-MAX_EBOOK_NAME_LENGTH-TXT_FOOTER_START_SIZE; */
- if (ebr_frm_is_empty_file(file_hnd, EBR_FRM_FILE_TYPE_TXT))
- {
- create_nfo_file = 1;
- return_value = EBR_FRM_EMPTY_BOOK;
- memset(g_curr_book_cntx_p->nfo_path, 0, sizeof(g_curr_book_cntx_p->nfo_path));
- goto end;
- }
- FS_Close(file_hnd);
- local_nfo_id = ebr_fmgr_get_nfo_id_for_txt_file(g_curr_book_cntx_p->memory_type_selected, (PS8) filename);
- file_hnd = FS_Open((const WCHAR*)ebook_file_name, FS_READ_WRITE);
- if (local_nfo_id != 0)
- {
- nfo_hnd = FS_Open((const WCHAR*)ebr_frm_get_nfo_file_name((S32) local_nfo_id), FS_READ_ONLY);
- if (nfo_hnd <= 0)
- {
- create_nfo_file = 1;
- FS_Seek(file_hnd, -TXT_FOOTER_START_SIZE - TXT_FOOTER_END_SIZE - MAX_EBOOK_NAME_LENGTH, FS_FILE_END);
- g_curr_book_cntx_p->g_nfo_book_struct.book_size =
- g_curr_book_cntx_p->g_nfo_book_struct.book_size + (-TXT_FOOTER_START_SIZE -
- TXT_FOOTER_END_SIZE - MAX_EBOOK_NAME_LENGTH);
- FS_Truncate(file_hnd);
- }
- else
- {
- FS_Read(
- nfo_hnd,
- &g_curr_book_cntx_p->g_nfo_book_struct,
- sizeof(g_curr_book_cntx_p->g_nfo_book_struct),
- &size);
- FS_GetFileSize(nfo_hnd, &nfo_file_size);
- isValidNfo = strncmp(
- (const S8*)g_curr_book_cntx_p->g_nfo_book_struct.checksum,
- (const S8*)EBR_TXT_FOOTER_START,
- TXT_FOOTER_START_SIZE);
- compare_type = pfnUnicodeStrcmp(
- (const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name,
- (const S8*)g_curr_book_cntx_p->nfo_name);
- if ((compare_type != 0) || (isValidNfo != 0) ||
- (nfo_file_size != sizeof(g_curr_book_cntx_p->g_nfo_book_struct)))
- {
- create_nfo_file = 1;
- if (FS_Seek(
- file_hnd,
- -TXT_FOOTER_START_SIZE - TXT_FOOTER_END_SIZE - MAX_EBOOK_NAME_LENGTH,
- FS_FILE_END))
- {
- g_curr_book_cntx_p->g_nfo_book_struct.book_size =
- g_curr_book_cntx_p->g_nfo_book_struct.book_size + (-TXT_FOOTER_START_SIZE -
- TXT_FOOTER_END_SIZE - MAX_EBOOK_NAME_LENGTH);
- }
- FS_Truncate(file_hnd);
- }
- else
- {
- return_value = EBR_FRM_NFO_CREATE_SUCCESS;
- }
- FS_Close(nfo_hnd);
- }
- }
- else
- {
- create_nfo_file = 1;
- }
- }
- else
- {
- return_value = EBR_FRM_NFO_CREATE_FAILURE;
- }
- if (create_nfo_file)
- {
- strlength = pfnUnicodeStrlen((const S8*)filename);
- pfnUnicodeStrncpy((S8*) display_name, (S8*) filename, strlength - EBR_EXTENSION_NAME_LENGTH - 1);
- local_nfo_id = ebr_frm_create_nfo_file(display_name, ebook_file_name, filename);
- if (local_nfo_id >= 0)
- {
- memset(tmp_str, 0, MAX_EBOOK_NAME_LENGTH);
- if (g_curr_book_cntx_p->src_application == EBR_FRM_SRC_APP_FMGR)
- { /* Means it is from file manager */
- ebr_frm_fmgr_set_nfo_id(local_nfo_id);
- }
- HW_itoa(g_curr_book_cntx_p->g_last_nfo_id_allocated, (S8*) tmp_str, 10);
- FS_Seek(file_hnd, 0, FS_FILE_END);
- FS_Write(file_hnd, EBR_TXT_FOOTER_START, TXT_FOOTER_START_SIZE, &size);
- FS_Write(file_hnd, tmp_str, MAX_EBOOK_NAME_LENGTH, &size);
- FS_Write(file_hnd, EBR_TXT_FOOTER_END, TXT_FOOTER_END_SIZE, &size);
- return_value = EBR_FRM_NFO_CREATE_SUCCESS;
- }
- else
- {
- return_value = EBR_FRM_NFO_CREATE_FAILURE;
- }
- }
- end:
- pfnUnicodeStrcpy((PS8) g_curr_book_cntx_p->book_name_path, (PS8) ebook_file_name);
- FS_Close(file_hnd);
- attr = FS_GetAttributes((const WCHAR*)ebook_file_name);
- if(is_read_only)
- {
- FS_SetAttributes((const WCHAR*)ebook_file_name, (U8) (attr | (FS_ATTR_READ_ONLY)));
- }
- return return_value;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_is_empty_file
- * DESCRIPTION
- * Check if it is an empty file
- * PARAMETERS
- * filename [IN]
- * RETURNS
- * void
- *****************************************************************************/
- MMI_BOOL ebr_frm_is_empty_file(FILE_HANDLE file_hnd, ebr_frm_filetype_enum type)
- {
- U32 filesize, size, offset;
- S8 file_header[10];
- S8 UCS2empty[2] = {0xFF, 0xFE};
- S8 UCS2BEempty[2] = {0xFE, 0xFF};
- S8 UTF8empty[3] = {0xEF, 0xBB, 0xBF};
- memset(&file_header, 0, 10);
- if (type == EBR_FRM_FILE_TYPE_TXT)
- {
- FS_GetFileSize(file_hnd, &filesize);
- FS_Read(file_hnd, &file_header, 10, &size);
- /* g_curr_book_cntx_p->g_nfo_book_struct.book_size=g_curr_book_cntx_p->g_nfo_book_struct.book_size-TXT_FOOTER_END_SIZE-MAX_EBOOK_NAME_LENGTH-TXT_FOOTER_START_SIZE; */
- if (filesize == 0)
- {
- return MMI_TRUE;
- }
- //else if (mmiEncoding == MMI_CHSET_UCS2 && (strncmp(file_header, UCS2empty, 2) == 0 || strncmp(file_header, UCS2BEempty, 2) == 0))
- else if (pfnUnicodeStrlen(file_header) == 1 && (strncmp(file_header, UCS2empty, 2) == 0 || strncmp(file_header, UCS2BEempty, 2) == 0))
- {
- return MMI_TRUE;
- }
- else if (strlen(file_header) == 3 && strncmp(file_header, UTF8empty, 3) == 0)
- {
- return MMI_TRUE;
- }
- return MMI_FALSE;
- }
- else
- {
- SEEK_REC_ENTRY(file_hnd, 1);
- if (FS_Read(file_hnd, &offset, 4, (U32*) & size) == FS_NO_ERROR)
- {
- offset = ntohl(offset);
- }
- if (g_curr_book_cntx_p->g_nfo_book_struct.book_size == 1)
- {
- if (FS_Seek(file_hnd, offset, FS_FILE_BEGIN) != FS_INVALID_FILE_POS)
- {
- FS_Read(file_hnd, file_header, 10, (U32*) &size);
- }
- if (file_header[0] == 0x20)
- {
- return TRUE;
- }
- }
- return FALSE;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_get_nfo_file_name
- * DESCRIPTION
- * Get Nfo File Name.
- * PARAMETERS
- * local_nfo_id [IN]
- * RETURNS
- * void
- *****************************************************************************/
- U8 *ebr_frm_get_nfo_file_name(S32 local_nfo_id)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- static U8 nfo_file_name[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH] = {0};
- static S32 prev_local_nfo_id = -1;
- S8 nfo_file_name_prefix_ascii[MAX_EBOOK_NAME_LENGTH - 3]; /* Extension length subtracted */
- S8 nfo_file_name_prefix_ucs2[(MAX_EBOOK_NAME_LENGTH - 3) * ENCODING_LENGTH];
- UI_string_type temp_str[MAX_EBOOK_NAME_LENGTH];
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (prev_local_nfo_id == local_nfo_id)
- {
- return nfo_file_name;
- }
- pfnUnicodeStrcpy(
- (S8*) nfo_file_name,
- (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
- sprintf(nfo_file_name_prefix_ascii, "%08d", local_nfo_id);
- AnsiiToUnicodeString((PS8) nfo_file_name_prefix_ucs2, (PS8) nfo_file_name_prefix_ascii);
- pfnUnicodeStrcat((PS8) nfo_file_name, nfo_file_name_prefix_ucs2);
- AnsiiToUnicodeString((PS8) temp_str, (PS8) EBR_EBOOK_NFO_FILE_EXT);
- pfnUnicodeStrcat((PS8) nfo_file_name, (PS8) temp_str);
- prev_local_nfo_id = local_nfo_id;
- return nfo_file_name;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_create_nfo_file
- * DESCRIPTION
- * Create Nfo File for TXT and PDB
- * PARAMETERS
- * display_name [IN]
- * ebook_file_name_with_path [IN]
- * ebook_file_name [IN]
- * RETURNS
- * void
- *****************************************************************************/
- S32 ebr_frm_create_nfo_file(U8 *display_name, U8 *ebook_file_name_with_path, U8 *ebook_file_name)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- FILE_HANDLE file_hnd;
- S32 return_val;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- ebr_frm_find_next_nfo_id();
- file_hnd = FS_Open(
- (const WCHAR*)ebr_frm_get_nfo_file_name(++g_curr_book_cntx_p->g_last_nfo_id_allocated),
- FS_CREATE | FS_ATTR_HIDDEN);
- if (file_hnd != 0)
- {
- return_val = ebr_frm_fill_nfo_file(file_hnd, display_name, (U8*) ebook_file_name);
- FS_Close(file_hnd);
- if (return_val == 0)
- {
- FS_Delete((const WCHAR*)
- ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
- return -1;
- }
- else
- {
- return g_curr_book_cntx_p->g_last_nfo_id_allocated;
- }
- }
- else
- {
- return -1;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_fill_nfo_file
- * DESCRIPTION
- * Fill the NFO file
- * PARAMETERS
- * file_hnd [IN]
- * display_name [IN]
- * ebook_file_name [IN]
- * RETURNS
- * void
- *****************************************************************************/
- S16 ebr_frm_fill_nfo_file(FILE_HANDLE file_hnd, U8 *display_name, U8 *ebook_file_name)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- ebr_frm_book_struct book_struct;
- ebr_frm_setting_struct g_setting;
- ebr_frm_setting_struct *g_setting_list = &g_setting;
- U8 i;
- U32 size;
- S16 error;
- S32 write_result;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- pfnUnicodeStrcpy((PS8) book_struct.e_book_name, (PS8) ebook_file_name);
- pfnUnicodeStrcpy((PS8) book_struct.display_name, (PS8) display_name);
- book_struct.book_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size;
- book_struct.temp_book_size = 0;
- book_struct.temp_encoding_file_format = ' ';
- book_struct.current_page_id = 0;
- book_struct.offset = 0;
- book_struct.jump_offset = 0;
- book_struct.last_showed_percentage = 0;
- book_struct.last_text_offset_y = 0;
- for (i = 0; i < EBR_FRM_MAX_NO_OF_BOOKMARKS; i++)
- {
- book_struct.book_marks[i].offset = 0;
- book_struct.book_marks[i].page_id = 0;
- pfnUnicodeStrcpy((PS8) book_struct.book_marks[i].bookmark_name, (PS8) NULL);
- book_struct.book_marks[i].percentage_associated_with_book_mark = 0;
- }
- ReadRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
- #ifndef MMI_ON_HARDWARE_P
- if (g_setting_list->common_settings.encoding_format == 0xff)
- {
- g_setting_list->common_settings.encoding_format = EBOOK_WESTERN_WINDOWS;
- g_setting_list->common_settings.font_size = EBR_FONT_SIZE_MEDIUM;
- g_setting_list->common_settings.font_style = EBR_FONT_STYLE_NORMAL;
- g_setting_list->memory_type = (S8)MMI_PUBLIC_DRV;
- g_setting_list->common_settings.screen_mode = EBR_FULL_SCREEN_OFF;
- g_setting_list->common_settings.auto_scroll_settings.scroll_flag = EBR_SCROLL_OFF;
- g_setting_list->common_settings.auto_scroll_settings.scroll_speed = EBR_AUTO_SCROLL_SPEED_1;
- g_setting_list->common_settings.auto_scroll_settings.scroll_type = EBR_SCROLL_BY_PAGE;
- WriteRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
- WriteRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
- }
- #endif /* MMI_ON_HARDWARE_P */
- book_struct.settings = g_setting_list->common_settings;
- strcpy((char*)book_struct.checksum, (const char*)EBR_TXT_FOOTER_START);
- if ((write_result = FS_Write(file_hnd, &book_struct, sizeof(ebr_frm_book_struct), (U32*) & size)) == FS_NO_ERROR)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_get_nfo_id_from_file_name
- * DESCRIPTION
- * Get the next NFO from File
- * PARAMETERS
- * file_name_without_path [IN]
- * RETURNS
- * void
- *****************************************************************************/
- S32 ebr_frm_get_nfo_id_from_file_name(U8 *file_name_without_path)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 previous_file_name[MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH];
- S32 i = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- while (file_name_without_path[i * 2] != '.')
- {
- previous_file_name[i] = file_name_without_path[i * 2];
- i++;
- }
- previous_file_name[i] = 0;
- return HW_atoi((const S8*)previous_file_name);
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_find_next_nfo_id
- * DESCRIPTION
- * Get the next NFO id
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_find_next_nfo_id(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S8 nfo_search_query[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
- FS_HANDLE fh_cur;
- FS_DOSDirEntry file_info;
- S32 count = 0;
- S32 file_id = 0;
- U8 file_name_without_path[MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH];
- S16 nfo_id_from_middle = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- pfnUnicodeStrcpy(
- (S8*) nfo_search_query,
- (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_NFO));
- if ((fh_cur = FS_FindFirst(
- (const WCHAR*)nfo_search_query,
- 0,
- 0,
- &file_info,
- (WCHAR*) file_name_without_path,
- MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
- {
- do
- {
- count++;
- if (!(file_info.Attributes & FS_ATTR_DIR))
- {
- file_id = ebr_frm_get_nfo_id_from_file_name(file_name_without_path);
- }
- if (count < file_id)
- {
- nfo_id_from_middle = 1;
- break;
- }
- } while ((FS_FindNext
- (fh_cur, &file_info, (U16*) file_name_without_path,
- MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH) == FS_NO_ERROR));
- FS_FindClose(fh_cur);
- }
- if (count > 0)
- {
- if (nfo_id_from_middle != 1)
- {
- g_curr_book_cntx_p->g_last_nfo_id_allocated = file_id;
- }
- else
- {
- g_curr_book_cntx_p->g_last_nfo_id_allocated = --count;
- }
- }
- else
- {
- g_curr_book_cntx_p->g_last_nfo_id_allocated = 0;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_delete_unused_nfo_file
- * DESCRIPTION
- * Delete invalid NFO files.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_delete_unused_nfo_file(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- FS_HANDLE fh_cur;
- FS_DOSDirEntry file_info;
- S8 path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
- U8 filename[MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH];
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- pfnUnicodeStrcpy(
- (S8*) path,
- (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_NFO));
- if ((fh_cur = FS_FindFirst(
- (const WCHAR*)path,
- 0,
- 0,
- &file_info,
- (U16*) filename,
- MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
- {
- do
- {
- if (!(file_info.Attributes & FS_ATTR_DIR))
- {
- ebr_frm_open_nfo_file_and_delete_unused_nfo(filename);
- }
- } while ((FS_FindNext(fh_cur, &file_info, (U16*) filename, MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH) ==
- FS_NO_ERROR));
- FS_FindClose(fh_cur);
- }
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_open_nfo_file_and_delete_unused_nfo
- * DESCRIPTION
- * Delete invalid NFO files.
- * PARAMETERS
- * filename [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_open_nfo_file_and_delete_unused_nfo(U8 *filename)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S8 nfo_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH + ENCODING_LENGTH];
- S8 file_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH + ENCODING_LENGTH];
- FILE_HANDLE nfo_hnd, file_hnd;
- U32 size, nfo_file_size;
- S32 nfo_id, strlen_file_name;
- pBOOL isValidNfo = FALSE;
- S32 local_nfo_id;
- S8 nfo_file_name[NFO_FILE_NAME_LENGTH] = {0};
- S8 nfo_file[NFO_FILE_NAME_VALUE] = {0};
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- UnicodeToAnsii((S8*) nfo_file_name, (S8*) filename);
- strncpy((S8*) nfo_file, (S8*) nfo_file_name, NFO_FILE_NAME_VALUE - 1);
- nfo_file[NFO_FILE_NAME_VALUE-1] = ' ';
- local_nfo_id = HW_atoi((const S8*)nfo_file);
- pfnUnicodeStrcpy(
- (S8*) nfo_path,
- (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
- pfnUnicodeStrcat((S8*) nfo_path, (S8*) filename);
- nfo_hnd = FS_Open((const WCHAR*)nfo_path, FS_READ_ONLY);
- FS_Read(nfo_hnd, &g_curr_book_cntx_p->g_nfo_book_struct, sizeof(g_curr_book_cntx_p->g_nfo_book_struct), &size);
- FS_GetFileSize(nfo_hnd, &nfo_file_size);
- if ((!strncmp
- ((const S8*)g_curr_book_cntx_p->g_nfo_book_struct.checksum, (const S8*)EBR_TXT_FOOTER_START,
- TXT_FOOTER_START_SIZE)) && (nfo_file_size == sizeof(g_curr_book_cntx_p->g_nfo_book_struct)))
- {
- isValidNfo = TRUE;
- }
- else
- {
- isValidNfo = FALSE;
- }
- FS_Close(nfo_hnd);
- if (isValidNfo)
- {
- strlen_file_name = pfnUnicodeStrlen((const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
- if ((g_curr_book_cntx_p->g_nfo_book_struct.e_book_name[strlen_file_name * 2 - 6] == 'p') ||
- (g_curr_book_cntx_p->g_nfo_book_struct.e_book_name[strlen_file_name * 2 - 6] == 'P'))
- {
- g_curr_book_cntx_p->gbook_type = EBR_FRM_FILE_TYPE_PDB;
- }
- else
- {
- g_curr_book_cntx_p->gbook_type = EBR_FRM_FILE_TYPE_TXT;
- }
- pfnUnicodeStrncpy(
- (S8*) file_path,
- (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT),
- MAX_DWNL_EBK_PATH_LEN);
- pfnUnicodeStrncat(
- (S8*) file_path,
- (S8*) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name,
- MAX_DWNL_EBK_PATH_LEN - pfnUnicodeStrlen((S8*) file_path));
- file_hnd = FS_Open((const WCHAR*)file_path, FS_READ_ONLY);
- if (file_hnd <= 0)
- {
- pfnUnicodeStrncpy(
- (S8*) file_path,
- (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT),
- MAX_DWNL_EBK_PATH_LEN);
- pfnUnicodeStrncat(
- (S8*) file_path,
- (S8*) g_curr_book_cntx_p->g_nfo_book_struct.temp_file_name,
- MAX_DWNL_EBK_PATH_LEN - pfnUnicodeStrlen((S8*) file_path));
- file_hnd = FS_Open((const WCHAR*)file_path, FS_READ_ONLY);
- if (file_hnd >= 0)
- {
- FS_Close(file_hnd);
- FS_Delete((const WCHAR*)file_path);
- }
- FS_Delete((const WCHAR*)nfo_path);
- }
- else
- {
- FS_Close(file_hnd);
- if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_TXT)
- {
- nfo_id = ebr_fmgr_get_nfo_id_for_txt_file(
- g_curr_book_cntx_p->memory_type_selected,
- (S8*) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
- }
- else
- {
- nfo_id = ebr_fmgr_get_nfo_id_for_pdb_file(
- g_curr_book_cntx_p->memory_type_selected,
- (S8*) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
- }
- if (nfo_id <= 0 || (nfo_id != local_nfo_id))
- {
- FS_Delete((const WCHAR*)nfo_path);
- }
- }
- }
- else
- {
- FS_Delete((const WCHAR*)nfo_path);
- }
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_entry_refresh_book_shelf
- * DESCRIPTION
- * Refresh the book Shelf
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_entry_refresh_book_shelf(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- ebr_frm_delete_unused_nfo_file();
- g_curr_book_cntx_p->ebr_frm_end_book_flag = 1;
- g_curr_book_cntx_p->ebr_search_strlen = 0;
- g_curr_book_cntx_p->highlight_string_flag = 0;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_get_total_countof_nfo_file
- * DESCRIPTION
- * Get the total count for nfo files
- * PARAMETERS
- * void
- * RETURNS
- * S32 count
- *****************************************************************************/
- S32 ebr_frm_get_total_countof_nfo_file()
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- FS_HANDLE fh_cur;
- FS_DOSDirEntry file_info;
- UI_character_type filename[MAX_EBOOK_NAME_LENGTH];
- U8 count = 0;
- S8 path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- pfnUnicodeStrcpy(
- (S8*) path,
- (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_PDB));
- if ((fh_cur = FS_FindFirst(
- (const WCHAR*)path,
- 0,
- 0,
- &file_info,
- (U16*) filename,
- MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
- {
- do
- {
- if (!(file_info.Attributes & FS_ATTR_DIR))
- {
- count++;
- break;
- }
- } while ((FS_FindNext(fh_cur, &file_info, (U16*) filename, MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH) ==
- FS_NO_ERROR));
- FS_FindClose(fh_cur);
- }
- if (count > 0)
- {
- return count;
- }
- else
- {
- pfnUnicodeStrcpy(
- (S8*) path,
- (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_TXT));
- if ((fh_cur = FS_FindFirst(
- (const WCHAR*)path,
- 0,
- 0,
- &file_info,
- (U16*) filename,
- MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
- {
- do
- {
- if (!(file_info.Attributes & FS_ATTR_DIR))
- {
- count++;
- break;
- }
- } while ((FS_FindNext(fh_cur, &file_info, (U16*) filename, MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH) ==
- FS_NO_ERROR));
- FS_FindClose(fh_cur);
- }
- }
- return count;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_get_file_path
- * DESCRIPTION
- * Get the file path
- * PARAMETERS
- * memory_type_selected [IN]
- * search_type_path [IN]
- * RETURNS
- * S32 count
- *****************************************************************************/
- S8 *ebr_frm_get_file_path(S8 memory_type_selected, ebr_frm_search_type_enum search_type_path)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S8 file_path_in_ascii[MAX_DWNL_EBK_PATH_LEN];
- static S8 file_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
- static ebr_frm_search_type_enum prev_search_type_path = EBR_FRM_SEARCH_MAX;
- static S8 prev_memory_type_selected = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (prev_memory_type_selected == memory_type_selected && prev_search_type_path == search_type_path)
- {
- return file_path;
- }
- switch (search_type_path)
- {
- case EBR_FRM_SEARCH_NFO:
- sprintf((char*)file_path_in_ascii, "%c%s%s", memory_type_selected, EBR_DOWNLOADED_EBOOK_PATH, EBR_EBOOK_SEARCH_NFO_STR);
- break;
- case EBR_FRM_SEARCH_PDB:
- sprintf((char*)file_path_in_ascii, "%c%s%s", memory_type_selected, EBR_DOWNLOADED_EBOOK_PATH, EBR_EBOOK_SEARCH_PDB_STR);
- break;
- case EBR_FRM_SEARCH_TXT:
- sprintf((char*)file_path_in_ascii, "%c%s%s", memory_type_selected, EBR_DOWNLOADED_EBOOK_PATH, EBR_EBOOK_SEARCH_TXT_STR);
- break;
- case EBR_FRM_SEARCH_TXZ:
- sprintf((char*)file_path_in_ascii, "%c%s%s", memory_type_selected, EBR_DOWNLOADED_EBOOK_PATH, EBR_EBOOK_SEARCH_TXZ_STR);
- break;
- case EBR_FRM_SEARCH_PBZ:
- sprintf((char*)file_path_in_ascii, "%c%s%s", memory_type_selected, EBR_DOWNLOADED_EBOOK_PATH, EBR_EBOOK_SEARCH_PBZ_STR);
- break;
- default:
- sprintf((char*)file_path_in_ascii, "%c%s", memory_type_selected, EBR_DOWNLOADED_EBOOK_PATH);
- break;
- }
- AnsiiToUnicodeString((PS8) file_path, file_path_in_ascii);
- prev_memory_type_selected = memory_type_selected;
- prev_search_type_path = search_type_path;
- return file_path;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_get_path_for_bookshelf
- * DESCRIPTION
- * Get the book shelf path
- * PARAMETERS
- * void
- * RETURNS
- * S32 count
- *****************************************************************************/
- S8 *ebr_frm_get_path_for_bookshelf(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- return ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT);
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_set_number_of_records
- * DESCRIPTION
- * Set number of records
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_set_number_of_records(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_curr_book_cntx_p->g_nfo_book_struct.book_size % EBR_RECORD_SIZE_MAX == 0)
- {
- g_curr_book_cntx_p->num_records = g_curr_book_cntx_p->g_nfo_book_struct.book_size / EBR_RECORD_SIZE_MAX;
- }
- else
- {
- g_curr_book_cntx_p->num_records = g_curr_book_cntx_p->g_nfo_book_struct.book_size / EBR_RECORD_SIZE_MAX + 1;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_set_temp_number_of_records
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_set_temp_number_of_records(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size % EBR_RECORD_SIZE_MAX == 0)
- {
- g_curr_book_cntx_p->num_records = g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size / EBR_RECORD_SIZE_MAX;
- }
- else
- {
- g_curr_book_cntx_p->num_records =
- g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size / EBR_RECORD_SIZE_MAX + 1;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * copy_record_in_passed_buffer
- * DESCRIPTION
- * Copy the data in previous buffer
- * PARAMETERS
- * file_hnd [IN]
- * record_id [IN]
- * output_buffer [IN]
- * input_buffer [IN]
- * size [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void copy_record_in_passed_buffer(FS_HANDLE file_hnd, S32 record_id, U8 *output_buffer, U8 *input_buffer, U32 *size)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 rec_size;
- S32 offset;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_TXT || g_curr_book_cntx_p->book_is_in_other_encoding_format)
- {
- rec_size = ebr_frm_get_record_size_txt(record_id);
- if (record_id >= 1) /* first record */
- {
- record_id -= 1;
- }
- FS_Seek(file_hnd, (record_id) * EBR_RECORD_SIZE_MAX, FS_FILE_BEGIN);
- FS_Read(file_hnd, g_curr_book_cntx_p->buffer, rec_size, size);
- }
- else
- {
- SEEK_REC_ENTRY(file_hnd, record_id);
- if (FS_Read(file_hnd, &offset, 4, size) == FS_NO_ERROR)
- {
- offset = ntohl(offset);
- }
- rec_size = ebr_frm_get_record_size_pdb(file_hnd, offset, record_id);
- FS_Seek(file_hnd, offset, FS_FILE_BEGIN);
- FS_Read(file_hnd, input_buffer, rec_size, size);
- ebr_frm_start_decompression(output_buffer, input_buffer, size);
- }
- }
- /*****************************************************************************
- * FUNCTION
- * copy_record_in_buffer
- * DESCRIPTION
- * Copy the data in current buffer
- * PARAMETERS
- * file_hnd [IN]
- * record_id [IN]
- * copy_type [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void copy_record_in_buffer(FS_HANDLE file_hnd, S32 record_id, ebr_frm_copy_type_enum copy_type)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 rec_size;
- S32 offset;
- S32 size;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_TXT || g_curr_book_cntx_p->pdb_converted_to_text)
- {
- switch (copy_type)
- {
- case EBR_FRM_COPY_TYPE_FIRST:
- memset(g_curr_book_cntx_p->start, 0, EBR_RECORD_SIZE_MAX * 2);
- offset = 0;
- break;
- case EBR_FRM_COPY_TYPE_SECOND:
- memset(g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, 0, EBR_RECORD_SIZE_MAX);
- offset = EBR_RECORD_SIZE_MAX;
- break;
- case EBR_FRM_COPY_TYPE_NEXT:
- memcpy(g_curr_book_cntx_p->start, g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, EBR_RECORD_SIZE_MAX);
- /* pfnUnicodeStrcpy((PS8)g_curr_book_cntx_p->start,(PS8)g_curr_book_cntx_p->start+EBR_RECORD_SIZE_MAX); */
- memset(g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, 0, EBR_RECORD_SIZE_MAX);
- offset = EBR_RECORD_SIZE_MAX;
- break;
- case EBR_FRM_COPY_TYPE_PREVIOUS:
- memcpy(g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, g_curr_book_cntx_p->start, EBR_RECORD_SIZE_MAX);
- memset(g_curr_book_cntx_p->start, 0, EBR_RECORD_SIZE_MAX);
- offset = 0;
- break;
- }
- rec_size = ebr_frm_get_record_size_txt(record_id);
- FS_Seek(file_hnd, (record_id - 1) * EBR_RECORD_SIZE_MAX, FS_FILE_BEGIN);
- FS_Read(file_hnd, g_curr_book_cntx_p->start + offset, rec_size, (U32*) & size);
- }
- else
- {
- SEEK_REC_ENTRY(file_hnd, record_id);
- if (FS_Read(file_hnd, &offset, 4, (U32*) & size) == FS_NO_ERROR)
- {
- offset = ntohl(offset);
- }
- rec_size = ebr_frm_get_record_size_pdb(file_hnd, offset, record_id);
- if (rec_size < 0 || (rec_size > EBR_RECORD_SIZE_MAX))
- {
- g_curr_book_cntx_p->is_in_valid = TRUE;
- }
- else
- {
- if (FS_Seek(file_hnd, offset, FS_FILE_BEGIN) != FS_INVALID_FILE_POS)
- {
- FS_Read(file_hnd, &g_curr_book_cntx_p->buffer, rec_size, (U32*) & size);
- ebr_frm_decompress_pdb((U8*) g_curr_book_cntx_p->buffer, (U32*) & size, copy_type);
- }
- else
- {
- g_curr_book_cntx_p->is_in_valid = TRUE;
- g_curr_book_cntx_p->gcurrent_record_id = g_curr_book_cntx_p->num_records;
- }
- }
- }
- }
- #ifdef __MMI_TOUCH_SCREEN__
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_get_data_during_scrolling
- * DESCRIPTION
- * Copy the data in buffer_local during scrolling
- * PARAMETERS
- * page_id [IN]
- * buffer_local [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_get_data_during_scrolling(S32 percentage_val,PU8 buffer_local)
- {
- S8 display_name[(MAX_EBOOK_NAME_LENGTH + 1) * ENCODING_LENGTH];
- gui_page_info_app ebook_frm_setting;
- if(percentage_val==100)
- {
- ebr_frm_jump_to_record(0,EBR_JUMP_END);
- /* Here 0 is being passed as percentage value reason being ,Ebook application consider jump to end case
- when percentage value is 0 : During dragging of scrollbar to reach to end of the book,it is being added*/
- }
- else
- {
- ebr_frm_jump_to_record(percentage_val,EBR_JUMP_PERCENTAGE);
- }
- ebr_frm_get_data_to_open_book(&ebook_frm_setting,buffer_local, display_name);
- wgui_paging_set_page_info(&ebook_frm_setting);
- }
- #endif /* __MMI_TOUCH_SCREEN__ */
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_decode_header
- * DESCRIPTION
- * Get the File Header for PDB and Footer for TXT file
- * PARAMETERS
- * ebook_file_name [IN]
- * RETURNS
- * S16 error_type
- *****************************************************************************/
- S16 ebr_frm_decode_header(U8 *ebook_file_name)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- FILE_HANDLE file_hnd;
- S16 ebr_page_size;
- S32 book_size = 0;
- // FS_DiskInfo disk_info;
- // S32 fs_ret;
- S8 file_path_in_ascii[5];
- S8 file_path[10];
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- // U64 disk_free_space;
- // U64 disk_total_space;
- if (g_curr_book_cntx_p->is_book_in_unicode || g_curr_book_cntx_p->book_is_in_other_encoding_format)
- {
- ebr_page_size = EBR_PAGE_SIZE * 2;
- }
- else
- {
- ebr_page_size = EBR_PAGE_SIZE;
- }
- file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->book_name_path, FS_READ_ONLY);
- if (file_hnd <= 0)
- {
- return -1;
- }
- if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
- {
- /* Create a new file in Unicode and change the book_size */
- S32 status;
- sprintf((char*)file_path_in_ascii, "%c", g_curr_book_cntx_p->memory_type_selected);
- strcat((char*)file_path_in_ascii, ":\");
- AnsiiToUnicodeString((PS8) file_path, file_path_in_ascii);
- status = ebr_frm_create_temp_file_in_ucs2(file_hnd);
- if (status == 0)
- {
- FS_Close(file_hnd);
- return 0;
- }
- else if (status == 1)
- {
- return 1;
- }
- else if (status == 2)
- {
- ebr_frm_set_temp_number_of_records();
- FS_Close(file_hnd);
- file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path, FS_READ_ONLY);
- book_size = g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size;
- }
- }
- else
- {
- ebr_frm_set_number_of_records();
- ebr_frm_delete_temp_file();
- book_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size;
- }
- if (!g_curr_book_cntx_p->ebr_frm_end_book_flag ||
- (g_curr_book_cntx_p->g_nfo_book_struct.current_page_id + 4) * ebr_page_size >= (U32) book_size)
- {
- if (book_size > EBR_RECORD_SIZE_MAX)
- {
- g_curr_book_cntx_p->gcurrent_record_id = g_curr_book_cntx_p->num_records - 1;
- g_curr_book_cntx_p->gnext_record_id = g_curr_book_cntx_p->gcurrent_record_id + 1;
- }
- else
- {
- g_curr_book_cntx_p->gcurrent_record_id =
- g_curr_book_cntx_p->g_start_id / (EBR_RECORD_SIZE_MAX / ebr_page_size) + 1;
- g_curr_book_cntx_p->gnext_record_id = g_curr_book_cntx_p->gcurrent_record_id + 1;
- }
- }
- else
- {
- g_curr_book_cntx_p->gcurrent_record_id =
- g_curr_book_cntx_p->g_start_id / (EBR_RECORD_SIZE_MAX / ebr_page_size) + 1;
- g_curr_book_cntx_p->gnext_record_id = g_curr_book_cntx_p->gcurrent_record_id + 1;
- }
- copy_record_in_buffer(file_hnd, g_curr_book_cntx_p->gcurrent_record_id, EBR_FRM_COPY_TYPE_FIRST);
- if(g_curr_book_cntx_p->book_is_in_other_encoding_format)
- {
- if(g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size>EBR_RECORD_SIZE_MAX)
- {
- copy_record_in_buffer(file_hnd, g_curr_book_cntx_p->gnext_record_id, EBR_FRM_COPY_TYPE_SECOND);
- }
- }
- else
- {
- if(g_curr_book_cntx_p->g_nfo_book_struct.book_size>EBR_RECORD_SIZE_MAX)
- {
- copy_record_in_buffer(file_hnd, g_curr_book_cntx_p->gnext_record_id, EBR_FRM_COPY_TYPE_SECOND);
- }
- }
- FS_Close(file_hnd);
- if (g_curr_book_cntx_p->is_in_valid)
- {
- g_curr_book_cntx_p->is_in_valid = FALSE;
- return 2;
- }
- return 1;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_delete_temp_file
- * DESCRIPTION
- * Get the record size for text file.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_delete_temp_file(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- pBOOL is_temp_file_present;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- ebr_frm_create_temp_file_path();
- is_temp_file_present = ebr_frm_check_if_file_exists_or_not();
- if (is_temp_file_present)
- {
- FS_Delete((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path);
- }
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_get_current_recursive_conversion_state
- * DESCRIPTION
- * Get the current conversion state.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- S32 ebr_frm_get_current_recursive_conversion_state(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- return g_curr_book_cntx_p->state_recursive_conversion;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_set_current_recursive_conversion_state
- * DESCRIPTION
- * Set the current conversion state.
- * PARAMETERS
- * state [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_set_current_recursive_conversion_state(S32 state)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_curr_book_cntx_p->state_recursive_conversion = state;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_register_recursive_callback_fn
- * DESCRIPTION
- * Reister Function for Recursive callback
- * PARAMETERS
- * fn [IN]
- * void (*fn)(?)
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_register_recursive_callback_fn(void (*fn) (void))
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_curr_book_cntx_p->g_recursive_callback_fn = fn;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_stop_recursion
- * DESCRIPTION
- * Stop the timer for Recursive callback
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_stop_recursion(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- StopTimer(EBOOK_RECURSIVE_TIMER);
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_convert_record
- * DESCRIPTION
- * Convert the record and write in temp file
- * PARAMETERS
- * file_hnd [IN]
- * new_file_hnd [IN]
- * record_id [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_convert_record(FILE_HANDLE file_hnd, FILE_HANDLE new_file_hnd, S32 record_id)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 rec_size = 0;
- S32 total_bytes_converted = 0;
- S32 offset = 0;
- S32 size = 0;
- U32 static over_the_record_border = 0;
- S32 converted_str_len;
- U8 mmiEncoding = mmi_ebook_util_get_chset(g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format);
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (record_id == 1)
- {
- over_the_record_border = 0;
- }
- if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_TXT)
- {
- rec_size = ebr_frm_create_temp_file_txt(record_id) - over_the_record_border;
- if (rec_size > EBR_RECORD_SIZE_MAX)
- {
- rec_size = EBR_RECORD_SIZE_MAX;
- over_the_record_border = 0;
- }
- memset(g_curr_book_cntx_p->buffer, 0, sizeof(g_curr_book_cntx_p->buffer));
- FS_Read(file_hnd, g_curr_book_cntx_p->buffer, rec_size, (U32*) & size);
- memset(g_curr_book_cntx_p->start, 0, sizeof(g_curr_book_cntx_p->start));
- mmi_chset_use_space_for_unknown_character();
- switch (mmiEncoding)
- {
- #if defined(MMI_ON_HARDWARE_P) && defined(__MMI_CHSET_BIG5__)
- case MMI_CHSET_BIG5:
- total_bytes_converted = ebr_frm_mmi_chset_text_to_ucs2_str(
- file_hnd,
- (U8*) g_curr_book_cntx_p->start,
- EBR_RECORD_SIZE_MAX * 2 + 10,
- (U8*) g_curr_book_cntx_p->buffer,
- (S16) size,
- BIG_5_ENCODING_TYPE,
- &over_the_record_border);
- break;
- #endif /* defined(MMI_ON_HARDWARE_P) && defined(__MMI_CHSET_BIG5__) */
- #if defined(MMI_ON_HARDWARE_P) && defined(__MMI_CHSET_GB2312__)
- case MMI_CHSET_GB2312:
- total_bytes_converted = ebr_frm_mmi_chset_text_to_ucs2_str(
- file_hnd,
- (U8*) g_curr_book_cntx_p->start,
- EBR_RECORD_SIZE_MAX * 2 + 10,
- (U8*) g_curr_book_cntx_p->buffer,
- (S16) size,
- GB2312_ENCODING_TYPE,
- &over_the_record_border);
- break;
- #endif /* defined(MMI_ON_HARDWARE_P) && defined(__MMI_CHSET_GB2312__) */
- #if defined(MMI_ON_HARDWARE_P)
- case MMI_CHSET_UTF8:
- total_bytes_converted = ebr_frm_mmi_chset_utf8_to_ucs2_string(
- file_hnd,
- (U8*) g_curr_book_cntx_p->start,
- EBR_RECORD_SIZE_MAX * 2 + 10,
- (U8*) g_curr_book_cntx_p->buffer,
- (S16) size,
- &over_the_record_border);
- break;
- #endif /* defined(MMI_ON_HARDWARE_P) */
- default:
- total_bytes_converted = mmi_chset_convert(
- (mmi_chset_enum) mmiEncoding,
- MMI_CHSET_UCS2,
- (S8*) g_curr_book_cntx_p->buffer,
- (S8*) g_curr_book_cntx_p->start,
- EBR_RECORD_SIZE_MAX * 2 + 10);
- break;
- }
- mmi_chset_do_not_use_space_for_unknown_character();
- converted_str_len = pfnUnicodeStrlen((S8*) g_curr_book_cntx_p->start);
- if (converted_str_len != (total_bytes_converted - 2) / 2)
- {
- g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
- FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
- }
- else if (mmiEncoding == MMI_CHSET_UTF8 && (total_bytes_converted - 2) < (size / 2))
- {
- g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
- FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
- }
- #ifdef __MMI_CHSET_BIG5__
- else if (mmiEncoding == MMI_CHSET_BIG5 && (total_bytes_converted - 2) < (size))
- {
- g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
- FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
- }
- #endif /* __MMI_CHSET_BIG5__ */
- #ifdef __MMI_CHSET_GB2312__
- else if (mmiEncoding == MMI_CHSET_GB2312 && (total_bytes_converted - 2) < (size))
- {
- g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
- FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
- }
- #endif /* __MMI_CHSET_GB2312__ */
- else if (record_id == g_curr_book_cntx_p->num_records)
- {
- FS_Write(new_file_hnd, g_curr_book_cntx_p->start, total_bytes_converted, (U32*) & size);
- }
- else
- {
- FS_Write(new_file_hnd, g_curr_book_cntx_p->start, total_bytes_converted - 2, (U32*) & size);
- }
- }
- else
- {
- memset(g_curr_book_cntx_p->start, 0, sizeof(g_curr_book_cntx_p->start));
- g_curr_book_cntx_p->pdb_converted_to_text = TRUE;
- SEEK_REC_ENTRY(file_hnd, record_id);
- if (FS_Read(file_hnd, &offset, 4, (U32*) & size) == FS_NO_ERROR)
- {
- offset = ntohl(offset);
- }
- rec_size = ebr_frm_get_record_size_pdb(file_hnd, offset, record_id);
- if (rec_size < 0 || (rec_size > EBR_RECORD_SIZE_MAX))
- {
- g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
- return;
- }
- if (FS_Seek(file_hnd, offset, FS_FILE_BEGIN) != FS_INVALID_FILE_POS)
- {
- FS_Read(file_hnd, g_curr_book_cntx_p->for_unicode_buffer, rec_size, (U32*) & size);
- }
- else
- {
- g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
- return;
- }
- if (size <= 0)
- {
- g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
- return;
- }
- ebr_frm_start_decompression(g_curr_book_cntx_p->buffer, g_curr_book_cntx_p->for_unicode_buffer, (U32*) & size);
- mmi_chset_use_space_for_unknown_character();
- total_bytes_converted = mmi_chset_convert(
- (mmi_chset_enum) mmiEncoding,
- MMI_CHSET_UCS2,
- (char*)g_curr_book_cntx_p->buffer,
- (char*)g_curr_book_cntx_p->start,
- EBR_RECORD_SIZE_MAX * 2 + 10);
- mmi_chset_do_not_use_space_for_unknown_character();
- converted_str_len = pfnUnicodeStrlen((S8*) g_curr_book_cntx_p->start);
- if (converted_str_len != (total_bytes_converted - 2) / 2)
- {
- g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
- FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
- }
- else if (mmiEncoding == MMI_CHSET_UTF8 && (total_bytes_converted - 2) < (size / 2))
- {
- g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
- FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
- }
- #ifdef __MMI_CHSET_BIG5__
- else if (mmiEncoding == MMI_CHSET_BIG5 && (total_bytes_converted - 2) < (size))
- {
- g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
- FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
- }
- #endif /* __MMI_CHSET_BIG5__ */
- #ifdef __MMI_CHSET_GB2312__
- else if (mmiEncoding == MMI_CHSET_GB2312 && (total_bytes_converted - 2) < (size))
- {
- g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
- FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
- }
- #endif /* __MMI_CHSET_GB2312__ */
- if (record_id == g_curr_book_cntx_p->num_records)
- {
- FS_Write(new_file_hnd, g_curr_book_cntx_p->start, total_bytes_converted, (U32*) & size);
- }
- else
- {
- memset(g_curr_book_cntx_p->buffer, 0, sizeof(g_curr_book_cntx_p->buffer));
- FS_Write(new_file_hnd, g_curr_book_cntx_p->start, total_bytes_converted - 2, (U32*) & size);
- }
- }
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_convert_record_record_recursively
- * DESCRIPTION
- * Convert record recursively
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_convert_record_record_recursively(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U32 size;
- static U32 failure_count = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- StopTimer(EBOOK_RECURSIVE_TIMER);
- if (g_curr_book_cntx_p->g_record_id <= g_curr_book_cntx_p->num_records)
- {
- FILE_HANDLE file_hnd, new_file_hnd;
- file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->book_name_path, FS_READ_ONLY);
- if (g_curr_book_cntx_p->g_record_id == 1)
- {
- new_file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path, FS_CREATE_ALWAYS | FS_ATTR_HIDDEN);
- failure_count = 0;
- }
- else
- {
- new_file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path, FS_READ_WRITE);
- if (file_hnd > 0)
- {
- FS_Seek(file_hnd, g_curr_book_cntx_p->g_file_hnd_offset, FS_FILE_BEGIN);
- }
- if (new_file_hnd > 0)
- {
- FS_Seek(new_file_hnd, 0, FS_FILE_END);
- }
- }
- if (new_file_hnd > 0 && file_hnd > 0)
- {
- S32 count = 0;
- while (count < MAX_RECORD_CONVERT_EACH_RECURSION)
- {
- ebr_frm_convert_record(file_hnd, new_file_hnd, g_curr_book_cntx_p->g_record_id);
- g_curr_book_cntx_p->g_record_id++;
- count++;
- if (g_curr_book_cntx_p->g_record_id > g_curr_book_cntx_p->num_records)
- {
- break;
- }
- }
- g_curr_book_cntx_p->g_file_hnd_offset = FS_Seek(file_hnd, 0, FS_FILE_CURRENT);
- failure_count = 0;
- }
- else
- {
- failure_count++;
- if (failure_count == MAX_FAILURE_RETRIES)
- {
- g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
- }
- }
- if (file_hnd > 0)
- {
- FS_Close(file_hnd);
- }
- if (new_file_hnd > 0)
- {
- FS_Close(new_file_hnd);
- }
- if(file_hnd>0)
- {
- if (g_curr_book_cntx_p->g_record_id > g_curr_book_cntx_p->num_records)
- {
- StartTimer(EBOOK_RECURSIVE_TIMER, 10, ebr_frm_convert_record_record_recursively);
- }
- else
- {
- StartTimer(EBOOK_RECURSIVE_TIMER, 10, ebr_frm_convert_record_record_recursively);
- }
- }
- else
- {
- g_curr_book_cntx_p->state_recursive_conversion = EBR_FRM_NFO_CONVERSION_COMPLETED;
- g_curr_book_cntx_p->g_recursive_callback_fn();
- }
- }
- else
- {
- FILE_HANDLE nfo_handle, new_file_hnd = 0;
- U8 nfo_extension_name[MAX_EBOOK_NAME_LENGTH];
- new_file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path, FS_READ_WRITE);
- FS_Seek(new_file_hnd, 0, FS_FILE_END);
- nfo_handle = ebr_frm_get_nfo_handle();
- FS_Seek(nfo_handle, 0, FS_FILE_BEGIN);
- g_curr_book_cntx_p->g_nfo_book_struct.temp_encoding_file_format = mmi_ebook_util_get_chset(g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format);
- memset(g_curr_book_cntx_p->g_nfo_book_struct.temp_file_name, 0, MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH);
- pfnUnicodeStrncat(
- (PS8) g_curr_book_cntx_p->g_nfo_book_struct.temp_file_name,
- (const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name,
- pfnUnicodeStrlen((const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name) - 4);
- if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_TXT)
- {
- AnsiiToUnicodeString((S8*) nfo_extension_name, (S8*) TXT_TEMP_EXT_STR);
- }
- else
- {
- AnsiiToUnicodeString((S8*) nfo_extension_name, (S8*) PDB_TEMP_EXT_STR);
- }
- pfnUnicodeStrcat((PS8) g_curr_book_cntx_p->g_nfo_book_struct.temp_file_name, (PS8) nfo_extension_name);
- FS_GetFileSize(new_file_hnd, &g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size);
- FS_Write(
- nfo_handle,
- &g_curr_book_cntx_p->g_nfo_book_struct,
- sizeof(g_curr_book_cntx_p->g_nfo_book_struct),
- &size);
- FS_Close(nfo_handle);
- FS_Close(new_file_hnd);
- ebr_frm_set_temp_number_of_records();
- g_curr_book_cntx_p->state_recursive_conversion = EBR_FRM_NFO_CONVERSION_COMPLETED;
- if (GetExitScrnID() == SCR_ID_EBOOK_WAITSCREEN)
- {
- g_curr_book_cntx_p->g_recursive_callback_fn();
- }
- else
- {
- return;
- }
- }
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_create_temp_file_in_ucs2
- * DESCRIPTION
- * Get the record size for text file.
- * PARAMETERS
- * file_hnd [IN]
- * RETURNS
- * S16 error_type
- *****************************************************************************/
- S32 ebr_frm_create_temp_file_in_ucs2(FILE_HANDLE file_hnd)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- pBOOL is_temp_file_present = FALSE;
- FS_DiskInfo disk_info;
- U64 disk_free_space;
- U64 disk_total_space;
- S32 fs_ret;
- S8 file_path_in_ascii[5];
- S8 file_path[10];
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- ebr_frm_create_temp_file_path();
- /* NEERAJ START */
- FS_Seek(file_hnd, 0, FS_FILE_BEGIN);
- /* Check wether the file with this encoding exists before or not. */
- is_temp_file_present = ebr_frm_check_if_file_exists_or_not();
- if (!is_temp_file_present)
- {
- sprintf((char*)file_path_in_ascii, "%c", g_curr_book_cntx_p->memory_type_selected);
- strcat((char*)file_path_in_ascii, ":\");
- AnsiiToUnicodeString((PS8) file_path, file_path_in_ascii);
- fs_ret = FS_GetDiskInfo((PU16) file_path, &disk_info, FS_DI_BASIC_INFO | FS_DI_FREE_SPACE);
- disk_free_space = 0;
- disk_total_space = 0;
- if (fs_ret >= 0)
- {
- disk_free_space = disk_info.FreeClusters * disk_info.SectorsPerCluster * disk_info.BytesPerSector;
- disk_total_space = disk_info.TotalClusters * disk_info.SectorsPerCluster * disk_info.BytesPerSector;
- if (disk_free_space <= g_curr_book_cntx_p->g_nfo_book_struct.book_size * 2)
- {
- // ebr_app_dispaly_less_memory_pop_up();
- // FS_Close(file_hnd);
- return 0;
- }
- }
- FS_Close(file_hnd);
- g_curr_book_cntx_p->g_record_id = 1;
- g_curr_book_cntx_p->state_recursive_conversion = EBR_FRM_CONVERSION_UNDERWAY;
- ebr_frm_convert_record_record_recursively();
- }
- else
- {
- if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_PDB)
- {
- g_curr_book_cntx_p->pdb_converted_to_text = TRUE;
- }
- return 2;
- }
- return 1;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_check_if_file_exists_or_not
- * DESCRIPTION
- * Get the record size for text file.
- * PARAMETERS
- * void
- * RETURNS
- * S16 error_type
- *****************************************************************************/
- pBOOL ebr_frm_check_if_file_exists_or_not(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 mmiEncoding;
- FS_HANDLE fh_cur;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- mmiEncoding = mmi_ebook_util_get_chset(g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format);
- if (mmiEncoding == g_curr_book_cntx_p->g_nfo_book_struct.temp_encoding_file_format)
- {
- fh_cur = FS_Open((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path, FS_READ_ONLY);
- if (fh_cur == 0 || fh_cur < 0)
- {
- FS_Close(fh_cur);
- return FALSE;
- }
- else
- {
- FS_Close(fh_cur);
- return TRUE;
- }
- }
- else
- {
- FS_Delete((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path);
- return FALSE;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_create_temp_file_path
- * DESCRIPTION
- * Get the record size for text file.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_create_temp_file_path(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 nfo_extension_name[MAX_EBOOK_NAME_LENGTH];
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- pfnUnicodeStrcpy(
- (S8*) g_curr_book_cntx_p->temp_book_name_path,
- (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
- pfnUnicodeStrncat(
- (PS8) g_curr_book_cntx_p->temp_book_name_path,
- (PS8) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name,
- pfnUnicodeStrlen((const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name) - 4);
- if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_TXT)
- {
- AnsiiToUnicodeString((S8*) nfo_extension_name, (S8*) TXT_TEMP_EXT_STR);
- }
- else
- {
- AnsiiToUnicodeString((S8*) nfo_extension_name, (S8*) PDB_TEMP_EXT_STR);
- }
- pfnUnicodeStrcat((PS8) g_curr_book_cntx_p->temp_book_name_path, (PS8) nfo_extension_name);
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_create_temp_file_txt
- * DESCRIPTION
- * Get the record size for text file.
- * PARAMETERS
- * rec_num [IN]
- * RETURNS
- * S16 error_type
- *****************************************************************************/
- S32 ebr_frm_create_temp_file_txt(S32 rec_num)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 rec_size;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (rec_num < g_curr_book_cntx_p->num_records)
- {
- rec_size = EBR_RECORD_SIZE_MAX;
- }
- else
- {
- rec_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size % EBR_RECORD_SIZE_MAX;
- }
- return rec_size;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_get_record_size_txt
- * DESCRIPTION
- *
- * PARAMETERS
- * rec_num [IN]
- * RETURNS
- *
- *****************************************************************************/
- S32 ebr_frm_get_record_size_txt(S32 rec_num)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 rec_size;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (rec_num < g_curr_book_cntx_p->num_records)
- {
- rec_size = EBR_RECORD_SIZE_MAX;
- }
- else
- {
- if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
- {
- rec_size = g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size % EBR_RECORD_SIZE_MAX;
- }
- else
- {
- rec_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size % EBR_RECORD_SIZE_MAX;
- }
- }
- return rec_size;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_get_record_size_pdb
- * DESCRIPTION
- * Get the offset for the current record to be displayed
- * PARAMETERS
- * file_hnd [IN]
- * offset [IN]
- * rec_num [IN]
- * RETURNS
- * S32
- *****************************************************************************/
- S32 ebr_frm_get_record_size_pdb(FILE_HANDLE file_hnd, S32 offset, S32 rec_num)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 size, rec_size;
- U32 next_offset;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (rec_num < g_curr_book_cntx_p->num_records)
- {
- SEEK_REC_ENTRY(file_hnd, rec_num + 1);
- if (FS_Read(file_hnd, &next_offset, 4, (U32*) & size) == FS_NO_ERROR)
- {
- next_offset = ntohl(next_offset);
- }
- rec_size = next_offset - offset;
- }
- else
- {
- rec_size = EBR_RECORD_SIZE_MAX;
- }
- return rec_size;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_start_decompression
- * DESCRIPTION
- * Start decompression
- * PARAMETERS
- * decompressed_buffer [IN]
- * compressed_buffer [IN]
- * size [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_start_decompression(U8 *decompressed_buffer, U8 *compressed_buffer, U32 *size)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U32 i, j = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- for (i = 0; i < *size;)
- {
- unsigned c = compressed_buffer[i++];
- if (c >= 1 && c <= 8)
- while (c--)
- /* copy 'c' bytes */
- {
- if (j >= EBR_RECORD_SIZE_MAX)
- {
- goto end;
- }
- decompressed_buffer[j++] = compressed_buffer[i++];
- }
- else if (c <= 0x7F)
- /* 0,09-7F = self */
- {
- if (j >= EBR_RECORD_SIZE_MAX)
- {
- goto end;
- }
- decompressed_buffer[j++] = c;
- }
- else if (c >= 0xC0) /* space + ASCII char */
- {
- if (j >= EBR_RECORD_SIZE_MAX - 1)
- {
- goto end;
- }
- decompressed_buffer[j++] = ' ', decompressed_buffer[j++] = c ^ 0x80;
- }
- else
- { /* 80-BF = sequences */
- S32 di, n;
- c = (c << 8) + compressed_buffer[i++];
- di = (c & 0x3FFF) >> COUNT_BITS;
- for (n = (c & ((1 << COUNT_BITS) - 1)) + 3; n--; ++j)
- {
- if (j >= EBR_RECORD_SIZE_MAX)
- {
- goto end;
- }
- decompressed_buffer[j] = decompressed_buffer[j - di];
- }
- }
- }
- end:
- *size = j;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_decompress_pdb
- * DESCRIPTION
- * Decompress the PDB record
- * PARAMETERS
- * b [IN]
- * size [IN]
- * copy_type [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_decompress_pdb(U8 *b, U32 *size, ebr_frm_copy_type_enum copy_type)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U32 offset = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- switch (copy_type)
- {
- case EBR_FRM_COPY_TYPE_FIRST:
- memset(g_curr_book_cntx_p->start, 0, EBR_RECORD_SIZE_MAX * 2);
- offset = 0;
- break;
- case EBR_FRM_COPY_TYPE_SECOND:
- memset(g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, 0, EBR_RECORD_SIZE_MAX);
- offset = EBR_RECORD_SIZE_MAX;
- break;
- case EBR_FRM_COPY_TYPE_NEXT:
- memcpy(g_curr_book_cntx_p->start, g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, EBR_RECORD_SIZE_MAX);
- memset(g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, 0, EBR_RECORD_SIZE_MAX);
- offset = EBR_RECORD_SIZE_MAX;
- break;
- case EBR_FRM_COPY_TYPE_PREVIOUS:
- memcpy(g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, g_curr_book_cntx_p->start, EBR_RECORD_SIZE_MAX);
- memset(g_curr_book_cntx_p->start, 0, EBR_RECORD_SIZE_MAX);
- offset = 0;
- break;
- }
- ebr_frm_start_decompression(g_curr_book_cntx_p->start + offset, b, size);
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_get_data_to_open_book
- * DESCRIPTION
- * Get the g_curr_book_cntx_p->buffer
- * PARAMETERS
- * ebook_frm_setting [IN]
- * buffer_data [IN]
- * book_display_name [IN]
- * RETURNS
- * U8*
- *****************************************************************************/
- S16 ebr_frm_get_data_to_open_book(gui_page_info_app *ebook_frm_setting, U8 *buffer_data, S8 *book_display_name)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- FILE_HANDLE nfo_hnd_local;
- S32 start_id, end_id;
- U8 mmiEncoding = 0;
- S16 returnval;
- S32 buffer_length, book_size = 0;
- S16 ebr_page_size;
- U32 strlength = 0;
- U8* buffer_start;
- U8 UCS2headerle[] = {0xFF,0xFE};
- U8 UCS2headerbe[] = {0xFE,0xFF};
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* Check here if the call is from file manager or not */
- memset(ebook_frm_setting, 0, sizeof(ebook_frm_setting));
- /* g_curr_book_cntx_p->g_nfo_book_struct.book_size = 0; */
- nfo_hnd_local = ebr_frm_get_nfo_handle();
- if (nfo_hnd_local <= 0)
- {
- return -1;
- }
- FS_Close(nfo_hnd_local);
- ebr_frm_get_book_encoding_type();
- memset(g_curr_book_cntx_p->start, 0, sizeof(g_curr_book_cntx_p->start));
- memset(g_curr_book_cntx_p->buffer, 0, sizeof(g_curr_book_cntx_p->buffer));
- if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
- {
- book_size = g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size;
- if (book_size < 0)
- {
- return 3;
- }
- }
- else
- {
- book_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size;
- if (book_size < 0)
- {
- return 3;
- }
- ebr_frm_set_number_of_records();
- }
- if (g_curr_book_cntx_p->is_book_in_unicode || g_curr_book_cntx_p->book_is_in_other_encoding_format ||
- g_curr_book_cntx_p->book_is_in_other_encoding_format)
- {
- ebr_page_size = EBR_PAGE_SIZE * 2;
- }
- else
- {
- ebr_page_size = EBR_PAGE_SIZE;
- ebr_frm_set_number_of_records();
- }
- if(g_curr_book_cntx_p->book_is_in_other_encoding_format)
- {
- ebr_frm_create_temp_file_path();
- if(ebr_frm_check_if_file_exists_or_not())
- {
- ebr_frm_set_temp_number_of_records();
- }
- else
- {
- ebr_frm_set_number_of_records();
- }
- }
- g_curr_book_cntx_p->g_start_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id;
- g_curr_book_cntx_p->prev_end_id = g_curr_book_cntx_p->g_start_id;
- g_curr_book_cntx_p->g_offset = g_curr_book_cntx_p->g_nfo_book_struct.offset;
- if (g_curr_book_cntx_p->num_records == 0)
- {
- return 2;
- }
- if (g_curr_book_cntx_p->g_start_id != 0)
- {
- if (!g_curr_book_cntx_p->ebr_frm_end_book_flag ||
- ((g_curr_book_cntx_p->g_nfo_book_struct.current_page_id + 4) * ebr_page_size >= (U32) book_size ||
- (g_curr_book_cntx_p->g_nfo_book_struct.offset > (U32) ebr_page_size * 3 ||
- g_curr_book_cntx_p->g_nfo_book_struct.jump_offset > (U32) ebr_page_size * 3)) &&
- (!g_curr_book_cntx_p->search_flag_is_on))
- {
- start_id = (g_curr_book_cntx_p->g_start_id) % (EBR_RECORD_SIZE_MAX / ebr_page_size);
- if ((start_id + EBR_RECORD_SIZE_MAX / ebr_page_size + 3) <= (EBR_RECORD_SIZE_MAX / ebr_page_size) * 2 - 1)
- {
- start_id += EBR_RECORD_SIZE_MAX / ebr_page_size;
- }
- else if (g_curr_book_cntx_p->g_start_id / (EBR_RECORD_SIZE_MAX / ebr_page_size) == g_curr_book_cntx_p->num_records - 1)
- {
- start_id += (EBR_RECORD_SIZE_MAX / ebr_page_size - start_id);
- }
- if (book_size < EBR_RECORD_SIZE_MAX)
- {
- start_id = g_curr_book_cntx_p->g_start_id;
- }
- }
- else
- {
- start_id = g_curr_book_cntx_p->g_start_id % (EBR_RECORD_SIZE_MAX / ebr_page_size);
- /* This check si required when the end page id to jump at is the last page id and it may come in
- first record */
- if (g_curr_book_cntx_p->g_start_id / (EBR_RECORD_SIZE_MAX / ebr_page_size) + 2 >
- g_curr_book_cntx_p->num_records)
- {
- start_id -= EBR_RECORD_SIZE_MAX / ebr_page_size;
- }
- if (book_size < EBR_RECORD_SIZE_MAX)
- {
- start_id = g_curr_book_cntx_p->g_start_id;
- }
- }
- }
- else
- {
- start_id = 0;
- }
- if (start_id < 0)
- {
- g_curr_book_cntx_p->g_start_id =
- g_curr_book_cntx_p->g_nfo_book_struct.current_page_id - EBR_RECORD_SIZE_MAX / ebr_page_size;
- if (g_curr_book_cntx_p->g_start_id < 0)
- {
- g_curr_book_cntx_p->g_start_id = 0;
- }
- }
- g_curr_book_cntx_p->g_end_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id + 3;
- returnval = ebr_frm_decode_header((U8*) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
- if (returnval == 0)
- {
- return 0;
- }
- if (returnval == 2)
- {
- return 3;
- }
- if (g_curr_book_cntx_p->state_recursive_conversion == EBR_FRM_CONVERSION_UNDERWAY)
- {
- return 1;
- }
- if (start_id < 0)
- {
- if (start_id == -1)
- {
- start_id += EBR_RECORD_SIZE_MAX / ebr_page_size;
- }
- else
- {
- start_id += (EBR_RECORD_SIZE_MAX / ebr_page_size * 2);
- }
- if (g_curr_book_cntx_p->is_book_in_unicode)
- {
- if (start_id > 5)
- {
- start_id = 5;
- }
- }
- if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
- {
- if (start_id >= 4 && (g_curr_book_cntx_p->g_nfo_book_struct.current_page_id >4))
- {
- if(g_curr_book_cntx_p->search_flag_is_on)
- {
- }
- else
- {
- start_id = 4;
- }
- }
- else
- {
- if(g_curr_book_cntx_p->g_nfo_book_struct.current_page_id<=4)
- {
- start_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id;
- }
- }
- }
- }
- end_id = start_id + 3;
- memset(g_curr_book_cntx_p->buffer, 0, ebr_page_size * 4);
- memcpy(g_curr_book_cntx_p->buffer, g_curr_book_cntx_p->start + ebr_page_size * start_id, ebr_page_size * 4);
- buffer_length = pfnUnicodeStrlen((const S8*)g_curr_book_cntx_p->buffer);
- mmiEncoding = mmi_ebook_util_get_chset(g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format);
- if ((mmiEncoding == MMI_CHSET_UCS2 || g_curr_book_cntx_p->book_is_in_other_encoding_format) && g_curr_book_cntx_p->g_start_id == 0)
- {
- buffer_start = g_curr_book_cntx_p->buffer;
- while (!pfnUnicodeStrncmp((S8*)buffer_start, (S8*)UCS2headerle,1))
- {
- buffer_start[0] = WHITE_SPACE;
- buffer_start[1] = 0;
- buffer_start += 2;
- }
- while (!pfnUnicodeStrncmp((S8*)buffer_start, (S8*)UCS2headerbe,1))
- {
- buffer_start[0] = WHITE_SPACE;
- buffer_start[1] = 0;
- buffer_start += 2;
- }
- }
- switch (mmiEncoding)
- {
- case MMI_CHSET_UCS2:
- pfnUnicodeStrncpy(
- (PS8) buffer_data,
- (PS8) g_curr_book_cntx_p->buffer,
- (EBR_RECORD_SIZE_MAX + GUI_SHARED_BYTES) / 2);
- break;
- case MMI_CHSET_WESTERN_WIN:
- returnval = AnsiiNToUnicodeString(
- (PS8) buffer_data,
- (PS8) g_curr_book_cntx_p->buffer,
- (EBR_RECORD_SIZE_MAX + GUI_SHARED_BYTES) / 2);
- break;
- default:
- pfnUnicodeStrncpy(
- (PS8) buffer_data,
- (PS8) g_curr_book_cntx_p->buffer,
- (EBR_RECORD_SIZE_MAX + GUI_SHARED_BYTES) / 2);
- break;
- }
- if (g_curr_book_cntx_p->is_book_in_unicode)
- {
- ebook_frm_setting->doc_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size / 2;
- }
- else
- {
- if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
- {
- ebook_frm_setting->doc_size = g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size / 2;
- }
- else
- {
- ebook_frm_setting->doc_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size;
- }
- }
- if (ebook_frm_setting->doc_size < EBR_PAGE_SIZE * 4)
- {
- ebook_frm_setting->end_id = ebook_frm_setting->doc_size / EBR_PAGE_SIZE - 1;
- if (ebook_frm_setting->doc_size % EBR_PAGE_SIZE != 0)
- {
- ebook_frm_setting->end_id = ebook_frm_setting->end_id + 1;
- }
- if (ebook_frm_setting->doc_size <= EBR_PAGE_SIZE)
- {
- ebook_frm_setting->end_id = 1;
- ebook_frm_setting->start_id = 0;
- }
- else
- {
- ebook_frm_setting->start_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id;
- }
- }
- else
- {
- ebook_frm_setting->start_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id; /* -reduce_start_id_by; */
- if ((book_size - g_curr_book_cntx_p->g_nfo_book_struct.current_page_id * EBR_PAGE_SIZE) < EBR_RECORD_SIZE_MAX)
- {
- if (book_size - g_curr_book_cntx_p->g_nfo_book_struct.current_page_id * EBR_PAGE_SIZE > EBR_PAGE_SIZE * 3)
- {
- ebook_frm_setting->end_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id + 3;
- }
- else
- {
- ebook_frm_setting->end_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id + 2;
- }
- }
- else
- {
- ebook_frm_setting->end_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id + 3;
- }
- }
- ebook_frm_setting->font_style = g_curr_book_cntx_p->g_nfo_book_struct.settings.font_style;
- ebook_frm_setting->font_size = g_curr_book_cntx_p->g_nfo_book_struct.settings.font_size;
- ebook_frm_setting->scroll_speed =
- g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_speed + 1;
- ebook_frm_setting->scroll_type = g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_type;
- ebook_frm_setting->text_offset = g_curr_book_cntx_p->g_nfo_book_struct.offset;
- ebook_frm_setting->jump_offset_from_app = g_curr_book_cntx_p->g_nfo_book_struct.jump_offset;
- ebook_frm_setting->scroll_flag = g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_flag;
- ebook_frm_setting->jump_to_end = g_curr_book_cntx_p->ebr_frm_end_book_flag;
- ebook_frm_setting->search_str_len = g_curr_book_cntx_p->ebr_search_strlen;
- ebook_frm_setting->highlight_string = g_curr_book_cntx_p->highlight_string_flag;
- ebook_frm_setting->search_flag_is_on = g_curr_book_cntx_p->search_flag_is_on;
- ebook_frm_setting->last_text_offset_y = g_curr_book_cntx_p->g_nfo_book_struct.last_text_offset_y;
- #ifdef __MMI_TOUCH_SCREEN__
- ebook_frm_setting->get_data_during_scrolling = ebr_frm_get_data_during_scrolling;
- #endif
- if (g_curr_book_cntx_p->search_flag_is_on == 0)
- {
- ebook_frm_setting->last_showed_percentage = g_curr_book_cntx_p->g_nfo_book_struct.last_showed_percentage;
- }
- else
- {
- ebook_frm_setting->last_showed_percentage = 0;
- }
- g_curr_book_cntx_p->highlight_string_flag = 0;
- g_curr_book_cntx_p->search_flag_is_on = 0;
- g_curr_book_cntx_p->ebr_frm_end_book_flag = 1;
- strlength = pfnUnicodeStrlen((const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
- pfnUnicodeStrncpy(
- (S8*) book_display_name,
- (S8*) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name,
- strlength - EBR_EXTENSION_NAME_LENGTH - 1);
- return 1;
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_get_book_encoding_type
- * DESCRIPTION
- * Get encoding type
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void ebr_frm_get_book_encoding_type(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 mmiEncoding = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- mmiEncoding = mmi_ebook_util_get_chset(g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format);
- if (mmiEncoding != MMI_CHSET_WESTERN_WIN)
- {
- if ((mmiEncoding == MMI_CHSET_UCS2))
- {
- g_curr_book_cntx_p->is_book_in_unicode = TRUE;
- g_curr_book_cntx_p->book_is_in_other_encoding_format = FALSE;
- }
- else
- {
- g_curr_book_cntx_p->is_book_in_unicode = FALSE;
- g_curr_book_cntx_p->book_is_in_other_encoding_format = TRUE;
- }
- }
- else
- {
- g_curr_book_cntx_p->is_book_in_unicode = FALSE;
- g_curr_book_cntx_p->book_is_in_other_encoding_format = FALSE;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * ebr_frm_get_encoded_data
- * DESCRIPTION