Add unfinished check-for-updates. Bump ffmpeg to get windows build fix.
authorCarl Hetherington <cth@carlh.net>
Tue, 7 Jan 2014 13:53:28 +0000 (13:53 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 7 Jan 2014 13:53:28 +0000 (13:53 +0000)
cscript
src/lib/update.cc [new file with mode: 0644]
src/lib/update.h [new file with mode: 0644]
src/lib/wscript
src/tools/dcpomatic.cc

diff --git a/cscript b/cscript
index 36cddc79e0b488c6dbe05f82de45d2a48c52424e..b164bc422b88c2cf2d93283f6b1768fcbee6538b 100644 (file)
--- a/cscript
+++ b/cscript
@@ -114,8 +114,8 @@ def make_control(version, bits, filename):
     print >>f,'  digital projectors.'
 
 def dependencies(target):
-    return (('ffmpeg-cdist', 'a629ea68a20d990b4e61c16067e91563d8d08f50'),
-            ('libdcp', 'v0.92'))
+    return (('ffmpeg-cdist', '5ac3a6af077c10f07c31954c372a8f29e4e18e2a'),
+            ('libdcp', 'cc8c14b765038405e75d7436cf0da3d56b61063b'))
 
 def build(target):
     cmd = './waf configure --prefix=%s' % target.work_dir_cscript()
diff --git a/src/lib/update.cc b/src/lib/update.cc
new file mode 100644 (file)
index 0000000..6e9d116
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+    Copyright (C) 2014 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
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <string>
+#include <sstream>
+#include <curl/curl.h>
+#include <libcxml/cxml.h>
+#include "update.h"
+#include "version.h"
+
+#define BUFFER_SIZE 1024
+
+using std::cout;
+using std::min;
+using std::string;
+using std::stringstream;
+
+UpdateChecker::UpdateChecker ()
+       : _buffer (new char[BUFFER_SIZE])
+       , _offset (0)
+{
+       
+}
+
+UpdateChecker::~UpdateChecker ()
+{
+       delete[] _buffer;
+}
+
+static size_t
+write_callback_wrapper (void* data, size_t size, size_t nmemb, void* user)
+{
+       return reinterpret_cast<UpdateChecker*>(user)->write_callback (data, size, nmemb);
+}
+
+UpdateChecker::Result
+UpdateChecker::run ()
+{
+       curl_global_init (CURL_GLOBAL_ALL);
+       CURL* curl = curl_easy_init ();
+       if (!curl) {
+               return MAYBE;
+       }
+
+       curl_easy_setopt (curl, CURLOPT_URL, "http://dcpomatic.com/update.php");
+       curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, write_callback_wrapper);
+       curl_easy_setopt (curl, CURLOPT_WRITEDATA, this);
+       string const agent = "dcpomatic/" + string (dcpomatic_version);
+       curl_easy_setopt (curl, CURLOPT_USERAGENT, agent.c_str ());
+       int r = curl_easy_perform (curl);
+       if (r != CURLE_OK) {
+               return MAYBE;
+       }
+
+       _buffer[BUFFER_SIZE-1] = '\0';
+       stringstream s;
+       s << _buffer;
+       cxml::Document doc ("Update");
+       doc.read_stream (s);
+
+       cout << doc.string_child ("Stable") << "\n";
+       return YES;
+}
+
+size_t
+UpdateChecker::write_callback (void* data, size_t size, size_t nmemb)
+{
+       size_t const t = min (size * nmemb, size_t (BUFFER_SIZE - _offset));
+       memcpy (_buffer + _offset, data, t);
+       _offset += t;
+       return t;
+}
diff --git a/src/lib/update.h b/src/lib/update.h
new file mode 100644 (file)
index 0000000..2063dd4
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+    Copyright (C) 2014 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
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+class UpdateChecker
+{
+public:
+       UpdateChecker ();
+       ~UpdateChecker ();
+
+       enum Result {
+               YES,
+               MAYBE,
+               NO
+       };
+
+       Result run ();
+
+       size_t write_callback (void *, size_t, size_t);
+
+private:       
+       char* _buffer;
+       int _offset;
+};
index 25186a3d3452895a06299b1a3cc286982f7a7dd3..81a55a160bc42ab200931e9bec862d712ab7d965 100644 (file)
@@ -57,6 +57,7 @@ sources = """
           transcoder.cc
           types.cc
           ui_signaller.cc
+          update.cc
           util.cc
           video_content.cc
           video_decoder.cc
index 7cbb08725e4d85c4fe8f4088cbeac5cd8d288a49..b69385e24fecdf555a464acbb2799eac2159dcc5 100644 (file)
@@ -55,6 +55,7 @@
 #include "lib/kdm.h"
 #include "lib/send_kdm_email_job.h"
 #include "lib/server_finder.h"
+#include "lib/update.h"
 
 using std::cout;
 using std::string;
@@ -185,6 +186,7 @@ enum {
        ID_jobs_show_dcp,
        ID_tools_hints,
        ID_tools_encoding_servers,
+       ID_tools_check_for_updates
 };
 
 void
@@ -223,7 +225,8 @@ setup_menu (wxMenuBar* m)
 
        wxMenu* tools = new wxMenu;
        add_item (tools, _("Hints..."), ID_tools_hints, 0);
-       add_item (tools, _("Encoding Servers..."), ID_tools_encoding_servers, 0);
+       add_item (tools, _("Encoding servers..."), ID_tools_encoding_servers, 0);
+       add_item (tools, _("Check for updates"), ID_tools_check_for_updates, 0);
 
        wxMenu* help = new wxMenu;
 #ifdef __WXOSX__       
@@ -269,19 +272,20 @@ public:
                setup_menu (bar);
                SetMenuBar (bar);
 
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_new, this),               ID_file_new);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_open, this),              ID_file_open);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_save, this),              ID_file_save);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_properties, this),        ID_file_properties);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_exit, this),              wxID_EXIT);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::edit_preferences, this),       wxID_PREFERENCES);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_make_dcp, this),          ID_jobs_make_dcp);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_make_kdms, this),         ID_jobs_make_kdms);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_send_dcp_to_tms, this),   ID_jobs_send_dcp_to_tms);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_show_dcp, this),          ID_jobs_show_dcp);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::tools_hints, this),            ID_tools_hints);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::tools_encoding_servers, this), ID_tools_encoding_servers);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::help_about, this),             wxID_ABOUT);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_new, this),                ID_file_new);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_open, this),               ID_file_open);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_save, this),               ID_file_save);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_properties, this),         ID_file_properties);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_exit, this),               wxID_EXIT);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::edit_preferences, this),        wxID_PREFERENCES);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_make_dcp, this),           ID_jobs_make_dcp);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_make_kdms, this),          ID_jobs_make_kdms);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_send_dcp_to_tms, this),    ID_jobs_send_dcp_to_tms);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_show_dcp, this),           ID_jobs_show_dcp);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::tools_hints, this),             ID_tools_hints);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::tools_encoding_servers, this),  ID_tools_encoding_servers);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::tools_check_for_updates, this), ID_tools_check_for_updates);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::help_about, this),              wxID_ABOUT);
 
                Bind (wxEVT_CLOSE_WINDOW, boost::bind (&Frame::close, this, _1));
 
@@ -530,6 +534,12 @@ private:
                _servers_list_dialog->Show ();
        }
 
+       void tools_check_for_updates ()
+       {
+               UpdateChecker c;
+               c.run ();
+       }
+
        void help_about ()
        {
                AboutDialog* d = new AboutDialog (this);