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

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_MMIDataDownload.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  MMI data download 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. #include <IniFiles.hpp>
  68. #pragma hdrstop
  69. #include "form_MMIDataDownload.h"
  70. #include "meta_utils.h"
  71. #include "man_active.h"
  72. //---------------------------------------------------------------------------
  73. #pragma package(smart_init)
  74. #pragma resource "*.dfm"
  75. AnsiString as_default_FAT_name;
  76. AnsiString as_default_FAT_path;
  77. AnsiString as_MMIDataStr;
  78. extern META_RESULT  MetaResult_MMIData;
  79. TfrmMMIDataDownload *frmMMIDataDownload;
  80. int Index_MMIData;
  81. //---------------------------------------------------------------------------
  82. void REQ_Write_To_FAT(void)
  83. {
  84.     frmMMIDataDownload->REQ_Write_To_FAT();
  85. }
  86. //---------------------------------------------------------------------------
  87. void REQ_Read_From_FAT(void)
  88. {
  89.     frmMMIDataDownload->MMI_FILE_Object.REQ_Read_From_FAT((as_default_FAT_path + as_default_FAT_name).c_str(), as_MMIDataStr.c_str());
  90. }
  91. //---------------------------------------------------------------------------
  92. void TfrmMMIDataDownload::set_DEFAULT_PATH(void)
  93. {
  94.     if(rbFullScreen->Checked)
  95.     {
  96.         as_default_FAT_path = as_default_FAT_fullscreen_path;
  97.     }
  98.     else if(RadioButtonAssociate->Checked)
  99.     {
  100.         as_default_FAT_path = as_default_FAT_associate_path;
  101.     }
  102.     else if(RadioButtonEMS->Checked)
  103.     {
  104.         as_default_FAT_path = as_default_FAT_EMS_path;
  105.     }
  106.     else if(rbMidi->Checked)
  107.     {
  108.         as_default_FAT_path = as_default_FAT_midi_path;
  109.     }
  110.     else if(rbiMelody->Checked)
  111.     {
  112.         as_default_FAT_path = as_default_FAT_imelody_path;
  113.     }
  114. }
  115. //---------------------------------------------------------------------------
  116. __fastcall TfrmMMIDataDownload::TfrmMMIDataDownload(TComponent* Owner)
  117.         : TForm(Owner)
  118. {
  119.     DirectoryListBoxMMIData->Drive = DriveComboBoxMMIData->Drive;
  120.     FileListBoxMMIData->Directory = DirectoryListBoxMMIData->Directory;
  121.     FileListBoxMMIData->Mask = FilterComboBoxMMIData->Mask;
  122.     read_MAX_FILE_COUNT();
  123. }
  124. //---------------------------------------------------------------------------
  125. void __fastcall TfrmMMIDataDownload::FilterComboBoxMMIDataChange(
  126.       TObject *Sender)
  127. {
  128.     FileListBoxMMIData->Mask = FilterComboBoxMMIData->Mask;
  129. }
  130. //---------------------------------------------------------------------------
  131. void __fastcall TfrmMMIDataDownload::DirectoryListBoxMMIDataChange(
  132.       TObject *Sender)
  133. {
  134.     FileListBoxMMIData->Directory = DirectoryListBoxMMIData->Directory;
  135. }
  136. //---------------------------------------------------------------------------
  137. void __fastcall TfrmMMIDataDownload::DriveComboBoxMMIDataChange(
  138.       TObject *Sender)
  139. {
  140.     DirectoryListBoxMMIData->Drive = DriveComboBoxMMIData->Drive;
  141. }
  142. //---------------------------------------------------------------------------
  143. void __fastcall TfrmMMIDataDownload::FileListBoxMMIDataChange(
  144.       TObject *Sender)
  145. {
  146.  //if(FileListBoxMMIData->FileName != "")
  147.  //  {
  148.  //   ImageMMIData->Picture->LoadFromFile(FileListBoxMMIData->FileName);
  149.  //   ImageMMIData->Height = ImageMMIData->Picture->Height;
  150.  //   ImageMMIData->Width = ImageMMIData->Picture->Width;
  151.  //  }
  152. }
  153. //---------------------------------------------------------------------------
  154. void __fastcall TfrmMMIDataDownload::btnAddToListClick(
  155.       TObject *Sender)
  156. {
  157.     btnRemoveFromList->Enabled = true;
  158.     if(rbFullScreen->Checked == true)
  159.     {
  160.         if(lbLocalMMIData->Items->Count < as_MAX_FULLSCREEN_FILE_COUNT.ToInt())
  161.         {
  162.             //lbLocalMMIData->Items->Add(FileListBoxMMIData->FileName);
  163.             //FileListBoxMMIData->CopySelection( lbLocalMMIData );
  164.             for(int i=0; i<FileListBoxMMIData->Count && i<as_MAX_FULLSCREEN_FILE_COUNT.ToInt(); i++)
  165.             {
  166.                 if( FileListBoxMMIData->Selected[i] )
  167.                 {
  168.                     lbLocalMMIData->Items->Add( DirectoryListBoxMMIData->Directory + "\" + FileListBoxMMIData->Items->Strings[i] );
  169.                 }
  170.             }
  171.             write_local_default_fullscreen_file_setting();
  172.         }
  173.         else
  174.         {
  175.             Application->MessageBox( "Max full screen file reached", "ERROR!", MB_OK );
  176.         }
  177.     }
  178.     else if(RadioButtonAssociate->Checked == true)
  179.     {
  180.         if(lbLocalMMIData->Items->Count < as_MAX_ASSOCIATE_FILE_COUNT.ToInt())
  181.         {
  182.             lbLocalMMIData->Items->Add(FileListBoxMMIData->FileName);
  183.             write_local_default_associate_file_setting();
  184.         }
  185.         else
  186.         {
  187.             Application->MessageBox( "Max full associate file reached", "ERROR!", MB_OK );
  188.         }
  189.     }
  190.     else if(RadioButtonEMS->Checked == true)
  191.     {
  192.         if(lbLocalMMIData->Items->Count < as_MAX_EMS_FILE_COUNT.ToInt())
  193.         {
  194.             lbLocalMMIData->Items->Add(FileListBoxMMIData->FileName);
  195.             write_local_default_EMS_file_setting();
  196.         }
  197.         else
  198.         {
  199.             Application->MessageBox( "Max full EMS file reached", "ERROR!", MB_OK );
  200.         }
  201.     }
  202.     else if(rbMidi->Checked == true)
  203.     {
  204.         if(lbLocalMMIData->Items->Count < as_MAX_MIDI_FILE_COUNT.ToInt())
  205.         {
  206.             lbLocalMMIData->Items->Add(FileListBoxMMIData->FileName);
  207.             write_local_default_midi_file_setting();
  208.         }
  209.         else
  210.         {
  211.             Application->MessageBox( "Max full midi file reached", "ERROR!", MB_OK );
  212.         }
  213.     }
  214.     else if(rbiMelody->Checked == true)
  215.     {
  216.         if(lbLocalMMIData->Items->Count < as_MAX_IMELODY_FILE_COUNT.ToInt())
  217.         {
  218.             lbLocalMMIData->Items->Add(FileListBoxMMIData->FileName);
  219.             write_local_default_imelody_file_setting();
  220.         }
  221.         else
  222.         {
  223.             Application->MessageBox( "Max iMelody file reached", "ERROR!", MB_OK );
  224.         }
  225.     }
  226. }
  227. //---------------------------------------------------------------------------
  228. void __fastcall TfrmMMIDataDownload::FormShow(TObject *Sender)
  229. {
  230.     show_download_type();
  231.     ShowFileSelected();
  232.     ModifyLastRadioButtonChecked();
  233. }
  234. //////////////////////////////////////////////////////////////////////////////////////////
  235. //---------------------------------------------------------------------------
  236. void __fastcall TfrmMMIDataDownload::FormClose(TObject *Sender,
  237.       TCloseAction &Action)
  238. {
  239.     // save graph setting
  240.     if(rbFullScreen->Checked == true)
  241.     {
  242.         write_local_default_fullscreen_file_setting();
  243.         as_download_type = "fullscreen";
  244.     }
  245.     else if(RadioButtonAssociate->Checked == true)
  246.     {
  247.         write_local_default_associate_file_setting();
  248.         as_download_type = "associate";
  249.     }
  250.     else if(RadioButtonEMS->Checked == true)
  251.     {
  252.         write_local_default_EMS_file_setting();
  253.         as_download_type = "ems";
  254.     }
  255.     else if(rbMidi->Checked == true)
  256.     {
  257.         write_local_default_midi_file_setting();
  258.         as_download_type = "midi";
  259.     }
  260.     else if(rbiMelody->Checked == true)
  261.     {
  262.         write_local_default_imelody_file_setting();
  263.         as_download_type = "imelody";
  264.     }
  265.     write_download_type("MF_setup.txt",
  266.                          Application->ExeName,
  267.                          as_download_type);
  268.  // ---------------- write local file setting to file ------------------------------------
  269. }
  270. //////////////////////////////////////////////////////////////////////////////////////////////
  271. //---------------------------------------------------------------------------
  272. void __fastcall TfrmMMIDataDownload::btnRemoveFromListClick(
  273.       TObject *Sender)
  274. {
  275.     if(lbLocalMMIData->ItemIndex < 0)
  276.     {
  277.         return;
  278.     }
  279.     else
  280.     {
  281.         int LocalMMIDataCount = lbLocalMMIData->Count;
  282.         int i, SelectedNum = 0, deletedNum = 0;
  283.         for(i=0; i<LocalMMIDataCount; i++)
  284.         {
  285.             if( lbLocalMMIData->Selected[i] )
  286.             {
  287.                 SelectedNum++;
  288.             }
  289.         }
  290.         while( SelectedNum != 0)
  291.         {
  292.            for(i=lbLocalMMIData->Count-1; i>=0; i--)
  293.            {
  294.                if( lbLocalMMIData->Selected[i] )
  295.                {
  296.                    lbLocalMMIData->Items->Delete(i );
  297.                    SelectedNum--;
  298.                    deletedNum++;
  299.                }
  300.            }
  301.         }
  302.         if(rbFullScreen->Checked == true)
  303.         {
  304.             write_local_default_fullscreen_file_setting();
  305.             local_default_fullscreen_file_count = local_default_fullscreen_file_count - lbLocalMMIData->SelCount;
  306.         }
  307.         else if(RadioButtonAssociate->Checked == true)
  308.         {
  309.             write_local_default_associate_file_setting();
  310.             local_default_associate_file_count = local_default_associate_file_count - lbLocalMMIData->SelCount;
  311.         }
  312.         else if(RadioButtonEMS->Checked == true)
  313.         {
  314.             write_local_default_EMS_file_setting();
  315.             local_default_EMS_file_count = local_default_EMS_file_count - lbLocalMMIData->SelCount;
  316.         }
  317.         else if(rbMidi->Checked == true)
  318.         {
  319.             write_local_default_midi_file_setting();
  320.             local_default_midi_file_count = local_default_midi_file_count - lbLocalMMIData->SelCount;
  321.         }
  322.         else if(rbiMelody->Checked == true)
  323.         {
  324.             write_local_default_imelody_file_setting();
  325.             local_default_imelody_file_count = local_default_imelody_file_count - lbLocalMMIData->SelCount;
  326.         }
  327.     }
  328. }
  329. //---------------------------------------------------------------------------
  330. void TfrmMMIDataDownload::write_local_default_fullscreen_file_setting(void)
  331. {
  332.     // erase local graph file section
  333.     int i;
  334.     for(i=0; i< local_default_fullscreen_file_count; i++)
  335.     {
  336.         delete_local_default_fullscreen_file_key("MF_setup.txt", Application->ExeName, IntToStr(i+1));
  337.     }
  338.     // write local graph file name
  339.     for(i=0; i<lbLocalMMIData->Items->Count; i++)
  340.     {
  341.         write_local_default_fullscreen_file_name("MF_setup.txt", Application->ExeName, i+1, lbLocalMMIData->Items->Strings[i].c_str());
  342.     }
  343.     // write local graph file count
  344.     write_local_default_fullscreen_file_count("MF_setup.txt", Application->ExeName, IntToStr(lbLocalMMIData->Items->Count));
  345. }
  346. //---------------------------------------------------------------------------
  347. void TfrmMMIDataDownload::write_local_default_associate_file_setting(void)
  348. {
  349.     // erase local graph file section
  350.     int i;
  351.     for(i=0; i< local_default_associate_file_count; i++)
  352.     {
  353.         delete_local_default_associate_file_key("MF_setup.txt", Application->ExeName, IntToStr(i+1));
  354.     }
  355.     // write local graph file name
  356.     for(i=0; i<lbLocalMMIData->Items->Count; i++)
  357.     {
  358.         write_local_default_associate_file_name("MF_setup.txt", Application->ExeName, i+1, lbLocalMMIData->Items->Strings[i].c_str());
  359.     }
  360.     // write local graph file count
  361.     write_local_default_associate_file_count("MF_setup.txt", Application->ExeName, IntToStr(lbLocalMMIData->Items->Count));
  362. }
  363. //---------------------------------------------------------------------------
  364. void TfrmMMIDataDownload::write_local_default_EMS_file_setting(void)
  365. {
  366.     // erase local graph file section
  367.     int i;
  368.     for(i=0; i< local_default_EMS_file_count; i++)
  369.     {
  370.         delete_local_default_EMS_file_key("MF_setup.txt", Application->ExeName, IntToStr(i+1));
  371.     }
  372.     // write local graph file name
  373.     for(i=0; i<lbLocalMMIData->Items->Count; i++)
  374.     {
  375.         write_local_default_EMS_file_name("MF_setup.txt", Application->ExeName, i+1, lbLocalMMIData->Items->Strings[i].c_str());
  376.     }
  377.     // write local graph file count
  378.     write_local_default_EMS_file_count("MF_setup.txt", Application->ExeName, IntToStr(lbLocalMMIData->Items->Count));
  379. }
  380. //---------------------------------------------------------------------------
  381. void TfrmMMIDataDownload::write_local_default_midi_file_setting(void)
  382. {
  383.     // erase local file section
  384.     int i;
  385.     for(i=0; i< local_default_midi_file_count; i++)
  386.     {
  387.         delete_local_default_midi_file_key("MF_setup.txt", Application->ExeName, IntToStr(i+1));
  388.     }
  389.     // write local file name
  390.     for(i=0; i<lbLocalMMIData->Items->Count; i++)
  391.     {
  392.         write_local_default_midi_file_name("MF_setup.txt", Application->ExeName, i+1, lbLocalMMIData->Items->Strings[i].c_str());
  393.     }
  394.     // write local file count
  395.     write_local_default_midi_file_count("MF_setup.txt", Application->ExeName, IntToStr(lbLocalMMIData->Items->Count));
  396. }
  397. //---------------------------------------------------------------------------
  398. void TfrmMMIDataDownload::write_local_default_imelody_file_setting(void)
  399. {
  400.     // erase local file section
  401.     int i;
  402.     for(i=0; i< local_default_imelody_file_count; i++)
  403.     {
  404.         delete_local_default_imelody_file_key("MF_setup.txt", Application->ExeName, IntToStr(i+1));
  405.     }
  406.     // write local file name
  407.     for(i=0; i<lbLocalMMIData->Items->Count; i++)
  408.     {
  409.         write_local_default_imelody_file_name("MF_setup.txt", Application->ExeName, i+1, lbLocalMMIData->Items->Strings[i].c_str());
  410.     }
  411.     // write local file count
  412.     write_local_default_imelody_file_count("MF_setup.txt", Application->ExeName, IntToStr(lbLocalMMIData->Items->Count));
  413. }
  414. ///////////////////////////////////////////////////////////////////////////////
  415.  // read FAT path from file
  416. void TfrmMMIDataDownload::read_DEFAULT_PATH(void)
  417. {
  418.     as_default_FAT_fullscreen_path = read_DEFAULT_FULLSCREEN_PATH ( "MF_setup.txt",
  419.                                                                     Application->ExeName
  420.                                                                   );
  421.     as_default_FAT_associate_path = read_DEFAULT_ASSOCIATE_PATH ("MF_setup.txt",
  422.                                                                  Application->ExeName
  423.                                                                  );
  424.     as_default_FAT_EMS_path = read_DEFAULT_EMS_PATH ("MF_setup.txt",
  425.                                                      Application->ExeName
  426.                                                     );
  427.     as_default_FAT_midi_path = read_DEFAULT_MIDI_PATH ("MF_setup.txt",
  428.                                                        Application->ExeName
  429.                                                        );
  430.     as_default_FAT_imelody_path = read_DEFAULT_IMELODY_PATH ("MF_setup.txt",
  431.                                                               Application->ExeName
  432.                                                             );
  433. }
  434. /////////////////////////////////////////////////////////////////////////////////////////////
  435. void  TfrmMMIDataDownload::ConfirmCallback_MMIDataDownload( void )
  436. {
  437.     int state = MMI_FILE_Object.ConfirmState;
  438.     if( state==STATE_MMI_GRAPH_FILE_DOWNLOAD_OK  )
  439.     {
  440.     }
  441.     else  if( state==STATE_MMI_GRAPH_FILE_DOWNLOAD_FAIL )
  442.     {
  443.         Application->MessageBox( "Execution Failure : MMI data download", "FAILURE", MB_OK );
  444.     }
  445.     else  if( state==STATE_MMI_GRAPH_FILE_DOWNLOAD_TIMEOUT )
  446.     {
  447.         Application->MessageBox( "Execution Timeout : MMI data download", "TIMEOUT", MB_OK );
  448.     }
  449.     else  if( state==STATE_MMI_GRAPH_FILE_DOWNLOAD_STOP )
  450.     {
  451.     }
  452. }
  453. //////////////////////////////////////////////////////////////////////////////////////////////
  454. void  TfrmMMIDataDownload::ShowFileSelected(void)
  455. {
  456.     lbLocalMMIData->Clear();
  457.     //*********************************** Full screen *********************************************
  458.     if(rbFullScreen->Checked)
  459.     {
  460.         AnsiString as_temp_local_default_fullscreen_file_count;
  461.         LabelListBoxMMIData->Caption = "Full screen file selected";
  462.         as_temp_local_default_fullscreen_file_count = read_local_default_fullscreen_file_count(
  463.                                                                                                 "MF_setup.txt",
  464.                                                                                                 Application->ExeName
  465.                                                                                               );
  466.         if( as_temp_local_default_fullscreen_file_count != "")
  467.         {
  468.             local_default_fullscreen_file_count = as_temp_local_default_fullscreen_file_count.ToInt();
  469.             if(local_default_fullscreen_file_count != 0)
  470.             {
  471.                 btnRemoveFromList->Enabled = true;
  472.             }
  473.         }
  474.         else
  475.         {
  476.             local_default_fullscreen_file_count = 0;
  477.         }
  478.         int i;
  479.         AnsiString as_temp_local_default_fullscreen_file_name;
  480.         for (i=0; i< local_default_fullscreen_file_count; i++)
  481.         {
  482.             as_temp_local_default_fullscreen_file_name = read_local_default_fullscreen_file_name(
  483.                                                                                                   "MF_setup.txt",
  484.                                                                                                   Application->ExeName,
  485.                                                                                                   IntToStr(i+1)
  486.                                                                                                 );
  487.             lbLocalMMIData->Items->Strings[i] = as_temp_local_default_fullscreen_file_name;
  488.         }
  489.     }
  490. //*********************************** Assocaite *********************************************
  491.     else if(RadioButtonAssociate->Checked)
  492.     {
  493.         AnsiString as_temp_local_default_associate_file_count;
  494.         LabelListBoxMMIData->Caption = "Associate file selected";
  495.         as_temp_local_default_associate_file_count = read_local_default_associate_file_count(
  496.                                                                                               "MF_setup.txt",
  497.                                                                                               Application->ExeName
  498.                                                                                             );
  499.         if( as_temp_local_default_associate_file_count != "")
  500.         {
  501.             local_default_associate_file_count = as_temp_local_default_associate_file_count.ToInt();
  502.             if(local_default_associate_file_count != 0)
  503.             {
  504.                 btnRemoveFromList->Enabled = true;
  505.             }
  506.         }
  507.         else
  508.         {
  509.             local_default_associate_file_count = 0;
  510.         }
  511.         int i;
  512.         AnsiString as_temp_local_default_associate_file_name;
  513.         for (i=0; i< local_default_associate_file_count; i++)
  514.         {
  515.             as_temp_local_default_associate_file_name = read_local_default_associate_file_name(
  516.                                                                                                 "MF_setup.txt",
  517.                                                                                                 Application->ExeName,
  518.                                                                                                 IntToStr(i+1)
  519.                                                                                                );
  520.             lbLocalMMIData->Items->Strings[i] = as_temp_local_default_associate_file_name;
  521.         }
  522.     }
  523. //*********************************** EMS *********************************************
  524.     else if(RadioButtonEMS->Checked)
  525.     {
  526.         AnsiString as_temp_local_default_EMS_file_count;
  527.         LabelListBoxMMIData->Caption = "EMS file selected";
  528.         as_temp_local_default_EMS_file_count = read_local_default_EMS_file_count(
  529.                                                                                   "MF_setup.txt",
  530.                                                                                   Application->ExeName
  531.                                                                                  );
  532.         if( as_temp_local_default_EMS_file_count != "")
  533.         {
  534.             local_default_EMS_file_count = as_temp_local_default_EMS_file_count.ToInt();
  535.             if(local_default_EMS_file_count != 0)
  536.             {
  537.                 btnRemoveFromList->Enabled = true;
  538.             }
  539.         }
  540.         else
  541.         {
  542.             local_default_EMS_file_count = 0;
  543.         }
  544.         int i;
  545.         AnsiString as_temp_local_default_EMS_file_name;
  546.         for (i=0; i< local_default_EMS_file_count; i++)
  547.         {
  548.             as_temp_local_default_EMS_file_name = read_local_default_EMS_file_name(
  549.                                                                                      "MF_setup.txt",
  550.                                                                                      Application->ExeName,
  551.                                                                                      IntToStr(i+1)
  552.                                                                                    );
  553.             lbLocalMMIData->Items->Strings[i] = as_temp_local_default_EMS_file_name;
  554.         }
  555.     }
  556.  //*********************************** Midi *********************************************
  557.     else if(rbMidi->Checked)
  558.     {
  559.         AnsiString as_temp_local_default_midi_file_count;
  560.         LabelListBoxMMIData->Caption = "Midi file selected";
  561.         as_temp_local_default_midi_file_count = read_local_default_midi_file_count(
  562.                                                                                     "MF_setup.txt",
  563.                                                                                     Application->ExeName
  564.                                                                                   );
  565.         if( as_temp_local_default_midi_file_count != "")
  566.         {
  567.             local_default_midi_file_count = as_temp_local_default_midi_file_count.ToInt();
  568.             if(local_default_midi_file_count != 0)
  569.             {
  570.                 btnRemoveFromList->Enabled = true;
  571.             }
  572.         }
  573.         else
  574.         {
  575.             local_default_midi_file_count = 0;
  576.         }
  577.         int i;
  578.         AnsiString as_temp_local_default_midi_file_name;
  579.         for (i=0; i< local_default_midi_file_count; i++)
  580.         {
  581.             as_temp_local_default_midi_file_name = read_local_default_midi_file_name(
  582.                                                                                       "MF_setup.txt",
  583.                                                                                       Application->ExeName,
  584.                                                                                       IntToStr(i+1)
  585.                                                                                     );
  586.             lbLocalMMIData->Items->Strings[i] = as_temp_local_default_midi_file_name;
  587.         }
  588.     }  // rbMIdi checked
  589. //*********************************** iMelody *********************************************
  590.     else if(rbiMelody->Checked)
  591.     {
  592.         AnsiString as_temp_local_default_imelody_file_count;
  593.         LabelListBoxMMIData->Caption = "iMelody file selected";
  594.         as_temp_local_default_imelody_file_count = read_local_default_imelody_file_count(
  595.                                                                                           "MF_setup.txt",
  596.                                                                                           Application->ExeName
  597.                                                                                          );
  598.         if( as_temp_local_default_imelody_file_count != "")
  599.         {
  600.             local_default_imelody_file_count = as_temp_local_default_imelody_file_count.ToInt();
  601.             if(local_default_imelody_file_count != 0)
  602.             {
  603.                 btnRemoveFromList->Enabled = true;
  604.             }
  605.         }
  606.         else
  607.         {
  608.             local_default_imelody_file_count = 0;
  609.         }
  610.         int i;
  611.         AnsiString as_temp_local_default_imelody_file_name;
  612.         for (i=0; i< local_default_imelody_file_count; i++)
  613.         {
  614.             as_temp_local_default_imelody_file_name = read_local_default_imelody_file_name(
  615.                                                                                             "MF_setup.txt",
  616.                                                                                             Application->ExeName,
  617.                                                                                             IntToStr(i+1)
  618.                                                                                           );
  619.             lbLocalMMIData->Items->Strings[i] = as_temp_local_default_imelody_file_name;
  620.         }
  621.     }
  622. }
  623. ///////////////////////////////////////////////////////////////////////////////////////////
  624. void  TfrmMMIDataDownload::ModifyLastRadioButtonChecked(void)
  625. {
  626.     if(rbFullScreen->Checked)
  627.     {
  628.         lastRadioButtonFullscreenChecked = true;
  629.         lastRadioButtonAssociateChecked = false;
  630.         lastRadioButtonEMSChecked = false;
  631.         lastRadioButtonMidiChecked = false;
  632.         lastRadioButtoniMelodyChecked = false;
  633.     }
  634.     else if(RadioButtonAssociate->Checked)
  635.     {
  636.         lastRadioButtonFullscreenChecked = false;
  637.         lastRadioButtonAssociateChecked = true;
  638.         lastRadioButtonEMSChecked = false;
  639.         lastRadioButtonMidiChecked = false;
  640.         lastRadioButtoniMelodyChecked = false;
  641.     }
  642.     else if(RadioButtonEMS->Checked)
  643.     {
  644.         lastRadioButtonFullscreenChecked = false;
  645.         lastRadioButtonAssociateChecked = false;
  646.         lastRadioButtonEMSChecked = true;
  647.         lastRadioButtonMidiChecked = false;
  648.         lastRadioButtoniMelodyChecked = false;
  649.     }
  650.     else if(rbMidi->Checked)
  651.     {
  652.         lastRadioButtonFullscreenChecked = false;
  653.         lastRadioButtonAssociateChecked = false;
  654.         lastRadioButtonEMSChecked = false;
  655.         lastRadioButtonMidiChecked = true;
  656.         lastRadioButtoniMelodyChecked = false;
  657.     }
  658.     else if(rbiMelody->Checked)
  659.     {
  660.         lastRadioButtonFullscreenChecked = false;
  661.         lastRadioButtonAssociateChecked = false;
  662.         lastRadioButtonEMSChecked = false;
  663.         lastRadioButtonMidiChecked = false;
  664.         lastRadioButtoniMelodyChecked = true;
  665.     }
  666. }
  667. //-----------------------------------------------------------------------------
  668. void __fastcall TfrmMMIDataDownload::rbFullScreenClick(
  669.       TObject *Sender)
  670. {
  671.     if(lastRadioButtonFullscreenChecked == false)
  672.     {
  673.         SaveLastFileShow();
  674.         ShowFileSelected();
  675.         ModifyLastRadioButtonChecked();
  676.     }
  677. }
  678. //---------------------------------------------------------------------------
  679. void __fastcall TfrmMMIDataDownload::RadioButtonAssociateClick(
  680.       TObject *Sender)
  681. {
  682.     if(lastRadioButtonAssociateChecked == false)
  683.     {
  684.         SaveLastFileShow();
  685.         ShowFileSelected();
  686.         ModifyLastRadioButtonChecked();
  687.     }
  688. }
  689. //---------------------------------------------------------------------------
  690. void __fastcall TfrmMMIDataDownload::RadioButtonEMSClick(TObject *Sender)
  691. {
  692.     if(lastRadioButtonEMSChecked == false)
  693.     {
  694.         SaveLastFileShow();
  695.         ShowFileSelected();
  696.         ModifyLastRadioButtonChecked();
  697.     }
  698. }
  699. //---------------------------------------------------------------------------
  700. void __fastcall TfrmMMIDataDownload::rbMidiClick(TObject *Sender)
  701. {
  702.     if(lastRadioButtonMidiChecked == false)
  703.     {
  704.         SaveLastFileShow();
  705.         ShowFileSelected();
  706.         ModifyLastRadioButtonChecked();
  707.     }
  708. }
  709. //---------------------------------------------------------------------------
  710. void TfrmMMIDataDownload::read_MAX_FILE_COUNT(void)
  711. {
  712.     as_MAX_FULLSCREEN_FILE_COUNT =  read_MAX_FULLSCREEN_FILE_COUNT(
  713.                                                                     "MF_setup.txt",
  714.                                                                     Application->ExeName
  715.                                                                   );
  716.     as_MAX_ASSOCIATE_FILE_COUNT =  read_MAX_ASSOCIATE_FILE_COUNT(
  717.                                                                    "MF_setup.txt",
  718.                                                                    Application->ExeName
  719.                                                                 );
  720.     as_MAX_EMS_FILE_COUNT =  read_MAX_EMS_FILE_COUNT(
  721.                                                       "MF_setup.txt",
  722.                                                       Application->ExeName
  723.                                                     );
  724.     as_MAX_MIDI_FILE_COUNT =  read_MAX_MIDI_FILE_COUNT(
  725.                                                         "MF_setup.txt",
  726.                                                         Application->ExeName
  727.                                                        );
  728.     as_MAX_IMELODY_FILE_COUNT =  read_MAX_IMELODY_FILE_COUNT(
  729.                                                                "MF_setup.txt",
  730.                                                                Application->ExeName
  731.                                                             );
  732. }
  733. /////////////////////////////////////////////////////////////////////////////////////////
  734. void TfrmMMIDataDownload::show_download_type(void)
  735. {
  736.     AnsiString as_temp_download_type;
  737.     as_temp_download_type = read_download_type("MF_setup.txt", Application->ExeName);
  738.     as_temp_download_type =  LowerCase(as_temp_download_type);
  739.     if(as_temp_download_type.AnsiCompare("fullscreen") == 0)
  740.     {
  741.         rbFullScreen->Checked = true;
  742.     }
  743.     else if(as_temp_download_type.AnsiCompare("associate") == 0)
  744.     {
  745.         RadioButtonAssociate->Checked = true;
  746.     }
  747.     else if(as_temp_download_type.AnsiCompare("ems") == 0)
  748.     {
  749.         RadioButtonEMS->Checked = true;
  750.     }
  751.     else if(as_temp_download_type.AnsiCompare("midi") == 0)
  752.     {
  753.         rbMidi->Checked = true;
  754.     }
  755.     else if(as_temp_download_type.AnsiCompare("imelody") == 0)
  756.     {
  757.         rbiMelody->Checked = true;
  758.     }
  759. }
  760. //------------------------------------------------------------------------------
  761. void __fastcall TfrmMMIDataDownload::TimerMMIDataDownloadTimer(
  762.       TObject *Sender)
  763. {
  764.     if( IsRunning_MMIData == false)
  765.     {
  766.         TimerMMIDataDownload->Enabled = false;
  767.          // enable button
  768.         btnDownloadToFAT->Enabled = true;
  769.         if (MetaResult_MMIData == META_RESULT_SUCCESSFUL)
  770.         {
  771.             sbMMIData->Panels->Items[0]->Text = (AnsiString) "  Write to FAT successful";
  772.         }
  773.         else
  774.         {
  775.             sbMMIData->Panels->Items[0]->Text = (AnsiString) "  Write to FAT fail";
  776.             Application->MessageBox( "Execution Failure : Write to FAT", "FAILURE", MB_OK );
  777.         }
  778.     } // if( IsRunning_MMIData == false)
  779. }
  780. //------------------------------------------------------------------------------
  781. void TfrmMMIDataDownload::SaveLastFileShow(void)
  782. {
  783.     if(lastRadioButtonFullscreenChecked == true)
  784.     {
  785.         write_local_default_fullscreen_file_setting();
  786.     }
  787.     else if(lastRadioButtonAssociateChecked == true)
  788.     {
  789.         write_local_default_associate_file_setting();
  790.     }
  791.     else if(lastRadioButtonEMSChecked == true)
  792.     {
  793.         write_local_default_EMS_file_setting();
  794.     }
  795.     else if(lastRadioButtonMidiChecked == true)
  796.     {
  797.         write_local_default_midi_file_setting();
  798.     }
  799.     else if(lastRadioButtoniMelodyChecked == true)
  800.     {
  801.         write_local_default_imelody_file_setting();
  802.     }
  803. }
  804. //=================================================================================================
  805. //---------------------------------------------------------------------------
  806. ///////////////////////////////////////////////////////////////////////////////////////////////////
  807. void __fastcall TfrmMMIDataDownload::btnDownloadToFATClick(
  808.       TObject *Sender)
  809. {
  810.     // disable button
  811.     btnDownloadToFAT->Enabled = false;
  812.     read_DEFAULT_PATH();
  813.     set_DEFAULT_PATH();
  814.     for(int i=0; i< lbLocalMMIData->Items->Count; i++)
  815.     {
  816.         getFilenameFromStr(lbLocalMMIData->Items->Strings[i].c_str(), as_default_FAT_name);
  817.         strcpy(MMI_FILE_Object.FAT_filepath[i], (as_default_FAT_path + as_default_FAT_name).c_str());
  818.         strcpy(MMI_FILE_Object.local_filepath[i], lbLocalMMIData->Items->Strings[i].c_str());
  819.     }
  820.     TimerMMIDataDownload->Interval = 1000;
  821.     TimerMMIDataDownload->Enabled = true;
  822.     sbMMIData->Panels->Items[0]->Text = (AnsiString) "  Write to FAT Progressing";
  823.     ActiveMan->SetActiveFunction( ::REQ_Write_To_FAT );
  824. }
  825. ////////////////////////////// Upload //////////////////////////////////////////
  826. //---------------------------------------------------------------------------
  827. //---------------------------------------------------------------------------
  828. void __fastcall TfrmMMIDataDownload::BitBtnUploadFromFATClick(
  829.       TObject *Sender)
  830. {
  831.     // disable BitBtnDownloadToFAT, BitBtnUploadFromFAT
  832.     btnDownloadToFAT->Enabled = false;
  833.     //BitBtnUploadFromFAT->Enabled = false;
  834.     read_DEFAULT_PATH();
  835.     set_DEFAULT_PATH();
  836.     Index_MMIData = 0;
  837.     as_default_FAT_name = "spring" + IntToStr(Index_MMIData);
  838.     as_MMIDataStr = "spring" + IntToStr(Index_MMIData);
  839.     TimerMMIDataUpload->Interval = 1000;
  840.     TimerMMIDataUpload->Enabled = true;
  841.     ActiveMan->SetActiveFunction( ::REQ_Read_From_FAT );
  842. }
  843. ////////////////////////////////////////////////////////////////////////////////
  844. void __fastcall TfrmMMIDataDownload::TimerMMIDataUploadTimer(
  845.       TObject *Sender)
  846. {
  847.     if( IsRunning_MMIData == false)
  848.     {
  849.         if( Index_MMIData == 10)
  850.         {
  851.             TimerMMIDataUpload->Enabled = false;
  852.             // enable BitBtnDownloadToFAT, BitBtnUploadFromFAT
  853.             btnDownloadToFAT->Enabled = true;
  854.             // BitBtnUploadFromFAT->Enabled = true;
  855.             if (MetaResult_MMIData == META_RESULT_SUCCESSFUL)
  856.             {
  857.                 sbMMIData->Panels->Items[0]->Text = (AnsiString) "  Read from FAT successful";
  858.             }
  859.             else
  860.             {
  861.                 sbMMIData->Panels->Items[0]->Text = (AnsiString) "  Read from FAT fail";
  862.                 Application->MessageBox( "Execution Failure : Read from FAT", "FAILURE", MB_OK );
  863.             }
  864.         }
  865.         else
  866.         {
  867.             if (MetaResult_MMIData == META_RESULT_SUCCESSFUL)
  868.             {
  869.                 Index_MMIData++;
  870.                 sbMMIData->Panels->Items[0]->Text = (AnsiString) "  Read from FAT Progressing";
  871.             }
  872.             else
  873.             {
  874.                 TimerMMIDataUpload->Enabled = false;
  875.                 // enable BitBtnDownloadToFAT, BitBtnUploadFromFAT
  876.                 btnDownloadToFAT->Enabled = true;
  877.                 // BitBtnUploadFromFAT->Enabled = true;
  878.                 sbMMIData->Panels->Items[0]->Text = (AnsiString) "  Read from FAT fail";
  879.                 Application->MessageBox( "Execution Failure : Read from FAT", "FAILURE", MB_OK );
  880.         }
  881.       }
  882.    } // if( IsRunning_MMIData == false)
  883. }
  884. //---------------------------------------------------------------------------
  885. void __fastcall TfrmMMIDataDownload::rbiMelodyClick(TObject *Sender)
  886. {
  887.    if(lastRadioButtoniMelodyChecked == false)
  888.    {
  889.     SaveLastFileShow();
  890.     ShowFileSelected();
  891.     ModifyLastRadioButtonChecked();
  892.    }
  893. }
  894. //---------------------------------------------------------------------------
  895. void TfrmMMIDataDownload::REQ_Write_To_FAT(void)
  896. {
  897.      MMI_FILE_Object.REQ_Write_To_FAT(lbLocalMMIData->Items->Count);
  898. }
  899. //---------------------------------------------------------------------------------------------
  900. //---------------------------------------------------------------------------
  901. void TfrmMMIDataDownload::write_download_type(
  902.                                        AnsiString asSetupFile,
  903.                                        AnsiString asExeName,
  904.                                        AnsiString as_download_type
  905.                                      )
  906.  {
  907.     AnsiString asPath;
  908.     if ( getPathFromStr(asExeName, asPath) &&
  909.          withPath( asPath) &&
  910.          !withPath( asSetupFile)
  911.        )
  912.     {
  913.        asSetupFile = asPath + asSetupFile;
  914.     }
  915.     TIniFile *ini;
  916.     try
  917.     {
  918.        ini = new TIniFile( asSetupFile );
  919.        if(ini != NULL)
  920.        {
  921.           ini->WriteString("MMI data download table", "download_type", as_download_type );
  922.           delete ini;
  923.           ini = NULL;
  924.        } 
  925.     }
  926.     catch (...)
  927.     {
  928.        ShowMessage( " META factory : write setup file : " + asSetupFile + " error ");
  929.     }
  930.  }