| 0 | 1 // Filename   : main.cpp | 
| 19 | 2 // Last Change: 04-Dec-2014. | 
| 0 | 3 // | 
|  | 4 #include "main.h" | 
|  | 5 #include "myframe.h" | 
| 19 | 6 #include "miniframe.h" | 
|  | 7 #include "wx/cmdline.h" | 
| 0 | 8 | 
|  | 9 IMPLEMENT_APP(MyApp) | 
|  | 10 | 
|  | 11 IMPLEMENT_CLASS( MyApp, wxApp ) | 
|  | 12 | 
|  | 13 MyApp::MyApp() | 
|  | 14 { | 
|  | 15 } | 
|  | 16 MyApp::~MyApp() | 
|  | 17 { | 
|  | 18 } | 
|  | 19 | 
|  | 20 bool MyApp::OnInit() | 
|  | 21 { | 
|  | 22     if ( !wxApp::OnInit() ) return false; | 
|  | 23 | 
|  | 24     wxImage::AddHandler( new wxJPEGHandler ); | 
|  | 25     wxImage::AddHandler( new wxPNGHandler ); | 
|  | 26 | 
|  | 27     InitLog(); | 
|  | 28     InitSetting(); | 
|  | 29 | 
| 19 | 30     if ( mode == 1 ) { | 
|  | 31         MiniFrame *miniframe = new MiniFrame( NULL, ID_MAIN, wxT("Mini Searcher"), wxDefaultPosition, wxSize( 100, 45 ), wxMINIMIZE_BOX|wxSYSTEM_MENU|wxCAPTION|wxCLOSE_BOX|wxCLIP_CHILDREN ); | 
|  | 32         miniframe->Show( true ); | 
|  | 33     } | 
|  | 34     else { | 
|  | 35         MyFrame *mainframe = new MyFrame( NULL, ID_MAIN, wxT("Searcher 03"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE ); | 
|  | 36         mainframe->SetSize( rect ); | 
|  | 37         mainframe->Show( true ); | 
|  | 38     } | 
| 0 | 39 | 
|  | 40     return true; | 
|  | 41 } | 
|  | 42 | 
|  | 43 int MyApp::OnExit() | 
|  | 44 { | 
|  | 45     SaveSetting(); | 
|  | 46     return 0; | 
|  | 47 } | 
|  | 48 | 
|  | 49 void MyApp::InitSetting() | 
|  | 50 { | 
|  | 51     conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf"); | 
|  | 52     config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); | 
|  | 53 | 
|  | 54     config->SetPath( wxT("/Geometry") ); | 
| 19 | 55     config->Read( wxT("mode"), &mode ); | 
| 0 | 56     config->Read( wxT("x"), &rect.x ); | 
|  | 57     config->Read( wxT("y"), &rect.y ); | 
|  | 58     config->Read( wxT("w"), &rect.width ); | 
|  | 59     config->Read( wxT("h"), &rect.height ); | 
| 1 | 60     delete config; | 
| 0 | 61 | 
|  | 62     WriteLog( wxT("Setting Parameters read.") ); | 
|  | 63 } | 
|  | 64 | 
|  | 65 void MyApp::SaveSetting() | 
|  | 66 { | 
| 1 | 67     config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); | 
|  | 68 | 
| 0 | 69     config->SetPath( wxT("/Geometry") ); | 
|  | 70     config->Write( wxT("x"), rect.x ); | 
|  | 71     config->Write( wxT("y"), rect.y ); | 
|  | 72     config->Write( wxT("w"), rect.width ); | 
|  | 73     config->Write( wxT("h"), rect.height ); | 
|  | 74     delete config; | 
|  | 75 | 
|  | 76     WriteLog( wxT("Setting Parameters saved.") ); | 
|  | 77 } | 
|  | 78 | 
|  | 79 void MyApp::InitLog() | 
|  | 80 { | 
|  | 81     log_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("log") + wxFILE_SEP_PATH + wxT("log"); | 
|  | 82     wxTextFile file( log_file ); | 
|  | 83 | 
|  | 84     if ( file.Exists() ) { | 
|  | 85         wxString log_bak = log_file + wxT(".bak"); | 
|  | 86         wxRenameFile( log_file, log_bak, true ); | 
|  | 87     } | 
|  | 88 | 
|  | 89     file.Create(); | 
|  | 90     WriteLog( wxT("[Application start...]") ); | 
|  | 91 } | 
|  | 92 | 
|  | 93 void MyApp::WriteLog( wxString msg ) | 
|  | 94 { | 
|  | 95     wxDateTime now = wxDateTime::Now(); | 
|  | 96     wxTextFile logfile; | 
|  | 97     logfile.Open( log_file ); | 
|  | 98     logfile.AddLine( now.Format(wxT("%Y-%m-%d %H:%M:%S ")) + msg ); | 
|  | 99     logfile.Write(); | 
|  | 100     logfile.Close(); | 
|  | 101 } | 
|  | 102 |