0
|
1 // Filename : main.cpp
|
6
|
2 // Last Change: 2018-10-23 火 10:09:42.
|
0
|
3 //
|
4
|
4 #include "id.h"
|
0
|
5 #include "main.h"
|
|
6 #include "auth.h"
|
|
7 #include "rsearcher.h"
|
|
8
|
|
9 IMPLEMENT_APP( MyApp )
|
|
10
|
|
11 IMPLEMENT_CLASS( MyApp, wxApp )
|
|
12
|
|
13 MyApp::MyApp()
|
|
14 {
|
1
|
15 develop = true;
|
0
|
16 }
|
|
17 MyApp::~MyApp()
|
|
18 {
|
|
19 }
|
|
20
|
|
21 bool MyApp::OnInit()
|
|
22 {
|
|
23 if ( !wxApp::OnInit() ) return false;
|
|
24
|
|
25 wxImage::AddHandler( new wxJPEGHandler );
|
|
26 wxImage::AddHandler( new wxPNGHandler );
|
|
27 InitSetting();
|
|
28
|
6
|
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
|
5
|
34 // Splash Screen
|
|
35 wxFileSystem::AddHandler( new wxZipFSHandler );
|
|
36 wxFileSystem* fs = new wxFileSystem();
|
|
37 wxString archive = wxT( "file:///./myapp.bin" );
|
|
38 for ( int i = 0; i < 11; i++ ) {
|
|
39 wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:startup%02d.png" ), i ) );
|
|
40 if ( file ) {
|
|
41 wxInputStream* s = file->GetStream();
|
|
42 wxImage image( *s, wxBITMAP_TYPE_PNG );
|
|
43 wxBitmap bmp = wxBitmap( image );
|
6
|
44 wxSplashScreen* splash = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 2500, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxSTAY_ON_TOP );
|
5
|
45 delete file;
|
|
46 }
|
6
|
47 wxMilliSleep( 200 );
|
5
|
48 }
|
|
49 delete fs;
|
3
|
50
|
5
|
51 if ( !authdlg->LoadDB() ) {
|
|
52 authdlg->Destroy();
|
|
53 return false;
|
|
54 }
|
1
|
55
|
3
|
56 if ( authdlg->ShowModal() == wxID_OK ) {
|
5
|
57 wxString ui = wxString::Format( wxT( "./image/" ) + authdlg->GetUser() + wxT( ".jpg" ) );
|
6
|
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 }
|
5
|
74
|
|
75 // Main Window
|
|
76 MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE );
|
|
77 mainframe->InDevelop( true );
|
|
78 mainframe->SetServer( m_server );
|
3
|
79 mainframe->SetUser( authdlg->GetUser() );
|
5
|
80 mainframe->LoadDB();
|
|
81 mainframe->SetTitle( wxT( "Re:Searcher - " ) + authdlg->GetUser() );
|
3
|
82 mainframe->Show( true );
|
5
|
83 //mainframe->Destroy();
|
3
|
84 }
|
|
85 authdlg->Destroy();
|
0
|
86
|
|
87 return true;
|
|
88 }
|
|
89
|
|
90 int MyApp::OnExit()
|
|
91 {
|
6
|
92 RemoveFile( wxT( "auth.db" ) );
|
|
93 RemoveFile( wxT( "hhs.db" ) );
|
|
94 RemoveFile( wxT( ".cache/*" ) );
|
0
|
95 SaveSetting();
|
|
96 return 0;
|
|
97 }
|
|
98
|
|
99 void MyApp::InitSetting()
|
|
100 {
|
2
|
101 conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT( "app.conf" );
|
|
102 config = new wxFileConfig( wxT( "MyApp" ), wxT( "T.Mutoh" ), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE );
|
|
103
|
|
104 config->SetPath( wxT( "/Geometry" ) );
|
|
105 config->Read( wxT( "x" ), &rect.x );
|
|
106 config->Read( wxT( "y" ), &rect.y );
|
|
107 config->Read( wxT( "w" ), &rect.width );
|
|
108 config->Read( wxT( "h" ), &rect.height );
|
0
|
109
|
3
|
110 wxString proxy;
|
2
|
111 config->SetPath( wxT( "/Server" ) );
|
|
112 config->Read( wxT( "server" ), &m_server );
|
3
|
113 config->Read( wxT( "proxy" ), &proxy );
|
0
|
114 delete config;
|
2
|
115
|
3
|
116 if ( !proxy.IsSameAs( wxEmptyString, false ) ) m_server = proxy;
|
2
|
117 //m_server = wxT( "192.168.79.124:80" );
|
|
118 if ( m_server.IsSameAs( wxEmptyString, false ) )
|
|
119 m_server = wxT( "192.168.21.151:80" ); // nginx
|
0
|
120 }
|
|
121
|
|
122 void MyApp::SaveSetting()
|
|
123 {
|
3
|
124 config = new wxFileConfig( wxT( "MyApp" ), wxT( "T.Mutoh" ), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE );
|
0
|
125
|
3
|
126 config->SetPath( wxT( "/Geometry" ) );
|
|
127 config->Write( wxT( "x" ), rect.x );
|
|
128 config->Write( wxT( "y" ), rect.y );
|
|
129 config->Write( wxT( "w" ), rect.width );
|
|
130 config->Write( wxT( "h" ), rect.height );
|
0
|
131 delete config;
|
|
132 }
|
|
133
|
6
|
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
|