OSDN Git Service

flash memory device listup の対応を追加
[unagi/old-svn-converted.git] / client / trunk / anago / anago_wxframe_main.cpp
1 #include <wx/wx.h>
2 #include <wx/log.h>
3 #include <wx/dir.h>
4 #include "wx.h"
5 #include "widget.h"
6 #include "anago_wxframe_main.h"
7 #include "reader_master.h"
8 //#include "reader_kazzo.h"
9 extern const struct reader_driver DRIVER_KAZZO;
10 extern "C"{
11 #include "script_dump.h"
12 #include "flash_device.h"
13 }
14
15 static void value_set(void *gauge, int value)
16 {
17         wxGauge *g = static_cast<wxGauge *>(gauge);
18         g->SetValue(value);
19 }
20
21 static void range_set(void *gauge, int value)
22 {
23         wxGauge *g = static_cast<wxGauge *>(gauge);
24         if(value == 0){
25                 value = 1;
26         }
27         g->SetRange(value);
28 }
29
30 static void text_append(void *log, const char *str)
31 {
32         wxTextCtrl *l = static_cast<wxTextCtrl *>(log);
33         *l << str;
34 }
35
36 static void label_set(void *label, const char *str)
37 {
38         wxStaticText *l = static_cast<wxStaticText *>(label);
39         l->SetLabel(str);
40 }
41
42 static void choice_append(void *choice, const char *str)
43 {
44         wxChoice *c = static_cast<wxChoice *>(choice);
45         c->Append(wxString(str));
46 }
47
48 class anago_wxframe_main : public frame_main
49 {
50 private:
51         enum {
52                 MODE_DUMP, MODE_PROGRAM
53         } m_mode;
54         void choise_script_init(wxString filespec)
55         {
56                 wxDir dir(wxGetCwd());
57                 wxString filename;
58
59                 m_choice_script->Clear();
60                 if ( !dir.IsOpened() ){
61                         return;
62                 }
63                 bool cont = dir.GetFirst(&filename, filespec, wxDIR_FILES);
64                 while ( cont ){
65                         m_choice_script->Append(filename);
66                         cont = dir.GetNext(&filename);
67                 }
68                 m_choice_script->Select(0);
69         }
70         void dump_form_init(void)
71         {
72                 m_mode = MODE_DUMP;
73                 this->choise_script_init(wxString("*.ad"));
74                 m_check_battery->Show();
75                 m_check_forcemapper->Show();
76                 m_text_forcemapper->Show();
77                 m_button_execute->SetLabel(wxString("&Dump"));
78                 m_choice_cpu_trans->Hide();
79                 m_choice_cpu_device->Hide();
80                 m_choice_ppu_trans->Hide();
81                 m_choice_ppu_device->Hide();
82         }
83         void choise_trans_init(wxChoice *c)
84         {
85                 c->Clear();
86                 c->Append(wxString("full"));
87                 c->Append(wxString("empty"));
88                 c->Append(wxString("top"));
89                 c->Append(wxString("bottom"));
90                 c->Select(0);
91         }
92         void program_form_init(void)
93         {
94                 m_mode = MODE_PROGRAM;
95                 this->choise_script_init(wxString("*.af"));
96                 m_check_battery->Hide();
97                 m_check_forcemapper->Hide();
98                 m_text_forcemapper->Hide();
99                 m_button_execute->SetLabel(wxString("&Program"));
100                 m_choice_cpu_trans->Show();
101                 m_choice_cpu_device->Show();
102                 m_choice_ppu_trans->Show();
103                 m_choice_ppu_device->Show();
104         }
105         void dump_execute(void)
106         {
107                 struct config_dump config;
108                 config.gauge_cpu.bar = m_gauge_cpu;
109                 config.gauge_cpu.label = m_label_cpu;
110                 config.gauge_cpu.label_set = label_set;
111                 config.gauge_cpu.range_set = range_set;
112                 config.gauge_cpu.value_set = value_set;
113
114                 config.gauge_ppu.bar = m_gauge_ppu;
115                 config.gauge_ppu.label = m_label_ppu;
116                 config.gauge_ppu.label_set = label_set;
117                 config.gauge_ppu.range_set = range_set;
118                 config.gauge_ppu.value_set = value_set;
119                 
120                 config.log.object = m_log;
121                 config.log.append = text_append;
122                 config.increase.cpu = 1;
123                 config.increase.ppu = 1;
124                 config.progress = true;
125                 wxString str_script = m_choice_script->GetStringSelection();
126                 config.script = str_script.fn_str();
127
128                 {
129                         wxString str;
130                         config.mappernum = -1;
131                         if(m_check_forcemapper->GetValue() == true){
132                                 str = m_text_forcemapper->GetValue();
133                                 if(str.ToLong(&config.mappernum) == false){
134                                         *m_log << "bad mapper number\n";
135                                         return;
136                                 }
137                         }
138                 }
139
140                 wxTextCtrl *text = m_picker_romimage->GetTextCtrl();
141                 wxString str_rom = text->GetValue();
142                 if(text->IsEmpty() == true){
143                         *m_log << "Enter filename to ROM image\n";
144                         return;
145                 }
146                 config.target = str_rom.fn_str();
147
148                 config.reader = &DRIVER_KAZZO;
149                 if(config.reader->open_or_close(READER_OPEN) == NG){
150                         *m_log << "reader open error\n";
151                         return;
152                 }
153                 m_choice_script->Disable();
154                 m_picker_romimage->Disable();
155                 m_check_battery->Disable();
156                 m_check_forcemapper->Disable();
157                 m_button_execute->Disable();
158                 if(m_check_forcemapper->GetValue() == true){
159                         m_text_forcemapper->Disable();
160                 }
161
162                 config.reader->init();
163                 script_dump_execute(&config);
164                 config.reader->open_or_close(READER_CLOSE);
165
166                 m_choice_script->Enable();
167                 m_picker_romimage->Enable();
168                 m_check_battery->Enable();
169                 m_check_forcemapper->Enable();
170                 m_button_execute->Enable();
171                 if(m_check_forcemapper->GetValue() == true){
172                         m_text_forcemapper->Enable();
173                 }
174         }
175 protected:
176         // Handlers for frame_main events.
177         void OnButtonClick( wxCommandEvent& event )
178         {
179                 this->dump_execute();
180         }
181
182         void mapper_change_check(wxCommandEvent& event)
183         {
184                 if(m_check_forcemapper->GetValue() == true){
185                         m_text_forcemapper->Enable();
186                 }else{
187                         m_text_forcemapper->Disable();
188                 }
189         }
190 public:
191         /** Constructor */
192         anago_wxframe_main( wxWindow* parent ) : frame_main (parent)
193         {
194                 //this->dump_form_init();
195                 this->program_form_init();
196                 this->choise_trans_init(m_choice_cpu_trans);
197                 this->choise_trans_init(m_choice_ppu_trans);
198
199                 struct flash_listup list;
200                 list.obj_cpu = m_choice_cpu_device;
201                 list.obj_ppu = m_choice_ppu_device;
202                 list.append = choice_append;
203                 flash_device_listup(&list);
204                 m_choice_cpu_device->Select(0);
205                 m_choice_ppu_device->Select(0);
206         }
207         
208 };
209
210
211
212 class MyApp : public wxApp
213 {
214 private:
215         anago_wxframe_main *m_frame;
216 public: 
217         bool OnInit()
218         {
219                 m_frame = new anago_wxframe_main(NULL);
220                 m_frame->Show();
221                 
222                 return true;
223         }
224 };
225 IMPLEMENT_APP(MyApp)