Rename dcpomatic_sleep -> dcpomatic_sleep_seconds.
[dcpomatic.git] / src / lib / cross.cc
index 75205dc1aa11709d84b651421f452005e0399b6d..1b83bad7c6dca9a02cf9696eccf8c8834f0fa8b7 100644 (file)
@@ -21,6 +21,7 @@
 #include "cross.h"
 #include "compose.hpp"
 #include "log.h"
+#include "dcpomatic_log.h"
 #include "config.h"
 #include "exceptions.h"
 extern "C" {
@@ -53,10 +54,6 @@ extern "C" {
 
 #include "i18n.h"
 
-#define LOG_GENERAL(...) log->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL);
-#define LOG_ERROR(...) log->log (String::compose (__VA_ARGS__), LogEntry::TYPE_ERROR);
-#define LOG_ERROR_NC(...) log->log (__VA_ARGS__, LogEntry::TYPE_ERROR);
-
 using std::pair;
 using std::list;
 using std::ifstream;
@@ -68,7 +65,7 @@ using boost::shared_ptr;
 
 /** @param s Number of seconds to sleep for */
 void
-dcpomatic_sleep (int s)
+dcpomatic_sleep_seconds (int s)
 {
 #ifdef DCPOMATIC_POSIX
        sleep (s);
@@ -182,7 +179,7 @@ shared_path ()
 }
 
 void
-run_ffprobe (boost::filesystem::path content, boost::filesystem::path out, shared_ptr<Log> log)
+run_ffprobe (boost::filesystem::path content, boost::filesystem::path out)
 {
 #ifdef DCPOMATIC_WINDOWS
        SECURITY_ATTRIBUTES security;
@@ -466,3 +463,54 @@ maybe_open_console ()
        }
 }
 #endif
+
+boost::filesystem::path
+home_directory ()
+{
+#if defined(DCPOMATIC_LINUX) || defined(DCPOMATIC_OSX)
+               return getenv("HOME");
+#endif
+#ifdef DCPOMATIC_WINDOWS
+               return boost::filesystem::path(getenv("HOMEDRIVE")) / boost::filesystem::path(getenv("HOMEPATH"));
+#endif
+}
+
+string
+command_and_read (string cmd)
+{
+#ifdef DCPOMATIC_LINUX
+       FILE* pipe = popen (cmd.c_str(), "r");
+       if (!pipe) {
+               throw runtime_error ("popen failed");
+       }
+
+       string result;
+       char buffer[128];
+       try {
+               while (fgets(buffer, sizeof(buffer), pipe)) {
+                       result += buffer;
+               }
+       } catch (...) {
+               pclose (pipe);
+               throw;
+       }
+
+       pclose (pipe);
+       return result;
+#endif
+
+       return "";
+}
+
+/** @return true if this process is a 32-bit one running on a 64-bit-capable OS */
+bool
+running_32_on_64 ()
+{
+#ifdef DCPOMATIC_WINDOWS
+       BOOL p;
+       IsWow64Process (GetCurrentProcess(), &p);
+       return p;
+#endif
+       /* XXX: assuming nobody does this on Linux / OS X */
+       return false;
+}