form_FATEditor.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:30k
源码类别:

MTK

开发平台:

C++ Builder

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *   form_FATEditor.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   FAT editor form source
  48.  *
  49.  * Author:
  50.  * -------
  51.  *  Andy Ueng (mtk00490)
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * $Revision$
  58.  * $Modtime$
  59.  * $Log$
  60.  * 
  61.  *------------------------------------------------------------------------------
  62.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  63.  *============================================================================
  64.  ****************************************************************************/
  65. //---------------------------------------------------------------------------
  66. #include <vcl.h>
  67. #pragma hdrstop
  68. #ifndef _FORM_MAIN_H_
  69. #include "form_main.h"
  70. #endif
  71. #ifndef _FORM_FATEDITOR_H_
  72. #include "form_FATEditor.h"
  73. #endif
  74. //#include "meta_utils.h"
  75. #ifndef  _MAN_ACTIVE_H_
  76. #include "man_active.h"
  77. #endif
  78. #ifndef _FAT_EDITOR_H_
  79. #include "FAT_Editor.h"
  80. #endif
  81. //---------------------------------------------------------------------------
  82. #pragma package(smart_init)
  83. #pragma resource "*.dfm"
  84. TfrmFATEditor *frmFATEditor;
  85. extern TfrmMainSel *frmMainSel;
  86. //===========================================================================
  87. static void CNF_GetFATDiskInfo(void)
  88. {
  89.     frmFATEditor->CNF_GetFATDiskInfo();
  90. }
  91. //---------------------------------------------------------------------------
  92. static void CNF_FATGetFileInfo(void)
  93. {
  94.     frmFATEditor->CNF_FATGetFileInfo();
  95. }
  96. //---------------------------------------------------------------------------
  97. static void CNF_FATGetDirectoryInfo(void)
  98. {
  99.     frmFATEditor->CNF_FATGetDirectoryInfo();
  100. }
  101. //---------------------------------------------------------------------------
  102. static void CNF_FAT_Read_To_File(void)
  103. {
  104.     frmFATEditor->CNF_FAT_Read_To_File();
  105. }
  106. //---------------------------------------------------------------------------
  107. static void CNF_FAT_Write_By_File(void)
  108. {
  109.     frmFATEditor->CNF_FAT_Write_By_File();
  110. }
  111. //---------------------------------------------------------------------------
  112. static void CNF_FAT_Delete(void)
  113. {
  114.     frmFATEditor->CNF_FAT_Delete();
  115. }
  116. //===========================================================================
  117. __fastcall TfrmFATEditor::TfrmFATEditor(TComponent* Owner)
  118.         : TForm(Owner)
  119. {
  120.     m_bFirstFormShow = true;
  121.     Init();
  122. }
  123. //---------------------------------------------------------------------------
  124. void TfrmFATEditor::Init(void)
  125. {
  126.     m_bInit = true;
  127. }
  128. //---------------------------------------------------------------------------
  129. void __fastcall TfrmFATEditor::FormShow(TObject *Sender)
  130. {
  131.     if (m_bFirstFormShow)
  132.     {
  133.        // m_asCurrentFatPath =
  134.         edtCurrentFATPath->Text = "C:\";
  135.         btnGetDirectoryListClick(NULL);
  136.         m_bFirstFormShow = false;
  137.   }
  138. }
  139. //---------------------------------------------------------------------------
  140. void __fastcall TfrmFATEditor::FormActivate(TObject *Sender)
  141. {
  142.     BBCHIP_TYPE bb_chip = frmMainSel->Get_FinalBBChip();
  143.      if( bb_chip == MT6205 || bb_chip == MT6205B )
  144.      {
  145.         btnGetFATDiskInfo->Visible = false;
  146.         lblSectorPerCluster->Visible = false;
  147.         lblFATTotalSize->Visible = false;
  148.         lblFATFreeSpace->Visible = false;
  149.         stSectorPerCluster->Visible = false;
  150.         stFATTotalSize->Visible = false;
  151.         stFATFreeSpace->Visible = false;
  152.      }
  153. }
  154. //---------------------------------------------------------------------------
  155. void __fastcall TfrmFATEditor::FormClose(TObject *Sender,
  156.       TCloseAction &Action)
  157. {
  158.     TimerFATProgressTimer->Enabled = false;
  159.     HintTimer->Enabled = false;
  160. }
  161. //==========================================================================
  162. void TfrmFATEditor::CurrentPageReset(void)
  163. {
  164.     btnWriteToFAT->Enabled = true;
  165.     btnGetDirectoryList->Enabled = true;
  166.     btnGetFileList->Enabled = true;
  167.     btnReadFromFAT->Enabled = true;
  168.     btnDeleteFromFAT->Enabled = true;
  169.     btnGetFATDiskInfo->Enabled = true;
  170. }
  171. //---------------------------------------------------------------------------
  172. void TfrmFATEditor::CurrentPageLock(void)
  173. {
  174.     btnWriteToFAT->Enabled = false;
  175.     btnGetDirectoryList->Enabled = false;
  176.     btnGetFileList->Enabled = false;
  177.     btnReadFromFAT->Enabled = false;
  178.     btnDeleteFromFAT->Enabled = false;
  179.     btnGetFATDiskInfo->Enabled = false;
  180. }
  181. //==========================================================================
  182. void __fastcall TfrmFATEditor::btnGetFATDiskInfoClick(TObject *Sender)
  183. {
  184.     AnsiString as_DriveLetter;
  185.     FAT_DiskInfo_T  DiskInfo;
  186.     clearProgressBar();
  187.     clearAllPanel();
  188.     getDriveLetterFromStr(edtCurrentFATPath->Text, as_DriveLetter);
  189.     if (as_DriveLetter.AnsiCompareIC("") == 0)
  190.     {
  191.         sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "   Can not get valid drive letter from current FAT path";
  192.         Application->MessageBox("Execution Failure : can not get valid drive letter from current FAT path", "FAILURE", MB_OK);
  193.         return;
  194.     }
  195.     char c_drive_letter[1];
  196.     strncpy(c_drive_letter, as_DriveLetter.c_str(), 1);
  197.     m_cFAT_EDITOR_Obj.ConfirmCallback = ::CNF_GetFATDiskInfo;
  198.     m_cFAT_EDITOR_Obj.Req_FAT_GetDiskInfo_Start(c_drive_letter[0]);
  199.     sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Get FAT disk info progressing";
  200. }
  201. //---------------------------------------------------------------------------
  202. void TfrmFATEditor::CNF_GetFATDiskInfo(void)
  203. {
  204.     E_METAAPP_RESULT_T state = m_cFAT_EDITOR_Obj.Get_ConfirmState();
  205.     switch (state)
  206.     {
  207.         case METAAPP_SUCCESS:
  208.         {
  209.             FAT_DiskInfo_T disk_info;
  210.             m_cFAT_EDITOR_Obj.Get_FatDiskInfo(disk_info);
  211.             stSectorPerCluster->Caption = IntToStr(disk_info.SectorsPerCluster );
  212.             stFATTotalSize->Caption = IntToStr(disk_info.TotalSize );
  213.             stFATFreeSpace->Caption = IntToStr(disk_info.FreeSpace );
  214.             sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Get FAT disk info successfully";
  215.         }
  216.         break;
  217.         case METAAPP_FAIL:
  218.         {
  219.             sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Get FAT disk info fail";
  220.             Application->MessageBox("Execution Failure : get FAT disk info", "FAILURE", MB_OK);
  221.         }
  222.         break;
  223.         case METAAPP_TIMEOUT:
  224.         {
  225.             sbFAT->Panels->Items[0]->Text = (AnsiString) "  Get FAT disk info timeout";
  226.             Application->MessageBox("Execution Timeout : get FAT disk info", "TIMEOUT", MB_OK);
  227.         }
  228.         break;
  229.         case METAAPP_STOP:
  230.         {
  231.             sbFAT->Panels->Items[0]->Text = (AnsiString) "  Get FAT disk info stop";
  232.         }
  233.         break;
  234.         default:
  235.         {
  236.             DisplayFATErrorMsg();
  237.         }
  238.         break;
  239.     }
  240.     CurrentPageReset();
  241. }
  242. //===========================================================================
  243. void __fastcall TfrmFATEditor::btnGetDirectoryListClick(TObject *Sender)
  244. {
  245.     AnsiString as_Drive;
  246.     CurrentPageLock();
  247.     clearProgressBar();
  248.     clearAllPanel();
  249.     //TimerFATDir->Enabled = true;
  250.    // m_asParentFatPath = m_asCurrentFatPath;
  251.     if (!getDriveFromStr(edtCurrentFATPath->Text, as_Drive))
  252.     {
  253.         sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "   Can not get valid drive from current FAT path";
  254.         Application->MessageBox("Execution Failure : can not get valid drive from current FAT path", "FAILURE", MB_OK );
  255.         return;
  256.     }
  257.     CurrentPageLock();
  258.     S_FAT_DIRECTORY_INFO_REQ_T sFatDirInfoReq;
  259.     sFatDirInfoReq.as_FAT_dir_path = edtCurrentFATPath->Text;
  260.     sFatDirInfoReq.as_FAT_dir_type = edtFileType->Text;
  261.     m_cFAT_EDITOR_Obj.ConfirmCallback = ::CNF_FATGetDirectoryInfo;
  262.     m_cFAT_EDITOR_Obj.Req_FAT_GetDirectoryInfo_Start(sFatDirInfoReq);
  263. }
  264. //----------------------------------------------------------
  265. void TfrmFATEditor::CNF_FATGetDirectoryInfo(void)
  266. {
  267.     E_METAAPP_RESULT_T state = m_cFAT_EDITOR_Obj.Get_ConfirmState();
  268.     switch (state)
  269.     {
  270.         case METAAPP_SUCCESS:
  271.         {
  272.             S_FAT_DIRECTORY_INFO_CNF_T dir_info;
  273.             m_cFAT_EDITOR_Obj.Get_FatDirInfo(dir_info);
  274.             lbFATDirectory->Clear();
  275.             vector<AnsiString>:: iterator iter;
  276.             for (iter = dir_info.v_FATDirName.begin(); iter != dir_info.v_FATDirName.end(); iter++)
  277.             {
  278.                 lbFATDirectory->Items->Add(*iter);
  279.             }
  280.             sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  FAT get directory info successfully";
  281.         }
  282.         break;
  283.         case METAAPP_FAIL:
  284.         {
  285.             DisplayFATErrorMsg();
  286.             sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Get FAT directory list fail";
  287.             Application->MessageBox("Execution Failure : get FAT directory list", "FAILURE", MB_OK);
  288.         }
  289.         break;
  290.         case METAAPP_TIMEOUT:
  291.         {
  292.             DisplayFATErrorMsg();
  293.             sbFAT->Panels->Items[0]->Text = (AnsiString) "  Get FAT directory list timeout";
  294.             Application->MessageBox("Execution Timeout : get FAT directory list", "TIMEOUT", MB_OK);
  295.         }
  296.         break;
  297.         case METAAPP_STOP:
  298.         {
  299.             sbFAT->Panels->Items[0]->Text = (AnsiString) "  Get FAT directory list stop";
  300.         }
  301.         break;
  302.         default:
  303.         {
  304.             DisplayFATErrorMsg();
  305.         }
  306.         break;
  307.     }
  308.     CurrentPageReset();
  309. }
  310. #if 0
  311. //==============================================================================
  312. void __fastcall TfrmFATEditor::TimerFATDirTimer(TObject *Sender)
  313. {
  314.         if ( m_cFAT_EDITOR_Obj.Get_MetaResult() == META_SUCCESS )
  315.         {
  316.              edtCurrentFATPath->Text = m_asCurrentFatPath;
  317.              lbFATDirectory->Clear();
  318.              for(int i=0; i<m_cFAT_EDITOR_Obj.FAT_filepath_size; i++)
  319.              {
  320.                  lbFATDirectory->Items->Add(m_cFAT_EDITOR_Obj.FAT_filepath[i]);
  321.              }
  322.              sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  FAT get directory info success";
  323.         }
  324.         else
  325.         {
  326.              DisplayFATErrorMsg();
  327.         }
  328.     }
  329. }
  330. #endif
  331. //---------------------------------------------------------------------------
  332. void __fastcall TfrmFATEditor::btnGetFileListClick(TObject *Sender)
  333. {
  334.     CurrentPageLock();
  335.     clearProgressBar();
  336.     clearAllPanel();
  337.     //m_asParentFatPath = m_asCurrentFatPath;
  338.     AnsiString as_Drive;
  339.     if (!getDriveFromStr(edtCurrentFATPath->Text, as_Drive))
  340.     {
  341.         sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "   Can not get valid drive from current FAT path";
  342.         Application->MessageBox("Execution Failure : can not get valid drive from current FAT path", "FAILURE", MB_OK );
  343.         return;
  344.     }
  345.     CurrentPageLock();
  346.     S_FAT_FILE_INFO_REQ_T sFatFileInfoReq;
  347.     sFatFileInfoReq.as_FAT_file_path = edtCurrentFATPath->Text;
  348.     sFatFileInfoReq.as_FAT_file_type = edtFileType->Text;
  349.     if (m_rbRecursive->Checked)
  350.     {
  351.         sFatFileInfoReq.e_FAT_find_mode = FAT_FIND_FILE_RECURSIVE;
  352.     }
  353.     else
  354.     {
  355.         sFatFileInfoReq.e_FAT_find_mode = FAT_FIND_FILE;
  356.     }
  357. //    TimerFATFile->Enabled = true;
  358.     m_cFAT_EDITOR_Obj.ConfirmCallback = ::CNF_FATGetFileInfo;
  359.     m_cFAT_EDITOR_Obj.Req_FAT_GetFileInfo_Start(sFatFileInfoReq);
  360. }
  361. //---------------------------------------------------------------------------
  362. void  TfrmFATEditor::CNF_FATGetFileInfo(void)
  363. {
  364.     E_METAAPP_RESULT_T state = m_cFAT_EDITOR_Obj.Get_ConfirmState();
  365.     switch (state)
  366.     {
  367.         case METAAPP_SUCCESS:
  368.         {
  369.             S_FAT_FILE_INFO_CNF_T file_info;
  370.             m_cFAT_EDITOR_Obj.Get_FatFileInfo(file_info);
  371.             lbFATFile->Clear();
  372.             vector<AnsiString>:: iterator iter;
  373.             for (iter = file_info.v_FATFileName.begin(); iter != file_info.v_FATFileName.end(); iter++)
  374.             {
  375.                 lbFATFile->Items->Add(*iter);
  376.             }
  377.             sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  FAT get file list successfully";
  378.         }
  379.         break;
  380.         case METAAPP_FAIL:
  381.         {
  382.             DisplayFATErrorMsg();
  383.             sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Get FAT file list fail";
  384.             Application->MessageBox("Execution Failure : get FAT file list", "FAILURE", MB_OK);
  385.         }
  386.         break;
  387.         case METAAPP_TIMEOUT:
  388.         {
  389.             DisplayFATErrorMsg();
  390.             sbFAT->Panels->Items[0]->Text = (AnsiString) "  Get FAT file list timeout";
  391.             Application->MessageBox("Execution Timeout : get FAT file list", "TIMEOUT", MB_OK);
  392.         }
  393.         break;
  394.         case METAAPP_STOP:
  395.         {
  396.             sbFAT->Panels->Items[0]->Text = (AnsiString) "  Get FAT file list stop";
  397.         }
  398.         break;
  399.         default:
  400.         {
  401.             DisplayFATErrorMsg();
  402.         }
  403.         break;
  404.     }
  405.     CurrentPageReset();
  406. }
  407. //---------------------------------------------------------------------------
  408. void __fastcall TfrmFATEditor::btnReadFromFATClick(TObject *Sender)
  409. {
  410.    //char str[512];
  411.    //bool ok;
  412.   // int i;
  413.     if (lbFATFile->ItemIndex < 0)
  414.     {
  415.         ShowMessage(" You have to select a FAT file to read ");
  416.         return;
  417.     }
  418.    //sbFAT->Panels->Items[STATUS_BAR_INDEX_FILENAME]->Text = "  " + lbFATFile->Items->Strings[lbFATFile->ItemIndex];
  419.    //getFilenameFromStr(lbFATFile->Items->Strings[lbFATFile->ItemIndex].c_str(), as_local_filename);
  420.    //SaveDialog->FileName = as_local_filename;
  421.    //ok = SaveDialog->Execute();
  422.    //if( !ok )  return;
  423.    //strcpy(local_filepath, SaveDialog->FileName.c_str() );
  424.    //strcpy(FAT_filename, lbFATFile->Items->Strings[lbFATFile->ItemIndex].c_str());
  425.    // FAT read
  426.     AnsiString as_last_local_filepath;
  427.     S_FAT_READ_T fat_read;
  428.     fat_read.as_LocalFilePath = lbLocalDir->Directory;
  429.     as_last_local_filepath = fat_read.as_LocalFilePath.SubString(fat_read.as_LocalFilePath.Length(), 1);
  430.     if (as_last_local_filepath.AnsiCompare("\") != 0)
  431.     {
  432.         fat_read.as_LocalFilePath += "\";
  433.     }
  434.     for (int i=0; i<lbFATFile->Count; i++)
  435.     {
  436.         if (lbFATFile->Selected[i])
  437.         {
  438.             fat_read.v_FATFileName.push_back(lbFATFile->Items->Strings[i]);
  439.         }
  440.     }
  441.    CurrentPageLock();
  442.    clearProgressBar();
  443.    clearAllPanel();
  444.    sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Read file from FAT progressing";
  445.    TimerFATProgressTimer->Enabled = true;
  446.    m_cFAT_EDITOR_Obj.ConfirmCallback = ::CNF_FAT_Read_To_File;
  447.    m_cFAT_EDITOR_Obj.Req_FAT_Read_To_File_Start(fat_read);
  448. }
  449. //-------------------------------------------------------------------------
  450. void TfrmFATEditor::CNF_FAT_Read_To_File(void)
  451. {
  452.     TimerFATProgressTimer->Enabled = false;
  453.     E_METAAPP_RESULT_T state = m_cFAT_EDITOR_Obj.Get_ConfirmState();
  454.     switch (state)
  455.     {
  456.         case METAAPP_SUCCESS:
  457.         {
  458.             OnTimerFATProgressTmer(NULL);
  459.             sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Read file from FAT successfully";
  460.         }
  461.         break;
  462.         case METAAPP_FAIL:
  463.         {
  464.             DisplayFATErrorMsg();
  465.             sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Read file from FAT fail";
  466.             Application->MessageBox("Execution Failure : read file from FAT", "FAILURE", MB_OK);
  467.         }
  468.         break;
  469.         case METAAPP_TIMEOUT:
  470.         {
  471.             DisplayFATErrorMsg();
  472.             sbFAT->Panels->Items[0]->Text = (AnsiString) "  Read file from FAT timeout";
  473.             Application->MessageBox("Execution Timeout : read file from FAT", "TIMEOUT", MB_OK);
  474.         }
  475.         break;
  476.         case METAAPP_STOP:
  477.         {
  478.             sbFAT->Panels->Items[0]->Text = (AnsiString) "  Read file from FAT stop";
  479.         }
  480.         break;
  481.         default:
  482.         {
  483.             DisplayFATErrorMsg();
  484.         }
  485.         break;
  486.     }
  487.     CurrentPageReset();
  488. }
  489. //==============================================================================
  490. void __fastcall TfrmFATEditor::btnWriteToFATClick(TObject *Sender)
  491. {
  492.     if (lbLocalFile->ItemIndex < 0)
  493.     {
  494.         ShowMessage(" You have to select a local file to write ");
  495.         return;
  496.     }
  497.     AnsiString as_CurrentFatPath;
  498.     //AnsiString as_FAT_filepath;
  499.     //AnsiString as_FAT_filename;
  500.     AnsiString as_local_filepath;
  501.     AnsiString as_last_local_filepath;
  502.     AnsiString as_last_FAT_filepath;
  503.     int current_local_filepath_length, current_FAT_path_length;
  504.     char *last_FAT_path_character;
  505.     S_FAT_WRITE_T fat_write;
  506.     clearProgressBar();
  507.     clearAllPanel();
  508.     CurrentPageLock();
  509.     // FAT write
  510.     as_local_filepath = lbLocalDir->Directory;
  511.     current_local_filepath_length = as_local_filepath.Length();
  512.     as_last_local_filepath = as_local_filepath.SubString(current_local_filepath_length, 1);
  513.     if (as_last_local_filepath.AnsiCompare("\") != 0)
  514.     {
  515.         as_local_filepath = as_local_filepath + "\";
  516.     }
  517.     fat_write.as_LocalFilePath = as_local_filepath;
  518.     for (int i=0; i<lbLocalFile->Count; i++)
  519.     {
  520.         if (lbLocalFile->Selected[i])
  521.         {
  522.             fat_write.v_LocalFileName.push_back(lbLocalFile->Items->Strings[i]);
  523.         }
  524.     }
  525.     as_last_FAT_filepath = (edtCurrentFATPath->Text.SubString(current_FAT_path_length, 1));
  526.     if (as_last_FAT_filepath.AnsiCompare("\") != 0)
  527.     {
  528.         as_CurrentFatPath = edtCurrentFATPath->Text + "\";
  529.     }
  530.     fat_write.as_FATFilePath = as_CurrentFatPath;
  531.     // FAT info
  532.     S_FAT_FILE_INFO_REQ_T sFatFileInfoReq;
  533.     sFatFileInfoReq.as_FAT_file_path = edtCurrentFATPath->Text;
  534.     sFatFileInfoReq.as_FAT_file_type = edtFileType->Text;
  535.     if (m_rbRecursive->Checked)
  536.     {
  537.         sFatFileInfoReq.e_FAT_find_mode = FAT_FIND_FILE_RECURSIVE;
  538.     }
  539.     else
  540.     {
  541.         sFatFileInfoReq.e_FAT_find_mode = FAT_FIND_FILE;
  542.     }
  543. #if 0
  544.     //as_FAT_filename = as_CurrentFatPath + lbLocalFile->Items->Strings[lbLocalFile->ItemIndex];
  545.     strcpy(FAT_filename, as_FAT_filename.c_str());
  546.    //strcpy(local_filepath, lbLocalDir->Directory.c_str());
  547.  //  strcat(local_filepath, "\");
  548.  //  strcpy( local_filepath, as_local_filepath.c_str());
  549.  //  strcat(local_filepath, lbLocalFile->Items->Strings[lbLocalFile->ItemIndex].c_str() );
  550.   // strcpy(FAT_filepath, m_asCurrentFatPath.c_str());
  551.   // as_filetype = setFileTypeFromEditor();
  552. #endif
  553.     TimerFATProgressTimer->Enabled = true;
  554.     sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Write file to FAT progressing";
  555.     m_cFAT_EDITOR_Obj.ConfirmCallback = ::CNF_FAT_Write_By_File;
  556.     m_cFAT_EDITOR_Obj.Req_FAT_Write_By_File_Start(fat_write, sFatFileInfoReq);
  557.   // m_cFAT_EDITOR_Obj.Req_FAT_Write_By_File_Start(FAT_filename, local_filepath, FAT_filepath, as_filetype.c_str());
  558. }
  559. //---------------------------------------------------------------------------
  560. void TfrmFATEditor::CNF_FAT_Write_By_File(void)
  561. {
  562.     TimerFATProgressTimer->Enabled = false;
  563.     E_METAAPP_RESULT_T state = m_cFAT_EDITOR_Obj.Get_ConfirmState();
  564.     switch (state)
  565.     {
  566.         case METAAPP_SUCCESS:
  567.         {
  568.             OnTimerFATProgressTmer(NULL);
  569.             S_FAT_FILE_INFO_CNF_T file_info;
  570.             m_cFAT_EDITOR_Obj.Get_FatFileInfo(file_info);
  571.             lbFATFile->Clear();
  572.             vector<AnsiString>:: iterator iter;
  573.             for (iter = file_info.v_FATFileName.begin(); iter != file_info.v_FATFileName.end(); iter++)
  574.             {
  575.                 lbFATFile->Items->Add(*iter);
  576.             }
  577.             sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Write file to FAT successfully";
  578.         }
  579.         break;
  580.         case METAAPP_FAIL:
  581.         {
  582.             DisplayFATErrorMsg();
  583.             sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Write file to FAT fail";
  584.             Application->MessageBox("Execution Failure : write file to FAT", "FAILURE", MB_OK);
  585.         }
  586.         break;
  587.         case METAAPP_TIMEOUT:
  588.         {
  589.             DisplayFATErrorMsg();
  590.             sbFAT->Panels->Items[0]->Text = (AnsiString) "  Write file to FAT timeout";
  591.             Application->MessageBox("Execution Timeout : write file to FAT", "TIMEOUT", MB_OK);
  592.         }
  593.         break;
  594.         case METAAPP_STOP:
  595.         {
  596.             sbFAT->Panels->Items[0]->Text = (AnsiString) "  Write file to FAT stop";
  597.         }
  598.         break;
  599.         default:
  600.         {
  601.             DisplayFATErrorMsg();
  602.         }
  603.         break;
  604.     }
  605.     CurrentPageReset();
  606. #if 0
  607.     if(m_cFAT_EDITOR_Obj.Get_IsRunning() == false)
  608.     {
  609.         EnableAllButton();
  610.         TimerFATProgressTimer->Enabled = false;
  611.         if ( m_cFAT_EDITOR_Obj.Get_MetaResult() == META_SUCCESS)
  612.         {
  613.              pbFAT->Position =  m_cFAT_EDITOR_Obj.Percent;
  614.              sbFAT->Panels->Items[STATUS_BAR_INDEX_SENT_AND_TOTAL]->Text = "  " + IntToStr(m_cFAT_EDITOR_Obj.SentBytes)+ " / " + IntToStr(m_cFAT_EDITOR_Obj.TotalBytes) + " bytes";
  615.              sbFAT->Panels->Items[STATUS_BAR_INDEX_PERCENT]->Text = "  " + IntToStr(m_cFAT_EDITOR_Obj.Percent) + "%";
  616.              lbFATFile->Clear();
  617.              for(int i=0; i<m_cFAT_EDITOR_Obj.FAT_filepath_size; i++)
  618.              {
  619.                  lbFATFile->Items->Add(m_cFAT_EDITOR_Obj.FAT_filepath[i]);
  620.                  sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Write file to FAT successfully";
  621.              }
  622.         }
  623.         else
  624.         {
  625.             DisplayFATErrorMsg( m_cFAT_EDITOR_Obj.Get_MetaResult());
  626.         }
  627.     }
  628.     else
  629.     {
  630. #endif
  631. }
  632. //---------------------------------------------------------------------------
  633. void __fastcall TfrmFATEditor::btnDeleteFromFATClick(TObject *Sender)
  634. {
  635.     //char  hint[] = "Delete FAT file progressing";
  636.     if (lbFATFile->ItemIndex < 0)
  637.     {
  638.         ShowMessage(" You have to select a FAT file to delete ");
  639.         return;
  640.     }
  641.     //ShowHintLabel( lbFATDirectory, hint);
  642.     CurrentPageLock();
  643.     clearProgressBar();
  644.     clearAllPanel();
  645.     // FAT delete
  646.     S_FAT_DELETE_T fat_delete;
  647.     for (int i=0; i<lbFATFile->Count; i++)
  648.     {
  649.         if (lbFATFile->Selected[i])
  650.         {
  651.             fat_delete.v_FATFileName.push_back(lbFATFile->Items->Strings[i]);
  652.         }
  653.     }
  654.     // FAT info
  655.     S_FAT_FILE_INFO_REQ_T sFatFileInfoReq;
  656.     sFatFileInfoReq.as_FAT_file_path = edtCurrentFATPath->Text;
  657.     sFatFileInfoReq.as_FAT_file_type = edtFileType->Text;
  658.     if (m_rbRecursive->Checked)
  659.     {
  660.         sFatFileInfoReq.e_FAT_find_mode = FAT_FIND_FILE_RECURSIVE;
  661.     }
  662.     else
  663.     {
  664.         sFatFileInfoReq.e_FAT_find_mode = FAT_FIND_FILE;
  665.     }
  666.     sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Delete FAT file progressing";
  667.     TimerFATProgressTimer->Enabled = true;
  668.     m_cFAT_EDITOR_Obj.ConfirmCallback = ::CNF_FAT_Delete;
  669.     m_cFAT_EDITOR_Obj.Req_FAT_Delete_Start(fat_delete, sFatFileInfoReq);
  670. }
  671. //---------------------------------------------------------------------------
  672. void TfrmFATEditor::CNF_FAT_Delete(void)
  673. {
  674.     TimerFATProgressTimer->Enabled = false;
  675.     E_METAAPP_RESULT_T state = m_cFAT_EDITOR_Obj.Get_ConfirmState();
  676.     switch (state)
  677.     {
  678.         case METAAPP_SUCCESS:
  679.         {
  680.             OnTimerFATProgressTmer(NULL);
  681.             S_FAT_FILE_INFO_CNF_T file_info;
  682.             m_cFAT_EDITOR_Obj.Get_FatFileInfo(file_info);
  683.             lbFATFile->Clear();
  684.             vector<AnsiString>:: iterator iter;
  685.             for (iter = file_info.v_FATFileName.begin(); iter != file_info.v_FATFileName.end(); iter++)
  686.             {
  687.                 lbFATFile->Items->Add(*iter);
  688.             }
  689.             sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Delete FAT file successfully";
  690.         }
  691.         break;
  692.         case METAAPP_FAIL:
  693.         {
  694.             DisplayFATErrorMsg();
  695.             sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = "  Delete FAT file fail";
  696.             Application->MessageBox("Execution Failure : delete FAT file ", "FAILURE", MB_OK);
  697.         }
  698.         break;
  699.         case METAAPP_TIMEOUT:
  700.         {
  701.             DisplayFATErrorMsg();
  702.             sbFAT->Panels->Items[0]->Text = (AnsiString) "  Delete FAT file timeout";
  703.             Application->MessageBox("Execution Timeout : delete FAT file ", "TIMEOUT", MB_OK);
  704.         }
  705.         break;
  706.         case METAAPP_STOP:
  707.         {
  708.             sbFAT->Panels->Items[0]->Text = (AnsiString) "  Delete FAT file stop";
  709.         }
  710.         break;
  711.         default:
  712.         {
  713.         }
  714.         break;
  715.     }
  716.     CurrentPageReset();
  717. }
  718. //---------------------------------------------------------------------------
  719. void __fastcall TfrmFATEditor::OnTimerFATProgressTmer(TObject *Sender)
  720. {
  721.     S_FAT_PROGRESS_T progress;
  722.     m_cFAT_EDITOR_Obj.Get_Progress(progress);
  723.     pbFAT->Position = progress.percent;
  724.     sbFAT->Panels->Items[STATUS_BAR_INDEX_FILENAME]->Text = "  " + progress.as_file_name;
  725.     sbFAT->Panels->Items[STATUS_BAR_INDEX_SENT_AND_TOTAL]->Text = "  " + IntToStr(progress.sent_bytes)+ " / " + IntToStr(progress.total_bytes) + " bytes";
  726.     sbFAT->Panels->Items[STATUS_BAR_INDEX_PERCENT]->Text = "  " + IntToStr(progress.percent) + "%";
  727. }
  728. //---------------------------------------------------------------------------
  729. void __fastcall TfrmFATEditor::cbDriveChange(TObject *Sender)
  730. {
  731.   lbLocalDir->Drive = cbDrive->Drive;
  732. }
  733. //---------------------------------------------------------------------------
  734. void __fastcall TfrmFATEditor::lbLocalDirChange(TObject *Sender)
  735. {
  736.    lbLocalFile->Directory = lbLocalDir->Directory;
  737. }
  738. //---------------------------------------------------------------------------
  739. void __fastcall TfrmFATEditor::cbLocalFiletypeChange(TObject *Sender)
  740. {
  741.     lbLocalFile->Mask = cbLocalFiletype->Mask;
  742. }
  743. //---------------------------------------------------------------------------
  744. void __fastcall TfrmFATEditor::lbFATDirectoryClick(TObject *Sender)
  745. {
  746.     edtCurrentFATPath->Text = lbFATDirectory->Items->Strings[lbFATDirectory->ItemIndex];
  747. }
  748. //==============================================================================
  749. void TfrmFATEditor::clearProgressBar( void )
  750. {
  751.     pbFAT->Position = 0;
  752. }
  753. //---------------------------------------------------------------------------
  754. void TfrmFATEditor::clearAllPanel( void )
  755. {
  756.     sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = (AnsiString) "";
  757.     sbFAT->Panels->Items[STATUS_BAR_INDEX_FILENAME]->Text = (AnsiString) "";
  758.     sbFAT->Panels->Items[STATUS_BAR_INDEX_SENT_AND_TOTAL]->Text = (AnsiString) "";
  759.     sbFAT->Panels->Items[STATUS_BAR_INDEX_PERCENT]->Text = (AnsiString) "";
  760. }
  761. //==============================================================================
  762. void  TfrmFATEditor::ShowHintLabel( TControl *sender, char* hint )
  763. {
  764.    TPoint pt0 = this->ClientOrigin;
  765.    TPoint pt1 = sender->ClientOrigin;
  766.    lblHint->Left = (pt1.x-pt0.x)+35;
  767.    lblHint->Top  = (pt1.y-pt0.y)+sender->Height-23;
  768.    lblHint->Caption = (AnsiString) hint;
  769.    lblHint->Visible = true;
  770.    HintTimer->Enabled = true;
  771. }
  772. //==============================================================================
  773. void  TfrmFATEditor::DisplayFATErrorMsg(void)
  774. {
  775.     AnsiString asErrMsg;
  776.     lbFATFile->Clear();
  777.     m_cFAT_EDITOR_Obj.Get_ErrorString(asErrMsg);
  778.     sbFAT->Panels->Items[STATUS_BAR_INDEX_STATUS]->Text = asErrMsg;
  779.     asErrMsg = "Execution Result : " + asErrMsg;
  780.     Application->MessageBox(asErrMsg.c_str(), "RESULT", MB_OK);
  781. }