changeset 11:799b6008db8e

auto-upgrade.
author pyon@macmini
date Mon, 12 Nov 2018 19:35:50 +0900
parents 36811fd22bd2
children 240752cbe11b
files Makefile include/id.h include/main.h include/mngdb.h include/net.h src/main.cpp src/mngdb.cpp src/net.cpp src/rsearcher.cpp upgrade.bat
diffstat 10 files changed, 256 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Nov 08 19:15:43 2018 +0900
+++ b/Makefile	Mon Nov 12 19:35:50 2018 +0900
@@ -1,5 +1,5 @@
 # Makefile for wxWidgets Application
-# Last Change: 2018-10-31 水 17:05:07.
+# Last Change: 2018-11-09 金 08:45:49.
 # by Takayuki Mutoh
 #
 
@@ -34,6 +34,7 @@
 
 OBJ = $(OBJDIR)/main.o \
 	  $(OBJDIR)/auth.o \
+	  $(OBJDIR)/mngdb.o \
 	  $(OBJDIR)/rsearcher.o \
 	  $(OBJDIR)/net.o
 
@@ -64,6 +65,9 @@
 $(OBJDIR)/net.o: net.cpp net.h 
 	$(CXX) -c $< -o $@ $(CXXFLAGS)
 
+$(OBJDIR)/mngdb.o: mngdb.cpp mngdb.h id.h
+	$(CXX) -c $< -o $@ $(CXXFLAGS)
+
 
 # for icon
 ifdef COMSPEC
--- a/include/id.h	Thu Nov 08 19:15:43 2018 +0900
+++ b/include/id.h	Mon Nov 12 19:35:50 2018 +0900
@@ -1,5 +1,5 @@
 // Filename   : id.h
-// Last Change: 2018-11-08 木 13:58:34.
+// Last Change: 2018-11-09 金 10:54:21.
 //
 
 #ifndef __ID_H__
@@ -7,8 +7,8 @@
 
 #include <wx/wx.h>
 
-#define RSVER "1.4"
-#define RSRELEASE "2018.11.01"
+#define RSVER "1.5"
+#define RSRELEASE "2018.11.12"
 
 enum {
 	/* for mainframe */
@@ -33,6 +33,11 @@
 	/* for auth */
 	ID_UID,
 	ID_PW,
+
+	/* for mange db */
+	ID_MNGBLD,
+	ID_MNGUPLD,
+	ID_MNGEXIT,
 };
 
 #endif // __ID_H__
--- a/include/main.h	Thu Nov 08 19:15:43 2018 +0900
+++ b/include/main.h	Mon Nov 12 19:35:50 2018 +0900
@@ -1,5 +1,5 @@
 // Filename   : main.h
-// Last Change: 2018-11-01 木 11:13:19.
+// Last Change: 2018-11-09 金 09:43:03.
 //
 #include <wx/wx.h>
 #include <wx/config.h>
@@ -7,7 +7,6 @@
 #include <wx/splash.h>
 #include <wx/fs_zip.h>
 #include <wx/filesys.h>
-#include <wx/wfstream.h>
 
 // private classes
 // Define a new application type, each program should derive a class from wxApp
@@ -34,6 +33,7 @@
 
 		void InitSetting();
 		void SaveSetting();
+		wxString GetVersion();
 		void SplashScreen( int ms );
 		void RemoveFile( wxString pattern );
 };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/mngdb.h	Mon Nov 12 19:35:50 2018 +0900
@@ -0,0 +1,53 @@
+// Filename   : mngdb.h
+// Last Change: 2018-11-09 金 09:02:17.
+//
+
+#ifndef __MNGDB_H__
+#define __MNGDB_H__
+
+#include <wx/gdicmn.h>
+#include <wx/font.h>
+#include <wx/colour.h>
+#include <wx/settings.h>
+#include <wx/button.h>
+#include <wx/sizer.h>
+#include <wx/stattext.h>
+#include <wx/datectrl.h>
+#include <wx/dateevt.h>
+#include <wx/filepicker.h>
+#include <wx/statline.h>
+#include <wx/msgdlg.h> 
+
+class ManageDBFrame : public wxFrame 
+{
+    DECLARE_EVENT_TABLE()
+	private:
+		wxString          m_server;
+	
+	protected:
+		wxStaticText*     m_staticTextDate;
+		wxDatePickerCtrl* m_datePicker;
+		wxStaticText* 	  m_staticTextHhs;
+		wxFilePickerCtrl* m_filePickerHhs;
+		wxStaticText*	  m_staticTextCcn;
+		wxFilePickerCtrl* m_filePickerCcn;
+		wxStaticLine*     m_staticline;
+		wxButton* 		  m_buttonBuild;
+		wxButton* 		  m_buttonUpld;
+		wxButton* 		  m_buttonExit;
+	
+	public:
+		ManageDBFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxCAPTION|wxTAB_TRAVERSAL );
+		~ManageDBFrame();
+
+		void OnBuild( wxCommandEvent& event );
+		void OnUpload( wxCommandEvent& event );
+		void OnExit( wxCommandEvent& event );
+
+		void Upload( wxString file );
+		void ClearServer( void );
+		void UpdateDB( void );
+};
+
+#endif //__MNGDB_H__
+
--- a/include/net.h	Thu Nov 08 19:15:43 2018 +0900
+++ b/include/net.h	Mon Nov 12 19:35:50 2018 +0900
@@ -1,5 +1,5 @@
 // Filename   : net.h
