diff src/iklist.cpp @ 2:c0f76f8e67fa draft v1.0

ver 1.0.0 release (add 2 items, time-limit@2022-09-30. & bug fix.)
author pyon <pyon@macmini>
date Sat, 28 Aug 2021 09:56:40 +0900
parents 520044113ef0
children d3e201c48ff8
line wrap: on
line diff
--- a/src/iklist.cpp	Tue Aug 24 21:30:47 2021 +0900
+++ b/src/iklist.cpp	Sat Aug 28 09:56:40 2021 +0900
@@ -1,5 +1,5 @@
 // Filename   : iklist.cpp
-// Last Change: 2021-08-20 金 12:48:51.
+// Last Change: 2021-08-27 金 14:20:56.
 //
 #include <wx/textfile.h>
 #include <wx/utils.h>
@@ -9,7 +9,9 @@
 #include <wx/txtstrm.h>
 #include <wx/fs_zip.h>
 #include <wx/filesys.h>
+#include <wx/datetime.h>
 #include <wx/msgdlg.h>
+#include <wx/fileconf.h>
 
 #include "iklist.h"
 
@@ -18,12 +20,22 @@
 MainFrame::MainFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) 
 	: wxFrame(parent, id, title, pos, size, style)
 {
+	// Check Limit Date
+	wxDateTime today = wxDateTime::Today();
+	wxDateTime limit(30, wxDateTime::Month::Sep, 2022);
+	if (today.IsLaterThan(limit)) {
+		wxMessageBox(wxT("使用期限が過ぎています."));
+		Close();
+	}
+
 	CreateControls();
 	LoadConfig();
+	m_statusBar->SetStatusText(wxString::Format(wxT(" Welcome to I.K.List - version %s"), m_version), 0);
 
 	// Connect Events
 	m_searchCtrl->Connect(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, wxCommandEventHandler(MainFrame::OnCancel), NULL, this);
 	m_searchCtrl->Connect(wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN, wxCommandEventHandler(MainFrame::OnSearch), NULL, this);
+	m_searchCtrl->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(MainFrame::OnText), NULL, this);
 	m_searchCtrl->Connect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(MainFrame::OnSearch), NULL, this);
 	m_textCtrl->Connect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(MainFrame::OnTextEnter), NULL, this);
 	m_button->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MainFrame::OnClick), NULL, this);
@@ -41,16 +53,17 @@
 	dir.IsOpened();
 	bool cont = dir.GetFirst(&filename, wxT("iklist-*"), wxDIR_FILES);
 	while (cont) {
-		wxRemoveFile(tmpdir + wxFILE_SEP_PATH + filename);
+		wxString file = tmpdir + wxFILE_SEP_PATH + filename;
+		if (wxFileName::IsFileWritable(file))
+			wxRemoveFile(file);
 		cont = dir.GetNext(&filename);
 	}
 
 	// Disconnect Events
 	m_searchCtrl->Disconnect(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, wxCommandEventHandler(MainFrame::OnCancel), NULL, this);
 	m_searchCtrl->Disconnect(wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN, wxCommandEventHandler(MainFrame::OnSearch), NULL, this);
+	m_searchCtrl->Disconnect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(MainFrame::OnText), NULL, this);
 	m_searchCtrl->Disconnect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(MainFrame::OnSearch), NULL, this);
-	m_textCtrl->Disconnect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(MainFrame::OnTextEnter), NULL, this);
-	m_button->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MainFrame::OnClick), NULL, this);
 	m_choiceCity->Disconnect(wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(MainFrame::OnCityChoice), NULL, this);
 	m_choiceKind->Disconnect(wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(MainFrame::OnKindChoice), NULL, this);
 	m_dataViewListCtrl->Disconnect(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEventHandler(MainFrame::OnListItemActivated), NULL, this);
@@ -65,6 +78,12 @@
 void MainFrame::OnCancel(wxCommandEvent& WXUNUSED(event))
 {
 	m_searchCtrl->Clear();
+	SetList();
+}
+
+void MainFrame::OnText(wxCommandEvent& WXUNUSED(event))
+{
+	SetList();
 }
 
 void MainFrame::OnTextEnter(wxCommandEvent& WXUNUSED(event))
@@ -95,18 +114,19 @@
 
 	wxString cmd = wxT("cmd /c start ") + pdf;
 	wxArrayString output, error;
