Mercurial > mercurial > hgweb_rsearcher.cgi
diff src/main.cpp @ 11:799b6008db8e
auto-upgrade.
author | pyon@macmini |
---|---|
date | Mon, 12 Nov 2018 19:35:50 +0900 |
parents | 36811fd22bd2 |
children | f5ffc34f045a |
line wrap: on
line diff
--- a/src/main.cpp Thu Nov 08 19:15:43 2018 +0900 +++ b/src/main.cpp Mon Nov 12 19:35:50 2018 +0900 @@ -1,11 +1,14 @@ // Filename : main.cpp -// Last Change: 2018-11-01 木 11:39:22. +// Last Change: 2018-11-09 金 11:54:20. // #include <wx/socket.h> +#include <wx/sstream.h> +#include <wx/protocol/http.h> #include "id.h" #include "main.h" #include "auth.h" +#include "net.h" #include "rsearcher.h" IMPLEMENT_APP( MyApp ) @@ -24,10 +27,26 @@ { if ( !wxApp::OnInit() ) return false; + InitSetting(); + + // Check New-Version + wxString newver = GetVersion(); + if ( newver.Cmp( RSVER ) == 1 ) { // 1.9 -> 1.91 -> 1.92 ... + wxString sv = wxString::Format( wxT( "%s:%d" ), m_serveraddr, m_serverport ); + + wxArrayString args; + args.Add( wxT( "upgrade.bat" ) ); + args.Add( sv ); + args.Add( RSVER ); + args.Add( newver ); + + wxExecute( wxJoin( args, ' ', '\\' ) ); + return false; + } + wxImage::AddHandler( new wxJPEGHandler ); wxImage::AddHandler( new wxPNGHandler ); wxFileSystem::AddHandler( new wxZipFSHandler ); - InitSetting(); // Main Window MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE ); @@ -175,6 +194,28 @@ delete fs; } +wxString MyApp::GetVersion( void ) +{ + wxHTTP get; + get.SetTimeout( 30 ); + get.SetFlags( wxSOCKET_WAITALL|wxSOCKET_BLOCK ); + while ( !get.Connect( m_serveraddr, m_serverport ) ) + wxSleep( 1 ); + + wxString version; + wxString url = wxT( "/release/version" ); + wxInputStream *http_istream = get.GetInputStream( url ); + if ( get.GetError() == wxPROTO_NOERR ) { + wxStringOutputStream out_stream( &version ); + http_istream->Read( out_stream ); + } + + wxDELETE( http_istream ); + get.Close(); + + return version; +} + void MyApp::RemoveFile( wxString pattern ) { wxString file = wxFindFirstFile( pattern );