comparison src/main.cpp @ 11:799b6008db8e

auto-upgrade.
author pyon@macmini
date Mon, 12 Nov 2018 19:35:50 +0900
parents 36811fd22bd2
children f5ffc34f045a
comparison
equal deleted inserted replaced
10:36811fd22bd2 11:799b6008db8e
1 // Filename : main.cpp 1 // Filename : main.cpp
2 // Last Change: 2018-11-01 木 11:39:22. 2 // Last Change: 2018-11-09 金 11:54:20.
3 // 3 //
4 4
5 #include <wx/socket.h> 5 #include <wx/socket.h>
6 #include <wx/sstream.h>
7 #include <wx/protocol/http.h>
6 #include "id.h" 8 #include "id.h"
7 #include "main.h" 9 #include "main.h"
8 #include "auth.h" 10 #include "auth.h"
11 #include "net.h"
9 #include "rsearcher.h" 12 #include "rsearcher.h"
10 13
11 IMPLEMENT_APP( MyApp ) 14 IMPLEMENT_APP( MyApp )
12 15
13 IMPLEMENT_CLASS( MyApp, wxApp ) 16 IMPLEMENT_CLASS( MyApp, wxApp )
21 } 24 }
22 25
23 bool MyApp::OnInit() 26 bool MyApp::OnInit()
24 { 27 {
25 if ( !wxApp::OnInit() ) return false; 28 if ( !wxApp::OnInit() ) return false;
29
30 InitSetting();
31
32 // Check New-Version
33 wxString newver = GetVersion();
34 if ( newver.Cmp( RSVER ) == 1 ) { // 1.9 -> 1.91 -> 1.92 ...
35 wxString sv = wxString::Format( wxT( "%s:%d" ), m_serveraddr, m_serverport );
36
37 wxArrayString args;
38 args.Add( wxT( "upgrade.bat" ) );
39 args.Add( sv );
40 args.Add( RSVER );
41 args.Add( newver );
42
43 wxExecute( wxJoin( args, ' ', '\\' ) );
44 return false;
45 }
26 46
27 wxImage::AddHandler( new wxJPEGHandler ); 47 wxImage::AddHandler( new wxJPEGHandler );
28 wxImage::AddHandler( new wxPNGHandler ); 48 wxImage::AddHandler( new wxPNGHandler );
29 wxFileSystem::AddHandler( new wxZipFSHandler ); 49 wxFileSystem::AddHandler( new wxZipFSHandler );
30 InitSetting();
31 50
32 // Main Window 51 // Main Window
33 MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE ); 52 MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE );
34 mainframe->SetServer( m_serveraddr, m_serverport ); 53 mainframe->SetServer( m_serveraddr, m_serverport );
35 mainframe->InDevelop( true ); 54 mainframe->InDevelop( true );
173 wxMilliSleep( ms ); 192 wxMilliSleep( ms );
174 } 193 }
175 delete fs; 194 delete fs;
176 } 195 }
177 196
197 wxString MyApp::GetVersion( void )
198 {
199 wxHTTP get;
200 get.SetTimeout( 30 );
201 get.SetFlags( wxSOCKET_WAITALL|wxSOCKET_BLOCK );
202 while ( !get.Connect( m_serveraddr, m_serverport ) )
203 wxSleep( 1 );
204
205 wxString version;
206 wxString url = wxT( "/release/version" );
207 wxInputStream *http_istream = get.GetInputStream( url );
208 if ( get.GetError() == wxPROTO_NOERR ) {
209 wxStringOutputStream out_stream( &version );
210 http_istream->Read( out_stream );
211 }
212
213 wxDELETE( http_istream );
214 get.Close();
215
216 return version;
217 }
218
178 void MyApp::RemoveFile( wxString pattern ) 219 void MyApp::RemoveFile( wxString pattern )
179 { 220 {
180 wxString file = wxFindFirstFile( pattern ); 221 wxString file = wxFindFirstFile( pattern );
181 while ( !file.empty() ) { 222 while ( !file.empty() ) {
182 wxRemoveFile( file ); 223 wxRemoveFile( file );