-// Last Change: 2018-11-08 譛ィ 10:09:04.
+// Last Change: 2018-11-09 驥 09:31:59.
 //
 
 #ifndef __NET_H__
--- 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 );
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/mngdb.cpp	Mon Nov 12 19:35:50 2018 +0900
@@ -0,0 +1,126 @@
+// Filename   : mngdeb.cpp
+// Last Change: 2018-11-09 驥 13:35:54.
+//
+
+#include "id.h"
+#include "mngdb.h"
+
+ManageDBFrame::ManageDBFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) 
+	: wxFrame( parent, id, title, pos, size, style )
+{
+	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
+	
+	wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL );
+	
+	wxFlexGridSizer* fgSizer = new wxFlexGridSizer( 0, 2, 0, 0 );
+	fgSizer->SetFlexibleDirection( wxBOTH );
+	fgSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
+	
+	m_staticTextDate = new wxStaticText( this, wxID_ANY, wxT( "Date" ), wxDefaultPosition, wxDefaultSize, 0 );
+	fgSizer->Add( m_staticTextDate, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5 );
+	
+	m_datePicker = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY );
+	fgSizer->Add( m_datePicker, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
+	
+	m_staticTextHhs = new wxStaticText( this, wxID_ANY, wxT( "HHS" ), wxDefaultPosition, wxDefaultSize, 0 );
+	fgSizer->Add( m_staticTextHhs, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 );
+	
+	m_filePickerHhs = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString, wxT( "Select a file" ), wxT( "*.db" ), wxDefaultPosition, wxDefaultSize, wxFLP_FILE_MUST_EXIST|wxFLP_OPEN|wxFLP_SMALL|wxFLP_USE_TEXTCTRL );
+	fgSizer->Add( m_filePickerHhs, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
+	
+	m_staticTextCcn = new wxStaticText( this, wxID_ANY, wxT( "CCN" ), wxDefaultPosition, wxDefaultSize, 0 );
+	fgSizer->Add( m_staticTextCcn, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5 );
+	
+	m_filePickerCcn = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString, wxT( "Select a file" ), wxT( "*.db" ), wxDefaultPosition, wxDefaultSize, wxFLP_FILE_MUST_EXIST|wxFLP_OPEN|wxFLP_SMALL|wxFLP_USE_TEXTCTRL );
+	fgSizer->Add( m_filePickerCcn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
+	
+	bSizerTop->Add( fgSizer, 0, wxALIGN_CENTER_HORIZONTAL, 5 );
+	
+	//---
+	m_staticline = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
+	bSizerTop->Add( m_staticline, 0, wxEXPAND|wxALL, 5 );
+	
+	wxBoxSizer* bSizerBtn = new wxBoxSizer( wxHORIZONTAL );
+	
+	m_buttonBuild = new wxButton( this, ID_MNGBLD, wxT( "Build" ), wxDefaultPosition, wxDefaultSize, 0 );
+	bSizerBtn->Add( m_buttonBuild, 0, wxALL, 5 );
+	
+	m_buttonUpld = new wxButton( this, ID_MNGUPLD, wxT( "Upload" ), wxDefaultPosition, wxDefaultSize, 0 );
+	bSizerBtn->Add( m_buttonUpld, 0, wxALL, 5 );
+	
+	m_buttonExit = new wxButton( this, ID_MNGEXIT, wxT( "Exit" ), wxDefaultPosition, wxDefaultSize, 0 );
+	bSizerBtn->Add( m_buttonExit, 0, wxALL, 5 );
+	
+	bSizerTop->Add( bSizerBtn, 0, wxALIGN_CENTER_HORIZONTAL, 5 );
+	
+	this->SetSizer( bSizerTop );
+	this->Layout();
+	
+	this->Centre( wxBOTH );
+}
+
+ManageDBFrame::~ManageDBFrame()
+{
+}
+
+// Event Table
+BEGIN_EVENT_TABLE( ManageDBFrame, wxFrame )
+	EVT_BUTTON( ID_MNGBLD,  ManageDBFrame::OnBuild )
+	EVT_BUTTON( ID_MNGUPLD, ManageDBFrame::OnUpload )
+	EVT_BUTTON( ID_MNGEXIT, ManageDBFrame::OnExit )
+END_EVENT_TABLE()
+
+// Event Handler
+void ManageDBFrame::OnBuild( wxCommandEvent& WXUNUSED(event) )
+{
+	wxMessageBox( wxT( "build done." ) );
+}
+
+void ManageDBFrame::OnUpload( wxCommandEvent& WXUNUSED(event) )
+{
+	ClearServer();
+	Upload( wxT( "index.db" ) );
+	Upload( wxT( "hhs.db" ) );
+	UpdateDB();
+	wxMessageBox( wxT( "upload done." ) );
+}
+
+void ManageDBFrame::OnExit( wxCommandEvent& WXUNUSED(event) )
+{
+	Close();
+}
+
+
+// Functions
+void ManageDBFrame::Upload( wxString file )
+{
+	wxArrayString args;
+	args.Add( wxT( "client.exe" ) );
+	args.Add( wxT( "-a" ) );
+	args.Add( m_server );
+	args.Add( file );
+
+	wxExecute( wxJoin( args, ' ', '\\' ) );
+}
+
+void ManageDBFrame::ClearServer( void )
+{
+// go-server get /clean -> rm -f upload/*
+	wxArrayString args;
+	args.Add( wxT( "client.exe" ) );
+	args.Add( m_server );
+
+	wxExecute( wxJoin( args, ' ', '\\' ) );
+}
+
+void ManageDBFrame::UpdateDB( void )
+{
+// go-server get /mangedb -> mv upload/xxx db/index.db
+//                           mv upload/yyy db/hhs.db
+	wxArrayString args;
+	args.Add( wxT( "client.exe" ) );
+	args.Add( m_server );
+
+	wxExecute( wxJoin( args, ' ', '\\' ) );
+}
+
--- a/src/net.cpp	Thu Nov 08 19:15:43 2018 +0900
+++ b/src/net.cpp	Mon Nov 12 19:35:50 2018 +0900
@@ -1,5 +1,5 @@
 // Filename   : net.cpp
