Skip to content

Commit

Permalink
Merge pull request #420 from lixun910/master
Browse files Browse the repository at this point in the history
1.8.6 GeoDa with TestMode
  • Loading branch information
lixun910 committed May 5, 2016
2 parents c0304e0 + f505135 commit ac64d55
Show file tree
Hide file tree
Showing 6 changed files with 1,383 additions and 1,305 deletions.
35 changes: 30 additions & 5 deletions DialogTools/AutoUpdateDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "../logger.h"
#include "../GeneralWxUtils.h"
#include "../GdaException.h"
#include "../ShapeOperations/OGRDataAdapter.h"
#include "AutoUpdateDlg.h"

using namespace std;
Expand Down Expand Up @@ -79,7 +80,7 @@ string ReadUrlContent(const char* url)

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_string);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
//curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 1L);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 1L);

res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
Expand All @@ -99,7 +100,7 @@ bool DownloadUrl(const char* url, const char* filepath)
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_file);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5L);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 1L);

res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
Expand All @@ -117,6 +118,12 @@ bool DownloadUrl(const char* url, const char* filepath)
// return Version or empty string
wxString AutoUpdate::CheckUpdate()
{
bool isTestMode = false;
std::vector<std::string> test_mode = OGRDataAdapter::GetInstance().GetHistory("test_mode");
if (!test_mode.empty() && test_mode[0] == "yes") {
isTestMode = true;
}

wxString checklist = GetCheckList();
wxStringTokenizer tokenizer;

Expand All @@ -128,8 +135,8 @@ wxString AutoUpdate::CheckUpdate()
}
}
wxString version = tokenizer.GetNextToken();

wxString version_regex = "^[0-9]\\.[0-9]\\.[0-9]+$";
wxString version_regex = "^[0-9]\\.[0-9]\\.[0-9]+(\\.[0-9]+)?$";
wxRegEx regex;
regex.Compile(version_regex);
if (!regex.Matches(version)) {
Expand All @@ -141,14 +148,32 @@ wxString AutoUpdate::CheckUpdate()
int update_major = wxAtoi(ver_tokenizer.GetNextToken());
int update_minor = wxAtoi(ver_tokenizer.GetNextToken());
int update_build = wxAtoi(ver_tokenizer.GetNextToken());

int update_subbuild = 0;

if (ver_tokenizer.HasMoreTokens()) {
update_subbuild = wxAtoi(ver_tokenizer.GetNextToken());
}

if (update_major < Gda::version_major) return "";
if (update_major > Gda::version_major) return version;
// update_major == version_major
if (update_minor < Gda::version_minor) return "";
if (update_minor > Gda::version_minor) return version;
// update_minor == version_minor
if (update_build > Gda::version_build) return version;

if (update_build > Gda::version_build && update_build % 2 == 0) {
// released version
return version;
}

// could be a testing version
if (isTestMode
&& update_build % 2 == 1 // e.g. 1.8.5
&& update_subbuild >= 0 ) { // 1.8.5.1
return version;
}

return "";
}

Expand Down
31 changes: 30 additions & 1 deletion GeoDa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5678,12 +5678,21 @@ void GdaFrame::OnCheckUpdates(wxCommandEvent& WXUNUSED(event) )
}
}

void GdaFrame::OnCheckTestMode(wxCommandEvent& event)
{
wxString checked = "no";
if (event.IsChecked()) {
checked = "yes";
}
OGRDataAdapter::GetInstance().AddEntry("test_mode", std::string(checked.mb_str()));
}

void GdaFrame::OnHelpAbout(wxCommandEvent& WXUNUSED(event) )
{
wxDialog dlg;
wxXmlResource::Get()->LoadDialog(&dlg, this, "IDD_ABOUTBOX");

wxStaticText* cr = dynamic_cast<wxStaticText*>
wxStaticText* cr = dynamic_cast<wxStaticText*>
(wxWindow::FindWindowById(XRCID("ID_COPYRIGHT"), &dlg));
wxString cr_s;
cr_s << "Copyright (C) 2011-" << Gda::version_year << " by Luc Anselin";
Expand All @@ -5700,6 +5709,11 @@ void GdaFrame::OnHelpAbout(wxCommandEvent& WXUNUSED(event) )
wxString vl_s;
vl_s << "GeoDa " << Gda::version_major << "." << Gda::version_minor << ".";
vl_s << Gda::version_build;

if (Gda::version_subbuild > 0) {
vl_s << "." << Gda::version_subbuild;
}

if (Gda::version_type == 0) {
vl_s << " (alpha),";
} else if (Gda::version_type == 1) {
Expand Down Expand Up @@ -5738,6 +5752,21 @@ void GdaFrame::OnHelpAbout(wxCommandEvent& WXUNUSED(event) )
if (vl) vl->SetLabelText(vl_s);

wxButton* btn_update = dynamic_cast<wxButton*>(wxWindow::FindWindowById(XRCID("ID_CHECKUPDATES"), &dlg));

wxCheckBox* chk_testmode = dynamic_cast<wxCheckBox*>(wxWindow::FindWindowById(XRCID("IDC_CHECK_TESTMODE"), &dlg));
std::vector<std::string> test_mode = OGRDataAdapter::GetInstance().GetHistory("test_mode");

bool isTestMode = false;
if (!test_mode.empty()) {
if (test_mode[0] == "yes") {
isTestMode = true;
chk_testmode->SetValue(true);
} else {
chk_testmode->SetValue(false);
}
}

chk_testmode->Connect(wxEVT_CHECKBOX, wxCommandEventHandler(GdaFrame::OnCheckTestMode), NULL, this);

btn_update->Connect(wxEVT_BUTTON, wxCommandEventHandler(GdaFrame::OnCheckUpdates), NULL, this);
dlg.ShowModal();
Expand Down
1 change: 1 addition & 0 deletions GeoDa.h
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ class GdaFrame: public wxFrame

void OnHelpAbout(wxCommandEvent& event);
void OnCheckUpdates(wxCommandEvent& event);
void OnCheckTestMode(wxCommandEvent& event);

void OnTableSetLocale(wxCommandEvent& event);
void OnEncodingUTF8(wxCommandEvent& event);
Expand Down
Loading

0 comments on commit ac64d55

Please sign in to comment.