1 /***************************************************************************
2 *  mainframe.cpp
3 *
4 *  Wed Sep  6 22:19:52 2006
5 *  Copyright  2006  liubin,China
6 *  Email multiget@gmail.com
7 ****************************************************************************/
8 
9 /*
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23  */
24 
25 
26 #include "mgapp.h"
27 #include "mainframe.h"
28 #include "listenpipe.h"
29 #include <list>
30 #include <wx/image.h>
31 #include <locale.h>
32 
33 #include "rightdownsplitter.h"
34 #include "taskmanager.h"
35 #include "lefttree.h"
36 #include "tasklist.h"
37 #include "mgnewtaskdlg.h"
38 #include "dropurl.h"
39 #include "mgurlparser.h"
40 #include "filemd5.h"
41 
42 #include "meterctrl.h"
43 #include "systray.h"
44 #include "floatwin.h"
45 #include "hidewin.h"
46 #include "proxydlg.h"
47 #include "configwin.h"
48 #include "mirroradmin.h"
49 #include "propertydlg.h"
50 #include "batch.h"
51 
52 #include "./newicons/16/new.xpm"
53 #include "./newicons/16/run.xpm"
54 #include "./newicons/16/stop.xpm"
55 #include "./newicons/16/delete.xpm"
56 #include "./newicons/16/up.xpm"
57 #include "./newicons/16/down.xpm"
58 #include "./newicons/16/plus.xpm"
59 #include "./newicons/16/sub.xpm"
60 #include "./newicons/16/reload.xpm"
61 #include "./newicons/16/option.xpm"
62 #include "./newicons/16/quit.xpm"
63 #include "./icons/about.xpm"
64 #include "./newicons/16/proxy.xpm"
65 #include "./newicons/16/save.xpm"
66 #include "./newicons/16/msgsystem_16.xpm"
67 
68 #include "./newicons/32/tool_new.xpm"
69 #include "./newicons/32/tool_run.xpm"
70 #include "./newicons/32/tool_pause.xpm"
71 #include "./newicons/32/tool_delete.xpm"
72 #include "./newicons/32/tool_up.xpm"
73 #include "./newicons/32/tool_down.xpm"
74 #include "./newicons/32/tool_option.xpm"
75 #include "./newicons/32/tool_sub.xpm"
76 #include "./newicons/32/tool_plus.xpm"
77 #include "./newicons/32/tool_reload.xpm"
78 #include "./newicons/32/tool_proxy.xpm"
79 #include "./newicons/32/tool_property.xpm"
80 
81 #include "./newicons/16/logo_16.xpm"
82 //#include "./newicons/24/logo_24.xpm"
83 #include "./newicons/32/logo_32.xpm"
84 #include "./newicons/48/logo_48.xpm"
85 #include "./newicons/24/logo_22.xpm"
86 
87 #include <fstream>
88 
89 using namespace std;
90 
91 DEFINE_EVENT_TYPE( mgID_TIMER )
92 DEFINE_EVENT_TYPE( mgEVT_TASK_FINISH )
93 DEFINE_EVENT_TYPE( mgEVT_URL_NOTICE )
94 DEFINE_EVENT_TYPE( mgEVT_CMD_NOTICE )
95 DEFINE_EVENT_TYPE( mgID_NEW_TASK )
96 DEFINE_EVENT_TYPE( mgID_START_TASK )
97 DEFINE_EVENT_TYPE( mgID_STOP_TASK )
98 DEFINE_EVENT_TYPE( mgID_CANCEL_TASK )
99 DEFINE_EVENT_TYPE( mgID_MOVEUP_TASK )
100 DEFINE_EVENT_TYPE( mgID_MOVEDOWN_TASK )
101 DEFINE_EVENT_TYPE( mgID_OPTION_CONFIG )
102 DEFINE_EVENT_TYPE( mgID_SUBTHREAD )
103 DEFINE_EVENT_TYPE( mgID_ADDTHREAD )
104 DEFINE_EVENT_TYPE( mgID_RELOAD )
105 
106 DEFINE_EVENT_TYPE( mgID_VIEW_LANG )
107 DEFINE_EVENT_TYPE( mgID_VIEW_LANG_EN_UTF8 )
108 DEFINE_EVENT_TYPE( mgID_VIEW_LANG_CN_UTF8 )
109 DEFINE_EVENT_TYPE( mgID_VIEW_LANG_GB18030 )
110 DEFINE_EVENT_TYPE( mgID_VIEW_LANG_TW_UTF8 )
111 DEFINE_EVENT_TYPE( mgID_VIEW_LANG_TW_BIG5 )
112 DEFINE_EVENT_TYPE( mgID_VIEW_LANG_DE_UTF8 )
113 
114 DEFINE_EVENT_TYPE( mgID_VIEW_TOOLBAR )
115 DEFINE_EVENT_TYPE( mgID_VIEW_TOOLBAR_SIZE16 )
116 DEFINE_EVENT_TYPE( mgID_VIEW_TOOLBAR_SIZE24 )
117 DEFINE_EVENT_TYPE( mgID_VIEW_TOOLBAR_SIZE32 )
118 DEFINE_EVENT_TYPE( mgID_VIEW_STATUSBAR )
119 DEFINE_EVENT_TYPE( mgID_OPTION_PROXY )
120 DEFINE_EVENT_TYPE( mgID_OPTION_PROPERTY )
121 
122 DEFINE_EVENT_TYPE( mgID_FILE_SAVECONFIG );
123 DEFINE_EVENT_TYPE( mgID_FILE_SAVETASK );
124 DEFINE_EVENT_TYPE( mgID_FILE_SAVEPROXY );
125 DEFINE_EVENT_TYPE( mgID_HELP_VISITHOME );
126 
127 // Event table for MainFrame
128 BEGIN_EVENT_TABLE( MainFrame, wxFrame )
129 EVT_MENU( wxID_ABOUT, MainFrame::OnAbout )
130 EVT_MENU( wxID_EXIT, MainFrame::OnQuit )
131 EVT_TIMER( mgID_TIMER, MainFrame::OnTimer )
132 EVT_SIZE( MainFrame::OnSize )
133 EVT_CLOSE( MainFrame::OnClose )
134 //EVT_WINDOW_DESTROY( MainFrame::OnDestroy )
135 EVT_COMMAND( wxID_ANY, mgEVT_TASK_FINISH, MainFrame::OnTaskFinish )
136 EVT_COMMAND( wxID_ANY, mgEVT_URL_NOTICE, MainFrame::OnUrlNotice )
137 EVT_COMMAND( wxID_ANY, mgEVT_CMD_NOTICE, MainFrame::OnCmdNotice )
138 EVT_ICONIZE( MainFrame::OnIconize )
139 EVT_MENU( mgID_NEW_TASK, MainFrame::OnNewTask )
140 EVT_MENU( mgID_START_TASK, MainFrame::OnStartTask )
141 EVT_MENU( mgID_STOP_TASK, MainFrame::OnStopTask )
142 EVT_MENU( mgID_CANCEL_TASK, MainFrame::OnCancelTask )
143 EVT_MENU( mgID_SUBTHREAD, MainFrame::OnDecreaseThread )
144 EVT_MENU( mgID_ADDTHREAD, MainFrame::OnIncreaseThread )
145 EVT_MENU( mgID_RELOAD, MainFrame::OnReloadFile )
146 EVT_MENU( mgID_OPTION_CONFIG, MainFrame::OnConfig )
147 EVT_MENU( mgID_MOVEDOWN_TASK, MainFrame::OnMoveDown )
148 EVT_MENU( mgID_MOVEUP_TASK, MainFrame::OnMoveUp )
149 EVT_MENU( mgID_VIEW_LANG_EN_UTF8, MainFrame::OnLangEnUtf8 )
150 EVT_MENU( mgID_VIEW_LANG_CN_UTF8, MainFrame::OnLangCnUtf8 )
151 EVT_MENU( mgID_VIEW_LANG_GB18030, MainFrame::OnLangCn18030 )
152 EVT_MENU( mgID_VIEW_LANG_TW_UTF8, MainFrame::OnLangTwUtf8 )
153 EVT_MENU( mgID_VIEW_LANG_TW_BIG5, MainFrame::OnLangTwBig5 )
154 EVT_MENU( mgID_VIEW_LANG_DE_UTF8, MainFrame::OnLangDeUtf8 )
155 EVT_MENU( mgID_VIEW_STATUSBAR, MainFrame::OnStatusBar )
156 EVT_MENU( mgID_VIEW_TOOLBAR_SIZE16, MainFrame::OnToolbarSize16 )
157 EVT_MENU( mgID_VIEW_TOOLBAR_SIZE24, MainFrame::OnToolbarSize24 )
158 EVT_MENU( mgID_VIEW_TOOLBAR_SIZE32, MainFrame::OnToolbarSize32 )
159 EVT_MENU( mgID_OPTION_PROXY, MainFrame::OnProxySetting )
160 EVT_MENU( mgID_OPTION_PROPERTY, MainFrame::OnProperty )
161 
162 EVT_MENU( mgID_FILE_SAVECONFIG, MainFrame::OnSaveConfig )
163 EVT_MENU( mgID_FILE_SAVEPROXY, MainFrame::OnSaveProxy )
164 EVT_MENU( mgID_FILE_SAVETASK, MainFrame::OnSaveTask )
165 EVT_MENU( mgID_HELP_VISITHOME, MainFrame::OnVisitHome )
166 
167 EVT_WINDOW_CREATE( MainFrame::OnWindowCreate )
168 EVT_MAXIMIZE( MainFrame::OnMaximize )
169 //EVT_SET_FOCUS( MainFrame::OnFocus )
170 //EVT_KILL_FOCUS( MainFrame::OnLostFocus )
171 END_EVENT_TABLE()
172 
173 #define  _MGSTR(s) wxGetApp().GetWxStr(s)
174 
175 extern int gRunTaskNum;
176 extern int gConnectTimeOut;
177 extern int gReceiveTimeOut;
178 extern int gTaskDefThread;
179 extern int gRetryTime;
180 extern int gRetryWait;
181 extern std::list<std::string> gSavePathHistory;
182 extern std::string gDefSavePath, gDefFtpPass, gsMonitorExt, gsIgnoreExt;
183 
184 extern bool gbIgnoreExt;
185 extern bool gbMonitorExt;
186 extern bool gbShowDropWin;
187 extern bool gbMonitorClip;
188 extern bool gbSoundTip;
189 extern bool gbAutoMd5;
190 extern int gDropWinX;
191 extern int gDropWinY;
192 extern int gSpeedMode;
193 
194 //a simple mirror admin,because filemanager need it.
195 //extern CMirrorAdmin gMirrorAdmin;
196 
OnIconize(wxIconizeEvent & event)197 void MainFrame::OnIconize( wxIconizeEvent& event )
198 {
199     if ( event.Iconized() )
200     {
201         Iconize( true );
202         Hide();
203     }
204 }
205 
OnWindowCreate(wxWindowCreateEvent & event)206 void MainFrame::OnWindowCreate( wxWindowCreateEvent& event )
207 {
208 #ifndef WIN32
209 //in windows ,this is called before ctor. so only use in linux
210     if ( m_FloatWin )
211     {
212 		m_FloatWin->Show();
213 	}
214 
215     if ( m_SysTray )
216     {
217 		m_SysTray->SetIcon( wxIcon( logo_22_xpm ), _MGSTR( _S_APP_NAME ) );
218 	}
219 #else
220 	event.Skip();
221 #endif
222 }
223 
MainFrame(const wxString & title)224 MainFrame::MainFrame( const wxString& title )
225         : wxFrame( NULL, wxID_ANY, title, wxDefaultPosition, wxSize( 800, 600 ),
226                    wxRESIZE_BORDER | wxDEFAULT_FRAME_STYLE | wxMAXIMIZE | wxFULL_REPAINT_ON_RESIZE )
227 {
228 
229 
230     m_nCurrentShowType = ( _STATUS_ROOT );
231     m_nTaskID = 0;
232     m_nCurrentSelectTaskID = -1;
233     m_lefttree = NULL;
234     m_tasklist = NULL;
235     m_vspliter = NULL;
236     m_hspliter = NULL;
237     m_vsubspliter = NULL;
238     m_ToolBar = NULL;
239     m_MenuBar = NULL;
240 	m_MeterBar = NULL;
241     m_HideWin = NULL;
242     m_NewTaskDlg = NULL;
243     m_PropertyDlg = NULL;
244 	m_lang = NULL;
245     //m_bMonitorClip = true;
246     m_bShowStatusBar = true;
247     TOOLBAR_SIZE = 32;
248     m_nWinSizeW = 800;
249     m_nWinSizeH = 600;
250     pthread_mutex_init ( &m_TaskMutex, NULL );
251     //change to SetIcons
252     wxIconBundle bund;
253     bund.AddIcon( wxIcon( logo_16_xpm ) );
254     bund.AddIcon( wxIcon( logo_22_xpm ) );
255     bund.AddIcon( wxIcon( logo_32_xpm ) );
256     bund.AddIcon( wxIcon( logo_48_xpm ) );
257 
258     SetIcons( bund );
259 
260 
261     m_TaskManager = new CTaskManager( this );
262 
263 
264     ReadTaskDB();
265 
266     ReadProxyDB();
267 
268     if ( !ReadConfig() )
269     {
270         GetUserHome( gDefSavePath );
271     }
272 
273     InitFileTypeList();
274 
275     InitMeterBar(); //call before onsize
276     InitSpliter();	//call before onsize
277     InitMenuBar(); //make menu generate a size event in win32
278 
279     InitToolBar();
280     InitStatusBar();
281 
282 
283 
284     m_Timer.SetOwner( this, mgID_TIMER );
285     m_Timer.Start( 1000 );
286 
287     if ( gbShowDropWin )
288         m_FloatWin = new CFloatWin( this );
289     else
290         m_FloatWin = NULL;
291 
292     m_SysTray = new CSysTray( this );
293 
294 #ifdef WIN32
295 //in windows
296     if ( m_FloatWin )
297     {//float win have trouble currently
298 		m_FloatWin->Show();
299 	}
300 
301     if ( m_SysTray )
302     {
303 		m_SysTray->SetIcon( wxIcon( logo_22_xpm ), _MGSTR( _S_APP_NAME ) );
304 	}
305 #endif
306 
307     m_HideWin = new CHideWin( this );
308 
309     m_HideWin->MonitorClip( gbMonitorClip );
310 
311     UpdateToolBar();
312 
313     ScheduleTask();
314 
315 #ifndef WIN32
316     CListenPipe *tpi = new CListenPipe( this );
317 
318     tpi->Create();
319 
320     tpi->Run();
321 
322 #endif
323 }
324 
325 
~MainFrame()326 MainFrame::~MainFrame()
327 {
328     delete m_TaskManager;
329 
330     if ( m_FloatWin )
331         m_FloatWin->Destroy();
332 
333     m_HideWin->Destroy();
334 }
335 
336 
InitMenuBar()337 void MainFrame::InitMenuBar()
338 {
339 
340 
341     wxMenu *fileMenu = new wxMenu;
342 
343     wxMenu *taskMenu = new wxMenu;
344 
345     wxMenu *viewMenu = new wxMenu;
346 
347     wxMenu *setMenu = new wxMenu;
348 
349     wxMenu *helpMenu = new wxMenu;
350 
351     wxMenuItem *visit =
352         new wxMenuItem( helpMenu, mgID_HELP_VISITHOME, _MGSTR( _S_MENU_HELP_VISITHOME ), wxT( "Visit homepage" ) );
353     visit->SetBitmap( wxBitmap( msgsystem_16_xpm ) );
354     helpMenu->Append( visit );
355 
356     wxMenuItem *about =
357         new wxMenuItem( helpMenu, wxID_ABOUT, _MGSTR( _S_MENU_HELP_ABOUT ), wxT( "About program" ) );
358     about->SetBitmap( wxBitmap( about_xpm ) );
359     helpMenu->Append( about );
360 
361     wxMenuItem *option =
362         new wxMenuItem( setMenu, mgID_OPTION_CONFIG, _MGSTR( _S_MENU_OPTION_CONFIG ), wxT( "sys setting" ) );
363     option->SetBitmap( wxBitmap( option_xpm ) );
364     setMenu->Append( option );
365 
366     wxMenuItem *proxy =
367         new wxMenuItem( setMenu, mgID_OPTION_PROXY, _MGSTR( _S_MENU_OPTION_PROXYCONFIG ), wxT( "proxy setting" ) );
368     proxy->SetBitmap( wxBitmap( proxy_xpm ) );
369     setMenu->Append( proxy );
370 
371 
372     wxMenuItem *saveconfig =
373         new wxMenuItem( fileMenu, mgID_FILE_SAVECONFIG, _MGSTR( _S_MENU_FILE_SAVECONFIG ), wxT( "Save Config" ) );
374     saveconfig->SetBitmap( wxBitmap( save_xpm ) );
375     fileMenu->Append( saveconfig );
376 
377     wxMenuItem *savetask =
378         new wxMenuItem( fileMenu, mgID_FILE_SAVETASK, _MGSTR( _S_MENU_FILE_SAVETASK ), wxT( "Save Task" ) );
379     savetask->SetBitmap( wxBitmap( save_xpm ) );
380     fileMenu->Append( savetask );
381 
382     wxMenuItem *saveproxy =
383         new wxMenuItem( fileMenu, mgID_FILE_SAVEPROXY, _MGSTR( _S_MENU_FILE_SAVEPROXY ), wxT( "Save Proxy" ) );
384     saveproxy->SetBitmap( wxBitmap( save_xpm ) );
385     fileMenu->Append( saveproxy );
386 
387 	fileMenu->AppendSeparator();
388 
389     wxMenuItem *quit =
390         new wxMenuItem( fileMenu, wxID_EXIT, _MGSTR( _S_MENU_FILE_QUIT ), wxT( "Quit program" ) );
391     quit->SetBitmap( wxBitmap( quit_xpm ) );
392     fileMenu->Append( quit );
393 
394     //view
395 
396     wxMenu *lang = new wxMenu;
397     lang->AppendRadioItem( mgID_VIEW_LANG_EN_UTF8, wxT( "English UTF-8" ), wxT( "change to english." ) );
398     lang->AppendSeparator();
399     lang->AppendRadioItem( mgID_VIEW_LANG_CN_UTF8, wxT( "Chinese UTF-8" ), wxT( "change to chinese" ) );
400     lang->AppendRadioItem( mgID_VIEW_LANG_GB18030, wxT( "Chinese GB18030/GB2312/GBK" ), wxT( "change to chinese" ) );
401     lang->AppendSeparator();
402     lang->AppendRadioItem( mgID_VIEW_LANG_TW_UTF8, wxT( "Taiwan UTF-8" ), wxT( "change to taiwan utf-8" ) );
403     lang->AppendRadioItem( mgID_VIEW_LANG_TW_BIG5, wxT( "Taiwan BIG5" ), wxT( "change to taiwan big5" ) );
404     lang->AppendSeparator();
405     lang->AppendRadioItem( mgID_VIEW_LANG_DE_UTF8, wxT( "German UTF-8" ), wxT( "change to German" ) );
406   //  lang->AppendSeparator();
407 
408 	m_lang=lang;
409 	CheckLangMenu( wxGetApp().GetLang() );
410 
411 
412     viewMenu->Append( mgID_VIEW_LANG, _MGSTR( _S_MENU_VIEW_LANG ), lang );
413     viewMenu->AppendSeparator();
414 
415     wxMenu *tool = new wxMenu;
416     tool->AppendRadioItem( mgID_VIEW_TOOLBAR_SIZE16, _MGSTR( _S_MENU_VIEW_TOOLBAR_SIZE16 ), wxT( "size 16" ) );
417     tool->AppendRadioItem( mgID_VIEW_TOOLBAR_SIZE24, _MGSTR( _S_MENU_VIEW_TOOLBAR_SIZE24 ), wxT( "size 24" ) );
418     tool->AppendRadioItem( mgID_VIEW_TOOLBAR_SIZE32, _MGSTR( _S_MENU_VIEW_TOOLBAR_SIZE32 ), wxT( "size 32" ) );
419     viewMenu->Append( mgID_VIEW_TOOLBAR, _MGSTR( _S_MENU_VIEW_TOOLBAR ), tool );
420 
421     switch ( TOOLBAR_SIZE )
422     {
423 
424         case 16:
425         tool->Check( mgID_VIEW_TOOLBAR_SIZE16, true );
426         break;
427 
428         case 24:
429         tool->Check( mgID_VIEW_TOOLBAR_SIZE24, true );
430         break;
431 
432         case 32:
433         tool->Check( mgID_VIEW_TOOLBAR_SIZE32, true );
434         break;
435     }
436 
437     viewMenu->AppendCheckItem( mgID_VIEW_STATUSBAR, _MGSTR( _S_MENU_VIEW_STATUSBAR ), wxT( "statusbar" ) );
438     viewMenu->Check( mgID_VIEW_STATUSBAR, m_bShowStatusBar );
439 
440     wxMenuItem *newtask =
441         new wxMenuItem( taskMenu, mgID_NEW_TASK, _MGSTR( _S_MENU_TASK_NEW ), wxT( "create a new task." ) );
442     newtask->SetBitmap( wxBitmap( new_xpm ) );
443     wxMenuItem *starttask =
444         new wxMenuItem( taskMenu, mgID_START_TASK, _MGSTR( _S_MENU_TASK_START ), wxT( "start current task." ) );
445     starttask->SetBitmap( wxBitmap( run_xpm ) );
446     wxMenuItem *pausetask =
447         new wxMenuItem( taskMenu, mgID_STOP_TASK, _MGSTR( _S_MENU_TASK_PAUSE ), wxT( "pause current task." ) );
448     pausetask->SetBitmap( wxBitmap( stop_xpm ) );
449     wxMenuItem *deletetask =
450         new wxMenuItem( taskMenu, mgID_CANCEL_TASK, _MGSTR( _S_MENU_TASK_DELETE ), wxT( "delete current task." ) );
451     deletetask->SetBitmap( wxBitmap( delete_xpm ) );
452 
453     wxMenuItem *moveup =
454         new wxMenuItem( taskMenu, mgID_MOVEUP_TASK, _MGSTR( _S_MENU_TASK_MOVEUP ), wxT( "moveup current task." ) );
455     moveup->SetBitmap( wxBitmap( up_xpm ) );
456     wxMenuItem *movedown =
457         new wxMenuItem( taskMenu, mgID_MOVEDOWN_TASK, _MGSTR( _S_MENU_TASK_MOVEDOWN ), wxT( "movedown current task." ) );
458     movedown->SetBitmap( wxBitmap( down_xpm ) );
459 
460     wxMenuItem *addant =
461         new wxMenuItem( taskMenu, mgID_ADDTHREAD, _MGSTR( _S_MENU_TASK_ADDTHREAD ), wxT( "increase a working thread." ) );
462     addant->SetBitmap( wxBitmap( plus_xpm ) );
463     wxMenuItem *subant =
464         new wxMenuItem( taskMenu, mgID_SUBTHREAD, _MGSTR( _S_MENU_TASK_SUBTHREAD ), wxT( "decrease a working thread." ) );
465     subant->SetBitmap( wxBitmap( sub_xpm ) );
466 
467     wxMenuItem *reload =
468         new wxMenuItem( taskMenu, mgID_RELOAD, _MGSTR( _S_MENU_TASK_RELOAD ), wxT( "redownload the task" ) );
469     reload->SetBitmap( wxBitmap( reload_xpm ) );
470 
471     taskMenu->Append( newtask );
472     taskMenu->Append( starttask );
473     taskMenu->Append( pausetask );
474     taskMenu->Append( deletetask );
475     taskMenu->AppendSeparator( );
476     taskMenu->Append( moveup );
477     taskMenu->Append( movedown );
478     taskMenu->AppendSeparator( );
479     taskMenu->Append( addant );
480     taskMenu->Append( subant );
481     taskMenu->AppendSeparator( );
482     taskMenu->Append( reload );
483     //root menu
484     wxMenuBar* menubar = new wxMenuBar( wxMB_DOCKABLE );
485     assert( menubar != NULL );
486     menubar->Append( fileMenu, _MGSTR( _S_MENU_FILE ) );
487     menubar->Append( taskMenu, _MGSTR( _S_MENU_TASK ) );
488     menubar->Append( viewMenu, _MGSTR( _S_MENU_VIEW ) );
489     menubar->Append( setMenu, _MGSTR( _S_MENU_OPTION ) );
490     menubar->Append( helpMenu, _MGSTR( _S_MENU_HELP ) );
491 
492 	//Under Windows, a size event is generated, so be sure to initialize data members properly before calling SetMenuBar.
493     SetMenuBar( menubar );
494 }
495 
InitToolBar()496 void MainFrame::InitToolBar()
497 {
498 
499     // delete and recreate the toolbar
500     long style;
501 
502     if ( GetToolBar() != NULL )
503     {
504         style = GetToolBar() ->GetWindowStyle();
505         delete GetToolBar();
506         SetToolBar( NULL );
507 
508     }
509     else
510     {
511         style = TOOLBAR_STYLE;
512     }
513 
514     wxToolBar* toolbar = CreateToolBar( style, -1 );
515 
516 
517     //tool icon is 32*32
518     wxBitmap bmpNew( tool_new_xpm );
519     wxBitmap bmpStart( tool_run_xpm );
520     wxBitmap bmpStop( tool_pause_xpm );
521     wxBitmap bmpCancel( tool_delete_xpm );
522     wxBitmap bmpMoveup( tool_up_xpm );
523     wxBitmap bmpMovedown( tool_down_xpm );
524     wxBitmap bmpAddAnts( tool_plus_xpm );
525     wxBitmap bmpSubAnts( tool_sub_xpm );
526     wxBitmap bmpReload( tool_reload_xpm );
527     wxBitmap bmpOption( tool_option_xpm );
528     wxBitmap bmpProxy( tool_proxy_xpm );
529     wxBitmap bmpProperty( tool_property_xpm );
530 
531 
532     if ( TOOLBAR_SIZE != 32 )
533     {
534         bmpNew = wxBitmap( bmpNew.ConvertToImage().Scale( TOOLBAR_SIZE, TOOLBAR_SIZE ) );
535         bmpStart = wxBitmap( bmpStart.ConvertToImage().Scale( TOOLBAR_SIZE, TOOLBAR_SIZE ) );
536         bmpStop = wxBitmap( bmpStop.ConvertToImage().Scale( TOOLBAR_SIZE, TOOLBAR_SIZE ) );
537         bmpCancel = wxBitmap( bmpCancel.ConvertToImage().Scale( TOOLBAR_SIZE, TOOLBAR_SIZE ) );
538         bmpMoveup = wxBitmap( bmpMoveup.ConvertToImage().Scale( TOOLBAR_SIZE, TOOLBAR_SIZE ) );
539         bmpMovedown = wxBitmap( bmpMovedown.ConvertToImage().Scale( TOOLBAR_SIZE, TOOLBAR_SIZE ) );
540         bmpAddAnts = wxBitmap( bmpAddAnts.ConvertToImage().Scale( TOOLBAR_SIZE, TOOLBAR_SIZE ) );
541         bmpSubAnts = wxBitmap( bmpSubAnts.ConvertToImage().Scale( TOOLBAR_SIZE, TOOLBAR_SIZE ) );
542         bmpReload = wxBitmap( bmpReload.ConvertToImage().Scale( TOOLBAR_SIZE, TOOLBAR_SIZE ) );
543         bmpOption = wxBitmap( bmpOption.ConvertToImage().Scale( TOOLBAR_SIZE, TOOLBAR_SIZE ) );
544         bmpProxy = wxBitmap( bmpProxy.ConvertToImage().Scale( TOOLBAR_SIZE, TOOLBAR_SIZE ) );
545         bmpProperty = wxBitmap( bmpProperty.ConvertToImage().Scale( TOOLBAR_SIZE, TOOLBAR_SIZE ) );
546 
547     }
548 
549     /*
550     	_S_TIP_NEWTASK,
551     	_S_TIP_RUNTASK,
552     	_S_TIP_STOPTASK,
553     	_S_TIP_DELETETASK,
554     	_S_TIP_MOVEUPTASK,
555     	_S_TIP_MOVEDOWNTASK,
556     	_S_TIP_ADDTASKTHREAD,
557     	_S_TIP_SUBTASKTHREAD,
558     	_S_TIP_RELOADTASK,
559     	_S_TIP_SYSCONFIG,
560     	_S_TIP_PROXYADMIN,
561     */
562     toolbar->SetMargins( 0, 0 );
563 	toolbar->SetToolBitmapSize(wxSize(TOOLBAR_SIZE, TOOLBAR_SIZE));
564 
565     toolbar->AddTool( mgID_NEW_TASK,
566                       _MGSTR( _S_MENU_TASK_NEW ),
567                       bmpNew,
568                       _MGSTR( _S_TIP_NEWTASK ) );
569 
570     toolbar->AddTool( mgID_START_TASK,
571                       _MGSTR( _S_MENU_TASK_START ),
572                       bmpStart,
573                       _MGSTR( _S_TIP_RUNTASK ) );
574 
575     toolbar->AddTool( mgID_STOP_TASK,
576                       _MGSTR( _S_MENU_TASK_PAUSE ),
577                       bmpStop,
578                       _MGSTR( _S_TIP_STOPTASK ) );
579 
580     toolbar->AddTool( mgID_CANCEL_TASK,
581                       _MGSTR( _S_MENU_TASK_DELETE ),
582                       bmpCancel,
583                       _MGSTR( _S_TIP_DELETETASK ) );
584 
585     toolbar->AddSeparator();
586 
587     toolbar->AddTool( mgID_MOVEUP_TASK,
588                       _MGSTR( _S_MENU_TASK_MOVEUP ),
589                       bmpMoveup,
590                       _MGSTR( _S_TIP_MOVEUPTASK ) );
591 
592     toolbar->AddTool( mgID_MOVEDOWN_TASK,
593                       _MGSTR( _S_MENU_TASK_MOVEDOWN ),
594                       bmpMovedown,
595                       _MGSTR( _S_TIP_MOVEDOWNTASK ) );
596 
597     toolbar->AddSeparator();
598 
599     toolbar->AddTool( mgID_ADDTHREAD,
600                       _MGSTR( _S_MENU_TASK_ADDTHREAD ),
601                       bmpAddAnts,
602                       _MGSTR( _S_TIP_ADDTASKTHREAD ) );
603 
604     toolbar->AddTool( mgID_SUBTHREAD,
605                       _MGSTR( _S_MENU_TASK_SUBTHREAD ),
606                       bmpSubAnts,
607                       _MGSTR( _S_TIP_SUBTASKTHREAD ) );
608 
609     toolbar->AddSeparator();
610 
611     toolbar->AddTool( mgID_RELOAD,
612                       _MGSTR( _S_MENU_TASK_RELOAD ),
613                       bmpReload,
614                       _MGSTR( _S_TIP_RELOADTASK ) );
615 
616     toolbar->AddSeparator();
617 
618     toolbar->AddTool( mgID_OPTION_CONFIG,
619                       _MGSTR( _S_MENU_OPTION_CONFIG ),
620                       bmpOption,
621                       _MGSTR( _S_TIP_SYSCONFIG ) );
622 
623     toolbar->AddTool( mgID_OPTION_PROXY,
624                       _MGSTR( _S_MENU_OPTION_PROXYCONFIG ),
625                       bmpProxy,
626                       _MGSTR( _S_TIP_PROXYADMIN ) );
627 
628     toolbar->AddSeparator();
629 
630     toolbar->AddTool( mgID_OPTION_PROPERTY,
631                       _MGSTR( _S_MENU_OPTION_PROPERTY ),
632                       bmpProperty,
633                       _MGSTR( _S_TIP_PROPERTY ) );
634 
635     toolbar->Realize();
636 
637     SetToolBar( toolbar );
638 }
639 
InitSpliter()640 void MainFrame::InitSpliter()
641 {
642 
643     m_vspliter = new wxSplitterWindow(
644                      this,
645                      wxID_ANY,
646                      wxDefaultPosition,
647                      wxDefaultSize,
648 #ifdef WIN32
649 					wxNO_BORDER,
650 #else
651 					wxSP_LIVE_UPDATE | wxSP_BORDER,
652 #endif
653                     wxT( "ms" )
654                  );
655     assert( m_vspliter != NULL );
656     m_vspliter->SetMinimumPaneSize( 150 );
657 
658     m_hspliter = new wxSplitterWindow(
659                      m_vspliter,
660                      wxID_ANY,
661                      wxDefaultPosition,
662                      wxDefaultSize,
663 #ifdef WIN32
664 					wxNO_BORDER,
665 #else
666                      wxSP_LIVE_UPDATE | wxSP_BORDER /*|wxSP_PERMIT_UNSPLIT*/,
667 #endif
668                      wxT( "rs" )
669                  );
670 
671 
672     assert( m_hspliter != NULL );
673     m_hspliter->SetMinimumPaneSize( 100 );
674     m_vsubspliter = new CRightDownSplitter( m_hspliter );
675 
676 
677     assert( m_vsubspliter != NULL );
678     m_lefttree = new CLeftTree( m_vspliter );
679 
680 
681     assert( m_lefttree != NULL );
682     m_tasklist = new CTaskList( m_hspliter );
683 
684 
685     assert( m_tasklist != NULL );
686 
687     m_hspliter->SetSashGravity( 0.5 );
688     m_vspliter->SetSashGravity( 0.1 );
689 
690 
691     m_vspliter->SplitVertically( m_lefttree, m_hspliter, 150 );
692     m_hspliter->SplitHorizontally( m_tasklist, m_vsubspliter, 200 );
693 }
694 
OnNewTask(wxCommandEvent & event)695 void MainFrame::OnNewTask( wxCommandEvent& event )
696 {
697     DoNewTask( wxT( "" ) );
698 }
699 
OnStartTask(wxCommandEvent & event)700 void MainFrame::OnStartTask( wxCommandEvent& event )
701 {
702 
703     vector<_TaskAttr>::iterator it;
704 
705     for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
706     {
707 
708         if ( it->nID == m_nCurrentSelectTaskID )
709         {
710             it->nStatus = _STATUS_WAITING;
711             ScheduleTask();
712             UpdateToolBar();
713             UpdateTaskList();
714             break ;
715         }
716     }
717 
718 }
719 
OnDecreaseThread(wxCommandEvent & event)720 void MainFrame::OnDecreaseThread( wxCommandEvent& event )
721 {
722     if ( m_nCurrentSelectTaskID < 0 )
723         return ;
724 
725     _TaskAttr* pcur = GetCurrentTask();
726 
727     if ( pcur == NULL )
728         return ;
729 
730     if ( pcur->nStatus == _STATUS_RUNNING )
731     {
732         if ( m_TaskManager->GetTaskStatus( m_nCurrentSelectTaskID ) != _TASK_NONE )
733         {
734             if ( m_TaskManager->ThreadDown( m_nCurrentSelectTaskID ) )
735             {
736                 if ( pcur->nThread > 1 )
737                 {
738                     pcur->nThread--;
739                     UpdateTaskList();
740                     UpdateRightDown();
741                 }
742             }
743         }
744     }
745     else if (
746         pcur->nStatus == _STATUS_WAITING ||
747         pcur->nStatus == _STATUS_WRONG ||
748         pcur->nStatus == _STATUS_PAUSE )
749     {
750         if ( pcur->nThread > 1 )
751         {
752             pcur->nThread--;
753             UpdateTaskList();
754             UpdateRightDown();
755         }
756     }
757     else if ( pcur->nStatus == _STATUS_DELETE )
758     {
759         if ( pcur->nThread > 1 )
760         {
761             pcur->nThread--;
762             UpdateTaskList();
763             UpdateRightDown();
764         }
765     }
766     else //finish or delete
767         return ;
768 }
769 
OnIncreaseThread(wxCommandEvent & event)770 void MainFrame::OnIncreaseThread( wxCommandEvent& event )
771 {
772 
773     _TaskAttr* pcur = GetCurrentTask();
774 
775     if ( pcur == NULL )
776         return ;
777 
778     if ( pcur->nStatus == _STATUS_RUNNING )
779     {
780         if ( m_TaskManager->GetTaskStatus( m_nCurrentSelectTaskID ) != _TASK_NONE )
781         {
782             if ( m_TaskManager->ThreadUp( m_nCurrentSelectTaskID ) )
783             {
784                 if ( pcur->nThread < 10 )
785                 {
786 					pthread_mutex_lock( &m_TaskMutex );
787                     pcur->nThread++;
788 
789                     UpdateTaskList();
790 					pthread_mutex_unlock( &m_TaskMutex );
791 
792                     UpdateRightDown();
793 
794 
795                 }
796             }
797         }
798     }
799     else if (
800         pcur->nStatus == _STATUS_WAITING ||
801         pcur->nStatus == _STATUS_WRONG ||
802         pcur->nStatus == _STATUS_PAUSE )
803     {
804         if ( pcur->nThread < 10 )
805         {
806 			pthread_mutex_lock( &m_TaskMutex );
807             pcur->nThread++;
808             UpdateTaskList();
809 			pthread_mutex_unlock( &m_TaskMutex );
810             UpdateRightDown();
811 
812         }
813     }
814 
815     else if ( pcur->nStatus == _STATUS_DELETE )
816     {
817         if ( pcur->nThread < 10 )
818         {
819 			pthread_mutex_lock( &m_TaskMutex );
820             pcur->nThread++;
821             UpdateTaskList();
822 			pthread_mutex_unlock( &m_TaskMutex );
823             UpdateRightDown();
824 
825         }
826     }
827     else //finish
828     {
829         return ;
830     }
831 }
832 
OnCancelTask(wxCommandEvent & event)833 void MainFrame::OnCancelTask( wxCommandEvent& event )
834 {
835 
836 
837     if ( m_nCurrentSelectTaskID < 0 )
838     {
839         return ;
840     }
841 
842     _TaskAttr* pcur = GetCurrentTask();
843 
844     if ( pcur == NULL )
845     {
846         return ;
847     }
848 
849 
850     if ( pcur->nStatus == _STATUS_DELETE )
851     { //delete all file
852 
853 
854         /* comfirm
855               wxString msg;
856               wxString url( pcur->sURL.c_str(), wxConvLocal );
857               msg = _MGSTR(_S_MAINFRAME_DELETESELECT) + wxT("\n") + url;
858               wxMessageDialog dlg( this, msg, _MGSTR( _S_MAINFRAME_DELETEWARNNING ),
859                                    wxICON_QUESTION | wxYES_NO | wxSTAY_ON_TOP | wxNO_DEFAULT );
860 
861               if ( wxID_NO == dlg.ShowModal() )
862               {
863                   return ;
864               }
865 		*/
866 
867 
868         std::string tempdir;
869 
870         if ( GetTempDir( tempdir ) )
871         {
872             std::string tempfile = tempdir;
873             tempfile += "/";
874             tempfile += pcur->sName;
875             tempfile += ".mg";
876             remove( tempfile.c_str() );
877             tempfile += "idx";
878             remove( tempfile.c_str() );
879         }
880 
881 
882         std::string destfile = pcur->sSavePath;
883         destfile += "/";
884         destfile += pcur->sName;
885         remove( destfile.c_str() );
886 
887         DeleteTaskFromTaskList( m_nCurrentSelectTaskID );
888 
889         m_nCurrentSelectTaskID = -1;
890 
891         UpdateTaskList();
892 
893         UpdateToolBar();
894 
895         UpdateRightDown();
896 
897     }
898     else
899     {
900 
901         StopTask( m_nCurrentSelectTaskID );
902         pcur->nStatus = _STATUS_DELETE;
903         UpdateTaskList();
904         UpdateToolBar();
905         UpdateRightDown();
906     }
907 
908 }
909 
OnConfig(wxCommandEvent & event)910 void MainFrame::OnConfig( wxCommandEvent& event )
911 {
912 
913     CConfigWindow conf( this );
914     m_SysTray->DlgShow( true );
915     int nret = conf.ShowModal();
916     m_SysTray->DlgShow( false );
917 
918     if ( wxID_OK == nret )
919     {
920 
921         gRunTaskNum = conf.m_nTask;
922         gConnectTimeOut = conf.m_nConnectTimeOut;
923         gReceiveTimeOut = conf.m_nTimeOut;
924         gTaskDefThread = conf.m_nThread;
925         gRetryTime = conf.m_nRetry;
926         gRetryWait = conf.m_nRetryWait;
927         gDefSavePath = conf.m_sSavePath.mb_str(); //
928         gDefFtpPass = conf.m_sPass.mb_str(); //
929         gsIgnoreExt = conf.m_sIgnoreExt.mb_str(); //
930         gsMonitorExt = conf.m_sMonitorExt.mb_str(); //
931         gbIgnoreExt = conf.m_bIgnoreExt; //
932         gbMonitorExt = conf.m_bMonitorExt;
933         gSpeedMode = ( _SPEED_MODE ) ( conf.m_SpeedMode );
934         gbSoundTip = conf.m_bSound;
935         gbAutoMd5 = conf.m_bAutoMd5;
936 
937     }
938 
939 }
940 
941 
StopTask(int taskid)942 void MainFrame::StopTask( int taskid )
943 {
944     vector<_TaskAttr>::iterator it;
945 
946     for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
947     {
948 
949         if ( it->nID == taskid )
950         {
951 
952             if ( it->nStatus == _STATUS_WAITING )
953             {
954 
955                 it->nStatus = _STATUS_PAUSE;
956                 return ;
957             }
958             else if ( it->nStatus == _STATUS_RUNNING )
959             {
960 
961                 if ( m_TaskManager->GetTaskStatus( taskid ) != _TASK_NONE )
962                 {
963                     m_TaskManager->CloseUpdateUI( taskid );
964                     m_TaskManager->RemoveTask( taskid );
965 
966                 }
967 
968                 it->nStatus = _STATUS_PAUSE;
969             }
970         }
971     }
972 }
973 
OnStopTask(wxCommandEvent & event)974 void MainFrame::OnStopTask( wxCommandEvent& event )
975 {
976     StopTask( m_nCurrentSelectTaskID );
977     ScheduleTask();
978     UpdateRightDown();
979     UpdateToolBar();
980 }
981 
DeleteTaskFromTaskList(int taskid)982 void MainFrame::DeleteTaskFromTaskList( int taskid )
983 {
984     vector<_TaskAttr>::iterator it;
985     pthread_mutex_lock( &m_TaskMutex );
986 
987     for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
988     {
989         if ( it->nID == taskid )
990         {
991 
992             m_AllTaskList.erase( it );
993 
994             break;
995         }
996     }
997 
998     pthread_mutex_unlock( &m_TaskMutex );
999 }
1000 
1001 
UpdateToolBar()1002 void MainFrame::UpdateToolBar()
1003 {
1004     wxToolBar * toolbar = GetToolBar();
1005 
1006     if ( toolbar == NULL )
1007         return ;
1008 
1009     wxMenuBar* menubar = GetMenuBar();
1010 
1011     if ( menubar == NULL )
1012         return ;
1013 
1014     if ( m_nCurrentSelectTaskID < 0 )
1015     {
1016 
1017         toolbar->EnableTool( mgID_NEW_TASK, true );
1018         toolbar->EnableTool( mgID_START_TASK, false );
1019         toolbar->EnableTool( mgID_STOP_TASK, false );
1020         toolbar->EnableTool( mgID_CANCEL_TASK, false );
1021         toolbar->EnableTool( mgID_MOVEUP_TASK, false );
1022         toolbar->EnableTool( mgID_MOVEDOWN_TASK, false );
1023         toolbar->EnableTool( mgID_SUBTHREAD, false );
1024         toolbar->EnableTool( mgID_ADDTHREAD, false );
1025         toolbar->EnableTool( mgID_RELOAD, false );
1026         toolbar->EnableTool( mgID_OPTION_PROPERTY, false );
1027 
1028         menubar->Enable( mgID_NEW_TASK, true );
1029         menubar->Enable( mgID_START_TASK, false );
1030         menubar->Enable( mgID_STOP_TASK, false );
1031         menubar->Enable( mgID_CANCEL_TASK, false );
1032         menubar->Enable( mgID_MOVEUP_TASK, false );
1033         menubar->Enable( mgID_MOVEDOWN_TASK, false );
1034         menubar->Enable( mgID_SUBTHREAD, false );
1035         menubar->Enable( mgID_ADDTHREAD, false );
1036         menubar->Enable( mgID_RELOAD, false );
1037 
1038     }
1039     else
1040     {
1041 
1042         vector<_TaskAttr>::iterator it;
1043 
1044         for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
1045         {
1046             if ( it->nID == m_nCurrentSelectTaskID )
1047             {
1048 
1049                 switch ( it->nStatus )
1050                 {
1051 
1052                     case _STATUS_RUNNING:
1053 
1054                     case _STATUS_WAITING:
1055                     toolbar->EnableTool( mgID_NEW_TASK, true );
1056                     toolbar->EnableTool( mgID_START_TASK, false );
1057                     toolbar->EnableTool( mgID_STOP_TASK, true );
1058                     toolbar->EnableTool( mgID_CANCEL_TASK, true );
1059                     toolbar->EnableTool( mgID_SUBTHREAD, true );
1060                     toolbar->EnableTool( mgID_ADDTHREAD, true );
1061                     toolbar->EnableTool( mgID_RELOAD, false );
1062 
1063                     menubar->Enable( mgID_NEW_TASK, true );
1064                     menubar->Enable( mgID_START_TASK, false );
1065                     menubar->Enable( mgID_STOP_TASK, true );
1066                     menubar->Enable( mgID_CANCEL_TASK, true );
1067                     menubar->Enable( mgID_SUBTHREAD, true );
1068                     menubar->Enable( mgID_ADDTHREAD, true );
1069                     menubar->Enable( mgID_RELOAD, false );
1070 
1071                     bool canup, candown;
1072                     m_tasklist->IsTaskCanMove( m_nCurrentSelectTaskID, canup, candown );
1073                     toolbar->EnableTool( mgID_MOVEUP_TASK, canup );
1074                     toolbar->EnableTool( mgID_MOVEDOWN_TASK, candown );
1075 
1076                     menubar->Enable( mgID_MOVEUP_TASK, canup );
1077                     menubar->Enable( mgID_MOVEDOWN_TASK, candown );
1078                     toolbar->EnableTool( mgID_OPTION_PROPERTY, true );
1079                     break;
1080 
1081                     case _STATUS_PAUSE:
1082 
1083                     case _STATUS_WRONG:
1084                     toolbar->EnableTool( mgID_NEW_TASK, true );
1085                     toolbar->EnableTool( mgID_START_TASK, true );
1086                     toolbar->EnableTool( mgID_STOP_TASK, false );
1087                     toolbar->EnableTool( mgID_CANCEL_TASK, true );
1088                     toolbar->EnableTool( mgID_SUBTHREAD, true );
1089                     toolbar->EnableTool( mgID_ADDTHREAD, true );
1090                     toolbar->EnableTool( mgID_MOVEUP_TASK, false );
1091                     toolbar->EnableTool( mgID_MOVEDOWN_TASK, false );
1092                     toolbar->EnableTool( mgID_RELOAD, true );
1093                     toolbar->EnableTool( mgID_OPTION_PROPERTY, true );
1094 
1095                     menubar->Enable( mgID_NEW_TASK, true );
1096                     menubar->Enable( mgID_START_TASK, true );
1097                     menubar->Enable( mgID_STOP_TASK, false );
1098                     menubar->Enable( mgID_CANCEL_TASK, true );
1099                     menubar->Enable( mgID_SUBTHREAD, true );
1100                     menubar->Enable( mgID_ADDTHREAD, true );
1101                     menubar->Enable( mgID_MOVEUP_TASK, false );
1102                     menubar->Enable( mgID_MOVEDOWN_TASK, false );
1103                     menubar->Enable( mgID_RELOAD, true );
1104 
1105                     break;
1106 
1107                     case _STATUS_FINISH_SOFT:
1108 
1109                     case _STATUS_FINISH_PACK:
1110 
1111                     case _STATUS_FINISH_MUSIC:
1112 
1113                     case _STATUS_FINISH_ISO:
1114 
1115                     case _STATUS_FINISH_MOVIE:
1116 
1117                     case _STATUS_FINISH_PUBLISH:
1118 
1119                     case _STATUS_FINISH_PICTURE:
1120 
1121                     case _STATUS_FINISH_UNKNOW:
1122                     toolbar->EnableTool( mgID_NEW_TASK, true );
1123                     toolbar->EnableTool( mgID_START_TASK, false );
1124                     toolbar->EnableTool( mgID_STOP_TASK, false );
1125                     toolbar->EnableTool( mgID_CANCEL_TASK, true );
1126                     toolbar->EnableTool( mgID_SUBTHREAD, false );
1127                     toolbar->EnableTool( mgID_ADDTHREAD, false );
1128                     toolbar->EnableTool( mgID_MOVEUP_TASK, false );
1129                     toolbar->EnableTool( mgID_MOVEDOWN_TASK, false );
1130                     toolbar->EnableTool( mgID_RELOAD, true );
1131 
1132                     menubar->Enable( mgID_NEW_TASK, true );
1133                     menubar->Enable( mgID_START_TASK, false );
1134                     menubar->Enable( mgID_STOP_TASK, false );
1135                     menubar->Enable( mgID_CANCEL_TASK, true );
1136                     menubar->Enable( mgID_SUBTHREAD, false );
1137                     menubar->Enable( mgID_ADDTHREAD, false );
1138                     menubar->Enable( mgID_MOVEUP_TASK, false );
1139                     menubar->Enable( mgID_MOVEDOWN_TASK, false );
1140                     menubar->Enable( mgID_RELOAD, true );
1141 
1142                     toolbar->EnableTool( mgID_OPTION_PROPERTY, true );
1143                     break;
1144 
1145                     case _STATUS_DELETE:
1146 
1147                     default:
1148                     toolbar->EnableTool( mgID_NEW_TASK, true );
1149                     toolbar->EnableTool( mgID_START_TASK, true );
1150                     toolbar->EnableTool( mgID_STOP_TASK, false );
1151                     toolbar->EnableTool( mgID_CANCEL_TASK, true );
1152                     toolbar->EnableTool( mgID_SUBTHREAD, true );
1153                     toolbar->EnableTool( mgID_ADDTHREAD, true );
1154                     toolbar->EnableTool( mgID_MOVEUP_TASK, false );
1155                     toolbar->EnableTool( mgID_MOVEDOWN_TASK, false );
1156                     toolbar->EnableTool( mgID_RELOAD, false );
1157 
1158                     menubar->Enable( mgID_NEW_TASK, true );
1159                     menubar->Enable( mgID_START_TASK, true );
1160                     menubar->Enable( mgID_STOP_TASK, false );
1161                     menubar->Enable( mgID_CANCEL_TASK, true );
1162                     menubar->Enable( mgID_SUBTHREAD, true );
1163                     menubar->Enable( mgID_ADDTHREAD, true );
1164                     menubar->Enable( mgID_MOVEUP_TASK, false );
1165                     menubar->Enable( mgID_MOVEDOWN_TASK, false );
1166                     menubar->Enable( mgID_RELOAD, false );
1167                     toolbar->EnableTool( mgID_OPTION_PROPERTY, true );
1168 
1169                     break;
1170 
1171                 } //switch
1172 
1173                 break;
1174             } //if
1175         } //for
1176     } //else
1177 
1178 }
1179 
GetNewTaskID()1180 int MainFrame::GetNewTaskID()
1181 {
1182     return ++m_nTaskID;
1183 }
1184 
OnAbout(wxCommandEvent & event)1185 void MainFrame::OnAbout( wxCommandEvent& event )
1186 {
1187     wxString msg;
1188     msg = _MGSTR( _S_INFO_WELCOME );
1189     msg += wxT( "\n\n" );
1190     msg += _MGSTR( _S_COPYRIGHT );
1191     msg += wxT( "\n\n" );
1192     msg += _MGSTR( _S_VERSION );
1193     msg += wxT( "\n\n" );
1194     msg += _MGSTR( _S_ABOUT_BUGREPORT );
1195     msg += wxT( "\n\n" );
1196     msg += _MGSTR( _S_ABOUT_MAINPUBLISH );
1197     msg += wxT( "\n\n" );
1198 	msg += wxT( "----------------------------------------\n");
1199 	msg += _MGSTR( _S_THANKS_CJACKER );
1200     msg += wxT( "\n" );
1201 	msg += _MGSTR( _S_THANKS_GUOHONGTAO );
1202     msg += wxT( "\n" );
1203 	msg += _MGSTR( _S_THANKS_LANGUE );
1204     msg += wxT( "\n" );
1205 	msg += _MGSTR( _S_THANKS_MATTHE );
1206     msg += wxT( "\n" );
1207 	msg += _MGSTR( _S_THANKS_ABEL );
1208     msg += wxT( "\n" );
1209 	msg += _MGSTR( _S_THANKS_ISJFK );
1210     msg += wxT( "\n" );
1211 	msg += _MGSTR( _S_THANKS_BRYAN );
1212     msg += wxT( "\n" );
1213 	msg += _MGSTR( _S_THANKS_MICHAEL_FRASE );
1214     msg += wxT( "\n" );
1215 	msg += wxT( "----------------------------------------\n\n");
1216 
1217 
1218     msg += _MGSTR( _S_ABOUT_ANNOUNCE );
1219 
1220     m_SysTray->DlgShow( true );
1221     ::wxMessageBox( msg, _MGSTR( _S_ABOUT_MULTIGET ),
1222                     wxOK | wxICON_INFORMATION, this );
1223 
1224     m_SysTray->DlgShow( false );
1225 
1226 }
1227 
OnQuit(wxCommandEvent & event)1228 void MainFrame::OnQuit( wxCommandEvent& event )
1229 {
1230 //really quit?
1231 	Hide();
1232     Close();
1233     return ;
1234 
1235 }
1236 
1237 
OnSize(wxSizeEvent & event)1238 void MainFrame::OnSize( wxSizeEvent& event )
1239 {
1240     int w, h;
1241     GetClientSize( &w, &h );
1242 
1243 	if(m_MeterBar)    m_MeterBar->SetSize( 0, 0, w, 30 );
1244     if(m_vspliter)	  m_vspliter->SetSize( 0, 31, w, h - 30 );
1245 
1246 //    m_nWinSizeW = w;
1247 //    m_nWinSizeH = h;
1248 }
1249 
1250 
OnSelectType(_TASK_TYPE type)1251 void MainFrame::OnSelectType( _TASK_TYPE type )
1252 {
1253     switch ( type )
1254     {
1255 
1256         case _STATUS_ROOT:
1257         m_nCurrentShowType = ( _STATUS_ROOT );
1258         break;
1259 
1260         case _STATUS_RUNNING:
1261         m_nCurrentShowType = ( _STATUS_RUNNING );
1262         break;
1263 
1264         case _STATUS_PAUSE:
1265         m_nCurrentShowType = ( _STATUS_PAUSE );
1266         break;
1267 
1268         case _STATUS_WRONG:
1269         m_nCurrentShowType = ( _STATUS_WRONG );
1270         break;
1271 
1272         case _STATUS_FINISH:
1273         m_nCurrentShowType = ( _STATUS_FINISH );
1274         break;
1275 
1276         case _STATUS_FINISH_SOFT:
1277         m_nCurrentShowType = ( _STATUS_FINISH_SOFT );
1278         break;
1279 
1280         case _STATUS_FINISH_PACK:
1281         m_nCurrentShowType = ( _STATUS_FINISH_PACK );
1282         break;
1283 
1284         case _STATUS_FINISH_MUSIC:
1285         m_nCurrentShowType = ( _STATUS_FINISH_MUSIC );
1286         break;
1287 
1288         case _STATUS_FINISH_ISO:
1289         m_nCurrentShowType = ( _STATUS_FINISH_ISO );
1290         break;
1291 
1292         case _STATUS_FINISH_MOVIE:
1293         m_nCurrentShowType = ( _STATUS_FINISH_MOVIE );
1294         break;
1295 
1296         case _STATUS_FINISH_PUBLISH:
1297         m_nCurrentShowType = ( _STATUS_FINISH_PUBLISH );
1298         break;
1299 
1300         case _STATUS_FINISH_PICTURE:
1301         m_nCurrentShowType = ( _STATUS_FINISH_PICTURE );
1302         break;
1303 
1304         case _STATUS_FINISH_UNKNOW:
1305         m_nCurrentShowType = ( _STATUS_FINISH_UNKNOW );
1306         break;
1307 
1308         case _STATUS_DELETE:
1309         m_nCurrentShowType = ( _STATUS_DELETE );
1310         break;
1311 
1312         default:
1313         m_nCurrentShowType = ( _STATUS_ROOT );
1314         break;
1315     }
1316 
1317     UpdateTaskList();
1318 }
1319 
1320 
OnSelectTask(int taskid)1321 void MainFrame::OnSelectTask( int taskid )
1322 {
1323 
1324     m_TaskManager->CloseUpdateUI( m_nCurrentSelectTaskID );
1325     m_nCurrentSelectTaskID = taskid;
1326 
1327     UpdateRightDown();
1328     UpdateToolBar();
1329 
1330 
1331     _TaskAttr *task = GetCurrentTask();
1332 
1333     if ( task != NULL && task->nStatus == _STATUS_RUNNING )
1334     {
1335         m_TaskManager->UpdateRunningTable( task->nID, m_vsubspliter->GetShowTableWin() );
1336     }
1337 
1338     return ;
1339 }
1340 
1341 
UpdateRightDown()1342 void MainFrame::UpdateRightDown()
1343 {
1344     m_vsubspliter->ShowTask( GetCurrentTask() );
1345 }
1346 
1347 
UpdateTaskList()1348 void MainFrame::UpdateTaskList()
1349 {
1350 
1351     m_tasklist->DeleteAllItems();
1352 
1353     if ( m_nCurrentShowType == _STATUS_ROOT )
1354     {
1355         return ;
1356     }
1357 
1358 
1359     vector<_TaskAttr>::iterator it;
1360 
1361     for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
1362     {
1363         if ( m_nCurrentShowType == _STATUS_FINISH )
1364         {
1365 
1366             if (
1367                 it->nStatus == _STATUS_FINISH_SOFT ||
1368                 it->nStatus == _STATUS_FINISH_PACK ||
1369                 it->nStatus == _STATUS_FINISH_MUSIC ||
1370                 it->nStatus == _STATUS_FINISH_ISO	||
1371                 it->nStatus == _STATUS_FINISH_MOVIE ||
1372                 it->nStatus == _STATUS_FINISH_PUBLISH ||
1373                 it->nStatus == _STATUS_FINISH_PICTURE ||
1374                 it->nStatus == _STATUS_FINISH_UNKNOW
1375             )
1376             {
1377                 m_tasklist->AddTaskList( *it );
1378             }
1379 
1380         }
1381         else if ( m_nCurrentShowType == _STATUS_RUNNING )
1382         {
1383 
1384             if ( it->nStatus == _STATUS_RUNNING || it->nStatus == _STATUS_WAITING )
1385             {
1386                 m_tasklist->AddTaskList( *it );
1387             }
1388 
1389         }
1390         else
1391         {
1392             if ( it->nStatus == m_nCurrentShowType )
1393             {
1394                 m_tasklist->AddTaskList( *it );
1395             }
1396         }
1397     }
1398 
1399 
1400     int stask = m_tasklist->SelectTask( m_nCurrentSelectTaskID );
1401 
1402     if ( stask != m_nCurrentSelectTaskID )
1403     {
1404         m_nCurrentSelectTaskID = stask;
1405         UpdateRightDown();
1406     }
1407 }
1408 
1409 
ScheduleTask()1410 void MainFrame::ScheduleTask()
1411 {
1412     vector<_TaskAttr>::iterator it;
1413 
1414 
1415     for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
1416     {
1417         if ( it->nStatus == _STATUS_WAITING )
1418         {
1419 
1420 
1421             if ( _TASK_NONE == m_TaskManager->GetTaskStatus( it->nID ) &&
1422                     m_TaskManager->GetTaskNumber() < gRunTaskNum )
1423 
1424             {
1425 
1426                 it->nStatus = _STATUS_RUNNING;
1427                 m_TaskManager->AddTask( *it );
1428             }
1429         }
1430     }
1431 
1432 
1433     UpdateTaskList();
1434 
1435     UpdateStatusBar();
1436 
1437 }
1438 
GetCurrentTask()1439 _TaskAttr* MainFrame::GetCurrentTask()
1440 {
1441     return GetTask( m_nCurrentSelectTaskID );
1442 }
1443 
GetTask(int taskid)1444 _TaskAttr* MainFrame::GetTask( int taskid )
1445 {
1446     if ( taskid < 0 )
1447         return NULL;
1448 
1449     for ( int i = 0;i < int( m_AllTaskList.size() );i++ )
1450     {
1451         if ( m_AllTaskList[ i ].nID == taskid )
1452             return & m_AllTaskList[ i ];
1453     }
1454 
1455     return NULL;
1456 }
1457 
1458 
AddNewTask(string url,int threadnum,bool autorun)1459 int MainFrame::AddNewTask( string url, int threadnum, bool autorun )
1460 {
1461 
1462     if ( IsUrlExist( url ) )
1463     {
1464         m_SysTray->DlgShow( true );
1465         //wxMessageBox( "url exists" );
1466 		wxMessageBox(wxString::FromAscii("url exists")); //unicode patch
1467         m_SysTray->DlgShow( false );
1468 		return 0;
1469     }
1470 
1471 
1472     _TaskAttr atask;
1473     atask.nID = GetNewTaskID();
1474     atask.nThread = ( ( threadnum <= 0 || threadnum > 10 ) ? gTaskDefThread : threadnum );
1475 
1476     if ( !autorun )
1477     {
1478         atask.nStatus = _STATUS_PAUSE;
1479     }
1480     else
1481     {
1482         atask.nStatus = _STATUS_WAITING;
1483     }
1484 
1485     atask.sName = GetTempFileName( url );
1486     atask.sURL = url;
1487     pthread_mutex_lock( &m_TaskMutex );
1488     m_AllTaskList.push_back( atask );
1489     pthread_mutex_unlock( &m_TaskMutex );
1490 
1491     ScheduleTask();
1492     return atask.nID;
1493 }
1494 
GetTempFileName(string url)1495 string MainFrame::GetTempFileName( string url )
1496 {
1497     //no path file name
1498     char fn[ 512 ];
1499     strcpy( fn, url.c_str() );
1500     int i = strlen( fn );
1501 
1502     while ( fn[ i ] != '/' && i > 0 )
1503         i--;
1504 
1505     return string( fn + i + 1 );
1506 
1507 }
1508 
1509 
UpdateTaskList(int ntask)1510 void MainFrame::UpdateTaskList( int ntask )
1511 {
1512     vector<_TaskAttr>::iterator it;
1513 
1514     for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
1515     {
1516         if ( it->nID == ntask )
1517         {
1518             m_tasklist->UpdateTaskList( *it );
1519             break;
1520         }
1521     }
1522 
1523 }
1524 
1525 //should change to static
InitFileTypeList()1526 void MainFrame::InitFileTypeList()
1527 {
1528     //soft
1529     //.exe;.bin;.bat;.com;.dll;.so;.scr;.ttf;.ap;.app;.drv;
1530     m_FileTypeList[ 0 ].push_back( string( ".exe" ) );
1531     m_FileTypeList[ 0 ].push_back( string( ".bin" ) );
1532     m_FileTypeList[ 0 ].push_back( string( ".bat" ) );
1533     m_FileTypeList[ 0 ].push_back( string( ".com" ) );
1534     m_FileTypeList[ 0 ].push_back( string( ".dll" ) );
1535     m_FileTypeList[ 0 ].push_back( string( ".so" ) );
1536     m_FileTypeList[ 0 ].push_back( string( ".scr" ) );
1537     m_FileTypeList[ 0 ].push_back( string( ".ttf" ) );
1538     m_FileTypeList[ 0 ].push_back( string( ".ap" ) );
1539     m_FileTypeList[ 0 ].push_back( string( ".app" ) );
1540     m_FileTypeList[ 0 ].push_back( string( ".drv" ) );
1541 
1542     m_FileTypeList[ 0 ].resize( m_FileTypeList[ 0 ].size() );
1543     //pack
1544     //.gz;.tar;.zip;.rar;.bz2;.cab;.arj;.ace;.arc;.jar;.tgz;.lzh;
1545     m_FileTypeList[ 1 ].push_back( string( ".gz" ) );
1546     m_FileTypeList[ 1 ].push_back( string( ".tar" ) );
1547     m_FileTypeList[ 1 ].push_back( string( ".zip" ) );
1548     m_FileTypeList[ 1 ].push_back( string( ".rar" ) );
1549     m_FileTypeList[ 1 ].push_back( string( ".bz2" ) );
1550     m_FileTypeList[ 1 ].push_back( string( ".cab" ) );
1551     m_FileTypeList[ 1 ].push_back( string( ".arj" ) );
1552     m_FileTypeList[ 1 ].push_back( string( ".ace" ) );
1553     m_FileTypeList[ 1 ].push_back( string( ".arc" ) );
1554     m_FileTypeList[ 1 ].push_back( string( ".jar" ) );
1555     m_FileTypeList[ 1 ].push_back( string( ".tgz" ) );
1556     m_FileTypeList[ 1 ].push_back( string( ".lzh" ) );
1557     m_FileTypeList[ 1 ].push_back( string( ".7z" ) );
1558     m_FileTypeList[ 1 ].push_back( string( ".rpm" ) );
1559     m_FileTypeList[ 1 ].push_back( string( ".deb" ) );
1560     m_FileTypeList[ 1 ].resize( m_FileTypeList[ 1 ].size() );
1561     //MUSIC
1562     //.wav;.mp3;.wma;.ogg;.mid;.aif;.ra;.ram;.snd;.aiff;.aif;.svx;.voc;
1563     m_FileTypeList[ 2 ].push_back( string( ".wav" ) );
1564     m_FileTypeList[ 2 ].push_back( string( ".mp3" ) );
1565     m_FileTypeList[ 2 ].push_back( string( ".wma" ) );
1566     m_FileTypeList[ 2 ].push_back( string( ".ogg" ) );
1567     m_FileTypeList[ 2 ].push_back( string( ".mid" ) );
1568     m_FileTypeList[ 2 ].push_back( string( ".aif" ) );
1569     m_FileTypeList[ 2 ].push_back( string( ".ra" ) );
1570     m_FileTypeList[ 2 ].push_back( string( ".ram" ) );
1571     m_FileTypeList[ 2 ].push_back( string( ".snd" ) );
1572     m_FileTypeList[ 2 ].push_back( string( ".aiff" ) );
1573     m_FileTypeList[ 2 ].push_back( string( ".aif" ) );
1574     m_FileTypeList[ 2 ].push_back( string( ".svx" ) );
1575     m_FileTypeList[ 2 ].push_back( string( ".voc" ) );
1576 
1577     m_FileTypeList[ 2 ].resize( m_FileTypeList[ 2 ].size() );
1578     //ISO
1579     m_FileTypeList[ 3 ].push_back( string( ".iso" ) );
1580     m_FileTypeList[ 3 ].push_back( string( ".img" ) );
1581     m_FileTypeList[ 3 ].push_back( string( ".nrg" ) );
1582     m_FileTypeList[ 3 ].push_back( string( ".cue" ) );
1583 
1584     m_FileTypeList[ 3 ].resize( m_FileTypeList[ 3 ].size() );
1585     //MOVIE
1586     //.rm;.rmvb;.avi;.mov;.mpg;.asf;.wmv;.vod;.mpeg;.qt;.swf;
1587     m_FileTypeList[ 4 ].push_back( string( ".rm" ) );
1588     m_FileTypeList[ 4 ].push_back( string( ".rmvb" ) );
1589     m_FileTypeList[ 4 ].push_back( string( ".avi" ) );
1590     m_FileTypeList[ 4 ].push_back( string( ".mov" ) );
1591     m_FileTypeList[ 4 ].push_back( string( ".mpg" ) );
1592     m_FileTypeList[ 4 ].push_back( string( ".asf" ) );
1593     m_FileTypeList[ 4 ].push_back( string( ".wmv" ) );
1594     m_FileTypeList[ 4 ].push_back( string( ".vod" ) );
1595     m_FileTypeList[ 4 ].push_back( string( ".mpeg" ) );
1596     m_FileTypeList[ 4 ].push_back( string( ".qt" ) );
1597     m_FileTypeList[ 4 ].push_back( string( ".swf" ) );
1598 
1599     m_FileTypeList[ 4 ].resize( m_FileTypeList[ 4 ].size() );
1600     //PUBLISH
1601     //.pdf;.ps;.chm;.doc;.xls;.txt;.cad;.cpp;.c;.cxx;.h;.hxx;.dwg;.hlp;.rtf;.htm;
1602     m_FileTypeList[ 5 ].push_back( string( ".pdf" ) );
1603     m_FileTypeList[ 5 ].push_back( string( ".ps" ) );
1604     m_FileTypeList[ 5 ].push_back( string( ".chm" ) );
1605     m_FileTypeList[ 5 ].push_back( string( ".doc" ) );
1606     m_FileTypeList[ 5 ].push_back( string( ".xls" ) );
1607     m_FileTypeList[ 5 ].push_back( string( ".txt" ) );
1608     m_FileTypeList[ 5 ].push_back( string( ".cad" ) );
1609     m_FileTypeList[ 5 ].push_back( string( ".cpp" ) );
1610     m_FileTypeList[ 5 ].push_back( string( ".c" ) );
1611     m_FileTypeList[ 5 ].push_back( string( ".cxx" ) );
1612     m_FileTypeList[ 5 ].push_back( string( ".h" ) );
1613     m_FileTypeList[ 5 ].push_back( string( ".hxx" ) );
1614     m_FileTypeList[ 5 ].push_back( string( ".dwg" ) );
1615     m_FileTypeList[ 5 ].push_back( string( ".hlp" ) );
1616     m_FileTypeList[ 5 ].push_back( string( ".rtf" ) );
1617     m_FileTypeList[ 5 ].push_back( string( ".htm" ) );
1618 
1619     m_FileTypeList[ 5 ].resize( m_FileTypeList[ 5 ].size() );
1620     //PICTURE
1621     //.jpg;.jpeg;.png;.gif;.bmp;.xcf;.pix;.fli;.flc;.gcm;.g3;.xjt;.jpe;.ico;
1622     //.wmf;.psd;.psp;.tga;.tif;.tiff;.xpm;.xbm;.icon;.pcx;
1623     m_FileTypeList[ 6 ].push_back( string( ".jpg" ) );
1624     m_FileTypeList[ 6 ].push_back( string( ".jpeg" ) );
1625     m_FileTypeList[ 6 ].push_back( string( ".png" ) );
1626     m_FileTypeList[ 6 ].push_back( string( ".gif" ) );
1627     m_FileTypeList[ 6 ].push_back( string( ".bmp" ) );
1628     m_FileTypeList[ 6 ].push_back( string( ".xcf" ) );
1629     m_FileTypeList[ 6 ].push_back( string( ".pix" ) );
1630     m_FileTypeList[ 6 ].push_back( string( ".fli" ) );
1631     m_FileTypeList[ 6 ].push_back( string( ".flc" ) );
1632     m_FileTypeList[ 6 ].push_back( string( ".gcm" ) );
1633     m_FileTypeList[ 6 ].push_back( string( ".g3" ) );
1634     m_FileTypeList[ 6 ].push_back( string( ".xjt" ) );
1635     m_FileTypeList[ 6 ].push_back( string( ".jpe" ) );
1636     m_FileTypeList[ 6 ].push_back( string( ".ico" ) );
1637     m_FileTypeList[ 6 ].push_back( string( ".wmf" ) );
1638     m_FileTypeList[ 6 ].push_back( string( ".psd" ) );
1639     m_FileTypeList[ 6 ].push_back( string( ".psp" ) );
1640     m_FileTypeList[ 6 ].push_back( string( ".tga" ) );
1641     m_FileTypeList[ 6 ].push_back( string( ".tif" ) );
1642     m_FileTypeList[ 6 ].push_back( string( ".tiff" ) );
1643     m_FileTypeList[ 6 ].push_back( string( ".xpm" ) );
1644     m_FileTypeList[ 6 ].push_back( string( ".xbm" ) );
1645     m_FileTypeList[ 6 ].push_back( string( ".pcx" ) );
1646     m_FileTypeList[ 6 ].push_back( string( ".icon" ) );
1647 
1648 
1649     m_FileTypeList[ 6 ].resize( m_FileTypeList[ 6 ].size() );
1650 }
1651 
1652 
GetFileType(std::string sname)1653 int MainFrame::GetFileType( std::string sname )
1654 {
1655     for ( int i = 0;i < 7;i++ )
1656     {
1657         vector<string>::iterator it;
1658 
1659         for ( it = m_FileTypeList[ i ].begin();it != m_FileTypeList[ i ].end();it++ )
1660         {
1661             if ( CompareExtName( sname, *it ) )
1662                 return i + 1;
1663         }
1664     }
1665 
1666     return 0;
1667 }
1668 
CompareExtName(string sname,string ext)1669 bool MainFrame::CompareExtName( string sname, string ext )
1670 {
1671     if ( sname.length() == 0 || ext.length() == 0 )
1672         return false;
1673 
1674     if ( sname.length() < ext.length() )
1675         return false;
1676 
1677     string sub = sname.substr( sname.length() - ext.length(), ext.length() );
1678 
1679     return strcasecmp( sub.c_str(), ext.c_str() ) == 0;
1680 
1681 }
1682 
GetStatusByFileType(int type)1683 _TASK_TYPE MainFrame::GetStatusByFileType( int type )
1684 {
1685     switch ( type )
1686     {
1687 
1688         case 0:
1689         return _STATUS_FINISH_UNKNOW;
1690         break;
1691 
1692         case 1:
1693         return _STATUS_FINISH_SOFT;
1694         break;
1695 
1696         case 2:
1697         return _STATUS_FINISH_PACK;
1698         break;
1699 
1700         case 3:
1701         return _STATUS_FINISH_MUSIC;
1702         break;
1703 
1704         case 4:
1705         return _STATUS_FINISH_ISO;
1706         break;
1707 
1708         case 5:
1709         return _STATUS_FINISH_MOVIE;
1710         break;
1711 
1712         case 6:
1713         return _STATUS_FINISH_PUBLISH;
1714         break;
1715 
1716         case 7:
1717         return _STATUS_FINISH_PICTURE;
1718         break;
1719 
1720         default:
1721         return _STATUS_FINISH_UNKNOW;
1722 
1723     }
1724 }
1725 
OnTimer(wxTimerEvent & event)1726 void MainFrame::OnTimer( wxTimerEvent& event )
1727 {
1728 
1729     //send a beat so args will recalc
1730     m_TaskManager->HeartBeat();
1731 
1732     int TotalSpeed = 0;
1733 
1734     vector<_TaskAttr>::iterator it;
1735 
1736     for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
1737     {
1738         if ( it->nStatus == _STATUS_RUNNING )
1739         {
1740             if ( m_TaskManager->GetTaskStatus( it->nID ) != _TASK_RUNNING )
1741             {
1742                 continue;
1743             }
1744 
1745             bool bret =
1746                 m_TaskManager->GetRunningArgs( it->nID, it->fRatio, it->nFinish, it->nSpeed, it->nTime );
1747 
1748             if ( !bret )
1749                 continue;
1750 
1751             TotalSpeed += it->nSpeed;
1752 
1753 
1754             it->sName = m_TaskManager->GetTaskFilename( it->nID );
1755 
1756             it->nLen = m_TaskManager->GetTaskSize( it->nID );
1757 
1758             it->nThread = m_TaskManager->GetTaskThreadNum( it->nID );
1759 
1760             it->nError = m_TaskManager->GetErrorTime( it->nID );
1761 
1762             UpdateTaskList( it->nID );
1763 
1764         }
1765     } //for
1766 
1767     if ( GetStatusBar() )
1768     {
1769         wxString sp;
1770         sp.Printf( wxT( "%d KB/S" ) , TotalSpeed / 1024 );
1771         GetStatusBar() ->SetStatusText( _MGSTR( _S_STATUS_TOTALSPEED ) + sp, 3 );
1772     }
1773 
1774     m_MeterBar->PutSpeedData( TotalSpeed );
1775 
1776 }
1777 
OnClose(wxCloseEvent & event)1778 void MainFrame::OnClose( wxCloseEvent& event )
1779 {
1780 
1781     if ( event.CanVeto() )
1782     {
1783 
1784         if ( IsShown() )
1785         { //hide
1786             Hide();
1787             event.Veto();
1788             return ;
1789         }
1790 
1791         if ( m_TaskManager->GetTaskNumber() > 0 )
1792         {
1793             wxMessageDialog * dlg = new wxMessageDialog( this,
1794                                     _MGSTR( _S_INFO_TASKSTILLRUNNING ),
1795                                     _MGSTR( _S_INFO_WARNNING ),
1796                                     wxICON_QUESTION | wxYES_NO | wxSTAY_ON_TOP | wxNO_DEFAULT );
1797 
1798             m_SysTray->DlgShow( true );
1799             int dlgret = dlg->ShowModal();
1800             m_SysTray->DlgShow( false );
1801 
1802             if ( wxID_NO == dlgret )
1803             {
1804                 event.Veto();
1805                 dlg->Destroy();
1806                 return ;
1807             }
1808             else
1809             {
1810                 dlg->Destroy();
1811                 StopAllTask();
1812             }
1813         }
1814 
1815     }
1816     else
1817     { //can't veto
1818         //DBGOUT( "can't veto" );
1819     }
1820 
1821 
1822     SaveTaskDB();
1823     SaveProxyDB();
1824     SaveConfig();
1825 
1826     delete m_SysTray;
1827     m_SysTray = NULL;
1828 
1829     this->Destroy();
1830 }
1831 
OnTaskFinish(wxCommandEvent & event)1832 void MainFrame::OnTaskFinish( wxCommandEvent& event )
1833 {
1834 
1835     int ntask = event.GetId();
1836 
1837 
1838     vector<_TaskAttr>::iterator it;
1839 
1840     for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
1841     {
1842         if ( it->nID == ntask )
1843         {
1844 
1845             int status = m_TaskManager->GetTaskStatus( ntask );
1846 
1847             if ( status == _TASK_FINISH )
1848             {
1849                 int ntype = GetFileType( m_TaskManager->GetTaskFilename( ntask ) );
1850 
1851                 switch ( ntype )
1852                 {
1853 
1854                     case 0:
1855                     it->nStatus = _STATUS_FINISH_UNKNOW;
1856                     break;
1857 
1858                     case 1:
1859                     it->nStatus = _STATUS_FINISH_SOFT;
1860                     break;
1861 
1862                     case 2:
1863                     it->nStatus = _STATUS_FINISH_PACK;
1864                     break;
1865 
1866                     case 3:
1867                     it->nStatus = _STATUS_FINISH_MUSIC;
1868                     break;
1869 
1870                     case 4:
1871                     it->nStatus = _STATUS_FINISH_ISO;
1872                     break;
1873 
1874                     case 5:
1875                     it->nStatus = _STATUS_FINISH_MOVIE;
1876                     break;
1877 
1878                     case 6:
1879                     it->nStatus = _STATUS_FINISH_PUBLISH;
1880                     break;
1881 
1882                     case 7:
1883                     it->nStatus = _STATUS_FINISH_PICTURE;
1884                     break;
1885 
1886                     default:
1887                     it->nStatus = _STATUS_FINISH_UNKNOW;
1888                     break;
1889                 }
1890 
1891 
1892                 it->sName = m_TaskManager->GetTaskFilename( it->nID );
1893 
1894                 it->nLen = m_TaskManager->GetTaskSize( ntask );
1895 
1896                 it->nFinish = it->nLen;
1897 
1898                 it->nSpeed = 0;
1899 
1900                 it->nError = m_TaskManager->GetErrorTime( it->nID );
1901 
1902                 it->fRatio = 1.0f;
1903 
1904 
1905                 m_TaskManager->RemoveTask( ntask );
1906 
1907 
1908                 std::string sRename;
1909 
1910                 if ( !MoveFile( it->sName, it->sSavePath, sRename ) )
1911                 {
1912                     m_SysTray->DlgShow( true );
1913                     wxMessageBox( _MGSTR( _S_INFO_FILEMOVEFAIL ) );
1914                     m_SysTray->DlgShow( false );
1915                 }
1916 
1917                 it->sName = sRename; //
1918 
1919                 ScheduleTask();
1920 
1921 
1922                 if ( ntask == m_nCurrentSelectTaskID )
1923                 {
1924                     UpdateRightDown();
1925                 }
1926 
1927                 PlaySound( true );
1928                 //notice finish
1929                 m_MeterBar->SetTip( wxGetApp().GetStr( _S_INFO_TASKFINISH ) + it->sName );
1930 
1931                 if ( it->bAutoMd5 && gbAutoMd5 )
1932                     FileMd5( *it );
1933 
1934                 break;
1935             }
1936             else if ( status == _TASK_ERROR )
1937             {
1938 
1939                 it->nStatus = _STATUS_WRONG;
1940 
1941                 it->sName = m_TaskManager->GetTaskFilename( it->nID );
1942                 it->nLen = m_TaskManager->GetTaskSize( ntask );
1943 
1944                 int speed;
1945                 it->nFinish = m_TaskManager->GetFinishByte( ntask, speed );
1946 
1947                 it->nSpeed = speed;
1948                 it->nError = m_TaskManager->GetErrorTime( it->nID );
1949 
1950                 if ( it->nLen <= 0 )
1951                     it->fRatio = 0.0f;
1952 
1953                 else
1954                     it->fRatio = ( float( it->nFinish ) / it->nLen );
1955 
1956                 m_TaskManager->RemoveTask( ntask );
1957 
1958                 ScheduleTask();
1959 
1960                 if ( ntask == m_nCurrentSelectTaskID )
1961                 {
1962 
1963                     UpdateRightDown();
1964                 }
1965 
1966                 PlaySound( false );
1967                 //notice
1968                 m_MeterBar->SetTip( wxGetApp().GetStr( _S_INFO_TASKFAIL ) + it->sName );
1969                 break;
1970             }
1971             else
1972             {
1973                 break;
1974             }
1975         }
1976     }
1977 
1978 }
1979 
1980 
OnShowModeSwitch(int mode)1981 void MainFrame::OnShowModeSwitch( int mode )
1982 {
1983 
1984 	_TaskAttr* curtask = GetCurrentTask();
1985 	if( curtask == NULL ) return;
1986 
1987                 if ( m_TaskManager->GetTaskStatus( curtask->nID ) != _TASK_NONE )
1988                 {
1989 
1990                     if ( mode == -2 || mode == -1 || mode > 0 )
1991                     {
1992 
1993                         m_TaskManager->UpdateThreadInfo(
1994                             curtask->nID,
1995                             m_vsubspliter->GetThreadInfoWin(),
1996                             mode );
1997 
1998                     }
1999                     else if ( mode == -3 )
2000                     {
2001                         m_TaskManager->UpdateRunningTable(
2002                             curtask->nID,
2003                             m_vsubspliter->GetShowTableWin() );
2004                     }
2005                     else if ( mode == 0 )
2006                     {
2007                         m_TaskManager->CloseUpdateUI( curtask->nID );
2008                     }
2009                     else
2010                     {
2011                         return ;
2012                     }
2013                 }
2014                 else
2015                 {
2016                     return ;
2017                 }
2018 
2019 /*
2020     vector<_TaskAttr>::iterator it;
2021 
2022     for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
2023     {
2024 
2025         if ( it->nID == m_nCurrentSelectTaskID )
2026         {
2027             if ( it->nStatus == _STATUS_RUNNING )
2028             {
2029 
2030                 if ( m_TaskManager->GetTaskStatus( m_nCurrentSelectTaskID ) != _TASK_NONE )
2031                 {
2032 
2033                     if ( mode == -2 || mode == -1 || mode > 0 )
2034                     {
2035 						DBGOUT("before updatethreadinfo");
2036                         m_TaskManager->UpdateThreadInfo(
2037                             m_nCurrentSelectTaskID,
2038                             m_vsubspliter->GetThreadInfoWin(),
2039                             mode );
2040 						DBGOUT("after updatethreadinfo");
2041                     }
2042                     else if ( mode == -3 )
2043                     {
2044                         m_TaskManager->UpdateRunningTable(
2045                             m_nCurrentSelectTaskID,
2046                             m_vsubspliter->GetShowTableWin() );
2047                     }
2048                     else if ( mode == 0 )
2049                     {
2050                         m_TaskManager->CloseUpdateUI( m_nCurrentSelectTaskID );
2051                     }
2052                     else
2053                     {
2054                         return ;
2055                     }
2056                 }
2057                 else
2058                 {
2059                     return ;
2060                 }
2061             }
2062             else
2063             {
2064                 return ;
2065             }
2066         }
2067     }
2068 */
2069 }
2070 
SaveTaskDB()2071 bool MainFrame::SaveTaskDB()
2072 {
2073     //1.0版数据记录格式
2074     //记录格式采用2进制格式
2075     //文件头+数据+文件尾
2076     //文件头:版本[4]+文件头长度[4]+数据全长[4]+数据项目数[4]
2077     //数据项目:nStatus[4]+nThread[4]+nPriority[4]+sName[v]+nLen[8]+nFinish[8]+
2078     //sURL[v]+sSavePath[v]+sSockProxy[v]+sFtpProxy[v]+sHttpProxy[v]
2079     //文件尾:0xFFFF[4]
2080 
2081     //2.0版数据记录格式
2082     //记录格式采用2进制格式
2083     //文件头+数据+文件尾
2084     //文件头:版本[4]+文件头长度[4]+数据全长[4]+数据项目数[4]
2085     //数据项目:nStatus[4]+nThread[4]+nPriority[4]+sName[v]+nLen[8]+nFinish[8]+
2086     //sURL[v]+sSavePath[v]+sSockProxy[v]+sFtpProxy[v]+sHttpProxy[v]+sMD5[v]
2087     //文件尾:0xFFFF[4]
2088 
2089     //3.0版数据记录格式
2090     //记录格式采用2进制格式
2091     //文件头+数据+文件尾
2092     //文件头:版本[4]+文件头长度[4]+数据全长[4]+数据项目数[4]
2093     //数据项目:nStatus[4]+nThread[4]+nPriority[4]+sName[v]+nLen[8]+nFinish[8]+
2094     //nRetry[4]+nRetryWait[4]+
2095     //sURL[v]+sSavePath[v]+sSockProxy[v]+sFtpProxy[v]+sHttpProxy[v]+sMD5[v]
2096     //文件尾:0xFFFF[4]
2097 
2098     //4.0版数据记录格式
2099     //记录格式采用2进制格式
2100     //文件头+数据+文件尾
2101     //文件头:版本[4]+文件头长度[4]+数据全长[4]+数据项目数[4]
2102     //数据项目:nStatus[4]+nThread[4]+nPriority[4]+sName[v]+nLen[8]+nFinish[8]+
2103     //nRetry[4]+nRetryWait[4]+
2104     //sURL[v]+sSavePath[v]+sSockProxy[v]+sFtpProxy[v]+sHttpProxy[v]+sMD5[v]+nMC[4]+
2105     //sMirrorURL[0][v]+....
2106     //文件尾:0xFFFF[4]
2107 
2108 
2109     //v5.0 data format
2110     //binary record
2111     //filehead+data+filetail
2112     //filehead:ver[4]+headlen[4]+datalen[4]+items[4]
2113     //items:nStatus[4]+nThread[4]+bAutoMd5[4]+sName[v]+nLen[8]+nFinish[8]+
2114     //nRetry[4]+nRetryWait[4]+
2115     //sURL[v]+sRefer[v]+sSavePath[v]+sSockProxy[v]+sFtpProxy[v]+sHttpProxy[v]+sMD5[v]+nMC[4]+
2116     //sMirrorURL[0][v]+....
2117     //filetail:0xFFFF[4]
2118 
2119     FILE * fp;
2120 
2121     std::string tempdb;
2122 
2123     if ( !GetTempDir( tempdb ) )
2124     {
2125         return false;
2126     }
2127 
2128     tempdb += "/task.db";
2129 
2130     fp = fopen( tempdb.c_str(), "wb" );
2131 
2132     if ( fp == NULL )
2133     {
2134         return false;
2135     }
2136 
2137     struct _fh
2138     {
2139         int ver;
2140         int headlen; //4*4=16
2141         int datalen;
2142         int count; //=m_AllTaskList.size()
2143     }fh;
2144 
2145     fh.ver = 5;
2146     fh.headlen = sizeof( fh );
2147     fh.datalen = 0;
2148     fh.count = m_AllTaskList.size();
2149 
2150     if ( 1 != fwrite( &fh, sizeof( fh ), 1, fp ) )
2151     {
2152         fclose( fp );
2153         return false;
2154     }
2155 
2156     int dl = 0;
2157     vector<_TaskAttr>::iterator it;
2158 
2159     for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
2160     {
2161 
2162         fwrite( &( it->nStatus ), sizeof( it->nStatus ), 1, fp );
2163         dl += sizeof( it->nStatus );
2164         fwrite( &( it->nThread ), sizeof( it->nThread ), 1, fp );
2165         dl += sizeof( it->nThread );
2166         fwrite( &( it->bAutoMd5 ), sizeof( it->bAutoMd5 ), 1, fp );
2167         dl += sizeof( it->bAutoMd5 );
2168         fwrite( it->sName.c_str(), it->sName.length() + 1, 1, fp );
2169         dl += it->sName.length() + 1;
2170         fwrite( &( it->nLen ), sizeof( it->nLen ), 1, fp );
2171         dl += sizeof( it->nLen );
2172         fwrite( &( it->nFinish ), sizeof( it->nFinish ), 1, fp );
2173         dl += sizeof( it->nFinish );
2174         fwrite( &( it->nRetry ), sizeof( it->nRetry ), 1, fp );
2175         dl += sizeof( it->nRetry );
2176         fwrite( &( it->nRetryWait ), sizeof( it->nRetryWait ), 1, fp );
2177         dl += sizeof( it->nRetryWait );
2178         fwrite( it->sURL.c_str(), it->sURL.length() + 1, 1, fp );
2179         dl += it->sURL.length() + 1;
2180         fwrite( it->sRefer.c_str(), it->sRefer.length() + 1, 1, fp );
2181         dl += it->sRefer.length() + 1;
2182         fwrite( it->sSavePath.c_str(), it->sSavePath.length() + 1, 1, fp );
2183         dl += it->sSavePath.length() + 1;
2184         fwrite( it->sSockProxy.c_str(), it->sSockProxy.length() + 1, 1, fp );
2185         dl += it->sSockProxy.length() + 1;
2186         fwrite( it->sFtpProxy.c_str(), it->sFtpProxy.length() + 1, 1, fp );
2187         dl += it->sFtpProxy.length() + 1;
2188         fwrite( it->sHttpProxy.c_str(), it->sHttpProxy.length() + 1, 1, fp );
2189         dl += it->sHttpProxy.length() + 1;
2190 
2191 
2192         fwrite( it->sMD5.c_str(), it->sMD5.length() + 1, 1, fp );
2193         dl += it->sMD5.length() + 1;
2194 
2195         //ver 4.0 add it
2196         //mirrorcount;
2197         int msize = it->sMirrorURL.size();
2198         fwrite( &msize, sizeof( int ), 1, fp );
2199         dl += sizeof( int );
2200         //mirrors
2201 
2202         for ( int i = 0;i < msize;i++ )
2203         {
2204             fwrite( it->sMirrorURL[ i ].c_str(), it->sMirrorURL[ i ].length() + 1, 1, fp );
2205             dl += it->sMirrorURL[ i ].length() + 1;
2206         }
2207 
2208     }
2209 
2210     fh.datalen = dl;
2211     int tail = 0x00FF;
2212     fwrite( &tail, sizeof( int ), 1, fp );
2213     fseek( fp, 0, SEEK_SET );
2214     fwrite( &fh, fh.headlen, 1, fp );
2215     fclose( fp );
2216 
2217     return true;
2218 
2219 }
2220 
2221 
ReadTaskDB()2222 bool MainFrame::ReadTaskDB()
2223 {
2224 
2225     m_AllTaskList.clear();
2226     //1.0版数据记录格式
2227     //记录格式采用2进制格式
2228     //文件头+数据+文件尾
2229     //文件头:版本[4]+文件头长度[4]+数据全长[4]+数据项目数[4]
2230     //数据项目:nStatus[4]+nThread[4]+nPriority[4]+sName[v]+nLen[8]+nFinish[8]+
2231     //sURL[v]+sSavePath[v]+sSockProxy[v]+sFtpProxy[v]+sHttpProxy[v]
2232     //文件尾:0xFFFF[4]
2233 
2234     //2.0版数据记录格式
2235     //记录格式采用2进制格式
2236     //文件头+数据+文件尾
2237     //文件头:版本[4]+文件头长度[4]+数据全长[4]+数据项目数[4]
2238     //数据项目:nStatus[4]+nThread[4]+nPriority[4]+sName[v]+nLen[8]+nFinish[8]+
2239     //sURL[v]+sSavePath[v]+sSockProxy[v]+sFtpProxy[v]+sHttpProxy[v]+sMD5[v]
2240     //文件尾:0xFFFF[4]
2241 
2242     //3.0版数据记录格式
2243     //记录格式采用2进制格式
2244     //文件头+数据+文件尾
2245     //文件头:版本[4]+文件头长度[4]+数据全长[4]+数据项目数[4]
2246     //数据项目:nStatus[4]+nThread[4]+nPriority[4]+sName[v]+nLen[8]+nFinish[8]+
2247     //nRetry[4]+nRetryWait[4]+
2248     //sURL[v]+sSavePath[v]+sSockProxy[v]+sFtpProxy[v]+sHttpProxy[v]+sMD5[v]
2249     //文件尾:0xFFFF[4]
2250 
2251     //4.0版数据记录格式
2252     //记录格式采用2进制格式
2253     //文件头+数据+文件尾
2254     //文件头:版本[4]+文件头长度[4]+数据全长[4]+数据项目数[4]
2255     //数据项目:nStatus[4]+nThread[4]+nPriority[4]+sName[v]+nLen[8]+nFinish[8]+
2256     //nRetry[4]+nRetryWait[4]+
2257     //sURL[v]+sSavePath[v]+sSockProxy[v]+sFtpProxy[v]+sHttpProxy[v]+sMD5[v]+nMC[4]+
2258     //sMirrorURL[0][v]+....
2259     //文件尾:0xFFFF[4]
2260 
2261     //v5.0 data format
2262     //binary record
2263     //filehead+data+filetail
2264     //filehead:ver[4]+headlen[4]+datalen[4]+items[4]
2265     //items:nStatus[4]+nThread[4]+bAutoMd5[4]+sName[v]+nLen[8]+nFinish[8]+
2266     //nRetry[4]+nRetryWait[4]+
2267     //sURL[v]+sRefer[v]+sSavePath[v]+sSockProxy[v]+sFtpProxy[v]+sHttpProxy[v]+sMD5[v]+nMC[4]+
2268     //sMirrorURL[0][v]+....
2269     //filetail:0xFFFF[4]
2270 
2271     FILE *fp;
2272 
2273     std::string tempdb;
2274 
2275     if ( !GetTempDir( tempdb ) )
2276     {
2277         return false;
2278     }
2279 
2280     tempdb += "/task.db";
2281 
2282     fp = fopen( tempdb.c_str(), "rb" );
2283 
2284     if ( fp == NULL )
2285     {
2286         return false;
2287     }
2288 
2289     struct _fh
2290     {
2291         int ver;
2292         int headlen; //4*4=16
2293         int datalen;
2294         int count; //=m_AllTaskList.size()
2295     }fh;
2296 
2297     fseek( fp, 0, SEEK_SET );
2298 
2299     if ( 1 != fread( &fh, sizeof( fh ), 1, fp ) )
2300     {
2301         fclose( fp );
2302         return false;
2303     }
2304 
2305     if ( fh.headlen != sizeof( fh ) )
2306     {
2307         fclose( fp );
2308         return false;
2309     }
2310 
2311     if ( fh.ver < 0 || fh.ver > 5 )
2312     {
2313         fclose( fp );
2314         return false;
2315     }
2316 
2317     if ( fh.count == 0 || fh.datalen == 0 )
2318     {
2319         fclose( fp );
2320         return true;
2321     }
2322 
2323 	if ( fh.datalen < 0 )
2324 	{
2325 		fclose( fp );
2326 		return false;
2327 	}
2328 
2329     fseek( fp, fh.headlen, SEEK_SET ); //moveto data
2330     char *buf = new char[ fh.datalen ];
2331 
2332     if ( 1 != fread( buf, fh.datalen, 1, fp ) )
2333     {
2334         delete[] buf;
2335         return false;
2336     }
2337 
2338     fclose( fp );
2339 
2340     _TaskAttr pa;
2341     pa.nSpeed = 0;
2342     pa.nTime = 0;
2343     pa.nError = 0;
2344 
2345 
2346     int movepos = 0;
2347     char strbuf[ 512 ];
2348 
2349     for ( int i = 0;i < fh.count;i++ )
2350     { //read dataitem
2351         pa.sMirrorURL.clear();
2352 
2353         memcpy( &pa.nStatus, buf + movepos, sizeof( pa.nStatus ) );
2354         movepos += sizeof( pa.nStatus );
2355 
2356         memcpy( &pa.nThread, buf + movepos, sizeof( pa.nThread ) );
2357         movepos += sizeof( pa.nThread );
2358 
2359         if ( fh.ver >= 5 )
2360         {
2361             memcpy( &pa.bAutoMd5, buf + movepos, sizeof( pa.bAutoMd5 ) );
2362             movepos += sizeof( pa.bAutoMd5 );
2363         }
2364         else
2365         {
2366             int nouse;
2367             memcpy( &nouse, buf + movepos, sizeof( nouse ) );
2368             movepos += sizeof( nouse );
2369             pa.bAutoMd5 = true;
2370         }
2371 
2372         strcpy( strbuf, buf + movepos );
2373         pa.sName = std::string( strbuf );
2374         movepos += strlen( strbuf ) + 1;
2375         memcpy( &pa.nLen, buf + movepos, sizeof( pa.nLen ) );
2376         movepos += sizeof( pa.nLen );
2377         memcpy( &pa.nFinish, buf + movepos, sizeof( pa.nFinish ) );
2378         movepos += sizeof( pa.nFinish );
2379 
2380         if ( fh.ver >= 3 )
2381         {
2382             memcpy( &pa.nRetry, buf + movepos, sizeof( pa.nRetry ) );
2383             movepos += sizeof( pa.nRetry );
2384             memcpy( &pa.nRetryWait, buf + movepos, sizeof( pa.nRetryWait ) );
2385             movepos += sizeof( pa.nRetryWait );
2386         }
2387         else
2388         {
2389             pa.nRetry = 3;
2390             pa.nRetryWait = 30;
2391         }
2392 
2393         strcpy( strbuf, buf + movepos );
2394         pa.sURL = std::string( strbuf );
2395         movepos += strlen( strbuf ) + 1;
2396 
2397         if ( fh.ver >= 5 )
2398         { //refer
2399             strcpy( strbuf, buf + movepos );
2400             pa.sRefer = std::string( strbuf );
2401             movepos += strlen( strbuf ) + 1;
2402         }
2403         else
2404         {
2405             pa.sRefer.clear();
2406         }
2407 
2408         strcpy( strbuf, buf + movepos );
2409         pa.sSavePath = std::string( strbuf );
2410         movepos += strlen( strbuf ) + 1;
2411         strcpy( strbuf, buf + movepos );
2412         pa.sSockProxy = std::string( strbuf );
2413         movepos += strlen( strbuf ) + 1;
2414         strcpy( strbuf, buf + movepos );
2415         pa.sFtpProxy = std::string( strbuf );
2416         movepos += strlen( strbuf ) + 1;
2417         strcpy( strbuf, buf + movepos );
2418         pa.sHttpProxy = std::string( strbuf );
2419         movepos += strlen( strbuf ) + 1;
2420 
2421         if ( fh.ver >= 2 )
2422         { //md5
2423             strcpy( strbuf, buf + movepos );
2424             pa.sMD5 = std::string( strbuf );
2425 
2426             if ( pa.sMD5.length() != 32 )
2427                 pa.sMD5.clear();
2428 
2429             movepos += strlen( strbuf ) + 1;
2430         }
2431         else
2432         {
2433             pa.sMD5.clear();
2434         }
2435 
2436         if ( fh.ver >= 4 )
2437         { //mirror url
2438             int msize;
2439             memcpy( &msize, buf + movepos, sizeof( int ) );
2440             movepos += sizeof( int );
2441 
2442             for ( int i = 0;i < msize;i++ )
2443             {
2444                 strcpy( strbuf, buf + movepos );
2445                 movepos += strlen( strbuf ) + 1;
2446 
2447                 pa.sMirrorURL.push_back( std::string( strbuf ) );
2448             }
2449         }
2450 
2451         if ( pa.nLen != 0 && pa.nLen != -1 )
2452             pa.fRatio = ( float ) pa.nFinish / pa.nLen;
2453         else
2454             pa.fRatio = 0;
2455 
2456         pa.nID = GetNewTaskID();
2457 
2458         m_AllTaskList.push_back( pa );
2459     }
2460 
2461 
2462     delete[] buf;
2463     return true;
2464 
2465 }
2466 
MoveFile(string mgfile,string destpath,std::string & renamestr)2467 bool MainFrame::MoveFile( string mgfile, string destpath, std::string& renamestr )
2468 {
2469     if ( mgfile.length() <= 3 )
2470         return false;
2471 
2472     std::string tempdir;
2473 
2474     if ( !GetTempDir( tempdir ) )
2475         return false;
2476 
2477     tempdir += "/";
2478 
2479     tempdir += mgfile;
2480 
2481     tempdir += ".mg";
2482 
2483 
2484     string destfile = destpath;
2485 
2486     if ( destfile[ destfile.length() - 1 ] != '/' )
2487         destfile += "/";
2488 
2489     destfile += mgfile;
2490 
2491 
2492     ifstream fcheck;
2493 
2494     fcheck.open( destfile.c_str(), ios::binary | ios::in );
2495 
2496     if ( fcheck.is_open() )
2497     {
2498 
2499         //file exists,make a new filename
2500         fcheck.close();
2501 
2502         int i = 0;
2503 
2504         while ( ++i )
2505         {
2506 
2507 
2508             char buf[ 512 ];
2509             sprintf( buf, "%s[%d]", destfile.c_str(), i );
2510 
2511             fcheck.open( buf, ios::binary | ios::in );
2512 
2513             if ( fcheck.is_open() )
2514             {
2515                 fcheck.close();
2516                 continue;
2517             }
2518             else
2519             {
2520 
2521                 destfile = std::string( buf );
2522                 renamestr = mgfile;
2523                 sprintf( buf, "[%d]", i );
2524                 renamestr += buf;
2525                 fcheck.close();
2526                 break;
2527             }
2528         }
2529     }
2530     else
2531     {
2532 
2533         renamestr = mgfile;
2534     }
2535 
2536 
2537 	return wxRenameFile( wxString(tempdir.c_str(),wxConvLocal), wxString(destfile.c_str(),wxConvLocal) );
2538 
2539 }
2540 
2541 
OnMoveDown(wxCommandEvent & event)2542 void MainFrame::OnMoveDown( wxCommandEvent& event )
2543 {
2544     int downid;
2545     m_tasklist->MoveDown( m_nCurrentSelectTaskID, downid );
2546 
2547     if ( downid < 0 )
2548     {
2549         return ;
2550     }
2551 
2552     _TaskAttr *pcur, *pdown;
2553     pcur = GetTask( m_nCurrentSelectTaskID );
2554     pdown = GetTask( downid );
2555 
2556     if ( pcur == NULL || pdown == NULL )
2557     {
2558         return ;
2559     }
2560 
2561     if ( pcur->nStatus == _STATUS_RUNNING && pdown->nStatus == _STATUS_WAITING )
2562     {
2563         if ( !m_TaskManager->RemoveTask( pcur->nID ) )
2564         {
2565             //DBGOUT( "delete task fail" );
2566         }
2567 
2568         pcur->nStatus = _STATUS_WAITING;
2569         pdown->nStatus = _STATUS_RUNNING;
2570         m_TaskManager->AddTask( *pdown );
2571     }
2572 
2573     SwapTaskTable( pcur->nID, pdown->nID );
2574 
2575     UpdateTaskList();
2576 
2577 }
2578 
2579 
OnMoveUp(wxCommandEvent & event)2580 void MainFrame::OnMoveUp( wxCommandEvent& event )
2581 {
2582     int upid;
2583     m_tasklist->MoveUp( m_nCurrentSelectTaskID, upid );
2584 
2585     if ( upid < 0 )
2586     {
2587         return ;
2588     }
2589 
2590     _TaskAttr	*pcur, *pup;
2591     pcur = GetTask( m_nCurrentSelectTaskID );
2592     pup = GetTask( upid );
2593 
2594     if ( pcur == NULL || pup == NULL )
2595     {
2596         //event.Skip();
2597         //DBGOUT( "pcur==NULL||pup==NULL" );
2598         return ;
2599     }
2600 
2601     if ( pcur->nStatus == _STATUS_WAITING && pup->nStatus == _STATUS_RUNNING )
2602     {
2603         if ( !m_TaskManager->RemoveTask( pup->nID ) )
2604         {
2605             //DBGOUT( "delete task fail" );
2606         }
2607 
2608         pcur->nStatus = _STATUS_RUNNING;
2609         pup->nStatus = _STATUS_WAITING;
2610         m_TaskManager->AddTask( *pcur );
2611     }
2612 
2613     SwapTaskTable( pcur->nID, pup->nID );
2614 
2615     UpdateTaskList();
2616 
2617 }
2618 
SwapTaskTable(int task1,int task2)2619 void MainFrame::SwapTaskTable( int task1, int task2 )
2620 {
2621     _TaskAttr swap;
2622     vector<_TaskAttr>::iterator it1, it2;
2623 
2624     for ( it1 = m_AllTaskList.begin();it1 != m_AllTaskList.end();it1++ )
2625     {
2626         if ( it1->nID == task1 )
2627         {
2628             break;
2629         }
2630     }
2631 
2632     for ( it2 = m_AllTaskList.begin();it2 != m_AllTaskList.end();it2++ )
2633     {
2634         if ( it2->nID == task2 )
2635         {
2636             break;
2637         }
2638     }
2639 
2640     swap = *it1;
2641     *it1 = *it2;
2642     *it2 = swap;
2643 
2644 }
2645 
OnDropURL(wxString url)2646 void MainFrame::OnDropURL( wxString url )
2647 {
2648 
2649     CUrlParser upar;
2650 
2651     if ( !upar.SetUrl( string( url.mb_str( wxConvLocal ) ) ) )  //?????
2652     {
2653         m_SysTray->DlgShow( true );
2654         wxMessageBox( _MGSTR( _S_INFO_NOTSUPPORTURL ) );
2655         m_SysTray->DlgShow( false );
2656         return ;
2657     }
2658 
2659     if ( IsUrlExist( std::string( url.mb_str( wxConvLocal ) ) ) )
2660     {
2661         m_SysTray->DlgShow( true );
2662         //wxMessageBox( "url exists" );  //maybe add some more code
2663 		wxMessageBox(wxString::FromAscii("url exists")); //unicode patch
2664         m_SysTray->DlgShow( false );
2665         return ;
2666     }
2667 
2668 
2669     DoNewTask( url );
2670 }
2671 
InitMeterBar()2672 void MainFrame::InitMeterBar()
2673 {
2674     m_MeterBar = new CMeterCtrl( this );
2675 }
2676 
SysTrayExitNotice()2677 void MainFrame::SysTrayExitNotice()
2678 {
2679     this->Hide();
2680     wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED,
2681                           wxID_EXIT );
2682     AddPendingEvent( event );
2683     return ;
2684 }
2685 
StopAllTask()2686 void MainFrame::StopAllTask()
2687 {
2688 
2689     vector<_TaskAttr>::iterator it;
2690     bool got = false;
2691 
2692     if ( m_TaskManager->RemoveAllTask() )
2693         got = true;
2694 
2695     for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
2696     {
2697         if ( it->nStatus == _STATUS_RUNNING || it->nStatus == _STATUS_WAITING )
2698         {
2699             it->nStatus = _STATUS_PAUSE;
2700             got = true;
2701         }
2702     }
2703 
2704     if ( got )
2705         ScheduleTask();
2706 }
2707 
StartAllTask()2708 void MainFrame::StartAllTask()
2709 {
2710     vector<_TaskAttr>::iterator it;
2711     bool got = false;
2712 
2713     for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
2714     {
2715         if ( it->nStatus == _STATUS_PAUSE )
2716         {
2717             it->nStatus = _STATUS_WAITING;
2718             got = true;
2719         }
2720     }
2721 
2722     if ( got )
2723         ScheduleTask();
2724 }
2725 
SwitchShowDropWin()2726 void MainFrame::SwitchShowDropWin()
2727 {
2728     if ( m_FloatWin )
2729     {
2730         m_FloatWin->Hide();
2731         m_FloatWin->Destroy();
2732         m_FloatWin = NULL;
2733         gbShowDropWin = false;
2734     }
2735     else
2736     {
2737         m_FloatWin = new CFloatWin( this );
2738         m_FloatWin->Show();
2739         gbShowDropWin = true;
2740     }
2741 	return;
2742 }
2743 
OnLangEnUtf8(wxCommandEvent &)2744 void MainFrame::OnLangEnUtf8( wxCommandEvent& )
2745 {
2746 	if( CheckLocale ( EN_US_UTF_8 ) )
2747 	{
2748     	wxGetApp().SetLang( EN_US_UTF_8 );
2749     	DynamicLang();
2750 	}
2751 	else
2752 	{
2753 		CheckLangMenu ( wxGetApp().GetLang() );
2754 		NoLangSupport();
2755 	}
2756 }
2757 
OnLangCnUtf8(wxCommandEvent &)2758 void MainFrame::OnLangCnUtf8( wxCommandEvent& )
2759 {
2760 	if( CheckLocale( ZH_CN_UTF_8 ) )
2761 	{
2762     	wxGetApp().SetLang( ZH_CN_UTF_8 );
2763     	DynamicLang();
2764 	}
2765 	else
2766 	{
2767 		CheckLangMenu ( wxGetApp().GetLang() );
2768 		NoLangSupport();
2769 	}
2770 }
2771 
OnLangCn18030(wxCommandEvent &)2772 void MainFrame::OnLangCn18030( wxCommandEvent& )
2773 {
2774 	if( CheckLocale( ZH_CN_18030 ) )
2775 	{
2776     	wxGetApp().SetLang( ZH_CN_18030 );
2777     	DynamicLang();
2778 	}
2779 	else
2780 	{
2781     	CheckLangMenu ( wxGetApp().GetLang() );
2782 		NoLangSupport();
2783 	}
2784 }
2785 
OnLangTwBig5(wxCommandEvent &)2786 void MainFrame::OnLangTwBig5( wxCommandEvent& )
2787 {
2788 	if( CheckLocale(ZH_TW_BIG5))
2789 	{
2790 	    wxGetApp().SetLang( ZH_TW_BIG5 );
2791     	DynamicLang();
2792 	}
2793 	else
2794 	{
2795 		CheckLangMenu ( wxGetApp().GetLang() );
2796 		NoLangSupport();
2797 	}
2798 
2799 }
2800 
OnLangTwUtf8(wxCommandEvent &)2801 void MainFrame::OnLangTwUtf8( wxCommandEvent& )
2802 {
2803 	if( CheckLocale(ZH_TW_UTF_8) )
2804 	{
2805     	wxGetApp().SetLang( ZH_TW_UTF_8 );
2806     	DynamicLang();
2807 	}
2808 	else
2809 	{
2810 		CheckLangMenu ( wxGetApp().GetLang() );
2811 		NoLangSupport();
2812 	}
2813 }
2814 
OnLangDeUtf8(wxCommandEvent &)2815 void MainFrame::OnLangDeUtf8( wxCommandEvent& )
2816 {
2817 	if( CheckLocale ( DE_DE_UTF_8 ) )
2818 	{
2819     	wxGetApp().SetLang( DE_DE_UTF_8 );
2820     	DynamicLang();
2821 	}
2822 	else
2823 	{
2824 		CheckLangMenu ( wxGetApp().GetLang() );
2825 		NoLangSupport();
2826 	}
2827 }
2828 
UpdateMenuText()2829 void MainFrame::UpdateMenuText()
2830 {
2831     wxMenuBar * menubar = GetMenuBar();
2832 
2833     if ( menubar == NULL )
2834         return ;
2835 
2836     //update root
2837     menubar->SetLabelTop( 0, _MGSTR( _S_MENU_FILE ) );
2838 
2839     menubar->SetLabelTop( 1, _MGSTR( _S_MENU_TASK ) );
2840 
2841     menubar->SetLabelTop( 2, _MGSTR( _S_MENU_VIEW ) );
2842 
2843     menubar->SetLabelTop( 3, _MGSTR( _S_MENU_OPTION ) );
2844 
2845     menubar->SetLabelTop( 4, _MGSTR( _S_MENU_HELP ) );
2846 
2847     //update other
2848     //file
2849     menubar->SetLabel( wxID_EXIT, _MGSTR( _S_MENU_FILE_QUIT ) );
2850 
2851 	menubar->SetLabel( mgID_FILE_SAVECONFIG, _MGSTR( _S_MENU_FILE_SAVECONFIG ) );
2852 
2853 	menubar->SetLabel( mgID_FILE_SAVEPROXY, _MGSTR( _S_MENU_FILE_SAVEPROXY ) );
2854 
2855 	menubar->SetLabel( mgID_FILE_SAVETASK, _MGSTR( _S_MENU_FILE_SAVETASK ) );
2856 
2857     //task
2858     menubar->SetLabel( mgID_NEW_TASK, _MGSTR( _S_MENU_TASK_NEW ) );
2859 
2860     menubar->SetLabel( mgID_START_TASK, _MGSTR( _S_MENU_TASK_START ) );
2861 
2862     menubar->SetLabel( mgID_STOP_TASK, _MGSTR( _S_MENU_TASK_PAUSE ) );
2863 
2864     menubar->SetLabel( mgID_CANCEL_TASK, _MGSTR( _S_MENU_TASK_DELETE ) );
2865 
2866     menubar->SetLabel( mgID_MOVEUP_TASK, _MGSTR( _S_MENU_TASK_MOVEUP ) );
2867 
2868     menubar->SetLabel( mgID_MOVEDOWN_TASK, _MGSTR( _S_MENU_TASK_MOVEDOWN ) );
2869 
2870     menubar->SetLabel( mgID_ADDTHREAD, _MGSTR( _S_MENU_TASK_ADDTHREAD ) );
2871 
2872     menubar->SetLabel( mgID_SUBTHREAD, _MGSTR( _S_MENU_TASK_SUBTHREAD ) );
2873 
2874     menubar->SetLabel( mgID_RELOAD, _MGSTR( _S_MENU_TASK_RELOAD ) );
2875 
2876     //view
2877     menubar->SetLabel( mgID_VIEW_LANG, _MGSTR( _S_MENU_VIEW_LANG ) );
2878 
2879     menubar->SetLabel( mgID_VIEW_TOOLBAR, _MGSTR( _S_MENU_VIEW_TOOLBAR ) );
2880 
2881     menubar->SetLabel( mgID_VIEW_TOOLBAR_SIZE16, _MGSTR( _S_MENU_VIEW_TOOLBAR_SIZE16 ) );
2882 
2883     menubar->SetLabel( mgID_VIEW_TOOLBAR_SIZE24, _MGSTR( _S_MENU_VIEW_TOOLBAR_SIZE24 ) );
2884 
2885     menubar->SetLabel( mgID_VIEW_TOOLBAR_SIZE32, _MGSTR( _S_MENU_VIEW_TOOLBAR_SIZE32 ) );
2886 
2887     menubar->SetLabel( mgID_VIEW_STATUSBAR, _MGSTR( _S_MENU_VIEW_STATUSBAR ) );
2888 
2889     //Setting
2890     menubar->SetLabel( mgID_OPTION_CONFIG, _MGSTR( _S_MENU_OPTION_CONFIG ) );
2891 
2892     menubar->SetLabel( mgID_OPTION_PROXY, _MGSTR( _S_MENU_OPTION_PROXYCONFIG ) );
2893 
2894     //help
2895 	menubar->SetLabel( mgID_HELP_VISITHOME, _MGSTR( _S_MENU_HELP_VISITHOME ) );
2896 
2897     menubar->SetLabel( wxID_ABOUT, _MGSTR( _S_MENU_HELP_ABOUT ) );
2898 }
2899 
UpdateToolText()2900 void MainFrame::UpdateToolText()
2901 {
2902     InitToolBar();
2903     UpdateToolBar();
2904 }
2905 
DynamicLang()2906 void MainFrame::DynamicLang()
2907 {
2908     SetTitle( _MGSTR( _S_APP_NAME ) );
2909     UpdateMenuText();
2910     UpdateToolText();
2911 	UpdateStatusBar();
2912     m_tasklist->DynamicLang();
2913     m_lefttree->DynamicLang();
2914     m_vsubspliter->DynamicLang();
2915     m_SysTray->SetIcon( wxIcon( logo_22_xpm ), _MGSTR( _S_APP_NAME ) );
2916 }
2917 
2918 //the only new task dlg
DoNewTask(wxString url,wxString refer,wxString savepath,wxString savefile)2919 void MainFrame::DoNewTask( wxString url, wxString refer, wxString savepath, wxString savefile )
2920 {
2921 
2922     if ( m_NewTaskDlg == NULL )
2923     {
2924 
2925         CUrlParser parser;
2926 
2927         if ( !url.IsNull() )
2928         {
2929 #ifndef _UNICODE
2930             if ( !parser.SetUrl( url.mb_str( wxConvLocal ) ) )
2931 #else
2932             if ( !parser.SetUrl( url.mb_str( wxConvLocal ).data() ) )
2933 #endif
2934                 return ;
2935         }
2936 
2937 
2938         m_NewTaskDlg = new CNewTaskDlg( this, url, refer, savepath );
2939 
2940         m_SysTray->DlgShow( true );
2941         int nret = m_NewTaskDlg->ShowModal();
2942         m_SysTray->DlgShow( false );
2943 
2944         if ( wxID_OK == nret )
2945         {
2946 
2947             //the way wxString->string,wxString::mb_str(wxConvLocal)
2948 
2949             std::string surl, ssavepath, srename;
2950 
2951             surl = m_NewTaskDlg->GetUrl();
2952 
2953             CBatch batch( surl );
2954 
2955             if ( batch.GetNum() == 1 )
2956             {
2957                 surl = batch.Get( 0 );
2958             }
2959             else
2960             {
2961 
2962                 int tnum = batch.GetNum();
2963                 //circle add task
2964                 //prepare all args
2965 #ifndef _UNICODE
2966                 std::string refer = m_NewTaskDlg->m_sRefer.mb_str( wxConvLocal );
2967                 std::string savepath = m_NewTaskDlg->m_sSavePath.mb_str( wxConvLocal );
2968                 std::string rename = m_NewTaskDlg->m_sRename.mb_str( wxConvLocal );
2969 #else
2970                 std::string refer = m_NewTaskDlg->m_sRefer.mb_str( wxConvLocal ).data();
2971                 std::string savepath = m_NewTaskDlg->m_sSavePath.mb_str( wxConvLocal ).data();
2972                 std::string rename = m_NewTaskDlg->m_sRename.mb_str( wxConvLocal ).data();
2973 #endif
2974                 std::string sock;
2975                 std::string ftp;
2976                 std::string http;
2977                 m_NewTaskDlg->GetProxyName( sock, ftp, http );
2978 
2979 
2980                 int threadnum = m_NewTaskDlg->m_nThreadNum;
2981                 bool runnow = m_NewTaskDlg->m_nRunNow == 0;
2982                 int retry = m_NewTaskDlg->m_nRetry;
2983                 int retrywait = m_NewTaskDlg->m_nRetryWait;
2984                 bool automd5 = gbAutoMd5;
2985 
2986 
2987 
2988                 //record path this time used;
2989                 RecordSavePath( savepath );
2990                 CBatch renamebatch( rename );
2991                 std::string selectfilename = m_NewTaskDlg->GetSelectFileName();
2992 
2993 
2994                 for ( int tasks = 0;tasks < tnum;tasks++ )
2995                 {
2996 
2997                     std::string mir[ 100 ];
2998                     int nmir = m_NewTaskDlg->GetMirrorUrl( 100, mir );
2999 
3000                     if ( nmir > 0 )
3001                     {
3002 
3003                         for ( int j = 0;j < nmir;j++ )
3004                         {
3005 
3006                             std::string temp = mir[ j ];
3007                             Trim( temp );
3008                             CBatch mirbatch( selectfilename );
3009 
3010                             if ( temp[ temp.length() - 1 ] == '/' )
3011                             {
3012 
3013                                 temp += mirbatch.Get( tasks );
3014 
3015                                 mir[ j ] = temp;
3016                             }
3017                         }
3018                     }
3019 
3020 
3021                     AddBatchTask(
3022                         batch.Get( tasks ),
3023                         refer,
3024                         savepath,
3025                         renamebatch.Get( tasks ),
3026                         threadnum,
3027                         runnow,
3028                         retry,
3029                         retrywait,
3030                         sock,
3031                         ftp,
3032                         http,
3033                         automd5,
3034                         nmir,
3035                         mir );
3036                 }
3037 
3038                 m_NewTaskDlg->Destroy();
3039                 m_NewTaskDlg = NULL;
3040                 //going task
3041                 ScheduleTask();
3042                 UpdateRightDown();
3043                 return ;
3044             }
3045 
3046             //single task treatment
3047             ssavepath = m_NewTaskDlg->m_sSavePath.mb_str( wxConvLocal );
3048 
3049             srename = m_NewTaskDlg->m_sRename.mb_str( wxConvLocal );
3050 
3051             if ( parser.SetUrl( surl ) )
3052             {
3053 
3054                 _TaskAttr atask;
3055                 atask.nID = GetNewTaskID();
3056                 atask.sURL = surl;
3057                 //add refer
3058                 atask.sRefer = m_NewTaskDlg->m_sRefer.mb_str( wxConvLocal );
3059                 Trim( atask.sRefer );
3060                 atask.sSavePath = ssavepath;
3061                 //check the path valid? create it if not exists
3062 
3063                 atask.nThread = m_NewTaskDlg->m_nThreadNum;
3064                 atask.nStatus = m_NewTaskDlg->m_nRunNow == 0 ? _STATUS_WAITING : _STATUS_PAUSE;
3065 
3066 
3067                 std::string finame = srename.empty() ? parser.GetFileName() : srename;
3068 
3069                 if ( finame.empty() )
3070                     atask.sName = "index.html";
3071                 else
3072                     atask.sName = finame;
3073 
3074                 //atask.sName = srename.empty()?parser.GetFileName():srename;
3075 
3076                 atask.nRetry = m_NewTaskDlg->m_nRetry;
3077 
3078                 atask.nRetryWait = m_NewTaskDlg->m_nRetryWait;
3079 
3080                 atask.nFinish = 0;
3081 
3082                 atask.fRatio = 0.0;
3083 
3084                 atask.nError = 0;
3085 
3086                 atask.nSpeed = 0;
3087 
3088                 atask.bAutoMd5 = gbAutoMd5;
3089 
3090                 atask.nLen = 0;
3091 
3092                 atask.nTime = 0;
3093 
3094                 m_NewTaskDlg->GetProxyName( atask.sSockProxy, atask.sFtpProxy, atask.sHttpProxy );
3095 
3096 
3097                 //get Mirror url and main url,make a group
3098 
3099                 std::string mir[ 100 ];
3100 
3101                 int nmir = m_NewTaskDlg->GetMirrorUrl( 100, mir );
3102 
3103                 if ( nmir > 0 )
3104                 {
3105 
3106                     for ( int j = 0;j < nmir;j++ )
3107                     {
3108                         std::string temp = mir[ j ];
3109 
3110                         if ( temp[ temp.length() - 1 ] == '/' )
3111                         {
3112                             temp += m_NewTaskDlg->GetSelectFileName();
3113                         }
3114 
3115                         atask.sMirrorURL.push_back( temp );
3116                     }
3117                 }
3118 
3119 
3120                 //delete dlg;
3121                 m_NewTaskDlg->Destroy();
3122 
3123                 m_NewTaskDlg = NULL;
3124 
3125                 //record path this time used;
3126                 RecordSavePath( atask.sSavePath );
3127 
3128                 //going task
3129                 m_AllTaskList.push_back( atask );
3130 
3131                 ScheduleTask();
3132 
3133                 UpdateRightDown();
3134 
3135             }
3136             else
3137             {
3138                 m_NewTaskDlg->Destroy();
3139                 m_NewTaskDlg = NULL;
3140                 m_SysTray->DlgShow( true );
3141 
3142                 wxMessageBox( _MGSTR( _S_INFO_NOTSUPPORTURL ),
3143                               _MGSTR( _S_WRONG ), wxICON_INFORMATION );
3144                 m_SysTray->DlgShow( false );
3145 
3146                 return ;
3147             }
3148 
3149 
3150         } //if ( wxID_OK == nret )
3151         else
3152         { //Cancel task;
3153 
3154             m_NewTaskDlg->Destroy();
3155             m_NewTaskDlg = NULL;
3156         }
3157 
3158     } //if(m_NewTaskDlg==NULL)
3159     else
3160     {
3161         CUrlParser parser;
3162 #ifndef _UNICODE
3163         if ( parser.SetUrl( url.mb_str( wxConvLocal ) ) )
3164 #else
3165 		if ( parser.SetUrl( url.mb_str( wxConvLocal ).data() ) )
3166 #endif
3167         {
3168             m_NewTaskDlg->AddMirrorUrl( url );
3169         }
3170         else if ( parser.IsValidMirror() )
3171         {
3172             m_NewTaskDlg->AddMirrorUrl( url );
3173         }
3174 
3175     }
3176 
3177 }
3178 
IsUrlExist(string url)3179 bool MainFrame::IsUrlExist( string url )
3180 {
3181     //check url in task list first
3182     vector<_TaskAttr>::iterator it;
3183 
3184     for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
3185     {
3186         if ( it->sURL == url )
3187         {
3188             return true;
3189         }
3190     }
3191 
3192     return false;
3193 }
3194 
MonitorClip(bool mo)3195 void MainFrame::MonitorClip( bool mo )
3196 {
3197     m_HideWin->MonitorClip( mo );
3198     gbMonitorClip = mo;
3199 }
3200 
OnStatusBar(wxCommandEvent & event)3201 void MainFrame::OnStatusBar( wxCommandEvent& event )
3202 {
3203     if ( m_bShowStatusBar )
3204     {
3205         wxStatusBar * bar = GetStatusBar();
3206         assert( bar != NULL );
3207         SetStatusBar( NULL );
3208         delete bar;
3209         m_bShowStatusBar = false;
3210     }
3211     else
3212     {
3213         wxStatusBar* bar = new wxStatusBar( this, wxID_ANY );
3214         int statusw[ 5 ] = { -1, 100, 100, 140 };
3215         bar->SetFieldsCount( 5, statusw );
3216         bar->SetStatusText( _MGSTR( _S_INFO_WELCOME ), 0 );
3217         SetStatusBar( bar );
3218         m_bShowStatusBar = true;
3219     }
3220 
3221     UpdateStatusBar();
3222 
3223 }
3224 
UpdateStatusBar()3225 void MainFrame::UpdateStatusBar()
3226 {
3227     if ( GetStatusBar() )
3228     {
3229         int nrun = 0, nwait = 0;
3230         vector<_TaskAttr>::const_iterator it;
3231 
3232         for ( it = m_AllTaskList.begin();it != m_AllTaskList.end();it++ )
3233         {
3234             if ( it->nStatus == _STATUS_RUNNING )
3235                 nrun++;
3236             else if ( it->nStatus == _STATUS_WAITING )
3237                 nwait++;
3238             else
3239                 continue;
3240         }
3241 
3242         wxString num;
3243         num.Printf( wxT( "%d" ), nrun );
3244         GetStatusBar() ->SetStatusText( _MGSTR( _S_STATUS_RUNNINGTASK ) + num, 1 );
3245         num.Printf( wxT( "%d" ), nwait );
3246         GetStatusBar() ->SetStatusText( _MGSTR( _S_STATUS_WAITINGTASK ) + num, 2 );
3247 
3248     }
3249 }
3250 
InitStatusBar()3251 void MainFrame::InitStatusBar()
3252 {
3253     if ( m_bShowStatusBar )
3254     {
3255         wxStatusBar * bar = new wxStatusBar( this, wxID_ANY );
3256         int statusw[ 5 ] = { -1, 100, 100, 140 };
3257         bar->SetFieldsCount( 5, statusw );
3258         bar->SetStatusText( _MGSTR( _S_INFO_WELCOME ), 0 );
3259         SetStatusBar( bar );
3260     }
3261 }
3262 
OnToolbarSize16(wxCommandEvent &)3263 void MainFrame::OnToolbarSize16( wxCommandEvent& )
3264 {
3265     wxToolBar * toolbar = GetToolBar();
3266 
3267     if ( TOOLBAR_SIZE == 16 )
3268         return ;
3269 
3270     TOOLBAR_SIZE = 16;
3271 
3272     SetToolBar( NULL );
3273 
3274     delete toolbar;
3275 
3276     InitToolBar();
3277 
3278     UpdateToolBar();
3279 }
3280 
OnToolbarSize24(wxCommandEvent &)3281 void MainFrame::OnToolbarSize24( wxCommandEvent& )
3282 {
3283     wxToolBar * toolbar = GetToolBar();
3284 
3285     if ( TOOLBAR_SIZE == 24 )
3286         return ;
3287 
3288     TOOLBAR_SIZE = 24;
3289 
3290     SetToolBar( NULL );
3291 
3292     delete toolbar;
3293 
3294     InitToolBar();
3295 
3296     UpdateToolBar();
3297 }
3298 
OnToolbarSize32(wxCommandEvent &)3299 void MainFrame::OnToolbarSize32( wxCommandEvent& )
3300 {
3301     wxToolBar * toolbar = GetToolBar();
3302 
3303     if ( TOOLBAR_SIZE == 32 )
3304         return ;
3305 
3306     TOOLBAR_SIZE = 32;
3307 
3308     SetToolBar( NULL );
3309 
3310     delete toolbar;
3311 
3312     InitToolBar();
3313 
3314     UpdateToolBar();
3315 }
3316 
3317 
OnProxySetting(wxCommandEvent &)3318 void MainFrame::OnProxySetting( wxCommandEvent& )
3319 {
3320     CProxyDlg * dlg = new CProxyDlg( this );
3321     m_SysTray->DlgShow( true );
3322     dlg->ShowModal();
3323     m_SysTray->DlgShow( false );
3324 }
3325 
GetProxyCount()3326 int MainFrame::GetProxyCount()
3327 {
3328     return m_AllProxyList.size();
3329 }
3330 
GetProxy(int seq)3331 _ProxyAttr& MainFrame::GetProxy( int seq )
3332 {
3333     return m_AllProxyList[ seq ];
3334 }
3335 
RemoveProxy(wxString name)3336 void MainFrame::RemoveProxy( wxString name )
3337 {
3338 #ifndef _UNICODE
3339     std::string na = name.mb_str( wxConvLocal );
3340 #else
3341 	std::string na = name.mb_str( wxConvLocal ).data();
3342 #endif
3343 
3344     std::vector<_ProxyAttr>::iterator it;
3345 
3346     for ( it = m_AllProxyList.begin();it != m_AllProxyList.end();it++ )
3347     {
3348         if ( it->sName == na )
3349         {
3350             m_AllProxyList.erase( it );
3351             break;
3352         }
3353     }
3354 }
3355 
AddProxy(int type,wxString name,wxString server,int port,wxString user,wxString pass)3356 bool MainFrame::AddProxy(
3357     int type, wxString name, wxString server, int port, wxString user, wxString pass )
3358 {
3359 #ifndef _UNICODE
3360     std::string na = name.mb_str( wxConvLocal );
3361 #else
3362     std::string na = name.mb_str( wxConvLocal ).data();
3363 #endif
3364     std::vector<_ProxyAttr>::iterator it;
3365 
3366     for ( it = m_AllProxyList.begin();it != m_AllProxyList.end();it++ )
3367     {
3368         if ( it->sName == na )
3369         {
3370             return false;
3371         }
3372     }
3373 
3374     _ProxyAttr newnode;
3375     newnode.nType = type;
3376     newnode.sName = na;
3377     newnode.sServer = server.mb_str( wxConvLocal );
3378     newnode.nPort = port;
3379     newnode.sUser = user.mb_str( wxConvLocal );
3380     newnode.sPass = pass.mb_str( wxConvLocal );
3381     m_AllProxyList.push_back( newnode );
3382     return true;
3383 }
3384 
SaveProxyDB()3385 bool MainFrame::SaveProxyDB()
3386 {
3387 
3388     //记录格式采用2进制格式
3389     //文件头+数据+文件尾
3390     //文件头:版本[4]+文件头长度[4]+数据全长[4]+数据项目数[4]
3391     //数据:类型[4]+名称[v]+服务器名[v]+端口[4]+用户名[v]+密码[v]
3392     //文件尾:0xFFFF[4]
3393 
3394     FILE * fp;
3395 
3396     std::string tempdb;
3397 
3398     if ( !GetTempDir( tempdb ) )
3399     {
3400         return false;
3401     }
3402 
3403     tempdb += "/proxy.db";
3404 
3405     fp = fopen( tempdb.c_str(), "wb" );
3406 
3407     if ( fp == NULL )
3408     {
3409         return false;
3410     }
3411 
3412     struct _fh
3413     {
3414         int ver;
3415         int headlen; //4*4=16
3416         int datalen;
3417         int count; //=m_AllProxyList.size()
3418     }
3419 
3420     fh;
3421 
3422     fh.ver = 1;
3423     fh.headlen = sizeof( fh );
3424     fh.datalen = 0;
3425     fh.count = m_AllProxyList.size();
3426 
3427     if ( 1 != fwrite( &fh, fh.headlen, 1, fp ) )
3428     {
3429         fclose( fp );
3430         return false;
3431     }
3432 
3433     int dl = 0;
3434 
3435     vector<_ProxyAttr>::iterator it;
3436 
3437     for ( it = m_AllProxyList.begin();it != m_AllProxyList.end();it++ )
3438     {
3439         fwrite( &( it->nType ), sizeof( int ), 1, fp );
3440         dl += sizeof( int );
3441         fwrite( it->sName.c_str(), it->sName.length() + 1, 1, fp );
3442         dl += it->sName.length() + 1;
3443         fwrite( it->sServer.c_str(), it->sServer.length() + 1, 1, fp );
3444         dl += it->sServer.length() + 1;
3445         fwrite( &( it->nPort ), sizeof( int ), 1, fp );
3446         dl += sizeof( int );
3447         fwrite( it->sUser.c_str(), it->sUser.length() + 1, 1, fp );
3448         dl += it->sUser.length() + 1;
3449         fwrite( it->sPass.c_str(), it->sPass.length() + 1, 1, fp );
3450         dl += it->sPass.length() + 1;
3451     }
3452 
3453     fh.datalen = dl;
3454 
3455     //file tail
3456     int tail = 0xFFFF;
3457     fwrite( &tail, sizeof( int ), 1, fp );
3458     fseek( fp, 0, SEEK_SET );
3459     fwrite( &fh, fh.headlen, 1, fp );
3460     fclose( fp );
3461     return true;
3462 }
3463 
ReadProxyDB()3464 bool MainFrame::ReadProxyDB()
3465 {
3466 
3467     m_AllProxyList.clear();
3468     //记录格式采用2进制格式
3469     //文件头+数据+文件尾
3470     //文件头:版本[4]+文件头长度[4]+数据全长[4]+数据项目数[4]
3471     //数据:类型[4]+名称[v]+服务器名[v]+端口[4]+用户名[v]+密码[v]
3472     //文件尾:0xFFFF[4]
3473 
3474     FILE *fp;
3475 
3476     std::string tempdb;
3477 
3478     if ( !GetTempDir( tempdb ) )
3479     {
3480         return false;
3481     }
3482 
3483     tempdb += "/proxy.db";
3484 
3485     fp = fopen( tempdb.c_str(), "rb" );
3486 
3487     if ( fp == NULL )
3488     {
3489         return false;
3490     }
3491 
3492     struct _fh
3493     {
3494         int ver;
3495         int headlen; //4*4=16
3496         int datalen;
3497         int count; //=m_AllProxyList.size()
3498     }
3499 
3500     fh;
3501 
3502     fseek( fp, 0, SEEK_SET );
3503 
3504     if ( 1 != fread( &fh, sizeof( fh ), 1, fp ) )
3505     {
3506         fclose( fp );
3507         return false;
3508     }
3509 
3510     if ( fh.ver != 1 || fh.headlen != sizeof( fh ) )
3511     {
3512         fclose( fp );
3513         return false;
3514     }
3515 
3516     if ( fh.count == 0 || fh.datalen == 0 )
3517     {
3518         fclose( fp );
3519         return true;
3520     }
3521 
3522     fseek( fp, fh.headlen, SEEK_SET ); //moveto data
3523     char *buf = new char[ fh.datalen ];
3524 
3525     if ( 1 != fread( buf, fh.datalen, 1, fp ) )
3526     {
3527         delete[] buf;
3528         return false;
3529     }
3530 
3531     _ProxyAttr pa;
3532     int movepos = 0;
3533     char strbuf[ 256 ];
3534 
3535     for ( int i = 0;i < fh.count;i++ )
3536     { //read dataitem
3537         memcpy( &pa.nType, buf + movepos, sizeof( int ) );
3538         movepos += sizeof( int );
3539         strcpy( strbuf, buf + movepos );
3540         pa.sName = std::string( strbuf );
3541         movepos += strlen( strbuf ) + 1;
3542         strcpy( strbuf, buf + movepos );
3543         pa.sServer = std::string( strbuf );
3544         movepos += strlen( strbuf ) + 1;
3545         memcpy( &pa.nPort, buf + movepos, sizeof( int ) );
3546         movepos += sizeof( int );
3547         strcpy( strbuf, buf + movepos );
3548         pa.sUser = std::string( strbuf );
3549         movepos += strlen( strbuf ) + 1;
3550         strcpy( strbuf, buf + movepos );
3551         pa.sPass = std::string( strbuf );
3552         movepos += strlen( strbuf ) + 1;
3553 
3554         m_AllProxyList.push_back( pa );
3555     }
3556 
3557     fclose( fp );
3558     delete[] buf;
3559     return true;
3560 
3561 }
3562 
GetProxyByName(std::string name,int & type,std::string & server,int & port,std::string & user,std::string & pass)3563 bool MainFrame::GetProxyByName(
3564     std::string name, int& type, std::string& server, int& port, std::string& user, std::string& pass )
3565 {
3566 
3567     vector<_ProxyAttr>::iterator it;
3568 
3569     for ( it = m_AllProxyList.begin();it != m_AllProxyList.end();it++ )
3570     {
3571 
3572         if ( it->sName == name )
3573         {
3574             type = it->nType;
3575             server = it->sServer;
3576             port = it->nPort;
3577             user = it->sUser;
3578             pass = it->sPass;
3579             return true;
3580         }
3581     }
3582 
3583     return false;
3584 }
3585 
PlaySound(bool success)3586 void MainFrame::PlaySound( bool success )
3587 {
3588 #if defined(__BSD__)|| defined(__DARWIN__)
3589 	return;
3590 #else
3591     if ( !gbSoundTip )
3592         return ;
3593 
3594     wxSound *snd = new wxSound;
3595 
3596     CreateSound( *snd, success );
3597 
3598     if ( snd->IsOk() )
3599     {
3600         snd->Play( wxSOUND_ASYNC );
3601     }
3602 #endif
3603 }
3604 
CreateSound(wxSound & snd,bool success)3605 void MainFrame::CreateSound( wxSound& snd, bool success )
3606 {
3607 #if defined(__BSD__)|| defined(__DARWIN__)
3608 	return;
3609 #else
3610     if ( success )
3611     { //right wav
3612         static const unsigned char goodsound[] =
3613             {
3614 
3615                 0x52, 0x49, 0x46, 0x46, 0xf5, 0x11, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20,
3616                 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x11, 0x2b, 0x00, 0x00, 0x11, 0x2b, 0x00, 0x00,
3617                 0x01, 0x00, 0x08, 0x00, 0x64, 0x61, 0x74, 0x61, 0xd1, 0x11, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80,
3618                 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
3619                 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
3620                 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7e, 0x7c, 0x78, 0x79,
3621                 0x7b, 0x7c, 0x7c, 0x84, 0x91, 0x8e, 0x8c, 0x8e, 0x8b, 0x81, 0x7d, 0x77, 0x90, 0x8a, 0x6f, 0x5f,
3622                 0x5c, 0x61, 0x70, 0x71, 0x6f, 0x8d, 0x8f, 0x95, 0x94, 0x9c, 0xb1, 0xa4, 0x68, 0x70, 0x88, 0x9f,
3623                 0x9d, 0x6b, 0x41, 0x44, 0x71, 0x7e, 0x7c, 0x5f, 0x5f, 0x83, 0x99, 0x9c, 0x95, 0x89, 0x89, 0x83,
3624                 0x8d, 0x98, 0x95, 0x8f, 0x92, 0xa1, 0xa9, 0x9f, 0x88, 0x71, 0x5f, 0x53, 0x46, 0x3b, 0x34, 0x3b,
3625                 0x4f, 0x6b, 0x81, 0x8b, 0x93, 0xa3, 0xbb, 0xd0, 0xd6, 0xc8, 0xb0, 0x99, 0x8d, 0x85, 0x76, 0x5c,
3626                 0x40, 0x35, 0x40, 0x5a, 0x75, 0x7f, 0x7b, 0x75, 0x77, 0x81, 0x88, 0x83, 0x77, 0x6f, 0x78, 0x91,
3627                 0xac, 0xbc, 0xbd, 0xb5, 0xad, 0xa6, 0x9b, 0x87, 0x6b, 0x51, 0x42, 0x40, 0x43, 0x46, 0x48, 0x4f,
3628                 0x61, 0x79, 0x92, 0xa1, 0xa9, 0xaf, 0xb7, 0xbe, 0xbd, 0xad, 0x94, 0x7b, 0x6e, 0x6e, 0x71, 0x6f,
3629                 0x69, 0x66, 0x6b, 0x76, 0x7e, 0x7a, 0x69, 0x57, 0x50, 0x59, 0x6a, 0x7a, 0x85, 0x8f, 0x9e, 0xb2,
3630                 0xc1, 0xc7, 0xbf, 0xaa, 0x95, 0x87, 0x7c, 0x6f, 0x5e, 0x4d, 0x43, 0x44, 0x4e, 0x58, 0x60, 0x68,
3631                 0x75, 0x88, 0x9b, 0xa7, 0xa9, 0xa3, 0x9d, 0x99, 0x97, 0x91, 0x88, 0x80, 0x7f, 0x85, 0x8e, 0x90,
3632                 0x87, 0x78, 0x69, 0x60, 0x5b, 0x55, 0x4e, 0x4a, 0x50, 0x63, 0x7e, 0x96, 0xa5, 0xab, 0xaf, 0xb3,
3633                 0xb7, 0xb5, 0xa8, 0x95, 0x82, 0x75, 0x6e, 0x68, 0x60, 0x55, 0x50, 0x53, 0x5e, 0x6c, 0x76, 0x7c,
3634                 0x80, 0x86, 0x8d, 0x92, 0x90, 0x8b, 0x87, 0x8a, 0x92, 0x9b, 0xa0, 0x9f, 0x9c, 0x98, 0x92, 0x87,
3635                 0x76, 0x61, 0x4f, 0x47, 0x49, 0x50, 0x59, 0x62, 0x6d, 0x7e, 0x91, 0xa1, 0xaa, 0xaa, 0xa6, 0xa4,
3636                 0xa3, 0xa0, 0x98, 0x8a, 0x7b, 0x71, 0x6c, 0x6b, 0x6a, 0x67, 0x65, 0x67, 0x6d, 0x75, 0x78, 0x76,
3637                 0x72, 0x71, 0x76, 0x7e, 0x86, 0x8d, 0x94, 0x9d, 0xa8, 0xaf, 0xaf, 0xa6, 0x97, 0x86, 0x78, 0x6b,
3638                 0x60, 0x55, 0x4e, 0x4f, 0x57, 0x63, 0x6f, 0x78, 0x7f, 0x87, 0x91, 0x9a, 0xa0, 0x9f, 0x9b, 0x97,
3639                 0x95, 0x93, 0x8e, 0x87, 0x7e, 0x78, 0x77, 0x78, 0x79, 0x76, 0x70, 0x6a, 0x67, 0x66, 0x66, 0x66,
3640                 0x66, 0x6c, 0x77, 0x87, 0x97, 0xa3, 0xa9, 0xab, 0xab, 0xa7, 0x9f, 0x92, 0x82, 0x73, 0x69, 0x64,
3641                 0x62, 0x60, 0x5f, 0x61, 0x66, 0x6e, 0x77, 0x7d, 0x81, 0x85, 0x8a, 0x90, 0x94, 0x95, 0x93, 0x90,
3642                 0x8f, 0x90, 0x90, 0x8f, 0x8b, 0x86, 0x81, 0x7d, 0x78, 0x70, 0x65, 0x5c, 0x58, 0x5a, 0x60, 0x69,
3643                 0x73, 0x7e, 0x8b, 0x98, 0xa3, 0xa8, 0xa6, 0xa0, 0x99, 0x93, 0x8c, 0x84, 0x7b, 0x73, 0x6e, 0x6c,
3644                 0x6c, 0x6c, 0x6b, 0x6b, 0x6c, 0x70, 0x76, 0x7a, 0x7d, 0x7f, 0x82, 0x87, 0x8c, 0x90, 0x92, 0x94,
3645                 0x96, 0x98, 0x99, 0x97, 0x90, 0x86, 0x7b, 0x71, 0x68, 0x61, 0x5c, 0x59, 0x5c, 0x64, 0x6f, 0x7b,
3646                 0x85, 0x8c, 0x92, 0x97, 0x9a, 0x9a, 0x98, 0x93, 0x8e, 0x8b, 0x88, 0x85, 0x80, 0x7b, 0x76, 0x73,
3647                 0x72, 0x71, 0x6f, 0x6d, 0x6c, 0x6e, 0x71, 0x74, 0x77, 0x7b, 0x7f, 0x86, 0x8e, 0x96, 0x9c, 0x9e,
3648                 0x9e, 0x9b, 0x97, 0x8f, 0x85, 0x79, 0x6e, 0x66, 0x63, 0x62, 0x64, 0x67, 0x6c, 0x73, 0x7a, 0x81,
3649                 0x86, 0x89, 0x8b, 0x8d, 0x8f, 0x91, 0x91, 0x90, 0x8e, 0x8c, 0x8a, 0x88, 0x85, 0x80, 0x7a, 0x76,
3650                 0x73, 0x70, 0x6d, 0x6a, 0x68, 0x69, 0x6c, 0x72, 0x79, 0x80, 0x88, 0x90, 0x97, 0x9d, 0x9f, 0x9d,
3651                 0x97, 0x90, 0x89, 0x81, 0x7a, 0x73, 0x6e, 0x6b, 0x6c, 0x6e, 0x70, 0x72, 0x73, 0x76, 0x79, 0x7d,
3652                 0x80, 0x83, 0x85, 0x88, 0x8c, 0x8f, 0x91, 0x92, 0x91, 0x8f, 0x8d, 0x8a, 0x86, 0x80, 0x7a, 0x73,
3653                 0x6e, 0x6a, 0x68, 0x66, 0x67, 0x6b, 0x71, 0x79, 0x82, 0x8a, 0x90, 0x94, 0x97, 0x97, 0x96, 0x92,
3654                 0x8c, 0x87, 0x82, 0x7f, 0x7c, 0x79, 0x76, 0x74, 0x73, 0x72, 0x72, 0x72, 0x72, 0x73, 0x75, 0x79,
3655                 0x7d, 0x81, 0x85, 0x89, 0x8d, 0x91, 0x93, 0x94, 0x93, 0x90, 0x8c, 0x88, 0x82, 0x7b, 0x74, 0x6e,
3656                 0x69, 0x68, 0x68, 0x6b, 0x6f, 0x74, 0x7b, 0x81, 0x87, 0x8c, 0x8e, 0x8e, 0x8e, 0x8e, 0x8d, 0x8c,
3657                 0x8a, 0x87, 0x85, 0x83, 0x81, 0x7e, 0x7a, 0x76, 0x73, 0x71, 0x70, 0x6f, 0x70, 0x71, 0x74, 0x79,
3658                 0x7e, 0x83, 0x88, 0x8c, 0x90, 0x93, 0x95, 0x94, 0x92, 0x8d, 0x87, 0x81, 0x7b, 0x76, 0x71, 0x6e,
3659                 0x6d, 0x6e, 0x70, 0x74, 0x77, 0x7a, 0x7e, 0x81, 0x83, 0x86, 0x87, 0x89, 0x8a, 0x8b, 0x8d, 0x8d,
3660                 0x8d, 0x8b, 0x88, 0x85, 0x81, 0x7d, 0x78, 0x74, 0x71, 0x6f, 0x6e, 0x6f, 0x70, 0x73, 0x77, 0x7c,
3661                 0x82, 0x87, 0x8c, 0x8f, 0x92, 0x92, 0x92, 0x8f, 0x8b, 0x86, 0x81, 0x7d, 0x79, 0x77, 0x75, 0x74,
3662                 0x74, 0x74, 0x75, 0x76, 0x77, 0x79, 0x7a, 0x7c, 0x7f, 0x83, 0x86, 0x89, 0x8c, 0x8e, 0x8f, 0x8f,
3663                 0x8d, 0x8b, 0x87, 0x83, 0x7e, 0x7a, 0x76, 0x72, 0x70, 0x6e, 0x6f, 0x71, 0x74, 0x77, 0x7c, 0x80,
3664                 0x85, 0x8a, 0x8c, 0x8e, 0x8e, 0x8d, 0x8b, 0x89, 0x87, 0x84, 0x81, 0x7f, 0x7d, 0x7b, 0x7a, 0x78,
3665                 0x76, 0x74, 0x74, 0x74, 0x75, 0x76, 0x79, 0x7c, 0x80, 0x84, 0x88, 0x8b, 0x8d, 0x8f, 0x8f, 0x8e,
3666                 0x8b, 0x88, 0x84, 0x80, 0x7b, 0x78, 0x74, 0x72, 0x71, 0x71, 0x72, 0x75, 0x78, 0x7c, 0x7f, 0x82,
3667                 0x85, 0x87, 0x89, 0x89, 0x89, 0x89, 0x89, 0x88, 0x88, 0x86, 0x84, 0x82, 0x7f, 0x7c, 0x79, 0x76,
3668                 0x74, 0x72, 0x72, 0x73, 0x75, 0x78, 0x7b, 0x7f, 0x83, 0x87, 0x8a, 0x8c, 0x8d, 0x8d, 0x8c, 0x8b,
3669                 0x88, 0x85, 0x81, 0x7d, 0x7a, 0x77, 0x75, 0x75, 0x74, 0x75, 0x76, 0x78, 0x7a, 0x7c, 0x7e, 0x80,
3670                 0x82, 0x84, 0x86, 0x88, 0x89, 0x8a, 0x8a, 0x8a, 0x89, 0x87, 0x84, 0x81, 0x7d, 0x7a, 0x77, 0x75,
3671                 0x73, 0x73, 0x73, 0x75, 0x78, 0x7b, 0x7e, 0x81, 0x84, 0x87, 0x8a, 0x8b, 0x8b, 0x8b, 0x89, 0x87,
3672                 0x85, 0x82, 0x80, 0x7d, 0x7b, 0x7a, 0x78, 0x78, 0x77, 0x77, 0x77, 0x78, 0x79, 0x7b, 0x7c, 0x7f,
3673                 0x81, 0x84, 0x87, 0x89, 0x8b, 0x8b, 0x8b, 0x8a, 0x88, 0x85, 0x82, 0x7e, 0x7b, 0x78, 0x76, 0x75,
3674                 0x74, 0x75, 0x76, 0x78, 0x7a, 0x7d, 0x80, 0x82, 0x85, 0x87, 0x88, 0x89, 0x89, 0x88, 0x87, 0x86,
3675                 0x84, 0x83, 0x81, 0x7f, 0x7d, 0x7b, 0x7a, 0x78, 0x77, 0x76, 0x76, 0x77, 0x78, 0x7a, 0x7d, 0x80,
3676                 0x83, 0x86, 0x88, 0x8a, 0x8b, 0x8a, 0x89, 0x87, 0x85, 0x82, 0x80, 0x7d, 0x7a, 0x78, 0x77, 0x76,
3677                 0x76, 0x77, 0x78, 0x7a, 0x7c, 0x7e, 0x80, 0x82, 0x83, 0x85, 0x86, 0x87, 0x87, 0x87, 0x87, 0x86,
3678                 0x85, 0x84, 0x82, 0x80, 0x7d, 0x7b, 0x79, 0x77, 0x76, 0x76, 0x76, 0x78, 0x7a, 0x7d, 0x7f, 0x82,
3679                 0x85, 0x87, 0x88, 0x89, 0x89, 0x88, 0x87, 0x85, 0x83, 0x81, 0x7f, 0x7d, 0x7b, 0x7a, 0x79, 0x78,
3680                 0x78, 0x79, 0x79, 0x7a, 0x7c, 0x7d, 0x7f, 0x81, 0x82, 0x84, 0x86, 0x87, 0x88, 0x88, 0x88, 0x87,
3681                 0x85, 0x83, 0x81, 0x7e, 0x7b, 0x79, 0x78, 0x77, 0x77, 0x77, 0x78, 0x7a, 0x7c, 0x7e, 0x81, 0x83,
3682                 0x84, 0x86, 0x87, 0x87, 0x87, 0x86, 0x85, 0x84, 0x83, 0x81, 0x7f, 0x7e, 0x7c, 0x7b, 0x7a, 0x79,
3683                 0x79, 0x79, 0x79, 0x7a, 0x7b, 0x7d, 0x7f, 0x81, 0x83, 0x85, 0x87, 0x88, 0x88, 0x88, 0x87, 0x85,
3684                 0x83, 0x81, 0x7f, 0x7d, 0x7b, 0x79, 0x78, 0x78, 0x78, 0x79, 0x7a, 0x7c, 0x94, 0x94, 0x93, 0x90,
3685                 0x8c, 0x88, 0x84, 0x7f, 0x7b, 0x78, 0x76, 0x75, 0x75, 0x76, 0x77, 0x79, 0x7a, 0x7c, 0x7d, 0x7e,
3686                 0x7f, 0x80, 0x81, 0x80, 0x80, 0x7f, 0x7e, 0x7e, 0x7e, 0x7f, 0x80, 0x82, 0x81, 0x80, 0x7c, 0x7e,
3687                 0x81, 0x83, 0x84, 0x8d, 0x9b, 0x97, 0x92, 0x90, 0x88, 0x7b, 0x76, 0x71, 0x92, 0x90, 0x73, 0x58,
3688                 0x43, 0x3e, 0x4d, 0x60, 0x76, 0xa7, 0xa7, 0xa1, 0x8c, 0x8c, 0xb0, 0xbd, 0x93, 0x9f, 0xa5, 0xa7,
3689                 0x94, 0x55, 0x20, 0x16, 0x3f, 0x54, 0x6c, 0x60, 0x64, 0x82, 0x96, 0xa7, 0xb9, 0xc0, 0xc0, 0xa9,
3690                 0x9d, 0x98, 0x8d, 0x81, 0x7a, 0x7d, 0x82, 0x81, 0x7d, 0x79, 0x76, 0x76, 0x78, 0x7a, 0x78, 0x71,
3691                 0x65, 0x57, 0x4b, 0x47, 0x4e, 0x60, 0x7a, 0x97, 0xaf, 0xbb, 0xbb, 0xad, 0x97, 0x7f, 0x6a, 0x5c,
3692                 0x55, 0x54, 0x57, 0x5a, 0x5d, 0x63, 0x6e, 0x81, 0x9c, 0xbc, 0xd8, 0xf0, 0xf9, 0xf1, 0xd9, 0xb8,
3693                 0x8f, 0x67, 0x46, 0x32, 0x24, 0x1e, 0x1e, 0x22, 0x2a, 0x36, 0x44, 0x5a, 0x73, 0x8c, 0xa3, 0xb3,
3694                 0xbd, 0xbf, 0xbc, 0xb4, 0xaa, 0xa1, 0x99, 0x94, 0x91, 0x90, 0x8f, 0x8e, 0x8b, 0x86, 0x7d, 0x73,
3695                 0x67, 0x5c, 0x55, 0x53, 0x56, 0x60, 0x6c, 0x7a, 0x87, 0x91, 0x97, 0x9a, 0x9b, 0x9b, 0x99, 0x95,
3696                 0x8b, 0x7c, 0x68, 0x52, 0x40, 0x33, 0x32, 0x3e, 0x54, 0x74, 0x96, 0xb4, 0xc8, 0xd4, 0xd8, 0xd6,
3697                 0xcf, 0xc4, 0xb9, 0xa7, 0x91, 0x76, 0x59, 0x40, 0x2f, 0x26, 0x29, 0x37, 0x4a, 0x62, 0x78, 0x88,
3698                 0x91, 0x94, 0x93, 0x91, 0x8e, 0x8d, 0x8c, 0x8c, 0x8a, 0x89, 0x87, 0x87, 0x88, 0x8a, 0x8e, 0x90,
3699                 0x90, 0x8d, 0x87, 0x7f, 0x76, 0x6e, 0x68, 0x66, 0x67, 0x6c, 0x76, 0x82, 0x90, 0x9f, 0xac, 0xb3,
3700                 0xb4, 0xad, 0x9e, 0x89, 0x72, 0x5b, 0x48, 0x3d, 0x35, 0x32, 0x36, 0x3e, 0x49, 0x5b, 0x73, 0x8f,
3701                 0xac, 0xc4, 0xd8, 0xe2, 0xe0, 0xd3, 0xc0, 0xa8, 0x8f, 0x7a, 0x6a, 0x61, 0x5b, 0x58, 0x56, 0x56,
3702                 0x58, 0x5e, 0x67, 0x72, 0x7e, 0x88, 0x8d, 0x8c, 0x87, 0x7e, 0x76, 0x71, 0x71, 0x74, 0x7b, 0x82,
3703                 0x87, 0x8a, 0x89, 0x87, 0x83, 0x7f, 0x7c, 0x7b, 0x7a, 0x7a, 0x7c, 0x80, 0x86, 0x8e, 0x98, 0xa2,
3704                 0xac, 0xb2, 0xb4, 0xb0, 0xa6, 0x98, 0x86, 0x71, 0x5c, 0x49, 0x3b, 0x2e, 0x28, 0x2a, 0x34, 0x43,
3705                 0x5a, 0x74, 0x8e, 0xa4, 0xb4, 0xbf, 0xc0, 0xc0, 0xbf, 0xb8, 0xaf, 0xa2, 0x94, 0x84, 0x75, 0x6a,
3706                 0x64, 0x63, 0x68, 0x70, 0x79, 0x80, 0x82, 0x80, 0x7c, 0x76, 0x71, 0x6e, 0x6e, 0x70, 0x73, 0x76,
3707                 0x78, 0x7a, 0x7c, 0x7f, 0x83, 0x87, 0x8b, 0x8c, 0x89, 0x83, 0x7a, 0x71, 0x6b, 0x68, 0x6b, 0x74,
3708                 0x80, 0x8e, 0x9c, 0xa9, 0xb2, 0xb8, 0xb9, 0xb6, 0xae, 0xa0, 0x8e, 0x79, 0x63, 0x4f, 0x40, 0x37,
3709                 0x33, 0x37, 0x40, 0x4e, 0x60, 0x74, 0x88, 0x9a, 0xa9, 0xb4, 0xb8, 0xb7, 0xb0, 0xa4, 0x96, 0x87,
3710                 0x7b, 0x73, 0x6e, 0x6d, 0x6e, 0x71, 0x74, 0x78, 0x7c, 0x81, 0x86, 0x8a, 0x8e, 0x8f, 0x8d, 0x89,
3711                 0x84, 0x7e, 0x7b, 0x7a, 0x7b, 0x7e, 0x81, 0x81, 0x7f, 0x7a, 0x72, 0x6b, 0x64, 0x60, 0x5f, 0x60,
3712                 0x64, 0x69, 0x70, 0x78, 0x83, 0x90, 0x9e, 0xac, 0xb8, 0xbf, 0xc0, 0xbb, 0xaf, 0xa0, 0x8e, 0x7c,
3713                 0x6c, 0x5e, 0x54, 0x4e, 0x4c, 0x4e, 0x55, 0x5e, 0x6a, 0x78, 0x84, 0x8e, 0x94, 0x96, 0x94, 0x8f,
3714                 0x89, 0x82, 0x7c, 0x77, 0x74, 0x72, 0x72, 0x75, 0x79, 0x7f, 0x86, 0x8d, 0x92, 0x95, 0x95, 0x93,
3715                 0x8f, 0x8b, 0x89, 0x87, 0x88, 0x89, 0x8a, 0x8a, 0x88, 0x85, 0x81, 0x7c, 0x77, 0x71, 0x6a, 0x63,
3716                 0x5b, 0x53, 0x4d, 0x4b, 0x4e, 0x56, 0x64, 0x76, 0x89, 0x9c, 0xac, 0xb8, 0xbf, 0xc0, 0xc0, 0xba,
3717                 0xb1, 0xa3, 0x94, 0x82, 0x71, 0x61, 0x56, 0x50, 0x50, 0x55, 0x5e, 0x69, 0x74, 0x7e, 0x86, 0x8c,
3718                 0x8e, 0x8f, 0x8d, 0x89, 0x83, 0x7c, 0x75, 0x6f, 0x6c, 0x6b, 0x6e, 0x73, 0x79, 0x80, 0x86, 0x8b,
3719                 0x8e, 0x90, 0x92, 0x92, 0x92, 0x92, 0x90, 0x8f, 0x8d, 0x8c, 0x8b, 0x8b, 0x8b, 0x8a, 0x88, 0x84,
3720                 0x7c, 0x73, 0x69, 0x60, 0x58, 0x54, 0x53, 0x55, 0x5a, 0x62, 0x6c, 0x77, 0x84, 0x91, 0x9e, 0xa8,
3721                 0xaf, 0xb2, 0xaf, 0xa8, 0x9d, 0x90, 0x83, 0x78, 0x70, 0x6a, 0x67, 0x67, 0x69, 0x6d, 0x73, 0x7a,
3722                 0x81, 0x88, 0x8e, 0x91, 0x91, 0x8f, 0x8a, 0x83, 0x7d, 0x77, 0x73, 0x70, 0x6f, 0x6f, 0x70, 0x71,
3723                 0x72, 0x74, 0x76, 0x79, 0x7c, 0x7e, 0x80, 0x82, 0x84, 0x86, 0x8a, 0x8f, 0x94, 0x9a, 0x9f, 0xa1,
3724                 0xa1, 0x9e, 0x99, 0x91, 0x88, 0x7d, 0x72, 0x68, 0x5e, 0x56, 0x51, 0x50, 0x54, 0x5c, 0x67, 0x74,
3725                 0x81, 0x8d, 0x96, 0x9c, 0x9e, 0x9d, 0x99, 0x93, 0x8c, 0x84, 0x7c, 0x75, 0x6f, 0x6c, 0x6c, 0x70,
3726                 0x77, 0x80, 0x8a, 0x92, 0x98, 0x9b, 0x9c, 0x99, 0x95, 0x8f, 0x89, 0x82, 0x7b, 0x74, 0x6e, 0x69,
3727                 0x65, 0x64, 0x65, 0x67, 0x6a, 0x6d, 0x70, 0x72, 0x74, 0x76, 0x78, 0x7c, 0x81, 0x87, 0x8e, 0x94,
3728                 0x9a, 0x9f, 0xa2, 0xa4, 0xa5, 0xa3, 0x9e, 0x97, 0x8e, 0x83, 0x77, 0x6c, 0x63, 0x5d, 0x5a, 0x5a,
3729                 0x5d, 0x63, 0x6a, 0x72, 0x7a, 0x82, 0x89, 0x8f, 0x92, 0x92, 0x8f, 0x89, 0x83, 0x7c, 0x77, 0x74,
3730                 0x73, 0x74, 0x77, 0x7c, 0x81, 0x86, 0x8b, 0x90, 0x94, 0x97, 0x98, 0x97, 0x94, 0x8f, 0x89, 0x83,
3731                 0x7d, 0x78, 0x75, 0x73, 0x71, 0x70, 0x6f, 0x6d, 0x6c, 0x6a, 0x6a, 0x6a, 0x6c, 0x6e, 0x72, 0x76,
3732                 0x7b, 0x81, 0x88, 0x8f, 0x96, 0x9d, 0xa2, 0xa4, 0xa3, 0x9f, 0x98, 0x90, 0x86, 0x7d, 0x75, 0x6e,
3733                 0x68, 0x65, 0x65, 0x67, 0x6c, 0x72, 0x7a, 0x82, 0x89, 0x8e, 0x91, 0x91, 0x8e, 0x89, 0x83, 0x7c,
3734                 0x76, 0x70, 0x6c, 0x6a, 0x69, 0x6b, 0x6f, 0x74, 0x7c, 0x83, 0x8a, 0x90, 0x94, 0x96, 0x96, 0x95,
3735                 0x92, 0x90, 0x8d, 0x8a, 0x88, 0x85, 0x82, 0x7f, 0x7d, 0x7b, 0x79, 0x77, 0x75, 0x72, 0x70, 0x6d,
3736                 0x6a, 0x69, 0x69, 0x6b, 0x70, 0x76, 0x7c, 0x83, 0x8a, 0x8f, 0x93, 0x96, 0x96, 0x95, 0x92, 0x8e,
3737                 0x88, 0x82, 0x7c, 0x77, 0x74, 0x73, 0x75, 0x78, 0x7d, 0x83, 0x88, 0x8c, 0x8f, 0x90, 0x90, 0x8d,
3738                 0x89, 0x84, 0x7d, 0x75, 0x6e, 0x68, 0x64, 0x62, 0x63, 0x66, 0x6a, 0x70, 0x76, 0x7c, 0x82, 0x87,
3739                 0x8c, 0x91, 0x94, 0x96, 0x97, 0x97, 0x96, 0x94, 0x92, 0x90, 0x8e, 0x8b, 0x88, 0x84, 0x7f, 0x7a,
3740                 0x74, 0x6f, 0x6a, 0x67, 0x66, 0x66, 0x68, 0x6b, 0x6f, 0x74, 0x7a, 0x80, 0x86, 0x8b, 0x8f, 0x91,
3741                 0x90, 0x8e, 0x8a, 0x85, 0x80, 0x7c, 0x7a, 0x78, 0x79, 0x7b, 0x7e, 0x82, 0x87, 0x8b, 0x90, 0x93,
3742                 0x95, 0x94, 0x91, 0x8d, 0x86, 0x7f, 0x78, 0x71, 0x6c, 0x68, 0x66, 0x66, 0x66, 0x65, 0x64, 0x68,
3743                 0x6d, 0x73, 0x78, 0x85, 0x95, 0x98, 0x9a, 0x9e, 0x9c, 0x95, 0x93, 0x91, 0xab, 0xab, 0x98, 0x82,
3744                 0x6d, 0x5d, 0x5c, 0x5b, 0x5f, 0x7c, 0x7a, 0x77, 0x6c, 0x6f, 0x8d, 0x99, 0x7f, 0x91, 0x9f, 0xad,
3745                 0xaa, 0x83, 0x5a, 0x49, 0x57, 0x58, 0x5b, 0x4a, 0x4a, 0x62, 0x76, 0x89, 0x9d, 0xa9, 0xb3, 0xa9,
3746                 0xaa, 0xaf, 0xad, 0xa7, 0xa1, 0x9e, 0x99, 0x8e, 0x81, 0x73, 0x68, 0x62, 0x62, 0x66, 0x6e, 0x76,
3747                 0x7e, 0x82, 0x81, 0x7c, 0x73, 0x68, 0x5d, 0x55, 0x52, 0x53, 0x59, 0x63, 0x6f, 0x7c, 0x88, 0x93,
3748                 0x9c, 0xa3, 0xa7, 0xa8, 0xa7, 0xa3, 0x9c, 0x93, 0x89, 0x7f, 0x75, 0x6d, 0x66, 0x62, 0x61, 0x64,
3749                 0x6a, 0x74, 0x82, 0x91, 0xa1, 0xb0, 0xbb, 0xc0, 0xbe, 0xb4, 0xa3, 0x8d, 0x75, 0x5f, 0x4c, 0x40,
3750                 0x3b, 0x3b, 0x40, 0x46, 0x51, 0x5c, 0x67, 0x72, 0x7d, 0x88, 0x94, 0xa0, 0xab, 0xb4, 0xb8, 0xb8,
3751                 0xb2, 0xa6, 0x97, 0x85, 0x75, 0x69, 0x62, 0x61, 0x66, 0x6f, 0x78, 0x81, 0x88, 0x8b, 0x8b, 0x89,
3752                 0x87, 0x85, 0x85, 0x86, 0x87, 0x87, 0x85, 0x81, 0x7a, 0x72, 0x6a, 0x65, 0x63, 0x65, 0x6b, 0x75,
3753                 0x80, 0x8c, 0x95, 0x9b, 0x9e, 0x9c, 0x96, 0x8c, 0x81, 0x75, 0x6a, 0x60, 0x59, 0x55, 0x55, 0x58,
3754                 0x5f, 0x68, 0x75, 0x83, 0x92, 0xa0, 0xad, 0xb8, 0xbf, 0xc0, 0xc0, 0xbb, 0xb1, 0xa4, 0x93, 0x81,
3755                 0x6f, 0x5e, 0x4f, 0x46, 0x42, 0x43, 0x4a, 0x56, 0x64, 0x71, 0x7d, 0x86, 0x8a, 0x8b, 0x88, 0x85,
3756                 0x81, 0x7f, 0x7e, 0x7f, 0x80, 0x82, 0x82, 0x82, 0x81, 0x80, 0x81, 0x84, 0x88, 0x8e, 0x95, 0x9b,
3757                 0x9e, 0x9e, 0x9a, 0x92, 0x89, 0x80, 0x77, 0x72, 0x70, 0x72, 0x76, 0x7c, 0x82, 0x87, 0x89, 0x88,
3758                 0x86, 0x82, 0x7d, 0x79, 0x75, 0x72, 0x6f, 0x6b, 0x67, 0x62, 0x5d, 0x58, 0x56, 0x56, 0x5b, 0x63,
3759                 0x6e, 0x7c, 0x8b, 0x9b, 0xa8, 0xb3, 0xbc, 0xc0, 0xc0, 0xbf, 0xb9, 0xaf, 0xa3, 0x95, 0x87, 0x78,
3760                 0x6c, 0x61, 0x5a, 0x56, 0x55, 0x56, 0x5a, 0x60, 0x68, 0x70, 0x78, 0x7f, 0x85, 0x89, 0x8b, 0x8a,
3761                 0x85, 0x7f, 0x76, 0x6e, 0x67, 0x63, 0x62, 0x66, 0x6f, 0x7a, 0x87, 0x94, 0x9f, 0xa7, 0xab, 0xab,
3762                 0xa8, 0xa3, 0x9b, 0x94, 0x8c, 0x84, 0x7d, 0x76, 0x6f, 0x6a, 0x66, 0x64, 0x66, 0x6b, 0x74, 0x7e,
3763                 0x89, 0x92, 0x98, 0x9a, 0x97, 0x8f, 0x85, 0x79, 0x6d, 0x63, 0x5c, 0x58, 0x57, 0x58, 0x5c, 0x62,
3764                 0x69, 0x72, 0x7b, 0x86, 0x90, 0x9b, 0xa5, 0xac, 0xb1, 0xb3, 0xb0, 0xaa, 0xa2, 0x97, 0x8b, 0x7f,
3765                 0x74, 0x6b, 0x65, 0x61, 0x5f, 0x60, 0x63, 0x68, 0x6e, 0x75, 0x7c, 0x83, 0x89, 0x8e, 0x90, 0x90,
3766                 0x8f, 0x8c, 0x88, 0x84, 0x7f, 0x7b, 0x78, 0x75, 0x72, 0x71, 0x70, 0x71, 0x74, 0x78, 0x7c, 0x81,
3767                 0x85, 0x88, 0x88, 0x87, 0x83, 0x7e, 0x7a, 0x76, 0x75, 0x77, 0x7b, 0x82, 0x89, 0x91, 0x97, 0x9c,
3768                 0x9f, 0xa0, 0x9e, 0x9c, 0x97, 0x91, 0x8a, 0x82, 0x79, 0x6f, 0x64, 0x5b, 0x53, 0x4f, 0x4e, 0x52,
3769                 0x59, 0x64, 0x71, 0x7e, 0x89, 0x92, 0x97, 0x9a, 0x99, 0x96, 0x92, 0x8d, 0x88, 0x84, 0x80, 0x7d,
3770                 0x7a, 0x79, 0x78, 0x79, 0x7c, 0x80, 0x85, 0x8b, 0x91, 0x95, 0x97, 0x98, 0x96, 0x92, 0x8d, 0x87,
3771                 0x81, 0x7b, 0x75, 0x70, 0x6c, 0x6a, 0x68, 0x69, 0x6a, 0x6d, 0x71, 0x75, 0x79, 0x7c, 0x7e, 0x7f,
3772                 0x7f, 0x7d, 0x7b, 0x79, 0x77, 0x76, 0x76, 0x76, 0x78, 0x7b, 0x7e, 0x83, 0x88, 0x8f, 0x96, 0x9e,
3773                 0xa6, 0xac, 0xb1, 0xb2, 0xaf, 0xa8, 0x9d, 0x90, 0x81, 0x73, 0x65, 0x5a, 0x52, 0x4d, 0x4a, 0x4b,
3774                 0x4e, 0x53, 0x5b, 0x64, 0x6e, 0x7a, 0x85, 0x90, 0x98, 0x9d, 0x9f, 0x9e, 0x99, 0x92, 0x8a, 0x82,
3775                 0x7c, 0x78, 0x76, 0x77, 0x7a, 0x7e, 0x83, 0x88, 0x8c, 0x90, 0x93, 0x94, 0x94, 0x93, 0x91, 0x8e,
3776                 0x89, 0x83, 0x7d, 0x77, 0x72, 0x6d, 0x6b, 0x6a, 0x6b, 0x6e, 0x71, 0x74, 0x77, 0x79, 0x7a, 0x7b,
3777                 0x7b, 0x7b, 0x7b, 0x7a, 0x7a, 0x79, 0x79, 0x79, 0x7a, 0x7c, 0x80, 0x84, 0x8a, 0x8f, 0x94, 0x98,
3778                 0x9b, 0x9c, 0x9b, 0x98, 0x95, 0x91, 0x8c, 0x86, 0x81, 0x7b, 0x75, 0x6f, 0x6a, 0x66, 0x64, 0x64,
3779                 0x66, 0x6a, 0x71, 0x78, 0x7f, 0x86, 0x8b, 0x8e, 0x8f, 0x8e, 0x8c, 0x89, 0x85, 0x81, 0x7e, 0x7a,
3780                 0x77, 0x75, 0x73, 0x71, 0x71, 0x73, 0x77, 0x7b, 0x81, 0x87, 0x8d, 0x90, 0x92, 0x92, 0x8f, 0x8c,
3781                 0x87, 0x83, 0x7f, 0x7d, 0x7c, 0x7c, 0x7d, 0x7f, 0x82, 0x84, 0x87, 0x89, 0x8b, 0x8b, 0x8b, 0x88,
3782                 0x85, 0x7f, 0x79, 0x72, 0x6a, 0x64, 0x5f, 0x5d, 0x5d, 0x60, 0x65, 0x6c, 0x74, 0x7e, 0x87, 0x8f,
3783                 0x97, 0x9c, 0xa0, 0xa2, 0xa1, 0x9e, 0x98, 0x92, 0x8a, 0x82, 0x7a, 0x74, 0x70, 0x6e, 0x6f, 0x71,
3784                 0x75, 0x79, 0x7e, 0x83, 0x87, 0x8a, 0x8d, 0x8f, 0x90, 0x8f, 0x8d, 0x89, 0x83, 0x7d, 0x75, 0x6e,
3785                 0x68, 0x63, 0x61, 0x61, 0x63, 0x66, 0x6b, 0x71, 0x77, 0x7d, 0x82, 0x87, 0x8c, 0x90, 0x93, 0x95,
3786                 0x96, 0x96, 0x95, 0x92, 0x90, 0x8d, 0x8a, 0x88, 0x88, 0x88, 0x89, 0x8a, 0x8b, 0x8a, 0x89, 0x86,
3787                 0x82, 0x7c, 0x76, 0x70, 0x6a, 0x65, 0x61, 0x5f, 0x5d, 0x5e, 0x60, 0x63, 0x69, 0x70, 0x79, 0x81,
3788                 0x8a, 0x91, 0x97, 0x9b, 0x9c, 0x9c, 0x99, 0x95, 0x91, 0x8c, 0x87, 0x83, 0x80, 0x7d, 0x7c, 0x7b,
3789                 0x7c, 0x7e, 0x81, 0x84, 0x86, 0x88, 0x89, 0x89, 0x87, 0x84, 0x80, 0x7c, 0x77, 0x73, 0x70, 0x6e,
3790                 0x6d, 0x6d, 0x6e, 0x6f, 0x71, 0x73, 0x76, 0x79, 0x7c, 0x7f, 0x82, 0x85, 0x87, 0x87, 0x87, 0x87,
3791                 0x85, 0x84, 0x84, 0x84, 0x85, 0x87, 0x89, 0x8c, 0x8e, 0x90, 0x91, 0x90, 0x8f, 0x8d, 0x8b, 0x88,
3792                 0x84, 0x80, 0x7b, 0x76, 0x70, 0x6b, 0x67, 0x64, 0x63, 0x64, 0x67, 0x6c, 0x72, 0x79, 0x80, 0x86,
3793                 0x8c, 0x90, 0x93, 0x94, 0x94, 0x92, 0x8f, 0x8a, 0x85, 0x7f, 0x7a, 0x74, 0x71, 0x6e, 0x6e, 0x70,
3794                 0x73, 0x79, 0x7f, 0x85, 0x8b, 0x90, 0x93, 0x95, 0x95, 0x94, 0x92, 0x8e, 0x89, 0x84, 0x7f, 0x79,
3795                 0x75, 0x71, 0x6f, 0x6e, 0x6f, 0x72, 0x75, 0x78, 0x7b, 0x7e, 0x7f, 0x80, 0x7f, 0x7e, 0x7d, 0x7c,
3796                 0x7a, 0x79, 0x79, 0x79, 0x7a, 0x7b, 0x7d, 0x7f, 0x82, 0x86, 0x89, 0x8d, 0x90, 0x93, 0x93, 0x93,
3797                 0x91, 0x8e, 0x89, 0x85, 0x80, 0x7c, 0x79, 0x77, 0x76, 0x75, 0x75, 0x76, 0x77, 0x79, 0x7b, 0x7d,
3798                 0x80, 0x82, 0x84, 0x85, 0x84, 0x83, 0x80, 0x7d, 0x79, 0x76, 0x72, 0x70, 0x6f, 0x6e, 0x6f, 0x72,
3799                 0x75, 0x78, 0x7d, 0x82, 0x87, 0x8c, 0x90, 0x94, 0x97, 0x99, 0x99, 0x98, 0x95, 0x92, 0x8d, 0x89,
3800                 0x85, 0x82, 0x7f, 0x7c, 0x7a, 0x78, 0x77, 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x70, 0x6f, 0x6e,
3801                 0x6d, 0x6d, 0x6e, 0x6f, 0x72, 0x75, 0x7a, 0x80, 0x86, 0x8c, 0x92, 0x96, 0x99, 0x9a, 0x9a, 0x98,
3802                 0x95, 0x92, 0x8d, 0x88, 0x83, 0x7f, 0x7a, 0x77, 0x74, 0x73, 0x74, 0x75, 0x78, 0x7c, 0x7f, 0x82,
3803                 0x85, 0x86, 0x86, 0x84, 0x82, 0x7f, 0x7b, 0x78, 0x74, 0x71, 0x6f, 0x6d, 0x6d, 0x6d, 0x6f, 0x72,
3804                 0x75, 0x7a, 0x7f, 0x85, 0x8a, 0x8e, 0x92, 0x94, 0x95, 0x95, 0x93, 0x91, 0x8e, 0x8b, 0x88, 0x85,
3805                 0x82, 0x80, 0x7e, 0x7c, 0x7b, 0x7a, 0x7a, 0x7b, 0x7c, 0x7c, 0x7d, 0x7c, 0x7c, 0x7a, 0x78, 0x76,
3806                 0x74, 0x73, 0x72, 0x72, 0x72, 0x74, 0x76, 0x79, 0x7c, 0x80, 0x84, 0x88, 0x8c, 0x8f, 0x91, 0x92,
3807                 0x91, 0x8f, 0x8c, 0x88, 0x83, 0x7f, 0x7b, 0x78, 0x76, 0x75, 0x76, 0x78, 0x7a, 0x7d, 0x80, 0x83,
3808                 0x86, 0x89, 0x8b, 0x8c, 0x8b, 0x8a, 0x88, 0x84, 0x80, 0x7c, 0x77, 0x74, 0x71, 0x6f, 0x6f, 0x70,
3809                 0x72, 0x74, 0x77, 0x7a, 0x7c, 0x7f, 0x81, 0x83, 0x84, 0x86, 0x86, 0x87, 0x86, 0x86, 0x85, 0x84,
3810                 0x84, 0x84, 0x84, 0x85, 0x85, 0x86, 0x87, 0x87, 0x87, 0x86, 0x85, 0x83, 0x82, 0x80, 0x7e, 0x7c,
3811                 0x7a, 0x79, 0x78, 0x77, 0x77, 0x77, 0x77, 0x79, 0x7a, 0x7c, 0x7e, 0x80, 0x81, 0x82, 0x82, 0x81,
3812                 0x7f, 0x7e, 0x7c, 0x7a, 0x79, 0x78, 0x77, 0x78, 0x79, 0x7a, 0x7d, 0x80, 0x84, 0x88, 0x8c, 0x90,
3813                 0x94, 0x96, 0x97, 0x97, 0x94, 0x91, 0x8d, 0x88, 0x82, 0x7d, 0x78, 0x74, 0x70, 0x6e, 0x6c, 0x6b,
3814                 0x6c, 0x6d, 0x6f, 0x72, 0x75, 0x78, 0x7b, 0x7d, 0x7f, 0x7f, 0x80, 0x7f, 0x7f, 0x7f, 0x7f, 0x80,
3815                 0x82, 0x84, 0x86, 0x88, 0x8b, 0x8d, 0x8f, 0x90, 0x90, 0x90, 0x8f, 0x8e, 0x8b, 0x88, 0x84, 0x80,
3816                 0x7b, 0x78, 0x74, 0x72, 0x71, 0x71, 0x72, 0x74, 0x76, 0x78, 0x7b, 0x7d, 0x7e, 0x80, 0x80, 0x81,
3817                 0x80, 0x7f, 0x7e, 0x7c, 0x7b, 0x79, 0x78, 0x77, 0x78, 0x79, 0x7b, 0x7e, 0x81, 0x85, 0x89, 0x8c,
3818                 0x8f, 0x91, 0x92, 0x93, 0x93, 0x91, 0x8f, 0x8c, 0x88, 0x84, 0x80, 0x7b, 0x77, 0x74, 0x71, 0x70,
3819                 0x70, 0x70, 0x71, 0x73, 0x75, 0x76, 0x78, 0x7a, 0x7b, 0x7d, 0x7e, 0x7f, 0x80, 0x80, 0x81, 0x81,
3820                 0x82, 0x82, 0x83, 0x84, 0x85, 0x87, 0x88, 0x89, 0x8a, 0x8a, 0x8a, 0x88, 0x86, 0x84, 0x82, 0x7f,
3821                 0x7d, 0x7c, 0x7a, 0x7a, 0x79, 0x7a, 0x7b, 0x7c, 0x7e, 0x80, 0x81, 0x83, 0x84, 0x85, 0x84, 0x83,
3822                 0x82, 0x7f, 0x7d, 0x7a, 0x77, 0x75, 0x74, 0x74, 0x74, 0x75, 0x77, 0x79, 0x7c, 0x7f, 0x82, 0x85,
3823                 0x87, 0x89, 0x8b, 0x8b, 0x8b, 0x8a, 0x89, 0x87, 0x85, 0x83, 0x81, 0x80, 0x7f, 0x7f, 0x7f, 0x7f,
3824                 0x7f, 0x7f, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7f, 0x7e, 0x7d, 0x7b, 0x7a, 0x78, 0x77, 0x77,
3825                 0x77, 0x77, 0x78, 0x7a, 0x7c, 0x7e, 0x7f, 0x81, 0x82, 0x83, 0x84, 0x84, 0x84, 0x84, 0x83, 0x83,
3826                 0x82, 0x81, 0x80, 0x80, 0x80, 0x81, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8b, 0x8c, 0x8c, 0x8a, 0x88,
3827                 0x86, 0x82, 0x7f, 0x7b, 0x77, 0x73, 0x6f, 0x6d, 0x6b, 0x6b, 0x6b, 0x6d, 0x70, 0x74, 0x78, 0x7c,
3828                 0x80, 0x84, 0x87, 0x89, 0x8b, 0x8c, 0x8c, 0x8c, 0x8b, 0x8a, 0x89, 0x87, 0x86, 0x85, 0x84, 0x83,
3829                 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x82, 0x81, 0x7f, 0x7e, 0x7c, 0x7a, 0x79, 0x77, 0x76, 0x76,
3830                 0x76, 0x76, 0x76, 0x77, 0x78, 0x79, 0x7b, 0x7c, 0x7e, 0x7f, 0x80, 0x81, 0x81, 0x82, 0x82, 0x81,
3831                 0x81, 0x82, 0x82, 0x83, 0x84, 0x85, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8b, 0x8b, 0x8a, 0x89, 0x88,
3832                 0x85, 0x83, 0x7f, 0x7c, 0x78, 0x75, 0x73, 0x71, 0x70, 0x6f, 0x70, 0x71, 0x73, 0x75, 0x78, 0x7a,
3833                 0x7d, 0x80, 0x82, 0x84, 0x86, 0x87, 0x87, 0x87, 0x87, 0x86, 0x85, 0x84, 0x84, 0x84, 0x84, 0x84,
3834                 0x84, 0x85, 0x85, 0x85, 0x85, 0x84, 0x83, 0x82, 0x81, 0x7f, 0x7e, 0x7c, 0x7b, 0x79, 0x79, 0x78,
3835                 0x78, 0x79, 0x7a, 0x7c, 0x7d, 0x7f, 0x80, 0x81, 0x82, 0x82, 0x82, 0x81, 0x80, 0x7e, 0x7d, 0x7c,
3836                 0x7a, 0x7a, 0x79, 0x7a, 0x7b, 0x7c, 0x7e, 0x80, 0x82, 0x85, 0x87, 0x8a, 0x8b, 0x8c, 0x8c, 0x8b,
3837                 0x8a, 0x88, 0x86, 0x83, 0x81, 0x7e, 0x7c, 0x7a, 0x79, 0x78, 0x77, 0x77, 0x78, 0x79, 0x7a, 0x7c,
3838                 0x7e, 0x7f, 0x80, 0x81, 0x81, 0x81, 0x80, 0x7f, 0x7e, 0x7d, 0x7d, 0x7c, 0x7c, 0x7c, 0x7c, 0x7d,
3839                 0x7e, 0x7f, 0x80, 0x82, 0x84, 0x85, 0x86, 0x87, 0x87, 0x87, 0x87, 0x86, 0x85, 0x84, 0x83, 0x82,
3840                 0x82, 0x81, 0x81, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x79, 0x78, 0x76,
3841                 0x75, 0x74, 0x74, 0x74, 0x75, 0x77, 0x79, 0x7c, 0x7f, 0x82, 0x85, 0x87, 0x89, 0x8b, 0x8c, 0x8d,
3842                 0x8d, 0x8c, 0x8b, 0x89, 0x87, 0x85, 0x83, 0x81, 0x80, 0x7f, 0x7e, 0x7d, 0x7d, 0x7d, 0x7d, 0x7d,
3843                 0x7d, 0x7c, 0x7c, 0x7c, 0x7b, 0x7a, 0x7a, 0x79, 0x79, 0x78, 0x78, 0x78, 0x79, 0x7a, 0x7b, 0x7c,
3844                 0x7e, 0x7f, 0x81, 0x83, 0x84, 0x85, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x85, 0x85,
3845                 0x85, 0x84, 0x84, 0x84, 0x84, 0x83, 0x83, 0x82, 0x81, 0x80, 0x7f, 0x7d, 0x7a, 0x78, 0x76, 0x74,
3846                 0x73, 0x72, 0x72, 0x72, 0x73, 0x75, 0x77, 0x7a, 0x7d, 0x80, 0x83, 0x86, 0x88, 0x8a, 0x8c, 0x8c,
3847                 0x8c, 0x8b, 0x8a, 0x88, 0x86, 0x84, 0x82, 0x80, 0x7f, 0x7e, 0x7e, 0x7d, 0x7d, 0x7e, 0x7e, 0x7f,
3848                 0x7f, 0x80, 0x80, 0x80, 0x7f, 0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x7a, 0x7a, 0x7a, 0x7b, 0x7c,
3849                 0x7d, 0x7e, 0x7f, 0x80, 0x80, 0x81, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x81, 0x81, 0x81, 0x81,
3850                 0x81, 0x82, 0x83, 0x83, 0x84, 0x85, 0x85, 0x85, 0x85, 0x85, 0x84, 0x83, 0x82, 0x80, 0x7e, 0x7d,
3851                 0x7b, 0x7a, 0x79, 0x78, 0x77, 0x77, 0x78, 0x79, 0x7a, 0x7c, 0x7d, 0x7f, 0x80, 0x81, 0x82, 0x82,
3852                 0x83, 0x83, 0x82, 0x82, 0x81, 0x81, 0x80, 0x80, 0x7f, 0x7f, 0x7f, 0x80, 0x81, 0x81, 0x82, 0x83,
3853                 0x84, 0x85, 0x85, 0x85, 0x85, 0x84, 0x83, 0x82, 0x81, 0x80, 0x7f, 0x7e, 0x7d, 0x7c, 0x7c, 0x7b,
3854                 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7a, 0x7a, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e,
3855                 0x80, 0x81, 0x83, 0x85, 0x87, 0x88, 0x8a, 0x8a, 0x8b, 0x8b, 0x8a, 0x89, 0x87, 0x85, 0x83, 0x81,
3856                 0x7f, 0x7d, 0x7b, 0x7a, 0x79, 0x79, 0x79, 0x79, 0x79, 0x7a, 0x7b, 0x7c, 0x7c, 0x7d, 0x7d, 0x7e,
3857                 0x7e, 0x7d, 0x7d, 0x7d, 0x7c, 0x7c, 0x7c, 0x7d, 0x7d, 0x7e, 0x7f, 0x81, 0x82, 0x84, 0x85, 0x86,
3858                 0x88, 0x88, 0x89, 0x89, 0x89, 0x88, 0x87, 0x86, 0x84, 0x82, 0x81, 0x7f, 0x7e, 0x7d, 0x7c, 0x7b,
3859                 0x7b, 0x7a, 0x7a, 0x7a, 0x7a, 0x7a, 0x7a, 0x79, 0x79, 0x79, 0x7a, 0x7a, 0x7a, 0x7b, 0x7b, 0x7c,
3860                 0x7e, 0x7f, 0x81, 0x83, 0x85, 0x87, 0x88, 0x89, 0x8a, 0x8a, 0x8a, 0x89, 0x88, 0x87, 0x85, 0x83,
3861                 0x81, 0x7f, 0x7d, 0x7c, 0x7b, 0x7a, 0x7a, 0x7a, 0x7a, 0x7b, 0x7c, 0x7d, 0x7d, 0x7e, 0x7f, 0x7f,
3862                 0x7f, 0x7f, 0x7e, 0x7e, 0x7e, 0x7d, 0x7d, 0x7d, 0x7d, 0x7d, 0x7e, 0x7e, 0x7f, 0x80, 0x81, 0x82,
3863                 0x83, 0x83, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x83, 0x83, 0x82, 0x82, 0x82, 0x81, 0x81, 0x81,
3864                 0x80, 0x80, 0x80, 0x7f, 0x7f, 0x7e, 0x7d, 0x7d, 0x7c, 0x7b, 0x7b, 0x7a, 0x7a, 0x7a, 0x7a, 0x7a,
3865                 0x7b, 0x7c, 0x7d, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x84, 0x85, 0x84, 0x84, 0x83, 0x83, 0x82,
3866                 0x81, 0x80, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x80, 0x81, 0x81, 0x82, 0x83, 0x83, 0x83, 0x83, 0x82,
3867                 0x82, 0x81, 0x80, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x79, 0x79, 0x7a, 0x7a, 0x7b, 0x7c, 0x7d,
3868                 0x7e, 0x7f, 0x80, 0x80, 0x81, 0x81, 0x82, 0x82, 0x82, 0x83, 0x83, 0x83, 0x84, 0x84, 0x85, 0x85,
3869                 0x86, 0x86, 0x86, 0x86, 0x85, 0x84, 0x83, 0x82, 0x80, 0x7e, 0x7d, 0x7b, 0x7a, 0x79, 0x78, 0x78,
3870                 0x78, 0x78, 0x78, 0x79, 0x7a, 0x7b, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x81, 0x82, 0x82, 0x82, 0x82,
3871                 0x82, 0x81, 0x81, 0x82, 0x82, 0x82, 0x83, 0x83, 0x84, 0x84, 0x85, 0x85, 0x86, 0x85, 0x85, 0x85,
3872                 0x84, 0x82, 0x81, 0x80, 0x7e, 0x7c, 0x7b, 0x7a, 0x79, 0x78, 0x78, 0x78, 0x78, 0x78, 0x79, 0x7a,
3873                 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x81, 0x82, 0x83, 0x83, 0x84, 0x85, 0x85, 0x86, 0x86,
3874                 0x86, 0x86, 0x86, 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, 0x7f, 0x7e, 0x7d, 0x7b, 0x7a, 0x7a, 0x79,
3875                 0x79, 0x7a, 0x7a, 0x7b, 0x7c, 0x7d, 0x7d, 0x7e, 0x7f, 0x7f, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7f,
3876                 0x7f, 0x7f, 0x7f, 0x7f, 0x80, 0x80, 0x81, 0x81, 0x82, 0x83, 0x84, 0x84, 0x85, 0x85, 0x85, 0x84,
3877                 0x84, 0x83, 0x82, 0x81, 0x80, 0x7f, 0x7f, 0x7e, 0x7d, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c,
3878                 0x7d, 0x7d, 0x7d, 0x7d, 0x7d, 0x7d, 0x7d, 0x7e, 0x7e, 0x7e, 0x7f, 0x7f, 0x80, 0x80, 0x81, 0x82,
3879                 0x83, 0x83, 0x84, 0x84, 0x84, 0x84, 0x84, 0x83, 0x83, 0x82, 0x81, 0x80, 0x7f, 0x7f, 0x7e, 0x7e,
3880                 0x7e, 0x7e, 0x7e, 0x7e, 0x7f, 0x7f, 0x80, 0x80, 0x80, 0x81, 0x80, 0x80, 0x7f, 0x7f, 0x7e, 0x7d,
3881                 0x7c, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7c, 0x7c, 0x7d, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85,
3882                 0x85, 0x85, 0x85, 0x85, 0x85, 0x84, 0x83, 0x83, 0x82, 0x82, 0x81, 0x81, 0x80, 0x80, 0x7f, 0x7f,
3883                 0x7e, 0x7d, 0x7d, 0x7c, 0x7c, 0x7b, 0x7b, 0x7b, 0x7a, 0x7a, 0x7b, 0x7b, 0x7b, 0x7c, 0x7d, 0x7e,
3884                 0x7f, 0x80, 0x81, 0x82, 0x82, 0x83, 0x83, 0x84, 0x84, 0x84, 0x84, 0x83, 0x83, 0x83, 0x83, 0x82,
3885                 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x81, 0x81, 0x80, 0x80, 0x7f, 0x7e, 0x7d, 0x7c, 0x7b,
3886                 0x7a, 0x79, 0x79, 0x79, 0x79, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x80, 0x81, 0x82, 0x83, 0x84,
3887                 0x84, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x84, 0x84, 0x83, 0x83, 0x83, 0x82, 0x82, 0x81, 0x80,
3888                 0x80, 0x7f, 0x7e, 0x7d, 0x7c, 0x7c, 0x7b, 0x7a, 0x7a, 0x7a, 0x7a, 0x7a, 0x7b, 0x7c, 0x7c, 0x7d,
3889                 0x7e, 0x7f, 0x80, 0x81, 0x81, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x81, 0x81, 0x81, 0x81,
3890                 0x81, 0x81, 0x82, 0x82, 0x82, 0x82, 0x83, 0x83, 0x83, 0x82, 0x82, 0x81, 0x80, 0x80, 0x7f, 0x7e,
3891                 0x7d, 0x7c, 0x7b, 0x7b, 0x7a, 0x7a, 0x7b, 0x7b, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x80, 0x81,
3892                 0x81, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82,
3893                 0x81, 0x81, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
3894                 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
3895                 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
3896                 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
3897                 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
3898                 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
3899                 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
3900                 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
3901                 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
3902                 0x80, 0x80, 0x80, 0x80, 0x81, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
3903             };
3904 
3905         snd.Create( sizeof( goodsound ), goodsound );
3906     }
3907     else
3908     { //error wav
3909         static const unsigned char badsound[] =
3910             {
3911 
3912                 0x52, 0x49, 0x46, 0x46, 0x83, 0x05, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20,
3913                 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x40, 0x1f, 0x00, 0x00, 0x40, 0x1f, 0x00, 0x00,
3914                 0x01, 0x00, 0x08, 0x00, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x05, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80,
3915                 0x85, 0x82, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7f, 0x77, 0x7e, 0x81, 0x8a, 0x89, 0x67, 0x6c, 0x79,
3916                 0x80, 0x82, 0x87, 0x80, 0x80, 0x97, 0x7c, 0x7f, 0x93, 0xa2, 0xa8, 0xaa, 0x89, 0x68, 0x4c, 0x3f,
3917                 0x3f, 0x3b, 0x3f, 0x6d, 0x97, 0xbe, 0xe5, 0xf1, 0xb8, 0x80, 0x58, 0x33, 0x2b, 0x65, 0x8f, 0xb0,
3918                 0xc1, 0xd1, 0xb0, 0x7a, 0x4e, 0x2f, 0x0f, 0x2f, 0x6f, 0x96, 0xb8, 0xd9, 0xc1, 0x88, 0x5c, 0x37,
3919                 0x13, 0x37, 0x77, 0xa4, 0xc5, 0xe1, 0xc9, 0x8d, 0x60, 0x3f, 0x23, 0x3b, 0x76, 0xa4, 0xc5, 0xe1,
3920                 0xdd, 0x9a, 0x6b, 0x3b, 0x13, 0x3b, 0x79, 0xa6, 0xcd, 0xdd, 0xb4, 0x77, 0x33, 0x1f, 0x48, 0x7d,
3921                 0xa6, 0xcd, 0xd1, 0x9c, 0x6c, 0x44, 0x23, 0x2b, 0x60, 0x92, 0xc5, 0xe1, 0xb6, 0x7c, 0x44, 0x23,
3922                 0x44, 0x7c, 0xa6, 0xc9, 0xd9, 0xa8, 0x78, 0x4e, 0x2b, 0x1f, 0x4a, 0x80, 0xac, 0xd5, 0xd1, 0x96,
3923                 0x6d, 0x48, 0x27, 0x3b, 0x73, 0x98, 0xc5, 0xe5, 0xc1, 0x87, 0x5c, 0x37, 0x1f, 0x48, 0x80, 0xb0,
3924                 0xcd, 0xc1, 0x8f, 0x68, 0x46, 0x37, 0x44, 0x71, 0x9c, 0xc9, 0xcd, 0xb2, 0x85, 0x5c, 0x42, 0x4e,
3925                 0x68, 0x8b, 0xb0, 0xb8, 0xa4, 0x87, 0x65, 0x48, 0x4a, 0x67, 0x85, 0xa2, 0xba, 0xb4, 0x93, 0x74,
3926                 0x54, 0x3f, 0x3f, 0x56, 0x78, 0x95, 0xb2, 0xac, 0x92, 0x7f, 0x68, 0x5c, 0x6a, 0x79, 0x81, 0x90,
3927                 0xa4, 0x90, 0x75, 0x58, 0x5e, 0x80, 0x91, 0x94, 0x81, 0x60, 0x58, 0x69, 0x79, 0x85, 0x92, 0xa6,
3928                 0xa4, 0x80, 0x5c, 0x44, 0x2f, 0x42, 0x76, 0x98, 0xbc, 0xd1, 0xb6, 0x84, 0x5c, 0x44, 0x3f, 0x4c,
3929                 0x78, 0xa0, 0xc1, 0xd1, 0xc9, 0x98, 0x6d, 0x46, 0x33, 0x33, 0x5c, 0x8d, 0xb6, 0xd1, 0xbe, 0x8f,
3930                 0x65, 0x3f, 0x3b, 0x4c, 0x6e, 0x8f, 0xb6, 0xc9, 0xbc, 0x8f, 0x72, 0x50, 0x3f, 0x52, 0x77, 0x8f,
3931                 0xb2, 0xc5, 0xc5, 0x98, 0x70, 0x52, 0x3b, 0x2f, 0x54, 0x7d, 0x97, 0xb8, 0xd1, 0xd1, 0xa8, 0x87,
3932                 0x60, 0x42, 0x3f, 0x50, 0x54, 0x64, 0x90, 0xb4, 0x97, 0xa6, 0xa0, 0x73, 0x6b, 0x80, 0x6e, 0x5e,
3933                 0x7d, 0xa2, 0x8f, 0x91, 0xa8, 0x7c, 0x54, 0x6c, 0x71, 0x6e, 0x7f, 0x98, 0x90, 0x7f, 0x8a, 0x7c,
3934                 0x54, 0x48, 0x3f, 0x50, 0x6d, 0x91, 0xb4, 0xa6, 0x91, 0x7e, 0x66, 0x58, 0x4c, 0x52, 0x7c, 0x9c,
3935                 0xbe, 0xd5, 0xd9, 0xc5, 0x92, 0x6d, 0x46, 0x2f, 0x37, 0x5e, 0x82, 0xac, 0xbc, 0xa4, 0x83, 0x6b,
3936                 0x4a, 0x44, 0x60, 0x82, 0xa2, 0xba, 0xc5, 0xbc, 0x97, 0x78, 0x56, 0x3f, 0x2f, 0x3b, 0x5e, 0x8c,
3937                 0xb2, 0xc9, 0xc9, 0xb6, 0x8a, 0x6a, 0x4e, 0x3b, 0x3f, 0x6c, 0x93, 0xb6, 0xcd, 0xd1, 0xb4, 0x85,
3938                 0x60, 0x48, 0x33, 0x3f, 0x67, 0x8c, 0xaa, 0xc1, 0xb6, 0x8f, 0x70, 0x56, 0x4c, 0x66, 0x86, 0xa4,
3939                 0xae, 0xb4, 0xac, 0x8b, 0x73, 0x52, 0x3f, 0x42, 0x65, 0x86, 0x9c, 0xa6, 0xa4, 0x88, 0x73, 0x64,
3940                 0x54, 0x5c, 0x76, 0x8c, 0xa0, 0xac, 0xa4, 0x96, 0x89, 0x7f, 0x75, 0x77, 0x83, 0x8f, 0x8f, 0x8e,
3941                 0x84, 0x70, 0x5c, 0x56, 0x56, 0x68, 0x7c, 0x93, 0xac, 0xb0, 0xac, 0x8f, 0x75, 0x60, 0x58, 0x65,
3942                 0x76, 0x82, 0x8f, 0x98, 0x93, 0x85, 0x7a, 0x6e, 0x66, 0x73, 0x83, 0x8f, 0x97, 0x9c, 0x8e, 0x7a,
3943                 0x6b, 0x60, 0x5a, 0x6e, 0x82, 0x91, 0xa2, 0xae, 0xa0, 0x83, 0x74, 0x74, 0x73, 0x7e, 0x8d, 0x91,
3944                 0x97, 0x9b, 0x8e, 0x7b, 0x5c, 0x56, 0x6a, 0x7b, 0x90, 0x95, 0x91, 0x8f, 0x89, 0x7e, 0x70, 0x71,
3945                 0x7b, 0x83, 0x90, 0x98, 0xa2, 0x8f, 0x7e, 0x79, 0x76, 0x7a, 0x80, 0x87, 0x92, 0x92, 0x93, 0x90,
3946                 0x7f, 0x73, 0x72, 0x71, 0x6e, 0x7e, 0x85, 0x8f, 0x8e, 0x8c, 0x84, 0x75, 0x73, 0x79, 0x80, 0x8a,
3947                 0x90, 0x9c, 0xa6, 0x98, 0x8e, 0x80, 0x73, 0x6d, 0x67, 0x6c, 0x76, 0x7f, 0x8b, 0x92, 0x8f, 0x92,
3948                 0x91, 0x85, 0x80, 0x7c, 0x76, 0x79, 0x7e, 0x83, 0x86, 0x81, 0x84, 0x80, 0x75, 0x72, 0x6f, 0x71,
3949                 0x77, 0x83, 0x8f, 0x98, 0x98, 0x90, 0x8a, 0x80, 0x7e, 0x80, 0x84, 0x84, 0x8a, 0x8e, 0x8a, 0x82,
3950                 0x77, 0x74, 0x71, 0x78, 0x81, 0x81, 0x83, 0x8a, 0x8f, 0x86, 0x80, 0x7c, 0x75, 0x75, 0x80, 0x87,
3951                 0x89, 0x8d, 0x8f, 0x8b, 0x7e, 0x7f, 0x7e, 0x7e, 0x85, 0x89, 0x8b, 0x8f, 0x8f, 0x8e, 0x86, 0x7e,
3952                 0x75, 0x74, 0x7b, 0x80, 0x7c, 0x7d, 0x80, 0x80, 0x83, 0x8c, 0x8f, 0x8f, 0x91, 0x98, 0x97, 0x92,
3953                 0x8f, 0x8d, 0x8b, 0x8c, 0x8d, 0x84, 0x81, 0x81, 0x7c, 0x73, 0x71, 0x71, 0x72, 0x7f, 0x87, 0x8a,
3954                 0x89, 0x8f, 0x8e, 0x84, 0x80, 0x82, 0x80, 0x82, 0x8c, 0x8c, 0x88, 0x8d, 0x93, 0x88, 0x80, 0x80,
3955                 0x7f, 0x7a, 0x80, 0x85, 0x80, 0x80, 0x87, 0x82, 0x7e, 0x80, 0x80, 0x7d, 0x7d, 0x80, 0x80, 0x80,
3956                 0x88, 0x8b, 0x8b, 0x8e, 0x90, 0x88, 0x84, 0x82, 0x7e, 0x80, 0x81, 0x83, 0x84, 0x82, 0x83, 0x80,
3957                 0x76, 0x75, 0x70, 0x73, 0x80, 0x82, 0x86, 0x8e, 0x8b, 0x86, 0x80, 0x7e, 0x78, 0x75, 0x7d, 0x83,
3958                 0x84, 0x8d, 0x8f, 0x89, 0x84, 0x80, 0x7f, 0x7c, 0x7e, 0x82, 0x85, 0x89, 0x8b, 0x85, 0x7f, 0x7b,
3959                 0x7b, 0x7f, 0x83, 0x8a, 0x8f, 0x8f, 0x8f, 0x8a, 0x80, 0x7c, 0x75, 0x76, 0x7a, 0x80, 0x86, 0x88,
3960                 0x8c, 0x8a, 0x83, 0x80, 0x7f, 0x7c, 0x80, 0x85, 0x87, 0x8a, 0x8e, 0x8e, 0x87, 0x84, 0x83, 0x82,
3961                 0x83, 0x87, 0x8d, 0x8a, 0x8b, 0x89, 0x81, 0x7b, 0x77, 0x7a, 0x7f, 0x83, 0x8e, 0x8f, 0x8d, 0x8c,
3962                 0x89, 0x81, 0x81, 0x81, 0x85, 0x8a, 0x8d, 0x8f, 0x90, 0x8d, 0x8c, 0x87, 0x83, 0x83, 0x82, 0x82,
3963                 0x82, 0x84, 0x82, 0x80, 0x7a, 0x7b, 0x7b, 0x7f, 0x82, 0x88, 0x8b, 0x8f, 0x90, 0x8c, 0x87, 0x80,
3964                 0x7e, 0x7e, 0x80, 0x80, 0x83, 0x85, 0x88, 0x8a, 0x88, 0x85, 0x82, 0x7f, 0x7d, 0x7a, 0x7a, 0x7e,
3965                 0x80, 0x84, 0x88, 0x89, 0x8d, 0x8c, 0x88, 0x84, 0x80, 0x7f, 0x7e, 0x7f, 0x80, 0x84, 0x86, 0x89,
3966                 0x87, 0x85, 0x81, 0x80, 0x80, 0x80, 0x80, 0x7f, 0x80, 0x80, 0x80, 0x81, 0x84, 0x88, 0x89, 0x89,
3967                 0x89, 0x85, 0x80, 0x7f, 0x7d, 0x79, 0x76, 0x79, 0x7e, 0x80, 0x81, 0x83, 0x83, 0x82, 0x82, 0x81,
3968                 0x80, 0x82, 0x86, 0x88, 0x87, 0x86, 0x82, 0x80, 0x7d, 0x7e, 0x7c, 0x7e, 0x81, 0x87, 0x89, 0x89,
3969                 0x86, 0x81, 0x7f, 0x7e, 0x7e, 0x7f, 0x81, 0x85, 0x89, 0x8c, 0x8b, 0x87, 0x83, 0x80, 0x80, 0x80,
3970                 0x80, 0x80, 0x82, 0x83, 0x83, 0x83, 0x83, 0x82, 0x84, 0x84, 0x86, 0x87, 0x88, 0x89, 0x87, 0x86,
3971                 0x85, 0x83, 0x82, 0x82, 0x81, 0x80, 0x80, 0x80, 0x80, 0x7f, 0x80, 0x80, 0x83, 0x85, 0x88, 0x89,
3972                 0x86, 0x85, 0x84, 0x83, 0x84, 0x86, 0x86, 0x87, 0x88, 0x88, 0x86, 0x83, 0x82, 0x80, 0x80, 0x7f,
3973                 0x7d, 0x7d, 0x7a, 0x78, 0x79, 0x7a, 0x7b, 0x7f, 0x80, 0x83, 0x85, 0x86, 0x88, 0x85, 0x84, 0x84,
3974                 0x82, 0x84, 0x84, 0x83, 0x81, 0x80, 0x7f, 0x7e, 0x7c, 0x7d, 0x7d, 0x7d, 0x7f, 0x80, 0x80, 0x83,
3975                 0x86, 0x84, 0x82, 0x81, 0x80, 0x7c, 0x79, 0x79, 0x76, 0x7a, 0x7f, 0x80, 0x81, 0x82, 0x82, 0x80,
3976                 0x7f, 0x80, 0x80, 0x80, 0x83, 0x84, 0x85, 0x85, 0x85, 0x81, 0x80, 0x80, 0x7e, 0x7d, 0x7d, 0x7f,
3977                 0x7f, 0x7f, 0x80, 0x80, 0x80, 0x81, 0x83, 0x80, 0x80, 0x80, 0x80, 0x7d, 0x7c, 0x7e, 0x7f, 0x80,
3978                 0x84, 0x86, 0x86, 0x85, 0x83, 0x80, 0x7e, 0x7e, 0x7e, 0x7f, 0x80, 0x84, 0x85, 0x85, 0x84, 0x83,
3979                 0x82, 0x81, 0x81, 0x80, 0x82, 0x84, 0x84, 0x83, 0x83, 0x80, 0x80, 0x7f, 0x7e, 0x81, 0x81, 0x84,
3980                 0x88, 0x86, 0x85, 0x81, 0x80, 0x7e, 0x7f, 0x7f, 0x80, 0x84, 0x87, 0x87, 0x87, 0x84, 0x82, 0x80,
3981                 0x80, 0x80, 0x81, 0x83, 0x86, 0x85, 0x84, 0x83, 0x80, 0x7e, 0x7c, 0x7c, 0x7d, 0x80, 0x80, 0x82,
3982                 0x84, 0x85, 0x85, 0x85, 0x85, 0x84, 0x84, 0x82, 0x82, 0x80, 0x7f, 0x7e, 0x7a, 0x79, 0x7a, 0x7a,
3983                 0x7b, 0x7f, 0x80, 0x81, 0x81, 0x81, 0x82, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7f, 0x7e,
3984                 0x7e, 0x7c, 0x7c, 0x7c, 0x7d, 0x7f, 0x80, 0x80, 0x81, 0x81, 0x81, 0x80, 0x7e, 0x7d, 0x7a, 0x79,
3985                 0x79, 0x79, 0x7b, 0x7c, 0x7e, 0x80, 0x80, 0x7f, 0x7d, 0x7e, 0x7e, 0x7e, 0x7e, 0x7f, 0x80, 0x80,
3986                 0x7f, 0x7e, 0x7b, 0x7a, 0x7a, 0x7c, 0x7d, 0x7f, 0x7f, 0x7f, 0x80, 0x80, 0x7d, 0x7c, 0x7c, 0x7c,
3987                 0x7d, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
3988                 0x80, 0x80, 0x80, 0x81, 0x83, 0x82, 0x83, 0x81, 0x80, 0x7f, 0x7d, 0x7c, 0x7c, 0x7f, 0x80, 0x82,
3989                 0x85, 0x85, 0x84, 0x82, 0x81, 0x80, 0x80, 0x80, 0x80, 0x81, 0x82, 0x83, 0x84, 0x83, 0x82, 0x81,
3990                 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x81, 0x81, 0x81, 0x83, 0x84, 0x84, 0x85, 0x85, 0x84, 0x82,
3991                 0x81, 0x80, 0x80, 0x7f, 0x80, 0x80, 0x80, 0x81, 0x82, 0x83, 0x83, 0x83, 0x81, 0x81, 0x81, 0x81,
3992                 0x81, 0x82, 0x83, 0x83, 0x83, 0x83, 0x82, 0x80, 0x81, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
3993                 0x80, 0x80, 0x7f, 0x7f, 0x7f, 0x80, 0x81, 0x82, 0x80, 0x81, 0x82, 0x81, 0x80, 0x80, 0x7f, 0x7f,
3994                 0x7e, 0x7f, 0x7f, 0x80, 0x7f, 0x80, 0x7e, 0x7d, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x80, 0x80, 0x80,
3995                 0x80, 0x7e, 0x7e, 0x7e, 0x7f, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7e, 0x7c, 0x7a, 0x79, 0x7a, 0x7c,
3996                 0x7e, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7e, 0x7d, 0x7d, 0x7e, 0x7f, 0x7f, 0x80, 0x80, 0x7f, 0x7e,
3997                 0x7e, 0x7e, 0x7e, 0x7f, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7f, 0x7f, 0x80, 0x80, 0x80, 0x80, 0x80,
3998                 0x80, 0x80, 0x7f, 0x7f, 0x7e, 0x7f, 0x7f, 0x7f, 0x7f, 0x80, 0x80, 0x7f, 0x7f, 0x80, 0x80, 0x80,
3999                 0x81, 0x81, 0x81, 0x81, 0x81, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x81, 0x82, 0x81, 0x81, 0x80,
4000                 0x80, 0x80, 0x80, 0x80, 0x81, 0x81, 0x83, 0x82, 0x83, 0x82, 0x81,
4001             };
4002 
4003         snd.Create( sizeof( badsound ), badsound );
4004     }
4005 
4006 #endif
4007 }
4008 
4009 //file have moved to dest
FileMd5(_TaskAttr & task)4010 void MainFrame::FileMd5( _TaskAttr& task )
4011 {
4012     CFileMd5 * t = new CFileMd5( task );
4013     t->Create();
4014     t->SetPriority( 20 );
4015     t->Run();
4016 }
4017 
4018 //
RecordSavePath(std::string path)4019 void MainFrame::RecordSavePath( std::string path )
4020 {
4021 
4022     std::list<std::string>::iterator it;
4023 
4024     for ( it = gSavePathHistory.begin();it != gSavePathHistory.end();it++ )
4025     {
4026         if ( *it == path )
4027         {
4028             std::string s1 = gSavePathHistory.front();
4029             std::string s2 = *it;
4030             *it = s1;
4031             gSavePathHistory.pop_front();
4032             gSavePathHistory.push_front( s2 );
4033             return ;
4034         }
4035     }
4036 
4037     gSavePathHistory.push_front( path );
4038 
4039     if ( gSavePathHistory.size() > 10 )
4040         gSavePathHistory.pop_back();
4041 
4042 }
4043 
4044 /*
4045 void MainFrame::OnDestroy( wxWindowDestroyEvent& event )
4046 {
4047     DBGOUT( "destory event" );
4048 }
4049 */
ReadConfig()4050 bool MainFrame::ReadConfig()
4051 {
4052 
4053 
4054     //记录格式采用2进制格式 v1.0
4055     //文件头+数据+文件尾
4056     //文件头:版本[4]+文件头长度[4]+数据全长[4]
4057     //数据:gRunTaskNum[4]+gTaskDefThread[4]+gRetryTime[4]+gRetryWait[4]+
4058     //gConnectTimeOut[4]+gReceiveTimeOut[4]+gbIgnoreExt[4]+gbMonitorExt[4]+
4059     //gbMonitorClip[4]+gbShowDropWin[4]+gDropWinX[4]+gDropWinY[4]+gSpeedMode[4]+hissize[4]+
4060     //gDefSavePath[v]+gDefFtpPass[v]+gsMonitorExt[v]+gsIgnoreExt[v]+
4061     //gSavePathHistory[0][v]+gSavePathHistory[1][v]...gSavePathHistory[9][v]
4062     //文件尾:0xFFEE[4]
4063 
4064 
4065     //记录格式采用2进制格式 v2.0
4066     //文件头+数据+文件尾
4067     //文件头:版本[4]+文件头长度[4]+数据全长[4]
4068     //数据:gRunTaskNum[4]+gTaskDefThread[4]+gRetryTime[4]+gRetryWait[4]+
4069     //gConnectTimeOut[4]+gReceiveTimeOut[4]+gbIgnoreExt[4]+gbMonitorExt[4]+
4070     //gbMonitorClip[4]+gbShowDropWin[4]+gbSoundTip[4]+gDropWinX[4]+gDropWinY[4]+gSpeedMode[4]+hissize[4]+
4071     //gDefSavePath[v]+gDefFtpPass[v]+gsMonitorExt[v]+gsIgnoreExt[v]+
4072     //gSavePathHistory[0][v]+gSavePathHistory[1][v]...gSavePathHistory[9][v]
4073     //文件尾:0xFFEE[4]
4074 
4075 
4076     //记录格式采用2进制格式 v3.0
4077     //文件头+数据+文件尾
4078     //文件头:版本[4]+文件头长度[4]+数据全长[4]
4079     //数据:gRunTaskNum[4]+gTaskDefThread[4]+gRetryTime[4]+gRetryWait[4]+
4080     //gConnectTimeOut[4]+gReceiveTimeOut[4]+gbIgnoreExt[4]+gbMonitorExt[4]+gbAutoMd5[4]+
4081     //gbMonitorClip[4]+gbShowDropWin[4]+gbSoundTip[4]+gDropWinX[4]+gDropWinY[4]+gSpeedMode[4]+hissize[4]+
4082     //gDefSavePath[v]+gDefFtpPass[v]+gsMonitorExt[v]+gsIgnoreExt[v]+
4083     //gSavePathHistory[0][v]+gSavePathHistory[1][v]...gSavePathHistory[9][v]
4084     //文件尾:0x00EE[4]
4085 
4086     FILE * fp;
4087 
4088     std::string temp;
4089 
4090     if ( !GetTempDir( temp ) )
4091     {
4092         return false;
4093     }
4094 
4095     temp += "/config.db";
4096 
4097     fp = fopen( temp.c_str(), "rb" );
4098 
4099     if ( fp == NULL )
4100     {
4101 
4102         return false;
4103     }
4104 
4105 
4106     struct _fh
4107     {
4108         int ver; //当前版本1.0
4109         int headlen; //4*3=12
4110         int datalen; //后确定
4111 
4112     }
4113 
4114     fh;
4115 
4116     fseek( fp, 0, SEEK_SET );
4117 
4118     if ( 1 != fread( &fh, sizeof( fh ), 1, fp ) )
4119     {
4120         fclose( fp );
4121         return false;
4122     }
4123 
4124     if ( fh.headlen != sizeof( fh ) )
4125     {
4126         fclose( fp );
4127         return false;
4128     }
4129 
4130     if ( fh.ver <= 0 || fh.ver > 3 || fh.datalen <= 0 )
4131     {
4132         fclose( fp );
4133         return false;
4134     }
4135 
4136     fseek( fp, fh.headlen, SEEK_SET ); //moveto data
4137     char *buf = new char[ fh.datalen ]; //完整读到内存中处理
4138 
4139     if ( 1 != fread( buf, fh.datalen, 1, fp ) )
4140     {
4141         delete[] buf;
4142         return false;
4143     }
4144 
4145     fclose( fp );
4146 
4147     int movepos = 0;
4148 
4149     memcpy( &gRunTaskNum, buf + movepos, sizeof( gRunTaskNum ) );
4150     movepos += sizeof( gRunTaskNum );
4151 
4152     memcpy( &gTaskDefThread, buf + movepos, sizeof( gTaskDefThread ) );
4153     movepos += sizeof( gTaskDefThread );
4154 
4155     memcpy( &gRetryTime, buf + movepos, sizeof( gRetryTime ) );
4156     movepos += sizeof( gRetryTime );
4157 
4158     memcpy( &gRetryWait, buf + movepos, sizeof( gRetryWait ) );
4159     movepos += sizeof( gRetryWait );
4160 
4161     memcpy( &gConnectTimeOut, buf + movepos, sizeof( gConnectTimeOut ) );
4162     movepos += sizeof( gConnectTimeOut );
4163 
4164     memcpy( &gReceiveTimeOut, buf + movepos, sizeof( gReceiveTimeOut ) );
4165     movepos += sizeof( gReceiveTimeOut );
4166 
4167     memcpy( &gbIgnoreExt, buf + movepos, sizeof( gbIgnoreExt ) );
4168     movepos += sizeof( gbIgnoreExt );
4169 
4170     memcpy( &gbMonitorExt, buf + movepos, sizeof( gbMonitorExt ) );
4171     movepos += sizeof( gbMonitorExt );
4172 
4173     if ( fh.ver >= 3 )
4174     {
4175         memcpy( &gbAutoMd5, buf + movepos, sizeof( gbAutoMd5 ) );
4176         movepos += sizeof( gbAutoMd5 );
4177     }
4178     else
4179     {
4180         gbAutoMd5 = true;
4181     }
4182 
4183     memcpy( &gbMonitorClip, buf + movepos, sizeof( gbMonitorClip ) );
4184     movepos += sizeof( gbMonitorClip );
4185 
4186     memcpy( &gbShowDropWin, buf + movepos, sizeof( gbShowDropWin ) );
4187     movepos += sizeof( gbShowDropWin );
4188 
4189     if ( fh.ver >= 2 )
4190     {
4191         memcpy( &gbSoundTip, buf + movepos, sizeof( gbSoundTip ) );
4192         movepos += sizeof( gbSoundTip );
4193     }
4194     else
4195     {
4196         gbSoundTip = true;
4197     }
4198 
4199     memcpy( &gDropWinX, buf + movepos, sizeof( gDropWinX ) );
4200     movepos += sizeof( gDropWinX );
4201 
4202     memcpy( &gDropWinY, buf + movepos, sizeof( gDropWinY ) );
4203     movepos += sizeof( gDropWinY );
4204 
4205     memcpy( &gSpeedMode, buf + movepos, sizeof( gSpeedMode ) );
4206     movepos += sizeof( gSpeedMode );
4207 
4208     int hissize;
4209     memcpy( &hissize, buf + movepos, sizeof( int ) );
4210     movepos += sizeof( int );
4211 
4212     if ( hissize < 0 || hissize > 10 )
4213     {
4214         delete[] buf;
4215         return false;
4216     }
4217 
4218     //strings
4219     char strbuf[ 512 ];
4220 
4221     strcpy( strbuf, buf + movepos );
4222 
4223     gDefSavePath = std::string( strbuf );
4224 
4225     movepos += strlen( strbuf ) + 1;
4226 
4227     strcpy( strbuf, buf + movepos );
4228 
4229     gDefFtpPass = std::string( strbuf );
4230 
4231     movepos += strlen( strbuf ) + 1;
4232 
4233     strcpy( strbuf, buf + movepos );
4234 
4235     gsMonitorExt = std::string( strbuf );
4236 
4237     movepos += strlen( strbuf ) + 1;
4238 
4239     strcpy( strbuf, buf + movepos );
4240 
4241     gsIgnoreExt = std::string( strbuf );
4242 
4243     movepos += strlen( strbuf ) + 1;
4244 
4245 
4246 
4247     for ( int i = 0;i < hissize;i++ )
4248     {
4249         strcpy( strbuf, buf + movepos );
4250         std::string temp = std::string( strbuf );
4251         movepos += strlen( strbuf ) + 1;
4252         gSavePathHistory.push_back( temp );
4253     }
4254 
4255     delete[] buf;
4256     return true;
4257 }
4258 
SaveConfig()4259 bool MainFrame::SaveConfig()
4260 {
4261 
4262 
4263 
4264     //记录格式采用2进制格式 v1.0
4265     //文件头+数据+文件尾
4266     //文件头:版本[4]+文件头长度[4]+数据全长[4]
4267     //数据:gRunTaskNum[4]+gTaskDefThread[4]+gRetryTime[4]+gRetryWait[4]+
4268     //gConnectTimeOut[4]+gReceiveTimeOut[4]+gbIgnoreExt[4]+gbMonitorExt[4]+
4269     //gbMonitorClip[4]+gbShowDropWin[4]+gDropWinX[4]+gDropWinY[4]+gSpeedMode[4]+hissize[4]+
4270     //gDefSavePath[v]+gDefFtpPass[v]+gsMonitorExt[v]+gsIgnoreExt[v]+
4271     //gSavePathHistory[0][v]+gSavePathHistory[1][v]...gSavePathHistory[9][v]
4272     //文件尾:0xFFEE[4]
4273 
4274 
4275     //记录格式采用2进制格式 v2.0
4276     //文件头+数据+文件尾
4277     //文件头:版本[4]+文件头长度[4]+数据全长[4]
4278     //数据:gRunTaskNum[4]+gTaskDefThread[4]+gRetryTime[4]+gRetryWait[4]+
4279     //gConnectTimeOut[4]+gReceiveTimeOut[4]+gbIgnoreExt[4]+gbMonitorExt[4]+
4280     //gbMonitorClip[4]+gbShowDropWin[4]+gbSoundTip[4]+gDropWinX[4]+gDropWinY[4]+gSpeedMode[4]+hissize[4]+
4281     //gDefSavePath[v]+gDefFtpPass[v]+gsMonitorExt[v]+gsIgnoreExt[v]+
4282     //gSavePathHistory[0][v]+gSavePathHistory[1][v]...gSavePathHistory[9][v]
4283     //文件尾:0xFFEE[4]
4284 
4285     //记录格式采用2进制格式 v3.0
4286     //文件头+数据+文件尾
4287     //文件头:版本[4]+文件头长度[4]+数据全长[4]
4288     //数据:gRunTaskNum[4]+gTaskDefThread[4]+gRetryTime[4]+gRetryWait[4]+
4289     //gConnectTimeOut[4]+gReceiveTimeOut[4]+gbIgnoreExt[4]+gbMonitorExt[4]+gbAutoMd5[4]+
4290     //gbMonitorClip[4]+gbShowDropWin[4]+gbSoundTip[4]+gDropWinX[4]+gDropWinY[4]+gSpeedMode[4]+hissize[4]+
4291     //gDefSavePath[v]+gDefFtpPass[v]+gsMonitorExt[v]+gsIgnoreExt[v]+
4292     //gSavePathHistory[0][v]+gSavePathHistory[1][v]...gSavePathHistory[9][v]
4293     //文件尾:0x00EE[4]
4294 
4295     FILE * fp;
4296 
4297     std::string temp;
4298 
4299     if ( !GetTempDir( temp ) )
4300     {
4301         return false;
4302     }
4303 
4304     temp += "/config.db";
4305 
4306     fp = fopen( temp.c_str(), "wb" );
4307 
4308     if ( fp == NULL )
4309     {
4310 
4311         return false;
4312     }
4313 
4314 
4315     struct _fh
4316     {
4317         int ver; //当前版本3.0
4318         int headlen; //4*3=12
4319         int datalen; //后确定
4320 
4321     }
4322 
4323     fh;
4324 
4325     fh.ver = 3;
4326     fh.headlen = sizeof( fh );
4327     fh.datalen = 0;
4328 
4329     if ( 1 != fwrite( &fh, sizeof( fh ), 1, fp ) )
4330     {
4331         fclose( fp );
4332         return false;
4333     }
4334 
4335 
4336     int dl = 0;
4337     fwrite( &gRunTaskNum, sizeof( gRunTaskNum ), 1, fp );
4338     dl += sizeof( gRunTaskNum );
4339     fwrite( &gTaskDefThread, sizeof( gTaskDefThread ), 1, fp );
4340     dl += sizeof( gTaskDefThread );
4341     fwrite( &gRetryTime, sizeof( gRetryTime ), 1, fp );
4342     dl += sizeof( gRetryTime );
4343     fwrite( &gRetryWait, sizeof( gRetryWait ), 1, fp );
4344     dl += sizeof( gRetryWait );
4345     fwrite( &gConnectTimeOut, sizeof( gConnectTimeOut ), 1, fp );
4346     dl += sizeof( gConnectTimeOut );
4347     fwrite( &gReceiveTimeOut, sizeof( gReceiveTimeOut ), 1, fp );
4348     dl += sizeof( gReceiveTimeOut );
4349     fwrite( &gbIgnoreExt, sizeof( gbIgnoreExt ), 1, fp );
4350     dl += sizeof( gbIgnoreExt );
4351     fwrite( &gbMonitorExt, sizeof( gbMonitorExt ), 1, fp );
4352     dl += sizeof( gbMonitorExt );
4353     fwrite( &gbAutoMd5, sizeof( gbAutoMd5 ), 1, fp );
4354     dl += sizeof( gbAutoMd5 );
4355     fwrite( &gbMonitorClip, sizeof( gbMonitorClip ), 1, fp );
4356     dl += sizeof( gbMonitorClip );
4357     fwrite( &gbShowDropWin, sizeof( gbShowDropWin ), 1, fp );
4358     dl += sizeof( gbShowDropWin );
4359     fwrite( &gbSoundTip, sizeof( gbSoundTip ), 1, fp );
4360     dl += sizeof( gbSoundTip );
4361     fwrite( &gDropWinX, sizeof( gDropWinX ), 1, fp );
4362     dl += sizeof( gDropWinX );
4363     fwrite( &gDropWinY, sizeof( gDropWinY ), 1, fp );
4364     dl += sizeof( gDropWinY );
4365     fwrite( &gSpeedMode, sizeof( gSpeedMode ), 1, fp );
4366     dl += sizeof( gSpeedMode );
4367     int hissize = gSavePathHistory.size();
4368 
4369     if ( hissize > 10 )
4370         hissize = 10;
4371 
4372     fwrite( &hissize, sizeof( int ), 1, fp );
4373 
4374     dl += sizeof( int );
4375 
4376     fwrite( gDefSavePath.c_str(), gDefSavePath.length() + 1, 1, fp );
4377 
4378     dl += gDefSavePath.length() + 1;
4379 
4380     fwrite( gDefFtpPass.c_str(), gDefFtpPass.length() + 1, 1, fp );
4381 
4382     dl += gDefFtpPass.length() + 1;
4383 
4384     fwrite( gsMonitorExt.c_str(), gsMonitorExt.length() + 1, 1, fp );
4385 
4386     dl += gsMonitorExt.length() + 1;
4387 
4388     fwrite( gsIgnoreExt.c_str(), gsIgnoreExt.length() + 1, 1, fp );
4389 
4390     dl += gsIgnoreExt.length() + 1;
4391 
4392     // savepath history,
4393 
4394     std::list<std::string>::iterator it;
4395 
4396     int counter = 0;
4397 
4398     for ( it = gSavePathHistory.begin();it != gSavePathHistory.end() && counter < 10;it++, counter++ )
4399     {
4400         fwrite( it->c_str(), it->length() + 1, 1, fp );
4401         dl += it->length() + 1;
4402     }
4403 
4404     fh.datalen = dl;
4405 
4406     //file tail
4407 
4408     hissize = 0x00EE;
4409     fwrite( &hissize, 4, 1, fp );
4410 
4411     //write file head
4412     fseek( fp, 0, SEEK_SET );
4413     fwrite( &fh, sizeof( fh ), 1, fp );
4414     fclose( fp );
4415     return true;
4416 
4417 }
4418 
OnReloadFile(wxCommandEvent & event)4419 void MainFrame::OnReloadFile( wxCommandEvent& event )
4420 {
4421     _TaskAttr * pcur = GetCurrentTask();
4422 
4423     if ( pcur == NULL )
4424         return ;
4425 
4426     if ( pcur->nStatus == _STATUS_RUNNING )
4427         return ;
4428 
4429     if ( pcur->nStatus == _STATUS_DELETE )
4430         return ;
4431 
4432     wxString msg;
4433 
4434     wxString url( pcur->sURL.c_str(), wxConvLocal );
4435 
4436     msg = _MGSTR( _S_MAINFRAME_RELOADDELETE ) + wxT( "\n" ) + url;
4437 
4438     wxMessageDialog dlg( this, msg, _MGSTR( _S_MAINFRAME_RELOADWARNNING ),
4439                          wxICON_QUESTION | wxYES_NO | wxSTAY_ON_TOP | wxNO_DEFAULT );
4440 
4441     if ( wxID_NO == dlg.ShowModal() )
4442     {
4443         return ;
4444     }
4445 
4446     std::string tempdir;
4447 
4448     if ( GetTempDir( tempdir ) )
4449     {
4450         std::string tempfile = tempdir;
4451         tempfile += "/";
4452         tempfile += pcur->sName;
4453         tempfile += ".mg";
4454 
4455         remove
4456             ( tempfile.c_str() );
4457 
4458         tempfile += "idx";
4459 
4460         remove
4461             ( tempfile.c_str() );
4462     }
4463 
4464     //删除目标文件(如果已完成)
4465     std::string destfile = pcur->sSavePath;
4466 
4467     destfile += "/";
4468 
4469     destfile += pcur->sName;
4470 
4471     remove
4472         ( destfile.c_str() );
4473 
4474     //修改任务参数任务
4475     pcur->nStatus = _STATUS_WAITING;
4476 
4477     pcur->nFinish = 0;
4478 
4479     pcur->nLen = -1;
4480 
4481     pcur->fRatio = 0;
4482 
4483     pcur->nSpeed = 0;
4484 
4485     pcur->nError = 0;
4486 
4487     pcur->sMD5 = string( "" );
4488 
4489     ScheduleTask();
4490 
4491 }
4492 
IsMonitorClip()4493 bool MainFrame::IsMonitorClip()
4494 {
4495     return gbMonitorClip;
4496 }
4497 /*
4498 void MainFrame::OnFocus( wxFocusEvent& event )
4499 {
4500     //DBGOUT( "focus event" );
4501 }
4502 
4503 void MainFrame::OnLostFocus( wxFocusEvent& event )
4504 {
4505     //DBGOUT( "lost event" );
4506 }
4507 */
OnUrlNotice(wxCommandEvent & event)4508 void MainFrame::OnUrlNotice( wxCommandEvent& event )
4509 {
4510 
4511     //
4512     int id = event.GetId();
4513     wxString url = event.GetString();
4514 
4515     if ( id == 1 )  //dropurl
4516     {
4517 
4518         if ( m_NewTaskDlg == NULL && m_PropertyDlg == NULL )
4519         {
4520             OnDropURL( url );
4521         }
4522         else if ( m_NewTaskDlg != NULL && m_PropertyDlg == NULL )
4523         {
4524             //DoNewTask(url);
4525             m_NewTaskDlg->AddMirrorUrl( url );
4526         }
4527         else if ( m_NewTaskDlg == NULL && m_PropertyDlg != NULL )
4528         {
4529             m_PropertyDlg->AddMirrorUrl( url );
4530         }
4531         else
4532         { // all dlg up?
4533             //DoNewTask(url);
4534             m_NewTaskDlg->AddMirrorUrl( url );
4535             m_PropertyDlg->AddMirrorUrl( url );
4536         }
4537 
4538     }
4539     else if ( id == 2 )  //clipbord
4540     {
4541 
4542         if ( m_NewTaskDlg == NULL && m_PropertyDlg == NULL )
4543         {
4544             DoNewTask( url );
4545         }
4546         else if ( m_NewTaskDlg != NULL && m_PropertyDlg == NULL )
4547         {
4548             //DoNewTask(url);
4549             m_NewTaskDlg->AddMirrorUrl( url );
4550         }
4551         else if ( m_NewTaskDlg == NULL && m_PropertyDlg != NULL )
4552         {
4553             m_PropertyDlg->AddMirrorUrl( url );
4554         }
4555         else
4556         { // all dlg up?
4557             //DoNewTask(url);
4558             m_NewTaskDlg->AddMirrorUrl( url );
4559             m_PropertyDlg->AddMirrorUrl( url );
4560         }
4561 
4562     }
4563     else
4564     {
4565         //DBGOUT( "unknow id give url" );
4566     }
4567 
4568 }
4569 
OnCmdNotice(wxCommandEvent & event)4570 void MainFrame::OnCmdNotice( wxCommandEvent& event )
4571 {
4572     wxString task = event.GetString();
4573 
4574     if ( event.GetId() == 1 )
4575     {
4576         //DBGOUT("task="<<task);
4577         //解析行,建立新任务
4578         //url=?,refer=?,mirror=?,
4579         wxArrayString group;
4580 
4581         if ( task.Length() <= 5 )
4582             return ;
4583 
4584         int lastpos = 0;
4585 
4586         for ( int i = 0;i < int( task.Length() );i++ )
4587         {
4588             if ( task[ i ] == wxT( '^' ) )
4589             {
4590                 group.Add( task.SubString( lastpos, i - 1 ) );
4591                 lastpos = i + 1;
4592             }
4593         }
4594 
4595         //parse ok
4596         //search url,mirror,refer;
4597         wxString url, mirror, refer;
4598 
4599         for ( int i = 0;i < int( group.Count() );i++ )
4600         {
4601             cout << group[ i ] << endl;
4602 
4603             if ( group[ i ].Left( 4 ) == wxT( "url=" ) )
4604             {
4605                 url = ( group[ i ].Right( group[ i ].Length() - 4 ) );
4606             }
4607             else if ( group[ i ].Left( 6 ) == wxT( "refer=" ) )
4608             {
4609                 refer = ( group[ i ].Right( group[ i ].Length() - 6 ) );
4610             }
4611         }
4612 
4613         if ( url.empty() )
4614             return ; //no url
4615 
4616         //do the task
4617         DoNewTask( url, refer );
4618 
4619     }
4620     else
4621     { //other id don't run
4622     }
4623 }
4624 
OnProperty(wxCommandEvent & event)4625 void MainFrame::OnProperty( wxCommandEvent& event )
4626 {
4627 
4628     if ( GetCurrentTask() == NULL )
4629         return ;
4630 
4631     m_PropertyDlg = new CPropertyDlg( this, m_nCurrentSelectTaskID );
4632 
4633     m_SysTray->DlgShow( true );
4634 
4635     int nret = m_PropertyDlg->ShowModal();
4636 
4637     m_SysTray->DlgShow( false );
4638 
4639     if ( nret == wxID_OK )
4640     {
4641         //get attr
4642         //if finish , no change.
4643         //if running ,only mirror list can change.
4644         //
4645         _TaskAttr * tsk = GetCurrentTask();
4646 
4647         tsk->sRefer = m_PropertyDlg->m_sRefer.mb_str( wxConvLocal );
4648         tsk->sURL = m_PropertyDlg->GetUrl();
4649         tsk->sSavePath = m_PropertyDlg->m_sSavePath.mb_str( wxConvLocal );
4650         tsk->sName = m_PropertyDlg->m_sRename.mb_str( wxConvLocal );
4651         tsk->nThread = m_PropertyDlg->m_nThreadNum;
4652         tsk->nRetry = m_PropertyDlg->m_nRetry;
4653         tsk->nRetryWait = m_PropertyDlg->m_nRetryWait;
4654         tsk->sSockProxy = m_PropertyDlg->GetSocksProxyName();
4655         tsk->sHttpProxy = m_PropertyDlg->GetHttpProxyName();
4656         tsk->sFtpProxy = m_PropertyDlg->GetFtpProxyName();
4657 
4658         std::string mu[ 80 ];
4659         int mn = m_PropertyDlg->GetMirrorUrl( 80, mu );
4660         tsk->sMirrorURL.clear();
4661 
4662         for ( int i = 0;i < mn;i++ )
4663         {
4664             tsk->sMirrorURL.push_back( mu[ i ] );
4665 
4666             if ( tsk->nStatus == _STATUS_RUNNING )
4667                 m_TaskManager->AddTaskMirrorUrl( tsk->nID, mu[ i ] );
4668         }
4669 
4670     }
4671     else
4672     {}
4673 
4674     m_PropertyDlg->Destroy();
4675 
4676     m_PropertyDlg = NULL;
4677 }
4678 
OnMaximize(wxMaximizeEvent & event)4679 void MainFrame::OnMaximize( wxMaximizeEvent& event )
4680 {
4681 
4682     if ( IsIconized() )
4683         Iconize( false );
4684 
4685     if ( !IsShown() )
4686         Show( true );
4687 
4688     RequestUserAttention();
4689 }
4690 
4691 //it will not call ScheduleTask
AddBatchTask(std::string mainurl,std::string refer,std::string savepath,std::string rename,int threadnum,bool runnow,int retry,int retrywait,std::string sock,std::string ftp,std::string http,bool automd5,int mirrorcount,std::string mir[])4692 void MainFrame::AddBatchTask(
4693     std::string mainurl,
4694     std::string refer,
4695     std::string savepath,
4696     std::string rename,
4697     int threadnum,
4698     bool runnow,
4699     int retry,
4700     int retrywait,
4701     std::string sock,
4702     std::string ftp,
4703     std::string http,
4704     bool automd5,
4705     int mirrorcount,
4706     std::string mir[]
4707 )
4708 {
4709     CUrlParser parser;
4710 
4711     if ( parser.SetUrl( mainurl ) )
4712     {
4713 
4714         _TaskAttr atask;
4715         atask.nID = GetNewTaskID();
4716         atask.sURL = mainurl;
4717         //add refer
4718         atask.sRefer = refer;
4719         Trim( atask.sRefer );
4720         atask.sSavePath = savepath;
4721 
4722         atask.nThread = threadnum;
4723         atask.nStatus = runnow ? _STATUS_WAITING : _STATUS_PAUSE;
4724 
4725         std::string finame = rename.empty() ? parser.GetFileName() : rename;
4726 
4727         if ( finame.empty() )
4728             atask.sName = "index.html";
4729         else
4730             atask.sName = finame;
4731 
4732         atask.nRetry = retry;
4733 
4734         atask.nRetryWait = retrywait;
4735 
4736         atask.nFinish = 0;
4737 
4738         atask.fRatio = 0.0;
4739 
4740         atask.nError = 0;
4741 
4742         atask.nSpeed = 0;
4743 
4744         atask.bAutoMd5 = automd5;
4745 
4746         atask.nLen = 0;
4747 
4748         atask.nTime = 0;
4749 
4750         atask.sSockProxy = sock;
4751 
4752         atask.sFtpProxy = ftp;
4753 
4754         atask.sHttpProxy = http;
4755 
4756         //mirror url
4757         for ( int j = 0;j < mirrorcount;j++ )
4758         {
4759             atask.sMirrorURL.push_back( mir[ j ] );
4760         }
4761 
4762         pthread_mutex_lock( &m_TaskMutex );
4763         m_AllTaskList.push_back( atask );
4764         pthread_mutex_unlock( &m_TaskMutex );
4765 
4766     }
4767     else
4768     {
4769         return ;
4770     }
4771 }
4772 
CheckLocale(_MGLANG lang)4773 bool MainFrame::CheckLocale(_MGLANG lang)
4774 {
4775 
4776     char *old_locale;
4777     old_locale = setlocale (LC_ALL, NULL);
4778 
4779 
4780 	bool bret=false;
4781 
4782 	switch(lang)
4783 	{
4784 		case EN_US_UTF_8:
4785 			{
4786 				if( NULL!=setlocale(LC_ALL,"en_US.utf8")||
4787 					NULL!=setlocale(LC_ALL,"en_AU.utf8")||
4788 					NULL!=setlocale(LC_ALL,"en_BW.utf8")||
4789 					NULL!=setlocale(LC_ALL,"en_CA.utf8")||
4790 					NULL!=setlocale(LC_ALL,"en_DK.utf8")||
4791 					NULL!=setlocale(LC_ALL,"en_GB.utf8")||
4792 					NULL!=setlocale(LC_ALL,"en_HK.utf8")||
4793 					NULL!=setlocale(LC_ALL,"en_IE.utf8")||
4794 					NULL!=setlocale(LC_ALL,"en_IN")	  ||
4795 					NULL!=setlocale(LC_ALL,"en_NZ.utf8")||
4796 					NULL!=setlocale(LC_ALL,"en_SG.utf8")||
4797 					NULL!=setlocale(LC_ALL,"en_PH.utf8")||
4798 					NULL!=setlocale(LC_ALL,"en_ZA.utf8")||
4799 					NULL!=setlocale(LC_ALL,"en_ZW.utf8") )
4800 				{
4801 					setlocale(LC_ALL,old_locale);
4802 					bret=true;
4803 					break;
4804 				}
4805 
4806 			}
4807 			break;
4808 		case ZH_CN_UTF_8:
4809 			{
4810 				if( NULL!=setlocale(LC_ALL,"zh_CN.utf8") )
4811 				{
4812 					setlocale(LC_ALL,old_locale);
4813 					bret=true;
4814 					break;
4815 				}
4816 			}
4817 			break;
4818 		case ZH_CN_18030:
4819 			{
4820 #ifndef WIN32
4821 				if( NULL!=setlocale(LC_ALL,"zh_CN.gb18030") ||
4822 					NULL!=setlocale(LC_ALL,"zh_CN.gbk") 	  ||
4823 					NULL!=setlocale(LC_ALL,"zh_CN.gb2312") )
4824 #else
4825 				if( NULL!=setlocale(LC_ALL,".936"))
4826 #endif
4827 				{
4828 					setlocale(LC_ALL,old_locale);
4829 					bret=true;
4830 					break;
4831 				}
4832 			}
4833 			break;
4834 		case ZH_TW_UTF_8:
4835 			{
4836 				if( NULL!=setlocale(LC_ALL,"zh_TW.utf8") )
4837 				{
4838 					setlocale(LC_ALL,old_locale);
4839 					bret=true;
4840 					break;
4841 				}
4842 			}
4843 			break;
4844 		case ZH_TW_BIG5:
4845 			{
4846 #ifndef WIN32
4847 				if( NULL!=setlocale(LC_ALL,"zh_TW.big5") )
4848 #else
4849 				if( NULL!=setlocale(LC_ALL,".950") )
4850 #endif
4851 				{
4852 					setlocale(LC_ALL,old_locale);
4853 					bret=true;
4854 					break;
4855 				}
4856 			}
4857 			break;
4858 		case DE_DE_UTF_8:
4859 			{
4860 #ifndef WIN32
4861 				if( NULL!=setlocale(LC_ALL,"de_DE.utf8")||
4862 					NULL!= setlocale(LC_ALL,"de_AT.utf8")||
4863 					NULL!= setlocale(LC_ALL,"de_BE.utf8")||
4864 					NULL!= setlocale(LC_ALL,"de_CH.utf8")||
4865 					NULL!= setlocale(LC_ALL,"de_LU.utf8"))
4866 #else
4867 				if( NULL!=setlocale(LC_ALL,".1252") )
4868 #endif
4869 				{
4870 					setlocale(LC_ALL,old_locale);
4871 					bret=true;
4872 					break;
4873 				}
4874 			}
4875 			break;
4876 	}
4877 
4878 	return bret;
4879 }
4880 
CheckLangMenu(_MGLANG lang)4881 void MainFrame::CheckLangMenu(_MGLANG lang)
4882 {
4883     switch ( lang )
4884     {
4885 
4886         case ZH_CN_UTF_8:
4887         m_lang->Check( mgID_VIEW_LANG_CN_UTF8, true );
4888         break;
4889 
4890         case EN_US_UTF_8:
4891         m_lang->Check( mgID_VIEW_LANG_EN_UTF8, true );
4892         break;
4893 
4894         case ZH_CN_18030:
4895         m_lang->Check( mgID_VIEW_LANG_GB18030, true );
4896         break;
4897 
4898         case ZH_TW_UTF_8:
4899         m_lang->Check( mgID_VIEW_LANG_TW_UTF8, true );
4900         break;
4901 
4902         case ZH_TW_BIG5:
4903         m_lang->Check( mgID_VIEW_LANG_TW_BIG5, true );
4904 
4905         default:
4906         break;
4907     }
4908 }
4909 
NoLangSupport()4910 void MainFrame::NoLangSupport()
4911 {
4912 	m_SysTray->DlgShow( true );
4913 	wxMessageDialog dlg(this,
4914 					wxString(wxT("Your system not supports this locale/language, please install language package.")),
4915 					wxString(wxT("Error!")),
4916 					wxOK|wxICON_ERROR|wxSTAY_ON_TOP);
4917 	dlg.ShowModal();
4918 	m_SysTray->DlgShow( false );
4919 }
4920 
OnSaveConfig(wxCommandEvent & event)4921 void MainFrame::OnSaveConfig(wxCommandEvent& event)
4922 {
4923     SaveConfig();
4924 }
4925 
OnSaveProxy(wxCommandEvent & event)4926 void MainFrame::OnSaveProxy(wxCommandEvent& event)
4927 {
4928     SaveProxyDB();
4929 }
4930 
OnSaveTask(wxCommandEvent & event)4931 void MainFrame::OnSaveTask(wxCommandEvent& event)
4932 {
4933     SaveTaskDB();
4934 }
4935 
OnVisitHome(wxCommandEvent & event)4936 void MainFrame::OnVisitHome(wxCommandEvent& event)
4937 {
4938 #ifdef WIN32
4939 	int n=system("iexplore http://multiget.sourceforge.net");
4940 	if(n!=0)
4941 	{
4942 		n=system("firefox http://multiget.sourceforge.net");
4943 	}
4944 #else
4945 	int n=system("firefox http://multiget.sourceforge.net");
4946 
4947 	if(n!=0)
4948 	{
4949 		n=system("konqueror http://multiget.sourceforge.net");
4950 	}
4951 
4952 	if(n!=0)
4953 	{
4954 		n=system("opera http://multiget.sourceforge.net");
4955 	}
4956 
4957 #endif
4958 
4959 }
4960