Mercurial > mercurial > hgweb_rsearcher.cgi
comparison src/main.cpp @ 6:9a8b581c1993
improve performance.
author | pyon@macmini |
---|---|
date | Tue, 23 Oct 2018 19:15:22 +0900 |
parents | e3b10fb860b3 |
children | 29829e98d510 |
comparison
equal
deleted
inserted
replaced
5:e3b10fb860b3 | 6:9a8b581c1993 |
---|---|
1 // Filename : main.cpp | 1 // Filename : main.cpp |
2 // Last Change: 2018-10-22 月 16:14:28. | 2 // Last Change: 2018-10-23 火 10:09:42. |
3 // | 3 // |
4 #include "id.h" | 4 #include "id.h" |
5 #include "main.h" | 5 #include "main.h" |
6 #include "auth.h" | 6 #include "auth.h" |
7 #include "rsearcher.h" | 7 #include "rsearcher.h" |
24 | 24 |
25 wxImage::AddHandler( new wxJPEGHandler ); | 25 wxImage::AddHandler( new wxJPEGHandler ); |
26 wxImage::AddHandler( new wxPNGHandler ); | 26 wxImage::AddHandler( new wxPNGHandler ); |
27 InitSetting(); | 27 InitSetting(); |
28 | 28 |
29 // Login Dialog | |
30 AuthDialog *authdlg = new AuthDialog( NULL, wxID_ANY, wxT( "Who are you ?" ), wxDefaultPosition, wxDefaultSize, wxCAPTION ); | |
31 authdlg->SetServer( m_server ); | |
32 authdlg->GetDB(); | |
33 | |
29 // Splash Screen | 34 // Splash Screen |
30 wxFileSystem::AddHandler( new wxZipFSHandler ); | 35 wxFileSystem::AddHandler( new wxZipFSHandler ); |
31 wxFileSystem* fs = new wxFileSystem(); | 36 wxFileSystem* fs = new wxFileSystem(); |
32 wxString archive = wxT( "file:///./myapp.bin" ); | 37 wxString archive = wxT( "file:///./myapp.bin" ); |
33 for ( int i = 0; i < 11; i++ ) { | 38 for ( int i = 0; i < 11; i++ ) { |
34 wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:startup%02d.png" ), i ) ); | 39 wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:startup%02d.png" ), i ) ); |
35 if ( file ) { | 40 if ( file ) { |
36 wxInputStream* s = file->GetStream(); | 41 wxInputStream* s = file->GetStream(); |
37 wxImage image( *s, wxBITMAP_TYPE_PNG ); | 42 wxImage image( *s, wxBITMAP_TYPE_PNG ); |
38 wxBitmap bmp = wxBitmap( image ); | 43 wxBitmap bmp = wxBitmap( image ); |
39 wxSplashScreen* splash = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 3000, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxSTAY_ON_TOP ); | 44 wxSplashScreen* splash = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 2500, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxSTAY_ON_TOP ); |
40 delete file; | 45 delete file; |
41 } | 46 } |
42 wxMilliSleep( 250 ); | 47 wxMilliSleep( 200 ); |
43 } | |
44 | |
45 unsigned int seed = (unsigned int)time( 0 ); | |
46 srand( seed ); | |
47 int n = rand() % 13; | |
48 wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:%02d.jpg" ), n ) ); | |
49 if ( file ) { | |
50 wxInputStream* s = file->GetStream(); | |
51 wxFileOutputStream of( wxT( "./image/hello.jpg" ) ); | |
52 s->Read( of ); | |
53 delete file; | |
54 } | 48 } |
55 delete fs; | 49 delete fs; |
56 | 50 |
57 // Login Dialog | |
58 AuthDialog *authdlg = new AuthDialog( NULL, wxID_ANY, wxT( "Who are you ?" ), wxDefaultPosition, wxDefaultSize, wxCAPTION ); | |
59 authdlg->SetServer( m_server ); | |
60 if ( !authdlg->LoadDB() ) { | 51 if ( !authdlg->LoadDB() ) { |
61 authdlg->Destroy(); | 52 authdlg->Destroy(); |
62 return false; | 53 return false; |
63 } | 54 } |
64 | 55 |
65 if ( authdlg->ShowModal() == wxID_OK ) { | 56 if ( authdlg->ShowModal() == wxID_OK ) { |
66 wxString ui = wxString::Format( wxT( "./image/" ) + authdlg->GetUser() + wxT( ".jpg" ) ); | 57 wxString ui = wxString::Format( wxT( "./image/" ) + authdlg->GetUser() + wxT( ".jpg" ) ); |
67 if ( wxFileExists( ui ) ) wxCopyFile( ui, wxT( "./image/hello.jpg" ), true ); | 58 if ( wxFileExists( ui ) ) { |
59 wxCopyFile( ui, wxT( "./image/hello.jpg" ), true ); | |
60 } else { | |
61 unsigned int seed = (unsigned int)time( 0 ); | |
62 srand( seed ); | |
63 int n = rand() % 13; | |
64 wxFileSystem* fs = new wxFileSystem(); | |
65 wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:%02d.jpg" ), n ) ); | |
66 if ( file ) { | |
67 wxInputStream* s = file->GetStream(); | |
68 wxFileOutputStream of( wxT( "./image/hello.jpg" ) ); | |
69 s->Read( of ); | |
70 delete file; | |
71 } | |
72 delete fs; | |
73 } | |
68 | 74 |
69 // Main Window | 75 // Main Window |
70 MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE ); | 76 MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE ); |
71 mainframe->InDevelop( true ); | 77 mainframe->InDevelop( true ); |
72 mainframe->SetServer( m_server ); | 78 mainframe->SetServer( m_server ); |
81 return true; | 87 return true; |
82 } | 88 } |
83 | 89 |
84 int MyApp::OnExit() | 90 int MyApp::OnExit() |
85 { | 91 { |
92 RemoveFile( wxT( "auth.db" ) ); | |
93 RemoveFile( wxT( "hhs.db" ) ); | |
94 RemoveFile( wxT( ".cache/*" ) ); | |
86 SaveSetting(); | 95 SaveSetting(); |
87 return 0; | 96 return 0; |
88 } | 97 } |
89 | 98 |
90 void MyApp::InitSetting() | 99 void MyApp::InitSetting() |
120 config->Write( wxT( "w" ), rect.width ); | 129 config->Write( wxT( "w" ), rect.width ); |
121 config->Write( wxT( "h" ), rect.height ); | 130 config->Write( wxT( "h" ), rect.height ); |
122 delete config; | 131 delete config; |
123 } | 132 } |
124 | 133 |
134 void MyApp::RemoveFile( wxString pattern ) | |
135 { | |
136 wxString file = wxFindFirstFile( pattern ); | |
137 while ( !file.empty() ) { | |
138 wxRemoveFile( file ); | |
139 file = wxFindNextFile(); | |
140 } | |
141 } | |
142 |