-	wxExecute(cmd, output, error, wxEXEC_HIDE_CONSOLE);
+	wxExecute(cmd, output, error, wxEXEC_ASYNC|wxEXEC_HIDE_CONSOLE);
 }
 
 // Functions
 void MainFrame::SetList()
 {
-	wxString kw = m_searchCtrl->GetValue();
+	wxString text = m_searchCtrl->GetValue();
 	wxString city = m_choiceCity->GetString(m_choiceCity->GetSelection());
 	wxString kind = m_choiceKind->GetString(m_choiceKind->GetSelection());
 
 	m_dataViewListCtrl->DeleteAllItems();
 	wxVector<wxVariant> data;
+	unsigned int n = 0;
     for (int i = 0; i < m_data.GetCount(); i++) {
 		wxArrayString str = wxSplit(m_data[i], ':');
 
@@ -115,30 +135,44 @@
 		data.push_back(wxVariant(str[1]));	// City
 		data.push_back(wxVariant(str[2]));	// Kind
 
-		unsigned int flag = 0;
-		if (!kw.IsEmpty() && str[0].Find(kw) == wxNOT_FOUND) flag |= 1;
-		if (!city.IsEmpty() && str[1].IsSameAs(city)) flag |= 2;
-		if (!kind.IsEmpty() && str[2].IsSameAs(kind)) flag |= 4;
-		if (flag != 0)
+		bool matched = true;
+		if (!text.IsEmpty() &&  str[0].Find(text) == wxNOT_FOUND) matched =false;
+		if (!city.IsEmpty() && !str[1].IsSameAs(city))            matched =false;
+		if (!kind.IsEmpty() && !str[2].IsSameAs(kind))            matched =false;
+
+		if (!m_inarea && str.GetCount() == 4 && str[3].IsSameAs(wxT("*"))) matched =false;
+
+		if (matched) {
 			m_dataViewListCtrl->AppendItem(data);
+			n++;
+		}
 
 		data.clear();
     }
+	//m_dataViewListCtrl->SetScrollPos(wxVERTICAL, 0, true);
+	m_dataViewListCtrl->Scroll(0, 0);
+	m_statusBar->SetStatusText(wxString::Format(wxT(" %d found."), n), 0);
 }
-
+#include <wx/sstream.h>
 wxString MainFrame::MakePDF(wxString index)
 {
-	wxString file = SearchFile(wxT("data03"), index);
-	wxFileInputStream si1(file);
-	file = SearchFile(wxT("data04"), index);
-	wxFileInputStream si2(file);
-	file = SearchFile(wxT("data08"), index);
-	wxFileInputStream si3(file);
-
 	wxString tmpdir;
 	wxGetEnv(wxT("TEMP"), &tmpdir);
 	wxString pdf = tmpdir + "/iklist-" + index + ".pdf";
+	if (wxFile::Exists(pdf)) return pdf;
+
+	wxStringInputStream si0(wxT("%PDF"));
+
+	wxString file;
+	file = SearchFile(wxT("data/03"), index);
+	wxFileInputStream si1(file);
+	file = SearchFile(wxT("data/04"), index);
+	wxFileInputStream si2(file);
+	file = SearchFile(wxT("data/08"), index);
+	wxFileInputStream si3(file);
+
 	wxFileOutputStream so(pdf);
+	so << si0;
 	so << si1 << si2 << si3;	// use chunk buffer to copy if file is big.
 
 	return pdf;
@@ -160,6 +194,118 @@
 	return directory + wxT("/") + filename;
 }
 
