EbookFramework.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:303k
源码类别:

MTK

开发平台:

C/C++

  1.  *  img_buff_p          [IN]        
  2.  *  str_img_mask        [IN]        
  3.  * RETURNS
  4.  *  void
  5.  *****************************************************************************/
  6. pBOOL ebr_get_book_mark_name_list(S32 item_index, UI_string_type str_buff, PU8 *img_buff_p, U8 str_img_mask)
  7. {
  8.     /*----------------------------------------------------------------*/
  9.     /* Local Variables                                                */
  10.     /*----------------------------------------------------------------*/
  11.     /*----------------------------------------------------------------*/
  12.     /* Code Body                                                      */
  13.     /*----------------------------------------------------------------*/
  14.     pfnUnicodeStrcpy(
  15.         (S8*) str_buff,
  16.         (S8*) g_curr_book_cntx_p->g_nfo_book_struct.book_marks[item_index].bookmark_name);
  17.     *img_buff_p = get_image(gIndexIconsImageList[item_index]);
  18.     return TRUE;
  19. }
  20. /*****************************************************************************
  21.  * FUNCTION
  22.  *  ebr_frm_get_count_of_book_marks
  23.  * DESCRIPTION
  24.  *  Count the number of book marks present
  25.  * PARAMETERS
  26.  *  void
  27.  * RETURNS
  28.  *  S16
  29.  *****************************************************************************/
  30. S16 ebr_frm_get_count_of_book_marks(void)
  31. {
  32.     /*----------------------------------------------------------------*/
  33.     /* Local Variables                                                */
  34.     /*----------------------------------------------------------------*/
  35.     S16 no_of_book_marks = 0;
  36.     /*----------------------------------------------------------------*/
  37.     /* Code Body                                                      */
  38.     /*----------------------------------------------------------------*/
  39.     while (g_curr_book_cntx_p->g_nfo_book_struct.book_marks[no_of_book_marks].bookmark_name[0] != 0 && (no_of_book_marks<EBR_FRM_MAX_NO_OF_BOOKMARKS))
  40.     {
  41.         no_of_book_marks++;
  42.     }
  43.     return no_of_book_marks;
  44. }
  45. /*****************************************************************************
  46.  * FUNCTION
  47.  *  ebr_frm_get_full_screen_flag_status
  48.  * DESCRIPTION
  49.  *  Get the status of full screen flag
  50.  * PARAMETERS
  51.  *  void
  52.  * RETURNS
  53.  *  S16
  54.  *****************************************************************************/
  55. S16 ebr_frm_get_full_screen_flag_status(void)
  56. {
  57.     /*----------------------------------------------------------------*/
  58.     /* Local Variables                                                */
  59.     /*----------------------------------------------------------------*/
  60.     /*----------------------------------------------------------------*/
  61.     /* Code Body                                                      */
  62.     /*----------------------------------------------------------------*/
  63.     if (g_curr_book_cntx_p->g_nfo_book_struct.settings.screen_mode == 0)
  64.     {
  65.         return 0;
  66.     }
  67.     else
  68.     {
  69.         return 1;
  70.     }
  71. }
  72. /*****************************************************************************
  73.  * FUNCTION
  74.  *  ebr_frm_get_auto_scroll_flag_status
  75.  * DESCRIPTION
  76.  *  Get the status of full screen flag
  77.  * PARAMETERS
  78.  *  void
  79.  * RETURNS
  80.  *  S16
  81.  *****************************************************************************/
  82. S16 ebr_frm_get_auto_scroll_flag_status(void)
  83. {
  84.     /*----------------------------------------------------------------*/
  85.     /* Local Variables                                                */
  86.     /*----------------------------------------------------------------*/
  87.     /*----------------------------------------------------------------*/
  88.     /* Code Body                                                      */
  89.     /*----------------------------------------------------------------*/
  90.     if (g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_flag == 0)
  91.     {
  92.         return 0;
  93.     }
  94.     else
  95.     {
  96.         return 1;
  97.     }
  98. }
  99. /*****************************************************************************
  100.  * FUNCTION
  101.  *  ebr_frm_create_new_file_path
  102.  * DESCRIPTION
  103.  *  
  104.  * PARAMETERS
  105.  *  void
  106.  * RETURNS
  107.  *  void
  108.  *****************************************************************************/
  109. void ebr_frm_create_new_file_path(void)
  110. {
  111.     /*----------------------------------------------------------------*/
  112.     /* Local Variables                                                */
  113.     /*----------------------------------------------------------------*/
  114.     /*----------------------------------------------------------------*/
  115.     /* Code Body                                                      */
  116.     /*----------------------------------------------------------------*/
  117.     memset(g_curr_book_cntx_p->fmgr_file_path, 0, sizeof(g_curr_book_cntx_p->fmgr_file_path));
  118.     pfnUnicodeStrcpy(
  119.             (S8*) g_curr_book_cntx_p->fmgr_file_path,
  120.             (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  121. }
  122. /*****************************************************************************
  123.  * FUNCTION
  124.  *  ebr_fmgr_is_book_shelf_path
  125.  * DESCRIPTION
  126.  *  Check whetther the path is for bookshelf
  127.  * PARAMETERS
  128.  *  path        [IN]        
  129.  * RETURNS
  130.  *  S32
  131.  *****************************************************************************/
  132. S32 ebr_fmgr_is_book_shelf_path(PS8 path)
  133. {
  134.     /*----------------------------------------------------------------*/
  135.     /* Local Variables                                                */
  136.     /*----------------------------------------------------------------*/
  137.     U8 nfo_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH] = {0};
  138.     U32 driveCount = 0;
  139.     S8 driveLatter[FMGR_TOTAL_STORAGE];    
  140.     U8 driveNum;
  141.     /*----------------------------------------------------------------*/
  142.     /* Code Body                                                      */
  143.     /*----------------------------------------------------------------*/
  144.     
  145.     memset(driveLatter, 0, FMGR_TOTAL_STORAGE);
  146.     mmi_fmgr_get_exist_drive_letter(driveLatter, &driveNum);
  147.         
  148.     while (driveLatter[driveCount] != 0)
  149.     {
  150.         pfnUnicodeStrcpy((S8*) nfo_path, (S8*) ebr_frm_get_file_path(driveLatter[driveCount], EBR_FRM_SEARCH_DEFAULT));
  151.         ebr_frm_convert_to_upper((S16*) nfo_path);
  152.         ebr_frm_convert_to_upper((S16*) path);    
  153.         if (!pfnUnicodeStrcmp((S8*) nfo_path, (S8*) path))
  154.         {
  155.      g_curr_book_cntx_p->memory_type_selected = driveLatter[driveCount];
  156.             return driveLatter[driveCount];             
  157.         }
  158. driveCount++;
  159.     }
  160.     return -1;
  161.         
  162. }
  163. /*****************************************************************************
  164.  * FUNCTION
  165.  *  ebr_fmgr_get_file_name
  166.  * DESCRIPTION
  167.  *  
  168.  * PARAMETERS
  169.  *  void
  170.  * RETURNS
  171.  *  
  172.  *****************************************************************************/
  173. S8 *ebr_fmgr_get_file_name(void)
  174. {
  175.     /*----------------------------------------------------------------*/
  176.     /* Local Variables                                                */
  177.     /*----------------------------------------------------------------*/
  178.     /*----------------------------------------------------------------*/
  179.     /* Code Body                                                      */
  180.     /*----------------------------------------------------------------*/
  181.     return (S8*) g_curr_book_cntx_p->book_name_path;
  182. }
  183. /*****************************************************************************
  184.  * FUNCTION
  185.  *  ebr_fmgr_set_file_type
  186.  * DESCRIPTION
  187.  *  Set the file type
  188.  * PARAMETERS
  189.  *  file_name       [IN]        
  190.  *  type        [IN]        
  191.  * RETURNS
  192.  *  void
  193.  *****************************************************************************/
  194. void ebr_fmgr_set_file_type(S8 *file_name)
  195. {
  196.     /*----------------------------------------------------------------*/
  197.     /* Local Variables                                                */
  198.     /*----------------------------------------------------------------*/
  199.     S16 strlen_file_name = 0;
  200.     /*----------------------------------------------------------------*/
  201.     /* Code Body                                                      */
  202.     /*----------------------------------------------------------------*/
  203.     strlen_file_name = pfnUnicodeStrlen((const S8*)file_name);
  204.     if ((g_curr_book_cntx_p->nfo_name[strlen_file_name * 2 - 6] == 't') ||
  205.         (g_curr_book_cntx_p->nfo_name[strlen_file_name * 2 - 6] == 'T'))
  206.     {
  207.         g_curr_book_cntx_p->g_fmgr_book_type = EBR_FRM_FILE_TYPE_TXT;
  208.     }
  209.     else
  210.     {
  211.         g_curr_book_cntx_p->g_fmgr_book_type = EBR_FRM_FILE_TYPE_PDB;
  212.     }
  213. }
  214. /*****************************************************************************
  215.  * FUNCTION
  216.  *  ebr_fmgr_set_file_name
  217.  * DESCRIPTION
  218.  *  Sets the File name for File manager
  219.  * PARAMETERS
  220.  *  fmgr_file_name      [IN]        
  221.  * RETURNS
  222.  *  void
  223.  *****************************************************************************/
  224. void ebr_fmgr_set_file_name(PS8 fmgr_file_name)
  225. {
  226.     /*----------------------------------------------------------------*/
  227.     /* Local Variables                                                */
  228.     /*----------------------------------------------------------------*/
  229.     /*----------------------------------------------------------------*/
  230.     /* Code Body                                                      */
  231.     /*----------------------------------------------------------------*/
  232.     pfnUnicodeStrcpy((S8*) g_curr_book_cntx_p->book_name_path, (S8*) fmgr_file_name);
  233. }
  234. /*****************************************************************************
  235.  * FUNCTION
  236.  *  ebr_set_selected_file_name
  237.  * DESCRIPTION
  238.  *  Gets the name of the selected book
  239.  * PARAMETERS
  240.  *  file_info       [IN]        
  241.  * RETURNS
  242.  *  void
  243.  *****************************************************************************/
  244. void ebr_set_selected_file_name(FMGR_FILE_INFO_STRUCT *file_info)
  245. {
  246.     /*----------------------------------------------------------------*/
  247.     /* Local Variables                                                */
  248.     /*----------------------------------------------------------------*/
  249.     U8 tmp_path_buf[(FMGR_MAX_PATH_LEN + 1) * ENCODING_LENGTH];
  250.     
  251.     /*----------------------------------------------------------------*/
  252.     /* Code Body                                                      */
  253.     /*----------------------------------------------------------------*/
  254.     if (file_info->is_short)
  255.     {
  256.         memset(tmp_path_buf, 0, (FMGR_MAX_PATH_LEN + 1) * ENCODING_LENGTH);
  257.         mmi_chset_mixed_text_to_ucs2_str(
  258.                     (U8*) tmp_path_buf,
  259.                     (FMGR_MAX_PATH_LEN + 1) * ENCODING_LENGTH,
  260.                     (U8*) file_info->file_name,
  261.                     g_chset_text_encoding);
  262.         pfnUnicodeStrcpy((S8*) g_curr_book_cntx_p->nfo_name, (S8*) tmp_path_buf);
  263.     }
  264.     else
  265.     {
  266.         pfnUnicodeStrcpy((S8*) g_curr_book_cntx_p->nfo_name, (S8*) file_info->file_name);
  267.     }
  268. }
  269. /*****************************************************************************
  270.  * FUNCTION
  271.  *  ebr_get_selected_file_name
  272.  * DESCRIPTION
  273.  *  Gets the name of the selected book
  274.  * PARAMETERS
  275.  *  void
  276.  * RETURNS
  277.  *  S8*
  278.  *****************************************************************************/
  279. U8 *ebr_get_selected_file_name(void)
  280. {
  281.     /*----------------------------------------------------------------*/
  282.     /* Local Variables                                                */
  283.     /*----------------------------------------------------------------*/
  284.     /*----------------------------------------------------------------*/
  285.     /* Code Body                                                      */
  286.     /*----------------------------------------------------------------*/
  287.     return (U8*) g_curr_book_cntx_p->nfo_name;
  288. }
  289. /*****************************************************************************
  290.  * FUNCTION
  291.  *  ebr_frm_get_book_size
  292.  * DESCRIPTION
  293.  *  Gets the Size of the ebook
  294.  * PARAMETERS
  295.  *  void
  296.  * RETURNS
  297.  *  S8*
  298.  *****************************************************************************/
  299. S32 ebr_frm_get_book_size(void)
  300. {
  301.     /*----------------------------------------------------------------*/
  302.     /* Local Variables                                                */
  303.     /*----------------------------------------------------------------*/
  304.     FILE_HANDLE file_hnd;
  305.     U32 file_size;
  306.     /*----------------------------------------------------------------*/
  307.     /* Code Body                                                      */
  308.     /*----------------------------------------------------------------*/
  309.     ebr_frm_create_book_path();
  310.     file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->book_name_path, FS_READ_ONLY);
  311.     FS_GetFileSize(file_hnd, (U32*) & file_size);
  312.     FS_Close(file_hnd);
  313.     return file_size;
  314. }
  315. /*****************************************************************************
  316.  * FUNCTION
  317.  *  ebr_frm_create_book_path
  318.  * DESCRIPTION
  319.  *  
  320.  * PARAMETERS
  321.  *  void
  322.  * RETURNS
  323.  *  void
  324.  *****************************************************************************/
  325. void ebr_frm_create_book_path(void)
  326. {
  327.     /*----------------------------------------------------------------*/
  328.     /* Local Variables                                                */
  329.     /*----------------------------------------------------------------*/
  330.     /*----------------------------------------------------------------*/
  331.     /* Code Body                                                      */
  332.     /*----------------------------------------------------------------*/
  333.     pfnUnicodeStrcpy(
  334.         (S8*) g_curr_book_cntx_p->book_name_path,
  335.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  336.     pfnUnicodeStrcat((PS8) g_curr_book_cntx_p->book_name_path, (PS8) g_curr_book_cntx_p->nfo_name);
  337. }
  338. /*****************************************************************************
  339.  * FUNCTION
  340.  *  ebr_frm_get_book_name
  341.  * DESCRIPTION
  342.  *  Gets the Name of the Ebook
  343.  * PARAMETERS
  344.  *  void
  345.  * RETURNS
  346.  *  S8*
  347.  *****************************************************************************/
  348. S8 *ebr_frm_get_book_name(void)
  349. {
  350.     /*----------------------------------------------------------------*/
  351.     /* Local Variables                                                */
  352.     /*----------------------------------------------------------------*/
  353.     /*----------------------------------------------------------------*/
  354.     /* Code Body                                                      */
  355.     /*----------------------------------------------------------------*/
  356.     return (S8*) g_curr_book_cntx_p->nfo_name;
  357. }
  358. /*****************************************************************************
  359.  * FUNCTION
  360.  *  ebr_frm_restore_default_book_shelf_settings
  361.  * DESCRIPTION
  362.  *  Restores the default settings for Book shelf
  363.  * PARAMETERS
  364.  *  void
  365.  * RETURNS
  366.  *  void
  367.  *****************************************************************************/
  368. S32 ebr_frm_restore_default_book_shelf_settings(void)
  369. {
  370.     /*----------------------------------------------------------------*/
  371.     /* Local Variables                                                */
  372.     /*----------------------------------------------------------------*/
  373.     S16 error;
  374.     ebr_frm_setting_struct g_setting;
  375.     ebr_frm_setting_struct *g_setting_list = &g_setting;
  376.     /*----------------------------------------------------------------*/
  377.     /* Code Body                                                      */
  378.     /*----------------------------------------------------------------*/
  379.     ReadRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  380. #ifndef MMI_ON_HARDWARE_P
  381.     if (g_setting_list->common_settings.encoding_format == 0xff)
  382.     {
  383.         g_setting_list->common_settings.encoding_format = EBOOK_WESTERN_WINDOWS;
  384.         g_setting_list->common_settings.font_size = EBR_FONT_SIZE_MEDIUM;
  385.         g_setting_list->common_settings.font_style = EBR_FONT_STYLE_NORMAL;
  386.         g_setting_list->memory_type = (S8)MMI_PUBLIC_DRV;
  387.         g_setting_list->common_settings.screen_mode = EBR_FULL_SCREEN_OFF;
  388.         g_setting_list->common_settings.auto_scroll_settings.scroll_flag = EBR_SCROLL_OFF;
  389.         g_setting_list->common_settings.auto_scroll_settings.scroll_speed = EBR_AUTO_SCROLL_SPEED_1;
  390.         g_setting_list->common_settings.auto_scroll_settings.scroll_type = EBR_SCROLL_BY_PAGE;
  391.     }
  392.     WriteRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  393. #endif /* MMI_ON_HARDWARE_P */ 
  394.     /* ebr_app_display_pop_up_default_settings_restored(); */
  395.     ebr_frm_restore_default_settings_for_each_book(g_setting_list);
  396.     return 1;
  397. }
  398. /*****************************************************************************
  399.  * FUNCTION
  400.  *  ebr_frm_restore_default_nvram
  401.  * DESCRIPTION
  402.  *  Restores Factory Default
  403.  * PARAMETERS
  404.  *  void
  405.  * RETURNS
  406.  *  void
  407.  *****************************************************************************/
  408. void ebr_frm_restore_default_nvram(void)
  409. {
  410.     /*----------------------------------------------------------------*/
  411.     /* Local Variables                                                */
  412.     /*----------------------------------------------------------------*/
  413.     S16 error;
  414.     ebr_frm_setting_struct g_setting;
  415.     ebr_frm_setting_struct *g_setting_list = &g_setting;
  416.     /*----------------------------------------------------------------*/
  417.     /* Code Body                                                      */
  418.     /*----------------------------------------------------------------*/
  419.     ReadRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  420.     g_setting_list->common_settings.encoding_format = EBOOK_WESTERN_WINDOWS;
  421.     g_setting_list->common_settings.font_size = EBR_FONT_SIZE_MEDIUM;
  422.     g_setting_list->common_settings.font_style = EBR_FONT_STYLE_NORMAL;
  423.     g_setting_list->memory_type = (S8)MMI_PUBLIC_DRV;
  424.     g_setting_list->common_settings.screen_mode = EBR_FULL_SCREEN_OFF;
  425.     g_setting_list->common_settings.auto_scroll_settings.scroll_flag = EBR_SCROLL_OFF;
  426.     g_setting_list->common_settings.auto_scroll_settings.scroll_speed = EBR_AUTO_SCROLL_SPEED_1;
  427.     g_setting_list->common_settings.auto_scroll_settings.scroll_type = EBR_SCROLL_BY_PAGE;
  428.     WriteRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  429. }
  430. /*****************************************************************************
  431.  * FUNCTION
  432.  *  ebr_frm_restore_default_settings_for_each_book
  433.  * DESCRIPTION
  434.  *  Restores the default settings for Book shelf
  435.  * PARAMETERS
  436.  *  g_setting_list      [IN]        
  437.  * RETURNS
  438.  *  void
  439.  *****************************************************************************/
  440. void ebr_frm_restore_default_settings_for_each_book(ebr_frm_setting_struct *g_setting_list)
  441. {
  442.     /*----------------------------------------------------------------*/
  443.     /* Local Variables                                                */
  444.     /*----------------------------------------------------------------*/
  445.     FS_HANDLE fh_cur;
  446.     FS_DOSDirEntry file_info;
  447.     S8 path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  448.     U8 filename[MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH];
  449.     U32 driveCount = 0;
  450.     S8 driveLatter[FMGR_TOTAL_STORAGE];
  451.     U8 driveNum;
  452.     
  453.     /*----------------------------------------------------------------*/
  454.     /* Code Body                                                      */
  455.     /*----------------------------------------------------------------*/
  456.     memset(driveLatter, 0, FMGR_TOTAL_STORAGE);
  457.     mmi_fmgr_get_exist_drive_letter(driveLatter, &driveNum);
  458.     
  459.     while (driveLatter[driveCount] != 0)
  460.     {
  461.         g_curr_book_cntx_p->memory_type_selected = driveLatter[driveCount];
  462.         pfnUnicodeStrcpy(
  463.             (S8*) path,
  464.             (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_NFO));
  465.         if ((fh_cur = FS_FindFirst(
  466.                         (const WCHAR*)path,
  467.                         0,
  468.                         0,
  469.                         &file_info,
  470.                         (U16*) filename,
  471.                         MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
  472.         {
  473.             do
  474.             {
  475.                 if (!(file_info.Attributes & FS_ATTR_DIR))
  476.                 {
  477.                     ebr_frm_open_nfo_file_and_restore_default(
  478.                         g_curr_book_cntx_p->memory_type_selected,
  479.                         filename,
  480.                         g_setting_list);
  481.                 }
  482.             } while ((FS_FindNext(fh_cur, &file_info, (U16*) filename, MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH) ==
  483.                       FS_NO_ERROR));
  484.             FS_FindClose(fh_cur);
  485.         }
  486.         driveCount++;
  487.     }
  488. }
  489. /*****************************************************************************
  490.  * FUNCTION
  491.  *  ebr_frm_open_nfo_file_and_restore_default
  492.  * DESCRIPTION
  493.  *  Restores the default settings for each book
  494.  * PARAMETERS
  495.  *  memory_type_selected        [IN]        
  496.  *  filename                    [IN]        
  497.  *  g_setting_list              [IN]        
  498.  * RETURNS
  499.  *  void
  500.  *****************************************************************************/
  501. void ebr_frm_open_nfo_file_and_restore_default(
  502.         S32 memory_type_selected,
  503.         U8 *filename,
  504.         ebr_frm_setting_struct *g_setting_list)
  505. {
  506.     /*----------------------------------------------------------------*/
  507.     /* Local Variables                                                */
  508.     /*----------------------------------------------------------------*/
  509.     FILE_HANDLE nfo_hnd;
  510.     S8 path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  511.     U32 size;
  512.     S32 retval;
  513.     /*----------------------------------------------------------------*/
  514.     /* Code Body                                                      */
  515.     /*----------------------------------------------------------------*/
  516.     pfnUnicodeStrcpy((S8*) path, (S8*) ebr_frm_get_file_path(memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  517.     pfnUnicodeStrcat((S8*) path, (S8*) filename);
  518.     nfo_hnd = FS_Open((const WCHAR*)path, FS_READ_WRITE);
  519.     if (nfo_hnd > 0)
  520.     {
  521.         FS_Read(nfo_hnd, &g_curr_book_cntx_p->g_nfo_book_struct, sizeof(g_curr_book_cntx_p->g_nfo_book_struct), &size);
  522.         g_curr_book_cntx_p->g_nfo_book_struct.settings.font_size = g_setting_list->common_settings.font_size;
  523.         g_curr_book_cntx_p->g_nfo_book_struct.settings.font_style = g_setting_list->common_settings.font_style;
  524.         g_curr_book_cntx_p->g_nfo_book_struct.settings.screen_mode = g_setting_list->common_settings.screen_mode;
  525.         g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format =
  526.             g_setting_list->common_settings.encoding_format;
  527.         g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_flag =
  528.             g_setting_list->common_settings.auto_scroll_settings.scroll_flag;
  529.         g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_speed =
  530.             g_setting_list->common_settings.auto_scroll_settings.scroll_speed;
  531.         g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_type =
  532.             g_setting_list->common_settings.auto_scroll_settings.scroll_type;
  533.         FS_Seek(nfo_hnd, 0, FS_FILE_BEGIN);
  534.         retval = FS_Write(
  535.                     nfo_hnd,
  536.                     &g_curr_book_cntx_p->g_nfo_book_struct,
  537.                     sizeof(g_curr_book_cntx_p->g_nfo_book_struct),
  538.                     &size);
  539.         FS_Close(nfo_hnd);
  540.     }
  541. }
  542. /*****************************************************************************
  543.  * FUNCTION
  544.  *  ebr_frm_delete_all_from_book_shelf
  545.  * DESCRIPTION
  546.  *  Delete all books from Book Shelf
  547.  * PARAMETERS
  548.  *  void
  549.  * RETURNS
  550.  *  void
  551.  *****************************************************************************/
  552. void ebr_frm_delete_all_from_book_shelf(void)
  553. {
  554.     /*----------------------------------------------------------------*/
  555.     /* Local Variables                                                */
  556.     /*----------------------------------------------------------------*/
  557.     FS_HANDLE fh_cur;
  558.     FS_DOSDirEntry file_info;
  559.     S8 path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  560.     S8 ebook_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  561.     WCHAR filename[MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH];
  562.     S16 retval;
  563.     /*----------------------------------------------------------------*/
  564.     /* Code Body                                                      */
  565.     /*----------------------------------------------------------------*/
  566.     pfnUnicodeStrcpy(
  567.         (S8*) path,
  568.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_NFO));
  569.     if ((fh_cur = FS_FindFirst(
  570.                     (const WCHAR*)path,
  571.                     0,
  572.                     0,
  573.                     &file_info,
  574.                     (U16*) filename,
  575.                     MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
  576.     {
  577.         do
  578.         {
  579.             if (!(file_info.Attributes & FS_ATTR_DIR))
  580.             {
  581.                 pfnUnicodeStrcpy(
  582.                     (S8*) ebook_path,
  583.                     (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  584.                 pfnUnicodeStrcat((S8*) ebook_path, (S8*) filename);
  585.                 retval = FS_Delete((const WCHAR*)ebook_path);
  586.             }
  587.         } while ((FS_FindNext(fh_cur, &file_info, (U16*) filename, MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH) ==
  588.                   FS_NO_ERROR));
  589.         FS_FindClose(fh_cur);
  590.     }
  591.     pfnUnicodeStrcpy(
  592.         (S8*) path,
  593.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_PDB));
  594.     if ((fh_cur = FS_FindFirst(
  595.                     (const WCHAR*)path,
  596.                     0,
  597.                     0,
  598.                     &file_info,
  599.                     (U16*) filename,
  600.                     MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
  601.     {
  602.         do
  603.         {
  604.             if (!(file_info.Attributes & FS_ATTR_DIR))
  605.             {
  606.                 pfnUnicodeStrcpy(
  607.                     (S8*) ebook_path,
  608.                     (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  609.                 pfnUnicodeStrcat((S8*) ebook_path, (S8*) filename);
  610.                 retval = FS_Delete((const WCHAR*)ebook_path);
  611.             }
  612.         } while ((FS_FindNext(fh_cur, &file_info, (U16*) filename, MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH) ==
  613.                   FS_NO_ERROR));
  614.         FS_FindClose(fh_cur);
  615.     }
  616.     pfnUnicodeStrcpy(
  617.         (S8*) path,
  618.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_TXT));
  619.     if ((fh_cur = FS_FindFirst(
  620.                     (const WCHAR*)path,
  621.                     0,
  622.                     0,
  623.                     &file_info,
  624.                     (U16*) filename,
  625.                     MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
  626.     {
  627.         do
  628.         {
  629.             if (!(file_info.Attributes & FS_ATTR_DIR))
  630.             {
  631.                 pfnUnicodeStrcpy(
  632.                     (S8*) ebook_path,
  633.                     (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  634.                 pfnUnicodeStrcat((S8*) ebook_path, (S8*) filename);
  635.                 retval = FS_Delete((const WCHAR*)ebook_path);
  636.             }
  637.         } while ((FS_FindNext(fh_cur, &file_info, (U16*) filename, MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH) ==
  638.                   FS_NO_ERROR));
  639.         FS_FindClose(fh_cur);
  640.     }
  641. }
  642. /*****************************************************************************
  643.  * FUNCTION
  644.  *  ebr_frm_restore_default_book_settings
  645.  * DESCRIPTION
  646.  *  Restore default settings for Book
  647.  * PARAMETERS
  648.  *  void
  649.  * RETURNS
  650.  *  void
  651.  *****************************************************************************/
  652. S32 ebr_frm_restore_default_book_settings(void)
  653. {
  654.     /*----------------------------------------------------------------*/
  655.     /* Local Variables                                                */
  656.     /*----------------------------------------------------------------*/
  657.     S16 error;
  658.     S16 retval;
  659.     U32 size;
  660.     FILE_HANDLE nfo_hnd_local;
  661.     ebr_frm_setting_struct g_setting;
  662.     ebr_frm_setting_struct *g_setting_list = &g_setting;
  663.     /*----------------------------------------------------------------*/
  664.     /* Code Body                                                      */
  665.     /*----------------------------------------------------------------*/
  666.     nfo_hnd_local = ebr_frm_get_nfo_handle();
  667.     if (nfo_hnd_local <= 0)
  668.     {
  669.         FS_Close(nfo_hnd_local);
  670.         return 0;
  671.     }
  672.     ReadRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  673.     g_curr_book_cntx_p->g_nfo_book_struct.settings = g_setting_list->common_settings;
  674.     FS_Seek(nfo_hnd_local, 0, FS_FILE_BEGIN);
  675.     retval = FS_Write(
  676.                 nfo_hnd_local,
  677.                 &g_curr_book_cntx_p->g_nfo_book_struct,
  678.                 sizeof(g_curr_book_cntx_p->g_nfo_book_struct),
  679.                 &size);
  680.     FS_Close(nfo_hnd_local);
  681.     return !retval;
  682. }
  683. /*****************************************************************************
  684.  * FUNCTION
  685.  *  ebr_frm_get_memory_type_selected
  686.  * DESCRIPTION
  687.  *  Get memory type selected
  688.  * PARAMETERS
  689.  *  void
  690.  * RETURNS
  691.  *  ebr_memory_type_enum
  692.  *****************************************************************************/
  693. ebr_memory_type_enum ebr_frm_get_memory_type_selected(void)
  694. {
  695.     /*----------------------------------------------------------------*/
  696.     /* Local Variables                                                */
  697.     /*----------------------------------------------------------------*/
  698.     ebr_frm_setting_struct g_setting;
  699.     ebr_frm_setting_struct *g_setting_list = &g_setting;
  700.     S16 error;
  701. MMI_BOOL status;
  702.         
  703.     /*----------------------------------------------------------------*/
  704.     /* Code Body                                                      */
  705.     /*----------------------------------------------------------------*/
  706. ReadRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  707. g_curr_book_cntx_p->memory_type_selected = g_setting_list->memory_type;    
  708. status = mmi_fmgr_is_drive_letter_valid(g_curr_book_cntx_p->memory_type_selected);
  709. if (status && FS_GetDevStatus(g_curr_book_cntx_p->memory_type_selected, FS_MOUNT_STATE_ENUM) == FS_NO_ERROR)
  710. {
  711. return g_curr_book_cntx_p->memory_type_selected;
  712. }
  713. else
  714. {
  715. g_setting_list->memory_type = MMI_PUBLIC_DRV;
  716.         WriteRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  717.     }        
  718.     g_curr_book_cntx_p->memory_type_selected = g_setting_list->memory_type;    
  719.     return g_curr_book_cntx_p->memory_type_selected;
  720.     
  721. }
  722. /*****************************************************************************
  723.  * FUNCTION
  724.  *  ebr_frm_fmgr_get_nfo_handle
  725.  * DESCRIPTION
  726.  *  Get nfo handle for File manager
  727.  * PARAMETERS
  728.  *  file_name       [IN]        
  729.  * RETURNS
  730.  *  FILE_HANDLE
  731.  *****************************************************************************/
  732. FILE_HANDLE ebr_frm_fmgr_get_nfo_handle(S8 *file_name)
  733. {
  734.     /*----------------------------------------------------------------*/
  735.     /* Local Variables                                                */
  736.     /*----------------------------------------------------------------*/
  737.     U8 nfo_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH] = {0};
  738.     FILE_HANDLE nfo_hnd;
  739.     /*----------------------------------------------------------------*/
  740.     /* Code Body                                                      */
  741.     /*----------------------------------------------------------------*/
  742.     pfnUnicodeStrcpy(
  743.         (S8*) nfo_path,
  744.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  745.     pfnUnicodeStrcat((S8*) nfo_path, (S8*) file_name);
  746.     nfo_hnd = FS_Open((const WCHAR*)nfo_path, FS_READ_WRITE);
  747.     return nfo_hnd;
  748. }
  749. /*****************************************************************************
  750.  * FUNCTION
  751.  *  ebr_frm_write_default_value_for_nfo_id_in_nvram
  752.  * DESCRIPTION
  753.  *  Write default value for NFO in NVRAM
  754.  * PARAMETERS
  755.  *  void
  756.  * RETURNS
  757.  *  void
  758.  *****************************************************************************/
  759. void ebr_frm_write_default_value_for_nfo_id_in_nvram(void)
  760. {
  761.     /*----------------------------------------------------------------*/
  762.     /* Local Variables                                                */
  763.     /*----------------------------------------------------------------*/
  764.     S16 local_nfo_id = 0;
  765.     S16 error;
  766.     /*----------------------------------------------------------------*/
  767.     /* Code Body                                                      */
  768.     /*----------------------------------------------------------------*/
  769.     WriteValue(NVRAM_EBOOK_NFO_LID, (void*)&local_nfo_id, DS_SHORT, &error);
  770. }
  771. /*****************************************************************************
  772.  * FUNCTION
  773.  *  ebr_fmgr_get_file_name_call_back
  774.  * DESCRIPTION
  775.  *  Get the file name
  776.  * PARAMETERS
  777.  *  fmgr_file_name      [IN]        
  778.  *  file_name           [IN]        
  779.  * RETURNS
  780.  *  void
  781.  *****************************************************************************/
  782. void ebr_fmgr_get_file_name_call_back(S8 *fmgr_file_name, S8 *file_name)
  783. {
  784.     /*----------------------------------------------------------------*/
  785.     /* Local Variables                                                */
  786.     /*----------------------------------------------------------------*/
  787.     S8 nfo_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  788.     ebr_frm_book_struct nfo_struct;
  789.     U32 size;
  790.     FILE_HANDLE nfo_hnd;
  791.     /*----------------------------------------------------------------*/
  792.     /* Code Body                                                      */
  793.     /*----------------------------------------------------------------*/
  794.     g_curr_book_cntx_p->memory_type_selected = ebr_get_drive_type();
  795.     pfnUnicodeStrcpy(
  796.         (S8*) nfo_path,
  797.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  798.     pfnUnicodeStrcat((S8*) nfo_path, fmgr_file_name);
  799.     nfo_hnd = FS_Open((const WCHAR*)nfo_path, FS_READ_ONLY);
  800.     if (nfo_hnd > 0)
  801.     {
  802.         FS_Seek(nfo_hnd, 0, FS_FILE_BEGIN);
  803.         FS_Read(nfo_hnd, &nfo_struct, sizeof(ebr_frm_book_struct), &size);
  804.     }
  805.     FS_Close(nfo_hnd);
  806.     pfnUnicodeStrcpy((S8*) file_name, (S8*) nfo_struct.e_book_name);
  807. }
  808. /*****************************************************************************
  809.  * FUNCTION
  810.  *  ebr_fmgr_get_display_name_call_back
  811.  * DESCRIPTION
  812.  *  Get the display file name
  813.  * PARAMETERS
  814.  *  fmgr_file_name      [IN]        
  815.  *  book_type           [IN]        
  816.  *  file_name           [IN]        
  817.  * RETURNS
  818.  *  void
  819.  *****************************************************************************/
  820. void ebr_fmgr_get_display_name_call_back(S8 *fmgr_file_name, ebr_frm_filetype_enum book_type, S8 *file_name)
  821. {
  822.     /*----------------------------------------------------------------*/
  823.     /* Local Variables                                                */
  824.     /*----------------------------------------------------------------*/
  825.     S8 nfo_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  826.     FILE_HANDLE file_hnd;
  827.     /*----------------------------------------------------------------*/
  828.     /* Code Body                                                      */
  829.     /*----------------------------------------------------------------*/
  830.     g_curr_book_cntx_p->memory_type_selected = ebr_get_drive_type();
  831.     pfnUnicodeStrcpy(
  832.         (S8*) nfo_path,
  833.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  834.     pfnUnicodeStrcat((S8*) nfo_path, fmgr_file_name);
  835.     file_hnd = FS_Open((const WCHAR*)nfo_path, FS_READ_ONLY);
  836.     if (book_type == EBR_FRM_FILE_TYPE_PDB)
  837.     {
  838.         pfnUnicodeStrncpy((S8*) file_name, (S8*) fmgr_file_name, pfnUnicodeStrlen((const S8*)fmgr_file_name) - 4);
  839.     }
  840.     else
  841.     {
  842.         pfnUnicodeStrncpy((S8*) file_name, (S8*) fmgr_file_name, pfnUnicodeStrlen((const S8*)fmgr_file_name) - 4);
  843.     }
  844.     FS_Close(file_hnd);
  845. }
  846. /*****************************************************************************
  847.  * FUNCTION
  848.  *  ebr_fmgr_get_file_size_and_name
  849.  * DESCRIPTION
  850.  *  Get the file name and size
  851.  * PARAMETERS
  852.  *  fmgr_file_name      [IN]        
  853.  * RETURNS
  854.  *  FILE_HANDLE
  855.  *****************************************************************************/
  856. S8 *ebr_fmgr_get_file_size_and_name(S8 *fmgr_file_name)
  857. {
  858.     /*----------------------------------------------------------------*/
  859.     /* Local Variables                                                */
  860.     /*----------------------------------------------------------------*/
  861.     FILE_HANDLE nfo_hnd;
  862.     ebr_frm_book_struct book_struct;
  863.     U32 size;
  864.     /*----------------------------------------------------------------*/
  865.     /* Code Body                                                      */
  866.     /*----------------------------------------------------------------*/
  867.     nfo_hnd = ebr_frm_fmgr_get_nfo_handle(fmgr_file_name);
  868.     FS_Read(nfo_hnd, &book_struct, sizeof(ebr_frm_book_struct), &size);
  869.     FS_Close(nfo_hnd);
  870.     return (S8*) book_struct.e_book_name;
  871. }
  872. /*****************************************************************************
  873.  * FUNCTION
  874.  *  ebr_fmgr_get_file_size
  875.  * DESCRIPTION
  876.  *  Get the file size
  877.  * PARAMETERS
  878.  *  fmgr_file_name      [IN]        
  879.  * RETURNS
  880.  *  FILE_HANDLE
  881.  *****************************************************************************/
  882. U32 ebr_fmgr_get_file_size(S8 *fmgr_file_name)
  883. {
  884.     /*----------------------------------------------------------------*/
  885.     /* Local Variables                                                */
  886.     /*----------------------------------------------------------------*/
  887.     FILE_HANDLE file_hnd;
  888.     U8 file_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  889.     U32 size;
  890.     /*----------------------------------------------------------------*/
  891.     /* Code Body                                                      */
  892.     /*----------------------------------------------------------------*/
  893.     pfnUnicodeStrcpy(
  894.         (S8*) file_path,
  895.         (S8*) (ebr_frm_get_file_path(ebr_frm_get_memory_type_selected(), EBR_FRM_SEARCH_DEFAULT)));
  896.     pfnUnicodeStrcat((S8*) file_path, (const S8*)fmgr_file_name);
  897.     file_hnd = FS_Open((const WCHAR*)file_path, FS_READ_ONLY);
  898.     FS_GetFileSize(file_hnd, &size);
  899.     FS_Close(file_hnd);
  900.     return size;
  901. }
  902. /*****************************************************************************
  903.  * FUNCTION
  904.  *  ebr_frm_fmgr_pre_entry_open_book
  905.  * DESCRIPTION
  906.  *  Pre entry function for Open book
  907.  * PARAMETERS
  908.  *  file_name       [IN]        
  909.  *  file_path       [IN]        
  910.  *  file_ext        [IN]        
  911.  * RETURNS
  912.  *  FILE_HANDLE
  913.  *****************************************************************************/
  914. S32 ebr_frm_fmgr_pre_entry_open_book(S8 *file_name, S8 *file_path, S8 *file_ext)
  915. {
  916.     /*----------------------------------------------------------------*/
  917.     /* Local Variables                                                */
  918.     /*----------------------------------------------------------------*/
  919.     S8 file_extension_name[FMGR_MAX_FILE_LEN * ENCODING_LENGTH];
  920.     S8 file_extension_name_ansii[FMGR_MAX_FILE_LEN * ENCODING_LENGTH];
  921.     S32 nfo_id;
  922.     /*----------------------------------------------------------------*/
  923.     /* Code Body                                                      */
  924.     /*----------------------------------------------------------------*/
  925.     pfnUnicodeStrcat((S8*) file_path, (S8*) file_name);
  926.     pfnUnicodeStrcpy((S8*) file_extension_name, (S8*) file_ext);
  927.     ebr_frm_convert_to_upper((S16*) file_extension_name);
  928.     UnicodeToAnsii((S8*) file_extension_name_ansii, (S8*) file_extension_name);
  929.     if (mmi_fmgr_is_drive_letter_valid(g_curr_book_cntx_p->memory_type_selected))
  930.     {
  931.         if (!strcmp(file_extension_name_ansii, EBR_FILE_TYPE_TXT))
  932.         {
  933.             g_curr_book_cntx_p->g_fmgr_book_type = EBR_FRM_FILE_TYPE_TXT;
  934.             nfo_id = ebr_fmgr_get_nfo_id_for_txt_file(g_curr_book_cntx_p->memory_type_selected, file_name);
  935.             return nfo_id;
  936.         }
  937.         else
  938.         {
  939.             g_curr_book_cntx_p->g_fmgr_book_type = EBR_FRM_FILE_TYPE_PDB;
  940.             nfo_id = ebr_fmgr_get_nfo_id_for_pdb_file(g_curr_book_cntx_p->memory_type_selected, file_name);
  941.             return nfo_id;
  942.         }
  943.     }
  944.     else
  945.     {
  946.         if (!strcmp(file_extension_name_ansii, EBR_FILE_TYPE_TXT))
  947.         {
  948.             g_curr_book_cntx_p->g_fmgr_book_type = EBR_FRM_FILE_TYPE_TXT;
  949.         }
  950.         else
  951.         {
  952.             g_curr_book_cntx_p->g_fmgr_book_type = EBR_FRM_FILE_TYPE_PDB;
  953.         }
  954.         return -1;
  955.     }
  956. }
  957. /*****************************************************************************
  958.  * FUNCTION
  959.  *  ebr_frm_check_is_ebook_folder_created
  960.  * DESCRIPTION
  961.  *  Is Ebook Folder created
  962.  * PARAMETERS
  963.  *  void
  964.  * RETURNS
  965.  *  void
  966.  *****************************************************************************/
  967. void ebr_frm_check_is_ebook_folder_created(void)
  968. {
  969.     /*----------------------------------------------------------------*/
  970.     /* Local Variables                                                */
  971.     /*----------------------------------------------------------------*/
  972.     S8 tmp_str[MAX_DWNL_EBK_PATH_LEN];
  973.     S8 ebook_folder_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  974.     /*----------------------------------------------------------------*/
  975.     /* Code Body                                                      */
  976.     /*----------------------------------------------------------------*/
  977.     sprintf(tmp_str, "%c%s", MMI_CARD_DRV, EBR_DOWNLOADED_EBOOK_PATH);
  978.     AnsiiToUnicodeString((S8*) ebook_folder_path, (S8*) tmp_str);
  979.     FS_CreateDir((PU16) ebook_folder_path);
  980.     sprintf(tmp_str, "%c%s", MMI_PUBLIC_DRV, EBR_DOWNLOADED_EBOOK_PATH);
  981.     AnsiiToUnicodeString((S8*) ebook_folder_path, (S8*) tmp_str);
  982.     FS_CreateDir((PU16) ebook_folder_path);
  983. }
  984. /*****************************************************************************
  985.  * FUNCTION
  986.  *  ebr_frm_init
  987.  * DESCRIPTION
  988.  *  
  989.  * PARAMETERS
  990.  *  void
  991.  * RETURNS
  992.  *  void
  993.  *****************************************************************************/
  994. void ebr_frm_init(void)
  995. {
  996.     /*----------------------------------------------------------------*/
  997.     /* Local Variables                                                */
  998.     /*----------------------------------------------------------------*/
  999.     /*----------------------------------------------------------------*/
  1000.     /* Code Body                                                      */
  1001.     /*----------------------------------------------------------------*/
  1002.     g_curr_book_cntx_p->state_recursive_conversion = EBR_FRM_NO_CONVERSION;
  1003.     ebr_frm_check_is_ebook_folder_created();
  1004.     ebr_frm_get_memory_type_selected();
  1005. }
  1006. /*****************************************************************************
  1007.  * FUNCTION
  1008.  *  ebr_frm_get_drive_type
  1009.  * DESCRIPTION
  1010.  *  Get drive type
  1011.  * PARAMETERS
  1012.  *  void
  1013.  * RETURNS
  1014.  *  FILE_HANDLE
  1015.  *****************************************************************************/
  1016. ebr_memory_type_enum ebr_frm_get_drive_type(void)
  1017. {
  1018.     /*----------------------------------------------------------------*/
  1019.     /* Local Variables                                                */
  1020.     /*----------------------------------------------------------------*/
  1021.     S16 error;
  1022.     ebr_frm_setting_struct g_setting;
  1023.     ebr_frm_setting_struct *g_setting_list = &g_setting;
  1024.     /*----------------------------------------------------------------*/
  1025.     /* Code Body                                                      */
  1026.     /*----------------------------------------------------------------*/
  1027.     ReadRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  1028.     return g_setting_list->memory_type;
  1029. }
  1030. /*****************************************************************************
  1031.  * FUNCTION
  1032.  *  ebr_frm_change_drive_type
  1033.  * DESCRIPTION
  1034.  *  Change the drive type and write in NVRAM
  1035.  * PARAMETERS
  1036.  *  void
  1037.  * RETURNS
  1038.  *  FILE_HANDLE
  1039.  *****************************************************************************/
  1040. S16 ebr_frm_change_drive_type(void)
  1041. {
  1042.     /*----------------------------------------------------------------*/
  1043.     /* Local Variables                                                */
  1044.     /*----------------------------------------------------------------*/
  1045.     S16 error;
  1046.     ebr_frm_setting_struct g_setting;
  1047.     ebr_frm_setting_struct *g_setting_list = &g_setting;
  1048.     /*----------------------------------------------------------------*/
  1049.     /* Code Body                                                      */
  1050.     /*----------------------------------------------------------------*/
  1051.     g_setting_list->memory_type = (U8) g_curr_book_cntx_p->memory_type_selected;
  1052.     WriteRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  1053.     return error;
  1054. }
  1055. /*****************************************************************************
  1056.  * FUNCTION
  1057.  *  ebr_frm_get_drive_status
  1058.  * DESCRIPTION
  1059.  *  Get drive status
  1060.  * PARAMETERS
  1061.  *  void
  1062.  * RETURNS
  1063.  *  FILE_HANDLE
  1064.  *****************************************************************************/
  1065. int ebr_frm_get_drive_status(void)
  1066. {
  1067.     /*----------------------------------------------------------------*/
  1068.     /* Local Variables                                                */
  1069.     /*----------------------------------------------------------------*/
  1070.     int drive, status;
  1071.     /*----------------------------------------------------------------*/
  1072.     /* Code Body                                                      */
  1073.     /*----------------------------------------------------------------*/
  1074.     drive = FS_GetDrive(FS_DRIVE_V_REMOVABLE, 1, FS_NO_ALT_DRIVE);
  1075.     status = FS_GetDevStatus(drive, FS_MOUNT_STATE_ENUM);
  1076.     return status;
  1077. }
  1078. /*****************************************************************************
  1079.  * FUNCTION
  1080.  *  gui_paging_reset_auto_scroll
  1081.  * DESCRIPTION
  1082.  *  Reset auto scroll
  1083.  * PARAMETERS
  1084.  *  void
  1085.  * RETURNS
  1086.  *  void
  1087.  *****************************************************************************/
  1088. void gui_paging_reset_auto_scroll(void)
  1089. {
  1090.     /*----------------------------------------------------------------*/
  1091.     /* Local Variables                                                */
  1092.     /*----------------------------------------------------------------*/
  1093.     FILE_HANDLE nfo_hnd;
  1094.     U32 size;
  1095.     int retval;
  1096.     /*----------------------------------------------------------------*/
  1097.     /* Code Body                                                      */
  1098.     /*----------------------------------------------------------------*/
  1099.     nfo_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->nfo_path, FS_READ_WRITE);
  1100.     g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_flag = 0;
  1101.     FS_Seek(nfo_hnd, 0, FS_FILE_BEGIN);
  1102.     retval = FS_Write(nfo_hnd, &g_curr_book_cntx_p->g_nfo_book_struct, sizeof(g_curr_book_cntx_p->g_nfo_book_struct), &size);
  1103.     retval = FS_Close(nfo_hnd);
  1104. }
  1105. /*****************************************************************************
  1106.  * FUNCTION
  1107.  *  ebr_frm_get_auto_scroll_status
  1108.  * DESCRIPTION
  1109.  *  Get auto scroll status
  1110.  * PARAMETERS
  1111.  *  void
  1112.  * RETURNS
  1113.  *  FILE_HANDLE
  1114.  *****************************************************************************/
  1115. pBOOL ebr_frm_get_auto_scroll_status(void)
  1116. {
  1117.     /*----------------------------------------------------------------*/
  1118.     /* Local Variables                                                */
  1119.     /*----------------------------------------------------------------*/
  1120.     /*----------------------------------------------------------------*/
  1121.     /* Code Body                                                      */
  1122.     /*----------------------------------------------------------------*/
  1123.     if (g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_flag == 1)
  1124.     {
  1125.         return FALSE;
  1126.     }
  1127.     else
  1128.     {
  1129.         return TRUE;
  1130.     }
  1131. }
  1132. /*****************************************************************************
  1133.  * FUNCTION
  1134.  *  get_highlight_id_from_nvram
  1135.  * DESCRIPTION
  1136.  *  Get auto scroll status
  1137.  * PARAMETERS
  1138.  *  void
  1139.  * RETURNS
  1140.  *  FILE_HANDLE
  1141.  *****************************************************************************/
  1142. S16 get_highlight_id_from_nvram(void)
  1143. {
  1144.     /*----------------------------------------------------------------*/
  1145.     /* Local Variables                                                */
  1146.     /*----------------------------------------------------------------*/
  1147.     S16 highlight_id = 0;
  1148.     S16 error;
  1149.     /*----------------------------------------------------------------*/
  1150.     /* Code Body                                                      */
  1151.     /*----------------------------------------------------------------*/
  1152.     ReadValue(NVRAM_EBOOK_LAST_HIGHLIGHT_ID, (void*)&highlight_id, DS_SHORT, &error);
  1153.     return highlight_id;
  1154. }
  1155. /*****************************************************************************
  1156.  * FUNCTION
  1157.  *  ebr_frm_set_current_highlight_id
  1158.  * DESCRIPTION
  1159.  *  Get highlight id
  1160.  * PARAMETERS
  1161.  *  index       [IN]        
  1162.  * RETURNS
  1163.  *  void
  1164.  *****************************************************************************/
  1165. void ebr_frm_set_current_highlight_id(S32 index)
  1166. {
  1167.     /*----------------------------------------------------------------*/
  1168.     /* Local Variables                                                */
  1169.     /*----------------------------------------------------------------*/
  1170.     /*----------------------------------------------------------------*/
  1171.     /* Code Body                                                      */
  1172.     /*----------------------------------------------------------------*/
  1173.     g_curr_book_cntx_p->current_highlight_book_id = index;
  1174. }
  1175. /*****************************************************************************
  1176.  * FUNCTION
  1177.  *  ebr_frm_get_book_size_from_nfo
  1178.  * DESCRIPTION
  1179.  *  
  1180.  * PARAMETERS
  1181.  *  void
  1182.  * RETURNS
  1183.  *  
  1184.  *****************************************************************************/
  1185. S32 ebr_frm_get_book_size_from_nfo(void)
  1186. {
  1187.     /*----------------------------------------------------------------*/
  1188.     /* Local Variables                                                */
  1189.     /*----------------------------------------------------------------*/
  1190.     /*----------------------------------------------------------------*/
  1191.     /* Code Body                                                      */
  1192.     /*----------------------------------------------------------------*/
  1193.     return g_curr_book_cntx_p->g_nfo_book_struct.book_size;
  1194. }
  1195. /*****************************************************************************
  1196.  * FUNCTION
  1197.  *  ebr_frm_get_book_temp_size_from_nfo
  1198.  * DESCRIPTION
  1199.  *  
  1200.  * PARAMETERS
  1201.  *  void
  1202.  * RETURNS
  1203.  *  
  1204.  *****************************************************************************/
  1205. S32 ebr_frm_get_book_temp_size_from_nfo(void)
  1206. {
  1207.     /*----------------------------------------------------------------*/
  1208.     /* Local Variables                                                */
  1209.     /*----------------------------------------------------------------*/
  1210.     /*----------------------------------------------------------------*/
  1211.     /* Code Body                                                      */
  1212.     /*----------------------------------------------------------------*/
  1213.     if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
  1214.     {
  1215.         return g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size;
  1216.     }
  1217.     else
  1218.     {
  1219.         return g_curr_book_cntx_p->g_nfo_book_struct.book_size;
  1220.     }
  1221. }
  1222. /*****************************************************************************
  1223.  * FUNCTION
  1224.  *  ebr_frm_get_page_size
  1225.  * DESCRIPTION
  1226.  *  
  1227.  * PARAMETERS
  1228.  *  void
  1229.  * RETURNS
  1230.  *  
  1231.  *****************************************************************************/
  1232. S32 ebr_frm_get_page_size(void)
  1233. {
  1234.     /*----------------------------------------------------------------*/
  1235.     /* Local Variables                                                */
  1236.     /*----------------------------------------------------------------*/
  1237.     /*----------------------------------------------------------------*/
  1238.     /* Code Body                                                      */
  1239.     /*----------------------------------------------------------------*/
  1240.     if (g_curr_book_cntx_p->is_book_in_unicode || g_curr_book_cntx_p->book_is_in_other_encoding_format)
  1241.     {
  1242.         return EBR_PAGE_SIZE * 2;
  1243.     }
  1244.     else
  1245.     {
  1246.         return EBR_PAGE_SIZE;
  1247.     }
  1248. }
  1249. /*****************************************************************************
  1250.  * FUNCTION
  1251.  *  ebr_frm_fmgr_get_nfo_id
  1252.  * DESCRIPTION
  1253.  *  Get nfo id
  1254.  * PARAMETERS
  1255.  *  void
  1256.  * RETURNS
  1257.  *  void
  1258.  *****************************************************************************/
  1259. S32 ebr_frm_fmgr_get_nfo_id(void)
  1260. {
  1261.     /*----------------------------------------------------------------*/
  1262.     /* Local Variables                                                */
  1263.     /*----------------------------------------------------------------*/
  1264.     /*----------------------------------------------------------------*/
  1265.     /* Code Body                                                      */
  1266.     /*----------------------------------------------------------------*/
  1267.     return g_curr_book_cntx_p->nfo_id;
  1268. }
  1269. /*****************************************************************************
  1270.  * FUNCTION
  1271.  *  ebr_frm_fmgr_set_nfo_id
  1272.  * DESCRIPTION
  1273.  *  Set nfo id
  1274.  * PARAMETERS
  1275.  *  local_nfo_id        [IN]        
  1276.  * RETURNS
  1277.  *  void
  1278.  *****************************************************************************/
  1279. void ebr_frm_fmgr_set_nfo_id(S32 local_nfo_id)
  1280. {
  1281.     /*----------------------------------------------------------------*/
  1282.     /* Local Variables                                                */
  1283.     /*----------------------------------------------------------------*/
  1284.     /*----------------------------------------------------------------*/
  1285.     /* Code Body                                                      */
  1286.     /*----------------------------------------------------------------*/
  1287.     g_curr_book_cntx_p->nfo_id = local_nfo_id;
  1288. }
  1289. /*****************************************************************************
  1290.  * FUNCTION
  1291.  *  ebr_fmgr_get_book_type
  1292.  * DESCRIPTION
  1293.  *  Get book type
  1294.  * PARAMETERS
  1295.  *  void
  1296.  * RETURNS
  1297.  *  void
  1298.  *****************************************************************************/
  1299. S16 ebr_fmgr_get_book_type(void)
  1300. {
  1301.     /*----------------------------------------------------------------*/
  1302.     /* Local Variables                                                */
  1303.     /*----------------------------------------------------------------*/
  1304.     /*----------------------------------------------------------------*/
  1305.     /* Code Body                                                      */
  1306.     /*----------------------------------------------------------------*/
  1307.     return g_curr_book_cntx_p->ebr_fmgr_book_type;
  1308. }
  1309. /*****************************************************************************
  1310.  * FUNCTION
  1311.  *  ebr_frm_fmgr_get_application_type
  1312.  * DESCRIPTION
  1313.  *  Get application type
  1314.  * PARAMETERS
  1315.  *  void
  1316.  * RETURNS
  1317.  *  void
  1318.  *****************************************************************************/
  1319. S16 ebr_frm_fmgr_get_application_type(void)
  1320. {
  1321.     /*----------------------------------------------------------------*/
  1322.     /* Local Variables                                                */
  1323.     /*----------------------------------------------------------------*/
  1324.     /*----------------------------------------------------------------*/
  1325.     /* Code Body                                                      */
  1326.     /*----------------------------------------------------------------*/
  1327.     return g_curr_book_cntx_p->src_application;
  1328. }
  1329. /*****************************************************************************
  1330.  * FUNCTION
  1331.  *  ebr_frm_fmgr_set_application_type
  1332.  * DESCRIPTION
  1333.  *  
  1334.  * PARAMETERS
  1335.  *  void
  1336.  * RETURNS
  1337.  *  void
  1338.  *****************************************************************************/
  1339. void ebr_frm_fmgr_set_application_type(void)
  1340. {
  1341.     /*----------------------------------------------------------------*/
  1342.     /* Local Variables                                                */
  1343.     /*----------------------------------------------------------------*/
  1344.     /*----------------------------------------------------------------*/
  1345.     /* Code Body                                                      */
  1346.     /*----------------------------------------------------------------*/
  1347.     g_curr_book_cntx_p->src_application = EBR_FRM_SRC_APP_FMGR;
  1348. }
  1349. /*****************************************************************************
  1350.  * FUNCTION
  1351.  *  ebr_frm_set_src_application_type
  1352.  * DESCRIPTION
  1353.  *  
  1354.  * PARAMETERS
  1355.  *  void
  1356.  * RETURNS
  1357.  *  void
  1358.  *****************************************************************************/
  1359. void ebr_frm_set_src_application_type(void)
  1360. {
  1361.     /*----------------------------------------------------------------*/
  1362.     /* Local Variables                                                */
  1363.     /*----------------------------------------------------------------*/
  1364.     /*----------------------------------------------------------------*/
  1365.     /* Code Body                                                      */
  1366.     /*----------------------------------------------------------------*/
  1367.     memset(g_curr_book_cntx_p->nfo_name, 0, sizeof(g_curr_book_cntx_p->nfo_name));
  1368.     g_curr_book_cntx_p->src_application = EBR_FRM_SRC_APP_EBOOK;
  1369. }
  1370. /*****************************************************************************
  1371.  * FUNCTION
  1372.  *  ebr_frm_check_nfo_file_present
  1373.  * DESCRIPTION
  1374.  *  
  1375.  * PARAMETERS
  1376.  *  nfo_id      [IN]        
  1377.  * RETURNS
  1378.  *  
  1379.  *****************************************************************************/
  1380. S32 ebr_frm_check_nfo_file_present(S32 nfo_id)
  1381. {
  1382.     /*----------------------------------------------------------------*/
  1383.     /* Local Variables                                                */
  1384.     /*----------------------------------------------------------------*/
  1385.     FILE_HANDLE nfo_handle;
  1386.     U32 size;
  1387.     S32 compare_type = 0;
  1388.     /*----------------------------------------------------------------*/
  1389.     /* Code Body                                                      */
  1390.     /*----------------------------------------------------------------*/
  1391.     nfo_handle = ebr_frm_get_nfo_handle();
  1392.     if (nfo_handle > 0)
  1393.     {
  1394.         FS_Read(
  1395.             nfo_handle,
  1396.             &g_curr_book_cntx_p->g_nfo_book_struct,
  1397.             sizeof(g_curr_book_cntx_p->g_nfo_book_struct),
  1398.             &size);
  1399.         FS_Close(nfo_handle);
  1400.         compare_type = pfnUnicodeStrcmp(
  1401.                         (const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name,
  1402.                         (const S8*)g_curr_book_cntx_p->nfo_name);
  1403.         if (compare_type != 0)
  1404.         {
  1405.             return 0;
  1406.         }
  1407.         else
  1408.         {
  1409.             return nfo_id;
  1410.         }
  1411.     }
  1412.     else
  1413.     {
  1414.         FS_Close(nfo_handle);
  1415.         return 0;
  1416.     }
  1417. }
  1418. /*****************************************************************************
  1419.  * FUNCTION
  1420.  *  ebr_frm_fmgr_set_file_type
  1421.  * DESCRIPTION
  1422.  *  
  1423.  * PARAMETERS
  1424.  *  file_name       [IN]        
  1425.  * RETURNS
  1426.  *  void
  1427.  *****************************************************************************/
  1428. void ebr_frm_fmgr_set_file_type(S8 *file_name)
  1429. {
  1430.     /*----------------------------------------------------------------*/
  1431.     /* Local Variables                                                */
  1432.     /*----------------------------------------------------------------*/
  1433. U8 tmp_path_buf[(FMGR_MAX_PATH_LEN + 1) * ENCODING_LENGTH];
  1434.     /*----------------------------------------------------------------*/
  1435.     /* Code Body                                                      */
  1436.     /*----------------------------------------------------------------*/
  1437. if (g_curr_book_cntx_p->is_short)
  1438.     {
  1439.         memset(tmp_path_buf, 0, (FMGR_MAX_PATH_LEN + 1) * ENCODING_LENGTH);
  1440.         mmi_chset_mixed_text_to_ucs2_str(
  1441.                     (U8*) tmp_path_buf,
  1442.                     (FMGR_MAX_PATH_LEN + 1) * ENCODING_LENGTH,
  1443.                     (U8*) file_name,
  1444.                     g_chset_text_encoding);
  1445.         pfnUnicodeStrcpy((S8*) g_curr_book_cntx_p->nfo_name, (S8*) tmp_path_buf);
  1446.     }
  1447.     else
  1448.     {
  1449.         pfnUnicodeStrcpy((S8*) g_curr_book_cntx_p->nfo_name, (S8*) file_name);
  1450.     }
  1451.     ebr_frm_set_file_type();
  1452. }
  1453. /*****************************************************************************
  1454.  * FUNCTION
  1455.  *  ebr_frm_set_file_name
  1456.  * DESCRIPTION
  1457.  *  
  1458.  * PARAMETERS
  1459.  *  nfo_id      [IN]        
  1460.  * RETURNS
  1461.  *  void
  1462.  *****************************************************************************/
  1463. void ebr_frm_set_file_name(S32 nfo_id)
  1464. {
  1465.     /*----------------------------------------------------------------*/
  1466.     /* Local Variables                                                */
  1467.     /*----------------------------------------------------------------*/
  1468.     FILE_HANDLE nfo_hnd;
  1469.     /*----------------------------------------------------------------*/
  1470.     /* Code Body                                                      */
  1471.     /*----------------------------------------------------------------*/
  1472.     nfo_hnd = ebr_frm_get_nfo_handle();
  1473.     pfnUnicodeStrcpy((PS8) g_curr_book_cntx_p->nfo_name, (PS8) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
  1474.     FS_Close(nfo_hnd);
  1475. }
  1476. /*****************************************************************************
  1477.  * FUNCTION
  1478.  *  ebr_frm_fmgr_move_ebook_file
  1479.  * DESCRIPTION
  1480.  *  
  1481.  * PARAMETERS
  1482.  *  void
  1483.  * RETURNS
  1484.  *  void
  1485.  *****************************************************************************/
  1486. void ebr_frm_fmgr_move_ebook_file(void)
  1487. {
  1488.     /*----------------------------------------------------------------*/
  1489.     /* Local Variables                                                */
  1490.     /*----------------------------------------------------------------*/
  1491.     S32 create_result;
  1492.     FS_HANDLE file_handle;
  1493. U8 name[FMGR_MAX_FILE_LEN*ENCODING_LENGTH];
  1494.     U8 tmp_path_buf[(FMGR_MAX_PATH_LEN + 1) * ENCODING_LENGTH];
  1495.     /*----------------------------------------------------------------*/
  1496.     /* Code Body                                                      */
  1497.     /*----------------------------------------------------------------*/
  1498.     pfnUnicodeStrcat((S8*) g_curr_book_cntx_p->fmgr_file_path, (S8*) g_curr_book_cntx_p->fmgr_file_name);
  1499. #ifndef __MMI_SHOW_FILE_EXT__
  1500.     pfnUnicodeStrcat((PS8) g_curr_book_cntx_p->fmgr_file_path, (PS8) g_curr_book_cntx_p->fmgr_file_extension);
  1501. #endif 
  1502.     pfnUnicodeStrcpy((PS8) g_curr_book_cntx_p->old_file_path, (PS8) g_curr_book_cntx_p->fmgr_file_path);
  1503.     /* short file name src file should be renamed to long file name */
  1504. #ifdef MMI_ON_HARDWARE_P
  1505.     if (g_curr_book_cntx_p->is_short == TRUE)
  1506.     {
  1507.         PS8 temp, temp1;
  1508.         temp = mmi_fmgr_extract_file_name((PS8) g_curr_book_cntx_p->fmgr_file_path);
  1509.         temp1 = mmi_fmgr_extract_file_name((PS8) g_curr_book_cntx_p->old_file_path);
  1510.         mmi_chset_mixed_text_to_ucs2_str(
  1511.             (U8*) temp1,
  1512.             (MAX_SUBMENU_CHARACTERS - 1) * ENCODING_LENGTH,
  1513.             (U8*) temp,
  1514.             PhnsetGetDefEncodingType());
  1515.         FS_Rename((PU16) g_curr_book_cntx_p->fmgr_file_path, (PU16) g_curr_book_cntx_p->old_file_path);
  1516.     }
  1517. #endif /* MMI_ON_HARDWARE_P */ 
  1518.     mmi_fmgr_remove_last_dir((PS8) g_curr_book_cntx_p->fmgr_file_path);
  1519. pfnUnicodeStrcpy((PS8) name, (PS8) FMGR_DEFAULT_FOLDER_EBOOKS);
  1520. mmi_fmgr_append_file_name((PS8) g_curr_book_cntx_p->fmgr_file_path, (PS8) name);
  1521. ebr_fmgr_is_book_shelf_path(g_curr_book_cntx_p->fmgr_file_path);
  1522. mmi_fmgr_remove_last_dir((PS8) g_curr_book_cntx_p->fmgr_file_path);
  1523.         ebr_frm_create_new_file_path();
  1524.     file_handle = FS_Open((U16*) g_curr_book_cntx_p->fmgr_file_path, FS_OPEN_DIR | FS_READ_ONLY);
  1525.     /* path already exist */
  1526.     if (file_handle >= 0)
  1527.     {
  1528.         FS_Close(file_handle);
  1529.         create_result = 0;
  1530.     }
  1531.     else
  1532.     {
  1533.         create_result = FS_CreateDir((PU16) g_curr_book_cntx_p->fmgr_file_path);
  1534.         pfnUnicodeStrcpy((PS8) g_curr_book_cntx_p->gebook_folder_path, (PS8) g_curr_book_cntx_p->fmgr_file_path);
  1535.         g_curr_book_cntx_p->g_isEbook_folder_created = TRUE;
  1536.     }
  1537.     if (mmi_fmgr_append_file_name((PS8) g_curr_book_cntx_p->fmgr_file_path, (PS8) g_curr_book_cntx_p->fmgr_file_name) ==
  1538.         TRUE)
  1539.     {
  1540.         if (g_curr_book_cntx_p->is_short)
  1541.         {
  1542.             memset(tmp_path_buf, 0, (FMGR_MAX_PATH_LEN + 1) * ENCODING_LENGTH);
  1543.             mmi_chset_mixed_text_to_ucs2_str(
  1544.                         (U8*) tmp_path_buf,
  1545.                         (FMGR_MAX_PATH_LEN + 1) * ENCODING_LENGTH,
  1546.                         (U8*) g_curr_book_cntx_p->fmgr_file_path,
  1547.                         g_chset_text_encoding);
  1548.             pfnUnicodeStrcpy((S8*) g_curr_book_cntx_p->fmgr_file_path, (S8*) tmp_path_buf);
  1549.         }
  1550.         ebr_frm_delete_unused_nfo_file();
  1551.         mmi_fmgr_send_copy_req(
  1552.                 FMGR_ACTION_MOVE,
  1553.                 (PU8) g_curr_book_cntx_p->old_file_path,
  1554.                 (PU8) g_curr_book_cntx_p->fmgr_file_path,
  1555.                 (PsFuncPtr) fmgr_ebook_move_rsp);
  1556. ebr_please_wait_actual_screen();        
  1557.     }
  1558. }
  1559. /*****************************************************************************
  1560.  * FUNCTION
  1561.  *  fmgr_ebook_move_rsp
  1562.  * DESCRIPTION
  1563.  *  Move response handler
  1564.  * PARAMETERS
  1565.  *  info        [IN]        
  1566.  * RETURNS
  1567.  *  void
  1568.  *****************************************************************************/
  1569. void fmgr_ebook_move_rsp(void *info)
  1570. {
  1571.     /*----------------------------------------------------------------*/
  1572.     /* Local Variables                                                */
  1573.     /*----------------------------------------------------------------*/
  1574.     mmi_fmt_copy_rsp_strcut *msgPtr;
  1575.     /*----------------------------------------------------------------*/
  1576.     /* Code Body                                                      */
  1577.     /*----------------------------------------------------------------*/
  1578.     msgPtr = (mmi_fmt_copy_rsp_strcut*) info;
  1579.     if (msgPtr->result >= 0)
  1580.     {
  1581.         ebr_fmgr_set_file_type((S8*) g_curr_book_cntx_p->fmgr_file_name);
  1582.         mmi_fmgr_remove_last_dir((PS8) g_curr_book_cntx_p->old_file_path);
  1583.         ebr_fmgr_copy_new_file_path_after_move(g_curr_book_cntx_p->old_file_path);
  1584.         DeleteScreenIfPresent(SCR_FMGR_FILE_OPTION);
  1585.         ebr_app_add_to_book_shelf();
  1586.     }
  1587.     else
  1588.     {
  1589.    ebr_display_error_pop_up(msgPtr->result);
  1590.     }
  1591. }
  1592. /*****************************************************************************
  1593.  * FUNCTION
  1594.  *  ebr_app_change_drive_type
  1595.  * DESCRIPTION
  1596.  *  Change drive type
  1597.  * PARAMETERS
  1598.  *  void
  1599.  * RETURNS
  1600.  *  void
  1601.  *****************************************************************************/
  1602. void ebr_app_change_drive_type(void)
  1603. {
  1604.     /*----------------------------------------------------------------*/
  1605.     /* Local Variables                                                */
  1606.     /*----------------------------------------------------------------*/
  1607.     S16 error;
  1608.     /*----------------------------------------------------------------*/
  1609.     /* Code Body                                                      */
  1610.     /*----------------------------------------------------------------*/
  1611.     error = ebr_frm_change_drive_type();
  1612.     ebr_app_get_nfo_id_from_fmgr(
  1613.         g_curr_book_cntx_p->fmgr_file_name,
  1614.         g_curr_book_cntx_p->fmgr_file_path,
  1615.         g_curr_book_cntx_p->fmgr_file_extension,
  1616.         g_curr_book_cntx_p->is_short);
  1617. }
  1618. /*****************************************************************************
  1619.  * FUNCTION
  1620.  *  ebr_fmgr_entry_open
  1621.  * DESCRIPTION
  1622.  *  Entry open book
  1623.  * PARAMETERS
  1624.  *  void
  1625.  * RETURNS
  1626.  *  void
  1627.  *****************************************************************************/
  1628. void ebr_fmgr_entry_open(void)
  1629. {
  1630.     /*----------------------------------------------------------------*/
  1631.     /* Local Variables                                                */
  1632.     /*----------------------------------------------------------------*/
  1633.     /*----------------------------------------------------------------*/
  1634.     /* Code Body                                                      */
  1635.     /*----------------------------------------------------------------*/
  1636.     ebr_app_get_nfo_id_from_fmgr(
  1637.         g_curr_book_cntx_p->fmgr_file_name,
  1638.         g_curr_book_cntx_p->fmgr_file_path,
  1639.         g_curr_book_cntx_p->fmgr_file_extension,
  1640.         g_curr_book_cntx_p->is_short);
  1641. }
  1642. /*****************************************************************************
  1643.  * FUNCTION
  1644.  *  ebr_fmgr_move_to_ebook_folder
  1645.  * DESCRIPTION
  1646.  *  Move to ebook folder
  1647.  * PARAMETERS
  1648.  *  void
  1649.  * RETURNS
  1650.  *  void
  1651.  *****************************************************************************/
  1652. void ebr_fmgr_move_to_ebook_folder(void)
  1653. {
  1654.     /*----------------------------------------------------------------*/
  1655.     /* Local Variables                                                */
  1656.     /*----------------------------------------------------------------*/
  1657.     /*----------------------------------------------------------------*/
  1658.     /* Code Body                                                      */
  1659.     /*----------------------------------------------------------------*/
  1660.     ebr_app_clear_all_key_handlers();
  1661.     ebr_frm_fmgr_move_ebook_file();
  1662. }
  1663. /*****************************************************************************
  1664.  * FUNCTION
  1665.  *  ebr_frm_check_file_validity
  1666.  * DESCRIPTION
  1667.  *  Move to ebook folder
  1668.  * PARAMETERS
  1669.  *  file_path       [?]     
  1670.  *  file_name       [?]    
  1671.  * RETURNS
  1672.  *  void
  1673.  *****************************************************************************/
  1674. pBOOL ebr_frm_check_file_validity(S8 *file_path, S8 *file_name)
  1675. {
  1676.     /*----------------------------------------------------------------*/
  1677.     /* Local Variables                                                */
  1678.     /*----------------------------------------------------------------*/
  1679.     FILE_HANDLE file_hnd;
  1680.     U32 size;
  1681.     ebr_frm_database_hdr_type file_header;
  1682.     /*----------------------------------------------------------------*/
  1683.     /* Code Body                                                      */
  1684.     /*----------------------------------------------------------------*/
  1685.     if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_TXT)
  1686.     {
  1687.         return TRUE;
  1688.     }
  1689.     pfnUnicodeStrcat((S8*) file_path, (S8*) file_name);
  1690.     file_hnd = FS_Open((const WCHAR*)file_path, FS_READ_ONLY);
  1691.     if (file_hnd > 0)
  1692.     {
  1693.         if (FS_Read(file_hnd, &file_header, EBR_FRM_DATABASE_HEADER_SIZE, &size) == FS_NO_ERROR)
  1694.         {
  1695.             if (memcmp(file_header.type, DOC_TYPE, strlen((PS8) DOC_TYPE)) == 0)
  1696.             {
  1697.                 FS_Close(file_hnd);
  1698.                 return TRUE;
  1699.             }
  1700.             else
  1701.             {
  1702.                 FS_Close(file_hnd);
  1703.                 return FALSE;
  1704.             }
  1705.         }
  1706.         else
  1707.         {
  1708.             return FALSE;
  1709.         }
  1710.     }
  1711.     else
  1712.     {
  1713.         return FALSE;
  1714.     }
  1715. }
  1716. /*****************************************************************************
  1717.  * FUNCTION
  1718.  *  ebr_frm_set_file_info_from_fmgr
  1719.  * DESCRIPTION
  1720.  *  Move to ebook folder
  1721.  * PARAMETERS
  1722.  *  file_name       [IN]        
  1723.  *  file_path       [IN]        
  1724.  *  file_ext        [IN]        
  1725.  *  is_short        [IN]        
  1726.  * RETURNS
  1727.  *  void
  1728.  *****************************************************************************/
  1729. void ebr_frm_set_file_info_from_fmgr(S8 *file_name, S8 *file_path, S8 *file_ext, BOOL is_short)
  1730. {
  1731.     /*----------------------------------------------------------------*/
  1732.     /* Local Variables                                                */
  1733.     /*----------------------------------------------------------------*/
  1734.     /*----------------------------------------------------------------*/
  1735.     /* Code Body                                                      */
  1736.     /*----------------------------------------------------------------*/
  1737.     pfnUnicodeStrcpy((PS8) g_curr_book_cntx_p->fmgr_file_name, (PS8) file_name);
  1738.     pfnUnicodeStrcpy((PS8) g_curr_book_cntx_p->fmgr_file_path, (PS8) file_path);
  1739.     pfnUnicodeStrcpy((PS8) g_curr_book_cntx_p->fmgr_file_extension, (PS8) file_ext);
  1740.     g_curr_book_cntx_p->is_short = is_short;
  1741. }
  1742. /*****************************************************************************
  1743.  * FUNCTION
  1744.  *  ebr_frm_delete_all_unused_nfo_file
  1745.  * DESCRIPTION
  1746.  *  Move to ebook folder
  1747.  * PARAMETERS
  1748.  *  void
  1749.  * RETURNS
  1750.  *  void
  1751.  *****************************************************************************/
  1752. void ebr_frm_delete_all_unused_nfo_file(void)
  1753. {
  1754.     /*----------------------------------------------------------------*/
  1755.     /* Local Variables                                                */
  1756.     /*----------------------------------------------------------------*/
  1757.     FS_HANDLE fh_cur;
  1758.     FS_DOSDirEntry file_info;
  1759.     S8 path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  1760.     U8 filename[MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH];
  1761.     U32 driveCount = 0;
  1762.     S8 driveLatter[FMGR_TOTAL_STORAGE];
  1763.     U8 driveNum;
  1764.     /*----------------------------------------------------------------*/
  1765.     /* Code Body                                                      */
  1766.     /*----------------------------------------------------------------*/
  1767.     memset(driveLatter, 0, FMGR_TOTAL_STORAGE);
  1768.     mmi_fmgr_get_exist_drive_letter(driveLatter, &driveNum);
  1769.             
  1770.     while (driveLatter[driveCount] != 0)
  1771.     {
  1772.         memset((char*)path, 0, MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH);
  1773.         
  1774.         pfnUnicodeStrcpy((S8*) path, (S8*) ebr_frm_get_file_path(driveLatter[driveCount], EBR_FRM_SEARCH_NFO));
  1775.             if ((fh_cur = FS_FindFirst(
  1776.                             (const WCHAR*)path,
  1777.                             0,
  1778.                             0,
  1779.                             &file_info,
  1780.                             (U16*) filename,
  1781.                             MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
  1782.             {
  1783.                 do
  1784.                 {
  1785.                     if (!(file_info.Attributes & FS_ATTR_DIR))
  1786.                     {
  1787.                         ebr_frm_open_nfo_file_and_delete_all_unused_nfo(driveLatter[driveCount], filename);
  1788.                     }
  1789.                 } while ((FS_FindNext(fh_cur, &file_info, (U16*) filename, MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH) ==
  1790.                           FS_NO_ERROR));
  1791.                 FS_FindClose(fh_cur);
  1792.             }
  1793.         driveCount++;
  1794.     }
  1795.     
  1796. }
  1797. /*****************************************************************************
  1798.  * FUNCTION
  1799.  *  ebr_frm_open_nfo_file_and_delete_all_unused_nfo
  1800.  * DESCRIPTION
  1801.  *  Move to ebook folder
  1802.  * PARAMETERS
  1803.  *  memory_type     [IN]        
  1804.  *  filename        [IN]        
  1805.  * RETURNS
  1806.  *  void
  1807.  *****************************************************************************/
  1808. void ebr_frm_open_nfo_file_and_delete_all_unused_nfo(S8 memory_type, U8 *filename)
  1809. {
  1810.     /*----------------------------------------------------------------*/
  1811.     /* Local Variables                                                */
  1812.     /*----------------------------------------------------------------*/
  1813.     S8 nfo_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  1814.     S8 file_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  1815.     FILE_HANDLE nfo_hnd, file_hnd;
  1816.     U32 size;
  1817.     S32 nfo_id, strlen_file_name;
  1818.     ebr_frm_book_struct book_struct;
  1819.     ebr_frm_filetype_enum book_type;
  1820.     /*----------------------------------------------------------------*/
  1821.     /* Code Body                                                      */
  1822.     /*----------------------------------------------------------------*/
  1823.     pfnUnicodeStrcpy((S8*) nfo_path, (S8*) ebr_frm_get_file_path(memory_type, EBR_FRM_SEARCH_DEFAULT));
  1824.     pfnUnicodeStrcat((S8*) nfo_path, (S8*) filename);
  1825.     nfo_hnd = FS_Open((const WCHAR*)nfo_path, FS_READ_ONLY);
  1826.     FS_Read(nfo_hnd, &book_struct, sizeof(book_struct), &size);
  1827.     FS_Close(nfo_hnd);
  1828.     strlen_file_name = pfnUnicodeStrlen((const S8*)book_struct.e_book_name);
  1829.     if (book_struct.e_book_name[strlen_file_name * 2 - 6] == 'p')
  1830.     {
  1831.         book_type = EBR_FRM_FILE_TYPE_PDB;
  1832.     }
  1833.     else
  1834.     {
  1835.         book_type = EBR_FRM_FILE_TYPE_TXT;
  1836.     }
  1837.     pfnUnicodeStrcpy((S8*) file_path, (S8*) ebr_frm_get_file_path(memory_type, EBR_FRM_SEARCH_DEFAULT));
  1838.     pfnUnicodeStrcat((S8*) file_path, (S8*) book_struct.e_book_name);
  1839.     file_hnd = FS_Open((const WCHAR*)file_path, FS_READ_ONLY);
  1840.     if (file_hnd <= 0)
  1841.     {
  1842.         FS_Delete((const WCHAR*)nfo_path);
  1843.     }
  1844.     else
  1845.     {
  1846.         FS_Close(file_hnd);
  1847.         if (book_type == EBR_FRM_FILE_TYPE_TXT)
  1848.         {
  1849.             nfo_id = ebr_fmgr_get_nfo_id_for_txt_file(memory_type, (S8*) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
  1850.         }
  1851.         else
  1852.         {
  1853.             nfo_id = ebr_fmgr_get_nfo_id_for_pdb_file(memory_type, (S8*) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
  1854.         }
  1855.         if (nfo_id <= 0)
  1856.         {
  1857.             FS_Delete((const WCHAR*)nfo_path);
  1858.         }
  1859.     }
  1860. }
  1861. #if defined(MMI_ON_HARDWARE_P) && (defined(__MMI_CHSET_BIG5__) || defined(__MMI_CHSET_GB2312__))
  1862. extern const key_index_t *g_chset_encode_to_ucs2_key_LSB_index[NO_OF_TEXT_ENCODING];
  1863. extern const kal_uint8 *g_chset_encode_to_ucs2_key_MSB[NO_OF_TEXT_ENCODING];
  1864. extern const kal_uint16 *g_chset_encode_to_ucs2_table[NO_OF_TEXT_ENCODING];
  1865. extern const kal_uint16 *g_chset_unknown_encode_char;
  1866. /*****************************************************************************
  1867.  * FUNCTION
  1868.  *  ebr_frm_mmi_chset_text_to_ucs2_str
  1869.  * DESCRIPTION
  1870.  *  
  1871.  * PARAMETERS
  1872.  *  file_hnd                    [IN]        
  1873.  *  dest                        [IN]        
  1874.  *  dest_size                   [IN]        
  1875.  *  src                         [IN]        
  1876.  *  src_size                    [IN]        
  1877.  *  encoding                    [IN]        
  1878.  *  over_the_record_border      [?]         
  1879.  * RETURNS
  1880.  *  
  1881.  *****************************************************************************/
  1882. U16 ebr_frm_mmi_chset_text_to_ucs2_str(
  1883.         FILE_HANDLE file_hnd,
  1884.         U8 *dest,
  1885.         S16 dest_size,
  1886.         U8 *src,
  1887.         S16 src_size,
  1888.         TextEncodingEnum encoding,
  1889.         U32 *over_the_record_border)
  1890. {
  1891.     /*----------------------------------------------------------------*/
  1892.     /* Local Variables                                                */
  1893.     /*----------------------------------------------------------------*/
  1894.     const key_index_t *key_LSB_index_table = g_chset_encode_to_ucs2_key_LSB_index[encoding];
  1895.     const kal_uint8 *key_MSB_table = g_chset_encode_to_ucs2_key_MSB[encoding];
  1896.     const kal_uint16 *ucs2_table = g_chset_encode_to_ucs2_table[encoding];
  1897.     U8 key_LSB;
  1898.     U8 key_MSB;
  1899.     S16 start;
  1900.     S16 end;
  1901.     S16 pos = 0;
  1902.     S16 index;
  1903.     S16 count = 0;
  1904.     /*----------------------------------------------------------------*/
  1905.     /* Code Body                                                      */
  1906.     /*----------------------------------------------------------------*/
  1907.     *over_the_record_border = 0;
  1908.     while (*(src) != 0) /* I do not know how we assume that this is end of data.. Currently we are taking only chinese encodings for
  1909.                            the optimized algo so we can take it as 2 bytes */
  1910.     {
  1911.         if (*(src) <= 0x7f)
  1912.         {
  1913.             *(dest + pos) = *src;
  1914.             pos++;
  1915.             *(dest + pos) = 0;
  1916.             pos++;
  1917.             src += 1;
  1918.             count += 1;
  1919.         }
  1920.         else
  1921.         {
  1922.             key_LSB = (U8) (*(src));
  1923.             count += 1;
  1924.             start = key_LSB_index_table[key_LSB].start;
  1925.             if (start < 0)
  1926.             {
  1927.                 dest[pos] = (U8) g_chset_unknown_encode_char[encoding];
  1928.                 dest[pos + 1] = (U8) (g_chset_unknown_encode_char[encoding] >> 8);
  1929.                 src += 1;
  1930.             }
  1931.             else
  1932.             {
  1933.                 if (count >= src_size)
  1934.                 {
  1935.                     U32 temp_size;
  1936.                     FS_Read(file_hnd, &key_MSB, 1, &temp_size);
  1937.                     if (temp_size != 1)
  1938.                     {
  1939.                         key_MSB = 0;
  1940.                     }
  1941.                     else
  1942.                     {
  1943.                         *over_the_record_border = 1;
  1944.                     }
  1945.                 }
  1946.                 else
  1947.                 {
  1948.                     key_MSB = (U8) (*(src + 1));
  1949.                 }
  1950.                 count += 1;
  1951.                 end = key_LSB_index_table[key_LSB].end;
  1952.                 if ((index = ebr_frm_mmi_chset_binary_search(key_MSB, key_MSB_table, start, end)) < 0)  /* key MSB not found */
  1953.                 {
  1954.                     dest[pos] = (U8) g_chset_unknown_encode_char[encoding];
  1955.                     dest[pos + 1] = (U8) (g_chset_unknown_encode_char[encoding] >> 8);
  1956.                 }
  1957.                 else
  1958.                 {
  1959.                     dest[pos] = (U8) ucs2_table[index];
  1960.                     dest[pos + 1] = (U8) (ucs2_table[index] >> 8);
  1961.                 }
  1962.                 src += 2;
  1963.             }
  1964.             
  1965.             pos += 2;
  1966.         }
  1967.         if (pos >= dest_size - 2)
  1968.         {
  1969.             break;
  1970.         }
  1971.     }
  1972.     dest[pos] = 0;
  1973.     dest[pos + 1] = 0;
  1974.     return pos + 2;
  1975. }
  1976. /* dest_size must be >= 4 */
  1977. /*****************************************************************************
  1978.  * FUNCTION
  1979.  *  ebr_frm_mmi_chset_binary_search
  1980.  * DESCRIPTION
  1981.  *  
  1982.  * PARAMETERS
  1983.  *  key                 [IN]        
  1984.  *  lookup_table        [IN]        
  1985.  *  start               [IN]        
  1986.  *  end                 [IN]        
  1987.  * RETURNS
  1988.  *  
  1989.  *****************************************************************************/
  1990. S16 ebr_frm_mmi_chset_binary_search(const kal_uint8 key, const kal_uint8 *lookup_table, kal_int16 start, kal_int16 end)
  1991. {
  1992.     /*----------------------------------------------------------------*/
  1993.     /* Local Variables                                                */
  1994.     /*----------------------------------------------------------------*/
  1995.     /*----------------------------------------------------------------*/
  1996.     /* Code Body                                                      */
  1997.     /*----------------------------------------------------------------*/
  1998.     while (start <= end)
  1999.     {
  2000.         kal_int16 mid = (start + end) / 2;
  2001.         if (key > lookup_table[mid])
  2002.         {
  2003.             start = mid + 1;
  2004.         }
  2005.         else if (key < lookup_table[mid])
  2006.         {
  2007.             end = mid - 1;
  2008.         }
  2009.         else    /* key == target */
  2010.         {
  2011.             return mid;
  2012.         }
  2013.     }
  2014.     return -1;
  2015. }
  2016. #endif /* defined(MMI_ON_HARDWARE_P) && (defined(__MMI_CHSET_BIG5__) || defined(__MMI_CHSET_GB2312__)) */ /* defined(MMI_ON_HARDWARE_P) && defined(__MMI_CHSET_IDEOGRAM_SUPPORT__) */
  2017. #if defined(MMI_ON_HARDWARE_P)
  2018. const kal_uint8 g_ebr_frm_cheset_utf8_bytes_per_char[16] = 
  2019. {
  2020.     1, 1, 1, 1, 1, 1, 1, 1,
  2021.     0, 0, 0, 0, 2, 2, 3, 4  /* we don't support UCS4 */
  2022. };
  2023. extern kal_int32 mmi_chset_utf8_to_ucs2(kal_uint8 *dest, kal_uint8 *utf8);
  2024. /*****************************************************************************
  2025.  * FUNCTION
  2026.  *  ebr_frm_mmi_chset_utf8_to_ucs2_string
  2027.  * DESCRIPTION
  2028.  *  
  2029.  * PARAMETERS
  2030.  *  file_hnd                    [IN]        
  2031.  *  dest                        [IN]        
  2032.  *  dest_size                   [IN]        
  2033.  *  src                         [IN]        
  2034.  *  src_size                    [IN]        
  2035.  *  over_the_record_border      [IN]         
  2036.  * RETURNS
  2037.  *  
  2038.  *****************************************************************************/
  2039. S32 ebr_frm_mmi_chset_utf8_to_ucs2_string(
  2040.         FILE_HANDLE file_hnd,
  2041.         U8 *dest,
  2042.         S16 dest_size,
  2043.         U8 *src,
  2044.         S16 src_size,
  2045.         U32 *over_the_record_border)
  2046. {
  2047.     /*----------------------------------------------------------------*/
  2048.     /* Local Variables                                                */
  2049.     /*----------------------------------------------------------------*/
  2050.     S32 pos = 0;
  2051.     S32 cnt;
  2052.     S32 src_count = 0;
  2053.     /*----------------------------------------------------------------*/
  2054.     /* Code Body                                                      */
  2055.     /*----------------------------------------------------------------*/
  2056.     *over_the_record_border = 0;
  2057.     while (*src && pos < dest_size - 2)
  2058.     {
  2059.         cnt = g_ebr_frm_cheset_utf8_bytes_per_char[(*src) >> 4];
  2060.         if (src_count + cnt > src_size)
  2061.         {
  2062.             S32 i = 0;
  2063.             U8 utf8_char[4];
  2064.             U8 bytes_in_buffer;
  2065.             U32 size;
  2066.             *over_the_record_border = (src_count + cnt) - src_size;
  2067.             bytes_in_buffer = cnt - *over_the_record_border;
  2068.             
  2069.             for (i = 0; i < bytes_in_buffer; i++)
  2070.             {
  2071.                 utf8_char[i] = *src;
  2072.                 src += 1;
  2073.             }
  2074.             FS_Read(file_hnd, &utf8_char[bytes_in_buffer], *over_the_record_border, &size);
  2075.             if (size != *over_the_record_border)
  2076.             {
  2077.                 break;
  2078.             }
  2079.             else
  2080.             {
  2081.                 cnt = mmi_chset_utf8_to_ucs2(dest + pos, utf8_char);
  2082.             }
  2083.         }
  2084.         else
  2085.         {
  2086.             cnt = mmi_chset_utf8_to_ucs2(dest + pos, src);
  2087.         }
  2088.         if (cnt == 0)   /* abnormal case */
  2089.         {
  2090.             break;
  2091.         }
  2092.         else if (cnt == 4)
  2093.         {
  2094.             src += cnt;
  2095.         }
  2096.         else    /* normal case */
  2097.         {
  2098.             src += cnt;
  2099.             pos += 2;
  2100.         }
  2101.         src_count += cnt;
  2102.     }
  2103.     dest[pos] = 0;
  2104.     dest[pos + 1] = 0;
  2105.     return pos + 2;
  2106. }
  2107. #endif /* defined(MMI_ON_HARDWARE_P) */ 
  2108. /*****************************************************************************
  2109.  * FUNCTION
  2110.  *  ebr_frm_reset_find_next_data
  2111.  * DESCRIPTION
  2112.  *  Clears flags for find next on shortcut keys
  2113.  * PARAMETERS
  2114.  *  void
  2115.  * RETURNS
  2116.  *  void
  2117.  *****************************************************************************/
  2118. void ebr_frm_reset_find_next_data(void)
  2119. {
  2120.     /*----------------------------------------------------------------*/
  2121.     /* Local Variables                                                */
  2122.     /*----------------------------------------------------------------*/
  2123.     /*----------------------------------------------------------------*/
  2124.     /* Code Body                                                      */
  2125.     /*----------------------------------------------------------------*/
  2126.     g_curr_book_cntx_p->ebr_last_offset_string = -1;
  2127.     g_curr_book_cntx_p->search_found_flag = FALSE;
  2128.     g_curr_book_cntx_p->search_string_count = 0;
  2129.     g_curr_book_cntx_p->find_next_first_flag = 0;
  2130.     g_curr_book_cntx_p->last_record_flag = 0;
  2131.     g_curr_book_cntx_p->ebr_last_text_offset = 0;
  2132.     g_curr_book_cntx_p->ebr_last_page_id = 0;
  2133. }
  2134. /*****************************************************************************
  2135.  * FUNCTION
  2136.  *  ebr_frm_get_and_set_current_page_values
  2137.  * DESCRIPTION
  2138.  *  Sets current page values in case of Exit category
  2139.  * PARAMETERS
  2140.  *  void
  2141.  * RETURNS
  2142.  *  void
  2143.  *****************************************************************************/
  2144. void ebr_frm_get_and_set_current_page_values(void)
  2145. {
  2146.     /*----------------------------------------------------------------*/
  2147.     /* Local Variables                                                */
  2148.     /*----------------------------------------------------------------*/
  2149.     U32 page_id;
  2150.     S32 text_offset;
  2151.     U8 shared_bytes;
  2152.     U8 last_showed_percentage;
  2153.     S32 last_text_offset_y;
  2154.     /*----------------------------------------------------------------*/
  2155.     /* Code Body                                                      */
  2156.     /*----------------------------------------------------------------*/
  2157.     wgui_paging_multiline_get_current_page(
  2158.         &page_id,
  2159.         &text_offset,
  2160.         &shared_bytes,
  2161.         &last_showed_percentage,
  2162.         &last_text_offset_y);
  2163.     g_curr_book_cntx_p->ebr_last_text_offset = text_offset;
  2164.     g_curr_book_cntx_p->ebr_last_page_id = page_id;
  2165. }
  2166. #ifdef __MMI_LANG_HINDI__
  2167. /*****************************************************************************
  2168.  * FUNCTION
  2169.  *  ebr_frm_check_for_full_characters
  2170.  * DESCRIPTION
  2171.  *  
  2172.  * PARAMETERS
  2173.  *  pattern     [IN]        
  2174.  * RETURNS
  2175.  *  
  2176.  *****************************************************************************/
  2177. pBOOL ebr_frm_check_for_full_characters(S16 *pattern)
  2178. {
  2179.     /*----------------------------------------------------------------*/
  2180.     /* Local Variables                                                */
  2181.     /*----------------------------------------------------------------*/
  2182.     /*----------------------------------------------------------------*/
  2183.     /* Code Body                                                      */
  2184.     /*----------------------------------------------------------------*/
  2185.     if (pattern[pfnUnicodeStrlen((const S8*)pattern) - 1] == 2381)
  2186.     {
  2187.         return FALSE;
  2188.     }
  2189.     else
  2190.     {
  2191.         return TRUE;
  2192.     }
  2193. }
  2194. #endif /* __MMI_LANG_HINDI__ */ 
  2195. /*****************************************************************************
  2196.  * FUNCTION
  2197.  *  ebr_frm_check_drive_space
  2198.  * DESCRIPTION
  2199.  *  
  2200.  * PARAMETERS
  2201.  *  void
  2202.  * RETURNS
  2203.  *  
  2204.  *****************************************************************************/
  2205. pBOOL ebr_frm_check_drive_space(void)
  2206. {
  2207.     /*----------------------------------------------------------------*/
  2208.     /* Local Variables                                                */
  2209.     /*----------------------------------------------------------------*/
  2210.     S8 file_path_in_ascii[5];
  2211.     S8 file_path[10];
  2212.     U64 disk_free_space;
  2213.     U64 disk_total_space;
  2214.     S32 fs_ret;
  2215.     FS_DiskInfo disk_info;
  2216.     /*----------------------------------------------------------------*/
  2217.     /* Code Body                                                      */
  2218.     /*----------------------------------------------------------------*/
  2219.     sprintf((char*)file_path_in_ascii, "%c", g_curr_book_cntx_p->memory_type_selected);
  2220.     strcat((char*)file_path_in_ascii, ":\");
  2221.     AnsiiToUnicodeString((PS8) file_path, file_path_in_ascii);
  2222.     fs_ret = FS_GetDiskInfo((PU16) file_path, &disk_info, FS_DI_BASIC_INFO | FS_DI_FREE_SPACE);
  2223.     disk_free_space = 0;
  2224.     disk_total_space = 0;
  2225.     if (fs_ret >= 0)
  2226.     {
  2227.         disk_free_space = disk_info.FreeClusters * disk_info.SectorsPerCluster * disk_info.BytesPerSector;
  2228.         disk_total_space = disk_info.TotalClusters * disk_info.SectorsPerCluster * disk_info.BytesPerSector;
  2229.         if (disk_free_space <= g_curr_book_cntx_p->g_nfo_book_struct.book_size)
  2230.         {
  2231.             return FALSE;
  2232.         }
  2233.         else
  2234.         {
  2235.             return TRUE;
  2236.         }
  2237.     }
  2238.     return FALSE;
  2239. }
  2240. /*****************************************************************************
  2241.  * FUNCTION
  2242.  *  ebr_frm_check_nfo_file_size
  2243.  * DESCRIPTION
  2244.  *  
  2245.  * PARAMETERS
  2246.  *  void
  2247.  * RETURNS
  2248.  *  
  2249.  *****************************************************************************/
  2250. pBOOL ebr_frm_check_nfo_file_size(void)
  2251. {
  2252.     /*----------------------------------------------------------------*/
  2253.     /* Local Variables                                                */
  2254.     /*----------------------------------------------------------------*/
  2255.     S8 file_path_in_ascii[5];
  2256.     S8 file_path[10];
  2257.     U64 disk_free_space;
  2258.     U64 disk_total_space;
  2259.     S32 fs_ret;
  2260.     FS_DiskInfo disk_info;
  2261.     /*----------------------------------------------------------------*/
  2262.     /* Code Body                                                      */
  2263.     /*----------------------------------------------------------------*/
  2264.     sprintf((char*)file_path_in_ascii, "%c", g_curr_book_cntx_p->memory_type_selected);
  2265.     strcat((char*)file_path_in_ascii, ":\");
  2266.     AnsiiToUnicodeString((PS8) file_path, file_path_in_ascii);
  2267.     fs_ret = FS_GetDiskInfo((PU16) file_path, &disk_info, FS_DI_BASIC_INFO | FS_DI_FREE_SPACE);
  2268.     disk_free_space = 0;
  2269.     disk_total_space = 0;
  2270.     if (fs_ret >= 0)
  2271.     {
  2272.         disk_free_space = disk_info.FreeClusters * disk_info.SectorsPerCluster * disk_info.BytesPerSector;
  2273.         disk_total_space = disk_info.TotalClusters * disk_info.SectorsPerCluster * disk_info.BytesPerSector;
  2274.         if (disk_free_space <= sizeof(g_curr_book_cntx_p->g_nfo_book_struct))
  2275.         {
  2276.             return TRUE;
  2277.         }
  2278.         else
  2279.         {
  2280.             return FALSE;
  2281.         }
  2282.     }
  2283.     return FALSE;
  2284. }
  2285. /*****************************************************************************
  2286.  * FUNCTION
  2287.  *  ebr_fmgr_kernel_hide_ext_name
  2288.  * DESCRIPTION
  2289.  *  
  2290.  * PARAMETERS
  2291.  *  str_buf_ptr     [?]     
  2292.  *  info_ptr        [?]     
  2293.  * RETURNS
  2294.  *  void
  2295.  *****************************************************************************/
  2296. void ebr_fmgr_kernel_hide_ext_name(S8 *str_buf_ptr, FMGR_FILE_INFO_STRUCT *info_ptr)
  2297. {
  2298.     /*----------------------------------------------------------------*/
  2299.     /* Local Variables                                                */
  2300.     /*----------------------------------------------------------------*/
  2301.     S32 str_len;
  2302.     S32 ext_str_len;
  2303.     /*----------------------------------------------------------------*/
  2304.     /* Code Body                                                      */
  2305.     /*----------------------------------------------------------------*/
  2306.     str_len = pfnUnicodeStrlen((PS8) str_buf_ptr);
  2307.     ext_str_len = pfnUnicodeStrlen((PS8) info_ptr->file_ext);
  2308.     if (ext_str_len > 0)
  2309.     {
  2310.         ext_str_len += 1;
  2311.     }
  2312.     if (!(info_ptr->attribute & FS_ATTR_DIR))   /* not folder */
  2313.     {
  2314.         memset(&str_buf_ptr[(str_len - ext_str_len) * ENCODING_LENGTH], 0, ext_str_len * ENCODING_LENGTH);
  2315.     }
  2316. }
  2317. /*****************************************************************************
  2318.  * FUNCTION
  2319.  *  ebr_frm_remove_last_directory
  2320.  * DESCRIPTION
  2321.  *  
  2322.  * PARAMETERS
  2323.  *  void
  2324.  * RETURNS
  2325.  *  void
  2326.  *****************************************************************************/
  2327. void ebr_frm_remove_last_directory(void)
  2328. {
  2329.     /*----------------------------------------------------------------*/
  2330.     /* Local Variables                                                */
  2331.     /*----------------------------------------------------------------*/
  2332.     /*----------------------------------------------------------------*/
  2333.     /* Code Body                                                      */
  2334.     /*----------------------------------------------------------------*/
  2335.     mmi_fmgr_remove_last_dir((PS8) g_curr_book_cntx_p->book_name_path);
  2336.     ebr_fmgr_copy_new_file_path_after_move((S8*) g_curr_book_cntx_p->book_name_path);
  2337. }
  2338. /*****************************************************************************
  2339.  * FUNCTION
  2340.  *  ebr_frm_check_is_nfo_file_exist
  2341.  * DESCRIPTION
  2342.  *  
  2343.  * PARAMETERS
  2344.  *  nfo_id      [IN]        
  2345.  * RETURNS
  2346.  *  void
  2347.  *****************************************************************************/
  2348. void ebr_frm_check_is_nfo_file_exist(S16 nfo_id)
  2349. {
  2350.     /*----------------------------------------------------------------*/
  2351.     /* Local Variables                                                */
  2352.     /*----------------------------------------------------------------*/
  2353.     FILE_HANDLE nfo_hnd;
  2354.     S16 error;
  2355.     /*----------------------------------------------------------------*/
  2356.     /* Code Body                                                      */
  2357.     /*----------------------------------------------------------------*/
  2358.     nfo_hnd = FS_Open((const WCHAR*)ebr_frm_get_nfo_file_name((S32) nfo_id), FS_READ_ONLY);
  2359.     if (nfo_hnd <= 0)
  2360.     {
  2361.         nfo_id = 0;
  2362.         WriteValue(NVRAM_EBOOK_NFO_LID, (void*)&nfo_id, DS_SHORT, &error);
  2363.     }
  2364.     FS_Close(nfo_hnd);
  2365. }
  2366. /*****************************************************************************
  2367.  * FUNCTION
  2368.  *  ebr_frm_check_file_exist
  2369.  * DESCRIPTION
  2370.  *  
  2371.  * PARAMETERS
  2372.  *  void
  2373.  * RETURNS
  2374.  *  pBOOL
  2375.  *****************************************************************************/
  2376. pBOOL ebr_frm_check_file_exist(void)
  2377. {
  2378. FILE_HANDLE file_hnd;
  2379.     /*----------------------------------------------------------------*/
  2380.     /* Code Body                                                      */
  2381.     /*----------------------------------------------------------------*/
  2382. if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
  2383.     {
  2384.         file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path, FS_READ_ONLY);
  2385.     }
  2386.     else
  2387.     {
  2388.         file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->book_name_path, FS_READ_ONLY);
  2389.     }
  2390. if(file_hnd<=0)
  2391. return FALSE;
  2392. else
  2393. {
  2394. FS_Close(file_hnd);
  2395. return TRUE;
  2396. }
  2397. }
  2398. MMI_BOOL mmi_ebr_is_memory_type_changed(S8 memoryType)
  2399. {
  2400.     if (g_curr_book_cntx_p->g_nfo_book_struct.memory_type == memoryType)
  2401.     {
  2402.         return MMI_FALSE;
  2403.     }
  2404.     else
  2405.     {
  2406.         return MMI_TRUE;
  2407.     }
  2408. }
  2409. #endif /* __MMI_EBOOK_READER__ */