Fix quoting for ffprobe.
[dcpomatic.git] / src / lib / util.cc
index 859aa6de7ddda8efa646ee695247023d40169a7a..4cf57368a7aea6718302c21441e719cdeeb7eb96 100644 (file)
@@ -39,6 +39,7 @@
 #include <boost/lexical_cast.hpp>
 #include <boost/thread.hpp>
 #include <boost/filesystem.hpp>
+#include <glib.h>
 #include <openjpeg.h>
 #include <openssl/md5.h>
 #include <magick/MagickCore.h>
@@ -60,6 +61,9 @@ extern "C" {
 #include "filter.h"
 #include "sound_processor.h"
 #include "config.h"
+#ifdef DVDOMATIC_WINDOWS
+#include "stack.hpp"
+#endif
 
 #include "i18n.h"
 
@@ -75,12 +79,14 @@ using std::min;
 using std::max;
 using std::multimap;
 using std::pair;
+using std::ofstream;
 using boost::shared_ptr;
 using boost::lexical_cast;
 using boost::optional;
 using libdcp::Size;
 
 boost::thread::id ui_thread;
+boost::filesystem::path backtrace_file;
 
 /** Convert some number of seconds to a string representation
  *  in hours, minutes and seconds.
@@ -242,12 +248,28 @@ seconds (struct timeval t)
        return t.tv_sec + (double (t.tv_usec) / 1e6);
 }
 
+#ifdef DVDOMATIC_WINDOWS
+LONG WINAPI exception_handler(struct _EXCEPTION_POINTERS *)
+{
+       dbg::stack s;
+       ofstream f (backtrace_file.string().c_str());
+       std::copy(s.begin(), s.end(), std::ostream_iterator<dbg::stack_frame>(f, "\n"));
+       return EXCEPTION_CONTINUE_SEARCH;
+}
+#endif
+
 /** Call the required functions to set up DVD-o-matic's static arrays, etc.
  *  Must be called from the UI thread, if there is one.
  */
 void
 dvdomatic_setup ()
 {
+#ifdef DVDOMATIC_WINDOWS
+       backtrace_file /= g_get_user_config_dir ();
+       backtrace_file /= "backtrace.txt";
+       SetUnhandledExceptionFilter(exception_handler);
+#endif 
+       
        avfilter_register_all ();
        
        Format::setup_formats ();
@@ -274,7 +296,7 @@ mo_path ()
 #endif
 
 void
-dvdomatic_setup_i18n (string lang)
+dvdomatic_setup_gettext_i18n (string lang)
 {
 #ifdef DVDOMATIC_POSIX
        lang += ".UTF8";
@@ -615,8 +637,8 @@ Socket::read_uint32 ()
 /** @param other A Rect.
  *  @return The intersection of this with `other'.
  */
-Rect
-Rect::intersection (Rect const & other) const
+dvdomatic::Rect
+dvdomatic::Rect::intersection (Rect const & other) const
 {
        int const tx = max (x, other.x);
        int const ty = max (y, other.y);
@@ -920,32 +942,6 @@ still_image_file (string f)
        return (ext == N_(".tif") || ext == N_(".tiff") || ext == N_(".jpg") || ext == N_(".jpeg") || ext == N_(".png") || ext == N_(".bmp"));
 }
 
-/** @return A pair containing CPU model name and the number of processors */
-pair<string, int>
-cpu_info ()
-{
-       pair<string, int> info;
-       info.second = 0;
-       
-#ifdef DVDOMATIC_POSIX
-       ifstream f (N_("/proc/cpuinfo"));
-       while (f.good ()) {
-               string l;
-               getline (f, l);
-               if (boost::algorithm::starts_with (l, N_("model name"))) {
-                       string::size_type const c = l.find (':');
-                       if (c != string::npos) {
-                               info.first = l.substr (c + 2);
-                       }
-               } else if (boost::algorithm::starts_with (l, N_("processor"))) {
-                       ++info.second;
-               }
-       }
-#endif 
-
-       return info;
-}
-
 string
 audio_channel_name (int c)
 {
@@ -1054,8 +1050,8 @@ LocaleGuard::LocaleGuard ()
 
         if (old) {
                 _old = strdup (old);
-                if (strcmp (_old, "POSIX")) {
-                        setlocale (LC_NUMERIC, "POSIX");
+                if (strcmp (_old, "C")) {
+                        setlocale (LC_NUMERIC, "C");
                 }
         }
 }