Mercurial > mercurial > hgweb_dw.cgi
comparison src/main.cpp @ 0:7c3921bf511e
Beta2
| author | pyon@macmini |
|---|---|
| date | Sat, 20 Oct 2012 16:07:42 +0900 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:7c3921bf511e |
|---|---|
| 1 // Filename : main.cpp | |
| 2 // Last Change: 20-Oct-2012. | |
| 3 // | |
| 4 #include "main.h" | |
| 5 #include "myframe.h" | |
| 6 | |
| 7 IMPLEMENT_APP(MyApp) | |
| 8 | |
| 9 IMPLEMENT_CLASS( MyApp, wxApp ) | |
| 10 | |
| 11 MyApp::MyApp() | |
| 12 { | |
| 13 } | |
| 14 MyApp::~MyApp() | |
| 15 { | |
| 16 } | |
| 17 | |
| 18 bool MyApp::OnInit() | |
| 19 { | |
| 20 if ( !wxApp::OnInit() ) return false; | |
| 21 | |
| 22 wxImage::AddHandler( new wxPNGHandler ); | |
| 23 | |
| 24 InitLog(); | |
| 25 InitSetting(); | |
| 26 | |
| 27 MyFrame *mainframe = new MyFrame( NULL, ID_MAIN, wxT("Folder Watcher"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE ); | |
| 28 mainframe->SetSize( rect ); | |
| 29 mainframe->SetMinSize( wxSize( 350, 200 ) ); | |
| 30 mainframe->Show(true); | |
| 31 | |
| 32 return true; | |
| 33 } | |
| 34 | |
| 35 int MyApp::OnExit() | |
| 36 { | |
| 37 SaveSetting(); | |
| 38 return 0; | |
| 39 } | |
| 40 | |
| 41 void MyApp::InitSetting() | |
| 42 { | |
| 43 conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf"); | |
| 44 config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); | |
| 45 | |
| 46 config->SetPath( wxT("/Geometry") ); | |
| 47 config->Read( wxT("x"), &rect.x ); | |
| 48 config->Read( wxT("y"), &rect.y ); | |
| 49 config->Read( wxT("w"), &rect.width ); | |
| 50 config->Read( wxT("h"), &rect.height ); | |
| 51 | |
| 52 WriteLog( wxT("Setting Parameters read.") ); | |
| 53 } | |
| 54 | |
| 55 void MyApp::SaveSetting() | |
| 56 { | |
| 57 config->SetPath( wxT("/Geometry") ); | |
| 58 config->Write( wxT("x"), rect.x ); | |
| 59 config->Write( wxT("y"), rect.y ); | |
| 60 config->Write( wxT("w"), rect.width ); | |
| 61 config->Write( wxT("h"), rect.height ); | |
| 62 delete config; | |
| 63 | |
| 64 WriteLog( wxT("Setting Parameters saved.") ); | |
| 65 } | |
| 66 | |
| 67 void MyApp::InitLog() | |
| 68 { | |
| 69 log_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("log") + wxFILE_SEP_PATH + wxT("log"); | |
| 70 wxTextFile file( log_file ); | |
| 71 | |
| 72 if ( file.Exists() ) { | |
| 73 wxString log_bak = log_file + wxT(".bak"); | |
| 74 wxRenameFile( log_file, log_bak, true ); | |
| 75 } | |
| 76 | |
| 77 file.Create(); | |
| 78 WriteLog( wxT("[Application start...]") ); | |
| 79 } | |
| 80 | |
| 81 void MyApp::WriteLog( wxString msg ) | |
| 82 { | |
| 83 wxDateTime now = wxDateTime::Now(); | |
| 84 wxTextFile logfile; | |
| 85 logfile.Open( log_file ); | |
| 86 logfile.AddLine( now.Format(wxT("%Y-%m-%d %H:%M:%S ")) + msg ); | |
| 87 logfile.Write(); | |
| 88 logfile.Close(); | |
| 89 } | |
| 90 |
