@@ -217,8 +217,8 @@ bool Application::OnInit() {
217217 }
218218 }
219219 if (g_settings.getInteger (Config::USE_UPDATER) == 1 ) {
220- // UpdateChecker updater;
221- // updater.connect(g_gui.root);
220+ UpdateChecker updater;
221+ updater.connect (g_gui.root );
222222 }
223223#endif
224224
@@ -424,28 +424,48 @@ void MainFrame::OnIdle(wxIdleEvent& event) {
424424void MainFrame::OnUpdateReceived (wxCommandEvent& event) {
425425 std::string data = *(std::string*)event.GetClientData ();
426426 delete (std::string*)event.GetClientData ();
427- size_t first_colon = data.find (' :' );
428- size_t second_colon = data.find (' :' , first_colon + 1 );
429427
430- if (first_colon == std::string::npos || second_colon == std::string::npos) {
431- return ;
432- }
428+ try {
429+ json::mValue val;
430+ if (!json::read (data, val)) {
431+ return ;
432+ }
433433
434- std::string update = data.substr (0 , first_colon);
435- std::string verstr = data.substr (first_colon + 1 , second_colon - first_colon - 1 );
436- std::string url = (second_colon == data.size () ? " " : data.substr (second_colon + 1 ));
434+ json::mObject & obj = val.get_obj ();
435+ if (obj.count (" tag_name" ) == 0 ) {
436+ return ;
437+ }
437438
438- if (update == " yes" ) {
439- int ret = g_gui.PopupDialog (
440- " Update Notice" ,
441- wxString (" There is a newd update available (" ) << wxstr (verstr) << " ). Do you want to go to the website and download it?" ,
442- wxYES | wxNO,
443- " I don't want any update notices" ,
444- Config::AUTOCHECK_FOR_UPDATES
445- );
446- if (ret == wxID_YES) {
447- ::wxLaunchDefaultBrowser (wxstr(url), wxBROWSER_NEW_WINDOW);
439+ std::string tag = obj[" tag_name" ].get_str ();
440+ if (!tag.empty () && (tag[0 ] == ' v' || tag[0 ] == ' V' )) {
441+ tag = tag.substr (1 );
442+ }
443+
444+ // Parse version
445+ int major = 0 , minor = 0 , patch = 0 ;
446+ sscanf (tag.c_str (), " %d.%d.%d" , &major, &minor, &patch);
447+
448+ int remoteVersion = MAKE_VERSION_ID (major, minor, patch);
449+ int localVersion = __RME_VERSION_ID__;
450+
451+ if (remoteVersion > localVersion) {
452+ std::string url = obj[" html_url" ].get_str ();
453+ std::string name = obj[" name" ].get_str ();
454+
455+ int ret = g_gui.PopupDialog (
456+ " Update Notice" ,
457+ wxString (" There is a new update available (" ) << wxstr (name) << " ). Do you want to go to the download page?" ,
458+ wxYES | wxNO,
459+ " I don't want any update notices" ,
460+ Config::AUTOCHECK_FOR_UPDATES
461+ );
462+
463+ if (ret == wxID_YES) {
464+ ::wxLaunchDefaultBrowser (wxstr(url), wxBROWSER_NEW_WINDOW);
465+ }
448466 }
467+ } catch (...) {
468+ // Error parsing JSON, silently ignore
449469 }
450470}
451471#endif
0 commit comments