+void MainFrame::LoadConfig()
+{
+	wxFileSystem::AddHandler(new wxZipFSHandler);
+	wxFileSystem* fs = new wxFileSystem;
+	wxString archive = wxT("iklist.lib");
+
+	// Load Password
+	wxString pwfn = wxT("p8wypswd5c0x");
+	wxFSFile* pwfile = fs->OpenFile(archive + wxT("#zip:") + pwfn);
+	wxString buf;
+	if (pwfile) {
+		wxInputStream *zstream = pwfile->GetStream();
+		wxTextInputStream tstream(*zstream);
+		buf = tstream.ReadLine();
+		delete pwfile;
+	}
+	for (int i = 0; i < buf.Len(); i++) {	// XOR 17
+		m_pswd += wxString::Format(wxT("%c"), buf[i].GetValue() ^ 17); 
+	}
+
+	pwfn = wxT("_p8wypswd5c0x");
+	wxFSFile* gpwfile = fs->OpenFile(archive + wxT("#zip:") + pwfn);
+	if (gpwfile) {
+		wxInputStream *zstream = gpwfile->GetStream();
+		wxTextInputStream tstream(*zstream);
+		buf = tstream.ReadLine();
+		delete gpwfile;
+	}
+	for (int i = 0; i < buf.Len(); i++) {	// XOR 17
+		m_gpswd += wxString::Format(wxT("%c"), buf[i].GetValue() ^ 17); 
+	}
+
+	// Load List
+	wxString listfn = wxT("q534list8mor");
+	wxFSFile* listfile = fs->OpenFile(archive + wxT("#zip:") + listfn);
+	if (listfile) {
+		wxInputStream *zstream = listfile->GetStream();
+		wxTextInputStream tstream(*zstream);
+		for (int i = 0; i < 543; i++) {	//#########################
+		//while (!zstream->Eof()) {
+			m_data.Add(tstream.ReadLine());
+		}
+		delete listfile;
+	}
+	
+	// Load config
+    wxString conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf");
+    wxFileConfig* conf = new wxFileConfig(wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE);
+    conf->SetPath(wxT("/Misc"));
+    conf->Read(wxT("version"), &m_version);
+	delete conf;
+
+	// Set Filter
+	wxArrayString filter = GetChoiceArray(1);
+	for (int i = 0; i < filter.GetCount(); i++) {
+		m_choiceCity->Append(filter[i]);
+	}
+	m_choiceCity->SetSelection(0);
+
+	filter = GetChoiceArray(2);
+	for (int i = 0; i < filter.GetCount(); i++) {
+		m_choiceKind->Append(filter[i]);
+	}
+	m_choiceKind->SetSelection(0);
+
+	delete fs;
+}
+
+wxArrayString MainFrame::GetChoiceArray(int n)
+{
+	wxArrayString filter;
+	filter.Add(wxEmptyString);
+	for (int i = 0; i < m_data.GetCount(); i++) {
+		wxArrayString str = wxSplit(m_data[i], ':');
+		bool seen;
+		for (int j = 0; j < filter.GetCount(); j++) {
+			if (filter[j].IsSameAs(str[n])) {
+				seen = true;
+				break;
+			} else {
+				seen = false;
+			}
+		}
+		if (!seen) filter.Add(str[n]);
+	}
+	return filter;
+}
+
+void MainFrame::CheckPassword()
+{
+	m_inarea = false;
+	if (m_textCtrl->GetValue().IsSameAs(m_pswd, true)) {
+		m_inarea = true;
+	} else if (m_textCtrl->GetValue().IsSameAs(m_gpswd, true)) {
+		//;
+	} else {
+		m_textCtrl->SetBackgroundColour(wxColour(255, 160, 160));
+		m_textCtrl->SelectAll();
+		return;
+	}
+	m_staticTextWord->SetLabel(wxT("キーワード:"));
+
+	m_textCtrl->Disconnect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(MainFrame::OnTextEnter), NULL, this);
+	m_button->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MainFrame::OnClick), NULL, this);
+	m_textCtrl->Destroy();
+	m_button->Destroy();
+	m_searchCtrl->Show();
+	this->Layout();
+
+	SetList();
+}
+
 void MainFrame::CreateControls()
 {
     this->SetIcon(wxIcon(wxT("sample")));
@@ -174,14 +320,6 @@
 	m_staticTextWord = new wxStaticText(this, wxID_ANY, wxT("パスワード:"), wxDefaultPosition, wxDefaultSize, 0);
 	bSizerWord->Add(m_staticTextWord, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
 
-	m_searchCtrl = new wxSearchCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(0, -1), 0);
-	#ifndef __WXMAC__
-	m_searchCtrl->ShowSearchButton(true);
-	#endif
-	m_searchCtrl->ShowCancelButton(true);
-
-	bSizerWord->Add(m_searchCtrl, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
-
 	m_textCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, -1), wxTE_PASSWORD|wxTE_PROCESS_ENTER);
 	bSizerWord->Add(m_textCtrl, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
 	m_textCtrl->SetFocus();
@@ -189,6 +327,13 @@
 	m_button = new wxButton(this, wxID_ANY, wxT("OK"), wxDefaultPosition, wxSize(60, -1), 0);
 	bSizerWord->Add(m_button, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
 
+	m_searchCtrl = new wxSearchCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, -1), 0);
+	#ifndef __WXMAC__
+	m_searchCtrl->ShowSearchButton(true);
+	#endif
+	m_searchCtrl->ShowCancelButton(true);
+	bSizerWord->Add(m_searchCtrl, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
+
 	bSizerTop->Add(bSizerWord, 0, wxEXPAND, 5);
 
 	//--
@@ -203,6 +348,7 @@
 	wxArrayString m_choiceCityChoices;
 	m_choiceCity = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceCityChoices, 0);
 	m_choiceCity->SetSelection(0);
