summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-01-24 00:12:45 +0000
committerCarl Hetherington <cth@carlh.net>2015-01-24 00:12:45 +0000
commit1e4f8cc123ccf1661ea4d23a51625614c2cf2e59 (patch)
tree0abbbfac2097b52640ce447bc8fdc93e1939233e /src/lib
parent68f662ac50a00ad986e3bd258c3f7daac374ab26 (diff)
Hand-apply d4470377df181b4d15fbac86c454a8372b1a0f3d; fix update checker.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/update.cc68
-rw-r--r--src/lib/update.h20
-rw-r--r--src/lib/util.h2
3 files changed, 67 insertions, 23 deletions
diff --git a/src/lib/update.cc b/src/lib/update.cc
index c50022091..b41d8bb66 100644
--- a/src/lib/update.cc
+++ b/src/lib/update.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -26,13 +26,18 @@
#include "version.h"
#include "ui_signaller.h"
#include "safe_stringstream.h"
+#include "config.h"
+#include "util.h"
#define BUFFER_SIZE 1024
using std::cout;
using std::min;
using std::string;
+using std::vector;
using dcp::raw_convert;
+using boost::is_any_of;
+using boost::ends_with;
/** Singleton instance */
UpdateChecker* UpdateChecker::_instance = 0;
@@ -115,26 +120,27 @@ UpdateChecker::thread ()
string s (_buffer);
cxml::Document doc ("Update");
doc.read_string (s);
-
+
+ /* Read the current stable and test version numbers */
+
+ string stable;
+ string test;
+
{
boost::mutex::scoped_lock lm (_data_mutex);
- _stable = doc.string_child ("Stable");
- _test = doc.string_child ("Test");
+ stable = doc.string_child ("Stable");
+ test = doc.string_child ("Test");
}
-
- string current = string (dcpomatic_version);
- bool current_pre = false;
- if (boost::algorithm::ends_with (current, "pre")) {
- current = current.substr (0, current.length() - 3);
- current_pre = true;
+
+ if (version_less_than (dcpomatic_version, stable)) {
+ _stable = stable;
}
- float current_float = raw_convert<float> (current);
- if (current_pre) {
- current_float -= 0.005;
+ if (Config::instance()->check_for_test_updates() && version_less_than (dcpomatic_version, test)) {
+ _test = test;
}
-
- if (current_float < raw_convert<float> (_stable)) {
+
+ if (_stable || _test) {
set_state (YES);
} else {
set_state (NO);
@@ -176,4 +182,36 @@ UpdateChecker::instance ()
return _instance;
}
+bool
+UpdateChecker::version_less_than (string const & a, string const & b)
+{
+ vector<string> ap;
+ split (ap, a, is_any_of ("."));
+ vector<string> bp;
+ split (bp, b, is_any_of ("."));
+
+ DCPOMATIC_ASSERT (ap.size() == 3 && bp.size() == 3);
+
+ if (ap[0] != bp[0]) {
+ return raw_convert<int> (ap[0]) < raw_convert<int> (bp[0]);
+ }
+
+ if (ap[1] != bp[1]) {
+ return raw_convert<int> (ap[1]) < raw_convert<int> (bp[1]);
+ }
+ float am;
+ if (ends_with (ap[2], "devel")) {
+ am = raw_convert<int> (ap[2].substr (0, ap[2].length() - 5)) + 0.5;
+ } else {
+ am = raw_convert<int> (ap[2]);
+ }
+
+ float bm;
+ if (ends_with (bp[2], "devel")) {
+ bm = raw_convert<int> (bp[2].substr (0, bp[2].length() - 5)) + 0.5;
+ } else {
+ bm = raw_convert<int> (bp[2]);
+ }
+ return am < bm;
+}
diff --git a/src/lib/update.h b/src/lib/update.h
index f3a0ffc36..c3e2b5613 100644
--- a/src/lib/update.h
+++ b/src/lib/update.h
@@ -27,6 +27,8 @@
#include <boost/thread/condition.hpp>
#include <boost/thread.hpp>
+struct update_checker_test;
+
/** Class to check for the existance of an update for DCP-o-matic on a remote server */
class UpdateChecker
{
@@ -49,14 +51,14 @@ public:
return _state;
}
- /** @return the version string of the latest stable version (if _state == YES or NO) */
- std::string stable () {
+ /** @return new stable version, if there is one */
+ boost::optional<std::string> stable () {
boost::mutex::scoped_lock lm (_data_mutex);
return _stable;
}
- /** @return the version string of the latest test version (if _state == YES or NO) */
- std::string test () {
+ /** @return new test version, if there is one and Config is set to look for it */
+ boost::optional<std::string> test () {
boost::mutex::scoped_lock lm (_data_mutex);
return _test;
}
@@ -73,9 +75,13 @@ public:
static UpdateChecker* instance ();
-private:
+private:
+ friend struct update_checker_test;
+
static UpdateChecker* _instance;
+ static bool version_less_than (std::string const & a, std::string const & b);
+
void set_state (State);
void thread ();
@@ -86,8 +92,8 @@ private:
/** mutex to protect _state, _stable, _test and _emits */
mutable boost::mutex _data_mutex;
State _state;
- std::string _stable;
- std::string _test;
+ boost::optional<std::string> _stable;
+ boost::optional<std::string> _test;
int _emits;
boost::thread* _thread;
diff --git a/src/lib/util.h b/src/lib/util.h
index 9ae149ef4..b06c8a58b 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by