Mercurial > mercurial > hgweb_rsearcher.cgi
comparison src/main.cpp @ 15:c262e17de9b1
db download skip-mode.
| author | pyon@macmini |
|---|---|
| date | Sat, 08 Jun 2019 15:50:59 +0900 |
| parents | f5ffc34f045a |
| children |
comparison
equal
deleted
inserted
replaced
| 14:c1dc1fcee7fe | 15:c262e17de9b1 |
|---|---|
| 1 // Filename : main.cpp | 1 // Filename : main.cpp |
| 2 // Last Change: 2018-11-14 水 12:54:16. | 2 // Last Change: 2019-05-29 水 15:04:09. |
| 3 // | 3 // |
| 4 | 4 |
| 5 #include <wx/socket.h> | 5 #include <wx/socket.h> |
| 6 #include <wx/sstream.h> | 6 #include <wx/sstream.h> |
| 7 #include <wx/protocol/http.h> | 7 #include <wx/protocol/http.h> |
| 42 | 42 |
| 43 wxExecute( wxJoin( args, ' ', '\\' ) ); | 43 wxExecute( wxJoin( args, ' ', '\\' ) ); |
| 44 return false; | 44 return false; |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Validation Host | |
| 48 bool valid_host = false; | |
| 49 if ( !m_unlock_key.IsEmpty() ) { | |
| 50 wxIPV4address addr; | |
| 51 addr.Hostname( wxGetFullHostName() ); | |
| 52 | |
| 53 wxString key = wxT( "re:searcher" ) + addr.IPAddress(); | |
| 54 wxArrayString args; | |
| 55 args.Add( wxT( "crypto.exe" ) ); | |
| 56 args.Add( wxT( "-a" ) ); | |
| 57 args.Add( key ); | |
| 58 | |
| 59 wxArrayString output, errors; | |
| 60 wxExecute( wxJoin( args, ' ', '\\' ), output, errors ); | |
| 61 | |
| 62 if ( m_unlock_key.IsSameAs( output[0] ) ) valid_host = true; | |
| 63 } | |
| 64 | |
| 47 wxImage::AddHandler( new wxJPEGHandler ); | 65 wxImage::AddHandler( new wxJPEGHandler ); |
| 48 wxImage::AddHandler( new wxPNGHandler ); | 66 wxImage::AddHandler( new wxPNGHandler ); |
| 49 wxFileSystem::AddHandler( new wxZipFSHandler ); | 67 wxFileSystem::AddHandler( new wxZipFSHandler ); |
| 50 | 68 |
| 51 // Main Window | 69 // Main Window |
| 52 MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE ); | 70 MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE ); |
| 53 mainframe->SetServer( m_serveraddr, m_serverport ); | 71 mainframe->SetServer( m_serveraddr, m_serverport ); |
| 54 mainframe->SetDBdir( m_dbdir ); | 72 mainframe->SetDBdir( m_dbdir ); |
| 55 mainframe->InDevelop( true ); | 73 mainframe->InDevelop( true ); |
| 56 if ( !mainframe->GetDB( 1, 1, 1 ) ) { | 74 |
| 75 bool dlhhs = false; | |
| 76 if ( valid_host && !m_qdlhhs ) { | |
| 77 dlhhs = true; | |
| 78 } else { | |
| 79 wxMessageDialog dlg( NULL, wxT("download h-data ?"), wxT("Ask"), wxYES_NO ); | |
| 80 if ( wxID_YES == dlg.ShowModal() ) dlhhs = true; | |
| 81 } | |
| 82 | |
| 83 if ( !mainframe->GetDB( true, dlhhs, false ) ) { | |
| 57 mainframe->Destroy(); | 84 mainframe->Destroy(); |
| 58 return true; | 85 return true; |
| 59 } | 86 } |
| 60 | 87 |
| 61 // Splash Screen | 88 // Splash Screen |
| 62 SplashScreen( splash ); | 89 SplashScreen( m_splash ); |
| 63 | 90 |
| 64 // Mode | 91 if ( valid_host ) { |
| 65 if ( !unlock_key.IsEmpty() ) { | 92 mainframe->SetUser( wxT( "root" ) ); |
| 66 wxIPV4address addr; | 93 mainframe->SetTitle( wxT( "Re:Searcher - root" ) ); |
| 67 addr.Hostname( wxGetFullHostName() ); | 94 mainframe->LoadDB( dlhhs ); |
| 68 | 95 mainframe->Show( true ); |
| 69 wxString key = wxT( "re:searcher" ) + addr.IPAddress(); | 96 mainframe->Raise(); |
| 70 wxArrayString args; | 97 return true; |
| 71 args.Add( wxT( "crypto.exe" ) ); | |
| 72 args.Add( wxT( "-a" ) ); | |
| 73 args.Add( key ); | |
| 74 | |
| 75 wxArrayString output, errors; | |
| 76 wxExecute( wxJoin( args, ' ', '\\' ), output, errors ); | |
| 77 | |
| 78 if ( unlock_key.IsSameAs( output[0] ) ) { | |
| 79 mainframe->SetUser( wxT( "root" ) ); | |
| 80 mainframe->SetTitle( wxT( "Re:Searcher - root" ) ); | |
| 81 mainframe->LoadDB(); | |
| 82 mainframe->Show( true ); | |
| 83 return true; | |
| 84 } | |
| 85 } | 98 } |
| 86 | 99 |
| 87 // User Dialog | 100 // User Dialog |
| 88 AuthDialog *authdlg = new AuthDialog( NULL, wxID_ANY, wxT( "Who are you ?" ), wxDefaultPosition, wxDefaultSize, wxCAPTION ); | 101 AuthDialog *authdlg = new AuthDialog( NULL, wxID_ANY, wxT( "Who are you ?" ), wxDefaultPosition, wxDefaultSize, wxCAPTION ); |
| 89 if ( !authdlg->LoadDB() ) { | 102 if ( !authdlg->LoadDB() ) { |
| 111 delete fs; | 124 delete fs; |
| 112 } | 125 } |
| 113 | 126 |
| 114 mainframe->SetUser( authdlg->GetUser() ); | 127 mainframe->SetUser( authdlg->GetUser() ); |
| 115 mainframe->SetTitle( wxT( "Re:Searcher - " ) + authdlg->GetUser() ); | 128 mainframe->SetTitle( wxT( "Re:Searcher - " ) + authdlg->GetUser() ); |
| 116 mainframe->LoadDB(); | 129 mainframe->LoadDB( dlhhs ); |
| 117 mainframe->Show( true ); | 130 mainframe->Show( true ); |
| 118 } else { | 131 } else { |
| 119 mainframe->Destroy(); | 132 mainframe->Destroy(); |
| 120 } | 133 } |
| 121 authdlg->Destroy(); | 134 authdlg->Destroy(); |
| 146 config->Read( wxT( "w" ), &rect.width ); | 159 config->Read( wxT( "w" ), &rect.width ); |
| 147 config->Read( wxT( "h" ), &rect.height ); | 160 config->Read( wxT( "h" ), &rect.height ); |
| 148 | 161 |
| 149 config->SetPath( wxT( "/DBManage" ) ); | 162 config->SetPath( wxT( "/DBManage" ) ); |
| 150 config->Read( wxT( "dbdir" ), &m_dbdir ); | 163 config->Read( wxT( "dbdir" ), &m_dbdir ); |
| 164 config->Read( wxT( "qdlhhs" ), &m_qdlhhs ); | |
| 151 | 165 |
| 152 config->SetPath( wxT( "/Server" ) ); | 166 config->SetPath( wxT( "/Server" ) ); |
| 153 config->Read( wxT( "proxy_address" ), &m_serveraddr ); | 167 config->Read( wxT( "proxy_address" ), &m_serveraddr ); |
| 154 config->Read( wxT( "proxy_port" ), &m_serverport ); | 168 config->Read( wxT( "proxy_port" ), &m_serverport ); |
| 155 if ( m_serveraddr.IsSameAs( wxEmptyString, false ) ) { | 169 if ( m_serveraddr.IsSameAs( wxEmptyString, false ) ) { |
| 160 if ( m_serveraddr.IsSameAs( wxEmptyString, false ) ) { | 174 if ( m_serveraddr.IsSameAs( wxEmptyString, false ) ) { |
| 161 m_serveraddr = wxT( "192.168.21.151" ); // nginx | 175 m_serveraddr = wxT( "192.168.21.151" ); // nginx |
| 162 m_serverport = 80; | 176 m_serverport = 80; |
| 163 } | 177 } |
| 164 | 178 |
| 179 config->SetPath( wxT( "/Print" ) ); | |
| 180 config->Read( wxT( "zoom" ), &pzoom ); | |
| 181 | |
| 165 config->SetPath( wxT( "/Misc" ) ); | 182 config->SetPath( wxT( "/Misc" ) ); |
| 166 config->Read( wxT( "splash" ), &splash ); | 183 config->Read( wxT( "splash" ), &m_splash ); |
| 167 config->Read( wxT( "unlock_key" ), &unlock_key ); | 184 config->Read( wxT( "unlock_key" ), &m_unlock_key ); |
| 168 | 185 |
| 169 delete config; | 186 delete config; |
| 170 } | 187 } |
| 171 | 188 |
| 172 void MyApp::SaveSetting() | 189 void MyApp::SaveSetting() |
| 176 config->SetPath( wxT( "/Geometry" ) ); | 193 config->SetPath( wxT( "/Geometry" ) ); |
| 177 config->Write( wxT( "x" ), rect.x ); | 194 config->Write( wxT( "x" ), rect.x ); |
| 178 config->Write( wxT( "y" ), rect.y ); | 195 config->Write( wxT( "y" ), rect.y ); |
| 179 config->Write( wxT( "w" ), rect.width ); | 196 config->Write( wxT( "w" ), rect.width ); |
| 180 config->Write( wxT( "h" ), rect.height ); | 197 config->Write( wxT( "h" ), rect.height ); |
| 198 | |
| 199 config->SetPath( wxT( "/Print" ) ); | |
| 200 config->Write( wxT( "zoom" ), pzoom ); | |
| 201 | |
| 181 delete config; | 202 delete config; |
| 182 } | 203 } |
| 183 | 204 |
| 184 void MyApp::SplashScreen( int ms ) | 205 void MyApp::SplashScreen( int ms ) |
| 185 { | 206 { |
| 191 wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:startup%02d.png" ), i ) ); | 212 wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:startup%02d.png" ), i ) ); |
| 192 if ( file ) { | 213 if ( file ) { |
| 193 wxInputStream* s = file->GetStream(); | 214 wxInputStream* s = file->GetStream(); |
| 194 wxImage image( *s, wxBITMAP_TYPE_PNG ); | 215 wxImage image( *s, wxBITMAP_TYPE_PNG ); |
| 195 wxBitmap bmp = wxBitmap( image ); | 216 wxBitmap bmp = wxBitmap( image ); |
| 196 wxSplashScreen* splash = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 2000, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxSTAY_ON_TOP ); | 217 wxSplashScreen* splashwin = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 2000, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxSTAY_ON_TOP ); |
| 197 delete file; | 218 delete file; |
| 198 } | 219 } |
| 199 wxMilliSleep( ms ); | 220 wxMilliSleep( ms ); |
| 200 } | 221 } |
| 201 delete fs; | 222 delete fs; |