+	m_choiceCity->SetBackgroundColour(wxColour(220, 255, 255));
 	bSizerFilter->Add(m_choiceCity, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
 
 	m_staticTextKind = new wxStaticText(this, wxID_ANY, wxT("区分"), wxDefaultPosition, wxDefaultSize, 0);
@@ -211,6 +357,7 @@
 	wxArrayString m_choiceKindChoices;
 	m_choiceKind = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceKindChoices, 0);
 	m_choiceKind->SetSelection(0);
+	m_choiceKind->SetBackgroundColour(wxColour(220, 255, 255));
 	bSizerFilter->Add(m_choiceKind, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
 
 	bSizerTop->Add(bSizerFilter, 0, wxEXPAND, 5);
@@ -225,90 +372,10 @@
 
 	this->SetSizer(bSizerTop);
 	this->Layout();
+	m_statusBar = this->CreateStatusBar(1, wxSTB_SIZEGRIP, wxID_ANY);
+	m_statusBar->SetBackgroundColour(wxColour(130, 170, 210));
 
 	this->Centre(wxBOTH);
+	m_searchCtrl->Hide();
 }
 
-void MainFrame::LoadConfig()
-{
-	wxFileSystem::AddHandler(new wxZipFSHandler);
-	wxFileSystem* fs = new wxFileSystem;
-	wxString archive = wxT("iklist.lib");
-
-	// Load Password
-	wxString pwfn = wxT("p8wypswd5c0x");
-	wxFSFile* pwfile = fs->OpenFile(archive + wxT("#zip:") + pwfn);
-	if (pwfile) {
-		wxInputStream *zstream = pwfile->GetStream();
-		wxTextInputStream tstream(*zstream);
-		m_pswd = tstream.ReadLine();
-		delete pwfile;
-	}
-
-	// Load List
-	wxString listfn = wxT("q534list8mor");
-	wxFSFile* listfile = fs->OpenFile(archive + wxT("#zip:") + listfn);
-	if (listfile) {
-		wxInputStream *zstream = listfile->GetStream();
-		wxTextInputStream tstream(*zstream);
-		for (int i = 0; i < 541; i++) {	//#########################
-		//while (!zstream->Eof()) {
-			m_data.Add(tstream.ReadLine());
-		}
-		delete listfile;
-	}
-
-	// Set Filter
-	wxArrayString filter1, filter2;
-	filter1.Add(wxEmptyString);
-	filter2.Add(wxEmptyString);
-	for (int i = 0; i < m_data.GetCount(); i++) {
-		wxArrayString str = wxSplit(m_data[i], ':');
-		bool flag1, flag2;
-		for (int j = 0; j < filter1.GetCount(); j++) {
-			if (filter1[j].IsSameAs(str[1])) {
-				flag1 = false;
-			} else {
-				flag1 = true;
-			}
-		}
-		if (flag1) filter1.Add(str[1]);
-
-		for (int j = 0; j < filter2.GetCount(); j++) {
-			if (filter2[j].IsSameAs(str[2])) {
-				flag2 = false;
-			} else {
-				flag2 = true;
-			}
-		}
-		if (flag2) filter2.Add(str[2]);
-	}
-
-	for (int i = 0; i < filter1.GetCount(); i++) {
-		m_choiceCity->Append(filter1[i]);
-	}
-	m_choiceCity->SetSelection(0);
-	for (int i = 0; i < filter2.GetCount(); i++) {
-		m_choiceKind->Append(filter2[i]);
-	}
-	m_choiceKind->SetSelection(0);
-
-	delete fs;
-}
-
-void MainFrame::CheckPassword()
-{
-	if (m_textCtrl->GetValue().IsSameAs(m_pswd, true)) {
-		m_staticTextWord->SetLabel(wxT("キーワード:"));
-		m_searchCtrl->SetSize(200, -1);	
-		m_textCtrl->SetSize(0, -1);
-		m_textCtrl->Hide();
-		m_button->SetSize(0, -1);
-		m_button->Hide();
-		SetList();
-	} else {
-		m_textCtrl->SetBackgroundColour(wxColour(255, 160, 160));
-		m_textCtrl->SelectAll();
-	}
-}
-