-// Last Change: 2018-11-08 譛ィ 10:08:45.
+// Last Change: 2018-11-09 驥 09:32:56.
 //
 
 #include <wx/datetime.h>
--- a/src/rsearcher.cpp	Thu Nov 08 19:15:43 2018 +0900
+++ b/src/rsearcher.cpp	Mon Nov 12 19:35:50 2018 +0900
@@ -1,11 +1,12 @@
 // Filename   : rsearcher.cpp
-// Last Change: 2018-11-08 譛ィ 14:47:21.
+// Last Change: 2018-11-09 驥 09:01:40.
 //
 
 #include <wx/arrstr.h> 
 #include <wx/html/htmprint.h>
 #include <wx/clipbrd.h>
 #include "id.h"
+#include "mngdb.h"
 #include "rsearcher.h"
 #include "main.h"
 
@@ -628,8 +629,9 @@
 		return;
     }
 
-    if ( cmd.IsSameAs( wxT( "k" ), true ) ) {
-		// hiragana kensaku
+    if ( cmd.IsSameAs( wxT( "3915" ), true ) ) {
+		ManageDBFrame *mngframe = new ManageDBFrame( this, wxID_ANY, wxT( "Management Window" ), wxDefaultPosition, wxSize( 300, 180 ), wxCAPTION|wxTAB_TRAVERSAL );
+		mngframe->Show();
         return;
 	}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/upgrade.bat	Mon Nov 12 19:35:50 2018 +0900
@@ -0,0 +1,12 @@
+@echo off
+echo ===
+echo === Your version is [%2]
+echo === New version released. [%3]
+echo === Downloading new version
+echo ...
+client.exe -r %1
+copy /y client1.exe client.exe
+del client1.exe
+echo === Download finished
+echo ...
+pause