OSDN Git Service

14d478698d9c3e072c6c16635a8e99fec4b3ed49
[unagi/old-svn-converted.git] / client / trunk / anago / anago_wxframe_main.cpp
1 #include <stdio.h>
2 #include <wx/wx.h>
3 #include <wx/log.h>
4 #include <wx/dir.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 }
13
14 static void value_set(void *gauge, int value)
15 {
16         wxGauge *g = static_cast<wxGauge *>(gauge);
17         g->SetValue(value);
18 }
19
20 static void range_set(void *gauge, int value)
21 {
22         wxGauge *g = static_cast<wxGauge *>(gauge);
23         if(value == 0){
24                 value = 1;
25         }
26         g->SetRange(value);
27 }
28
29 static void text_append(void *log, const char *str)
30 {
31         wxTextCtrl *l = static_cast<wxTextCtrl *>(log);
32         *l << str;
33 }
34
35 static void label_set(void *label, const char *str)
36 {
37         wxStaticText *l = static_cast<wxStaticText *>(label);
38         l->SetLabel(str);
39 }
40
41 anago_wxframe_main::anago_wxframe_main( wxWindow* parent )
42   : frame_main( parent )
43 {
44
45         wxDir dir(wxGetCwd());
46         wxString filename;
47
48
49         if ( !dir.IsOpened() ){
50                 return;
51         }
52         bool cont = dir.GetFirst(&filename, wxString("*.ad"), wxDIR_FILES);
53         while ( cont ){
54                 m_combo_script->Append(filename);
55
56                 cont = dir.GetNext(&filename);
57         }
58         m_combo_script->Select(0);
59 }
60
61 void anago_wxframe_main::OnButtonClick(wxCommandEvent& event)
62 {
63         struct config_dump config;
64         config.gauge_cpu.bar = m_gauge_cpu;
65         config.gauge_cpu.label = m_label_cpu;
66         config.gauge_cpu.label_set = label_set;
67         config.gauge_cpu.range_set = range_set;
68         config.gauge_cpu.value_set = value_set;
69
70         config.gauge_ppu.bar = m_gauge_ppu;
71         config.gauge_ppu.label = m_label_ppu;
72         config.gauge_ppu.label_set = label_set;
73         config.gauge_ppu.range_set = range_set;
74         config.gauge_ppu.value_set = value_set;
75         
76         config.log.object = m_log;
77         config.log.append = text_append;
78         config.increase.cpu = 1;
79         config.increase.ppu = 1;
80         config.progress = true;
81         wxString str_script = m_combo_script->GetValue();
82         config.script = str_script.fn_str();
83
84         {
85                 wxString str;
86                 config.mappernum = -1;
87                 if(m_check_forcemapper->GetValue() == true){
88                         str = m_text_forcemapper->GetValue();
89                         if(str.ToLong(&config.mappernum) == false){
90                                 *m_log << "bad mapper number\n";
91                                 return;
92                         }
93                 }
94         }
95
96         wxTextCtrl *text = m_picker_romimage->GetTextCtrl();
97         wxString str_rom = text->GetValue();
98         if(text->IsEmpty() == true){
99                 *m_log << "Enter filename to ROM image\n";
100                 return;
101         }
102         config.target = str_rom.fn_str();
103
104         config.reader = &DRIVER_KAZZO;
105         if(config.reader->open_or_close(READER_OPEN) == NG){
106                 *m_log << "reader open error\n";
107                 return;
108         }
109         m_combo_script->Disable();
110         m_picker_romimage->Disable();
111         m_check_battery->Disable();
112         m_check_forcemapper->Disable();
113         m_button_dump->Disable();
114         if(m_check_forcemapper->GetValue() == true){
115                 m_text_forcemapper->Disable();
116         }
117
118         config.reader->init();
119         script_dump_execute(&config);
120         config.reader->open_or_close(READER_CLOSE);
121
122         m_combo_script->Enable();
123         m_picker_romimage->Enable();
124         m_check_battery->Enable();
125         m_check_forcemapper->Enable();
126         m_button_dump->Enable();
127         if(m_check_forcemapper->GetValue() == true){
128                 m_text_forcemapper->Enable();
129         }
130 }
131
132 void anago_wxframe_main::mapper_change_check(wxCommandEvent& event)
133 {
134         if(m_check_forcemapper->GetValue() == true){
135                 m_text_forcemapper->Enable();
136         }else{
137                 m_text_forcemapper->Disable();
138         }
139 }
140
141 class MyApp : public wxApp
142 {
143 private:
144         anago_wxframe_main *m_frame;
145 public: 
146         bool OnInit()
147         {
148                 m_frame = new anago_wxframe_main(NULL);
149                 m_frame->Show();
150                 
151                 return true;
152         }
153 /*      int OnExit()
154         {
155                 delete m_frame;
156                 m_frame = NULL;
157                 
158                 return 0;
159         }*/
160 };
161 IMPLEMENT_APP(MyApp)