add debug info for xjadeo binary
[ardour.git] / gtk2_ardour / video_tool_paths.cc
1 /*
2     Copyright (C) 2010-2013 Paul Davis
3     Author: Robin Gareus <robin@gareus.org>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20 #include <string>
21 #include <gtkmm.h>
22
23 #ifdef PLATFORM_WINDOWS
24 #include <windows.h>
25 #include <shlobj.h> // CSIDL_*
26 #include "pbd/windows_special_dirs.h"
27 #endif
28
29 #include "pbd/file_utils.h"
30 #include "pbd/error.h"
31 #include "video_tool_paths.h"
32 #include "i18n.h"
33
34 using namespace PBD;
35
36 #ifdef PLATFORM_WINDOWS
37
38 static bool
39 windows_install_dir (const char *regkey, std::string &rv) {
40         HKEY key;
41         DWORD size = PATH_MAX;
42         char tmp[PATH_MAX+1];
43
44         if (   (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ, &key))
45             && (ERROR_SUCCESS == RegQueryValueExA (key, "Install_Dir", 0, NULL, reinterpret_cast<LPBYTE>(tmp), &size))
46                  )
47         {
48                 rv = Glib::locale_to_utf8(tmp);
49                 return true;
50         }
51
52         if (   (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ | KEY_WOW64_32KEY, &key))
53             && (ERROR_SUCCESS == RegQueryValueExA (key, "Install_Dir", 0, NULL, reinterpret_cast<LPBYTE>(tmp), &size))
54                         )
55         {
56                 rv = Glib::locale_to_utf8(tmp);
57                 return true;
58         }
59
60         return false;
61 }
62 #endif
63
64 bool
65 ArdourVideoToolPaths::harvid_exe (std::string &harvid_exe)
66 {
67
68 #ifdef PLATFORM_WINDOWS
69         std::string reg;
70         const char *program_files = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
71 #endif
72
73         harvid_exe = "";
74
75         std::string icsd_file_path;
76         if (find_file (PBD::Searchpath(Glib::getenv("PATH")), X_("harvid"), icsd_file_path)) {
77                 harvid_exe = icsd_file_path;
78         }
79 #ifdef PLATFORM_WINDOWS
80         else if ( windows_install_dir("Software\\" PROGRAM_NAME "\\v" PROGRAM_VERSION "\\video", reg))
81         {
82                 harvid_exe = g_build_filename(reg.c_str(), "harvid", "harvid.exe", NULL);
83         }
84         else if ( windows_install_dir("Software\\RSS\\harvid", reg))
85         {
86                 harvid_exe = g_build_filename(reg.c_str(), "harvid.exe", NULL);
87         }
88         else if (program_files && Glib::file_test(g_build_filename(program_files, "harvid", "harvid.exe", NULL), Glib::FILE_TEST_EXISTS))
89         {
90                 harvid_exe = g_build_filename(program_files, "harvid", "harvid.exe", NULL);
91         }
92         else if (Glib::file_test(X_("C:\\Program Files\\harvid\\harvid.exe"), Glib::FILE_TEST_EXISTS)) {
93                 harvid_exe = X_("C:\\Program Files\\harvid\\harvid.exe");
94         }
95 #endif
96         else
97         {
98                 return false;
99         }
100         return true;
101 }
102
103 bool
104 ArdourVideoToolPaths::xjadeo_exe (std::string &xjadeo_exe)
105 {
106         std::string xjadeo_file_path;
107 #ifdef PLATFORM_WINDOWS
108         std::string reg;
109         const char *program_files = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
110 #endif
111         if (getenv("XJREMOTE")) {
112                 xjadeo_exe = getenv("XJREMOTE");
113         } else if (find_file (Searchpath(Glib::getenv("PATH")), X_("xjremote"), xjadeo_file_path)) {
114                 xjadeo_exe = xjadeo_file_path;
115                 info << "xjadeo from XJREMOTE: " << xjadeo_exe << endmsg;
116         } else if (find_file (Searchpath(Glib::getenv("PATH")), X_("xjadeo"), xjadeo_file_path)) {
117                 xjadeo_exe = xjadeo_file_path;
118                 info << "xjadeo from PATH: " << xjadeo_exe << endmsg;
119         }
120 #ifdef __APPLE__
121         else if (Glib::file_test(X_("/Applications/Xjadeo.app/Contents/MacOS/xjadeo"), Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) {
122                 xjadeo_exe = X_("/Applications/Xjadeo.app/Contents/MacOS/xjadeo");
123         }
124         else if (Glib::file_test(X_("/Applications/Jadeo.app/Contents/MacOS/Jadeo-bin"), Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) {
125                 xjadeo_exe = X_("/Applications/Jadeo.app/Contents/MacOS/Jadeo-bin");
126         }
127 #endif
128 #ifdef PLATFORM_WINDOWS
129         else if ( windows_install_dir("Software\\" PROGRAM_NAME "\\v" PROGRAM_VERSION "\\video", reg))
130         {
131                 xjadeo_exe = std::string(g_build_filename(reg.c_str(), "xjadeo", "xjadeo.exe", NULL));
132                 info << "xjadeo.exe from reg: " << "Software\\" PROGRAM_NAME "\\v" PROGRAM_VERSION "\\video" << ": " << xjadeo_exe << endmsg;
133         }
134         else if ( windows_install_dir("Software\\RSS\\xjadeo", reg))
135         {
136                 xjadeo_exe = std::string(g_build_filename(reg.c_str(), "xjadeo.exe", NULL));
137                 info << "xjadeo.exe from reg: Software\\RSS\\xjadeo: " << xjadeo_exe << endmsg;
138         }
139         else if (program_files && Glib::file_test(g_build_filename(program_files, "xjadeo", "xjadeo.exe", NULL), Glib::FILE_TEST_EXISTS))
140         {
141                 xjadeo_exe = std::string(g_build_filename(program_files, "xjadeo", "xjadeo.exe", NULL));
142                 info << "xjadeo.exe from CSIDL_PROGRAM_FILES: " << xjadeo_exe << endmsg;
143         }
144         else if (Glib::file_test(X_("C:\\Program Files\\xjadeo\\xjadeo.exe"), Glib::FILE_TEST_EXISTS)) {
145                 xjadeo_exe = X_("C:\\Program Files\\xjadeo\\xjadeo.exe");
146                 info << "xjadeo.exe from C:\\Program Files\\xjadeo\\ :" << xjadeo_exe << endmsg;
147         }
148 #endif
149         else  {
150                 xjadeo_exe = X_("");
151                 return false;
152         }
153         return true;
154 }
155
156 bool
157 ArdourVideoToolPaths::transcoder_exe (std::string &ffmpeg_exe, std::string &ffprobe_exe)
158 {
159 #ifdef PLATFORM_WINDOWS
160         std::string reg;
161         const char *program_files = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
162 #endif
163
164         ffmpeg_exe = X_("");
165         ffprobe_exe = X_("");
166
167         std::string ff_file_path;
168         if (find_file (Searchpath(Glib::getenv("PATH")), X_("ffmpeg_harvid"), ff_file_path)) {
169                 ffmpeg_exe = ff_file_path;
170         }
171 #ifdef PLATFORM_WINDOWS
172         else if ( windows_install_dir("Software\\" PROGRAM_NAME "\\v" PROGRAM_VERSION "\\video", reg))
173         {
174                 ffmpeg_exe = g_build_filename(reg.c_str(), X_("harvid"), X_("ffmpeg.exe"), NULL);
175                 ffprobe_exe = g_build_filename(reg.c_str(), X_("harvid"), X_("ffprobe.exe"), NULL);
176         }
177         else if ( windows_install_dir("Software\\RSS\\harvid", reg))
178         {
179                 ffmpeg_exe = g_build_filename(reg.c_str(), X_("ffmpeg.exe"), NULL);
180                 ffprobe_exe = g_build_filename(reg.c_str(), X_("ffprobe.exe"), NULL);
181         }
182
183         if (Glib::file_test(ffmpeg_exe, Glib::FILE_TEST_EXISTS)) {
184                 ;
185         }
186         else if (program_files && Glib::file_test(g_build_filename(program_files, "harvid", "ffmpeg.exe", NULL), Glib::FILE_TEST_EXISTS)) {
187                 ffmpeg_exe = g_build_filename(program_files, "harvid", "ffmpeg.exe", NULL);
188         }
189         else if (Glib::file_test(X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe"), Glib::FILE_TEST_EXISTS)) {
190                 ffmpeg_exe = X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe");
191         } else {
192                 ffmpeg_exe = X_("");
193         }
194 #endif
195
196         if (find_file (Searchpath(Glib::getenv("PATH")), X_("ffprobe_harvid"), ff_file_path)) {
197                 ffprobe_exe = ff_file_path;
198         }
199 #ifdef PLATFORM_WINDOWS
200         if (Glib::file_test(ffprobe_exe, Glib::FILE_TEST_EXISTS)) {
201                 ;
202         }
203         else if (program_files && Glib::file_test(g_build_filename(program_files, "harvid", "ffprobe.exe", NULL), Glib::FILE_TEST_EXISTS)) {
204                 ffprobe_exe = g_build_filename(program_files, "harvid", "ffprobe.exe", NULL);
205         }
206         else if (Glib::file_test(X_("C:\\Program Files\\ffmpeg\\ffprobe.exe"), Glib::FILE_TEST_EXISTS)) {
207                 ffprobe_exe = X_("C:\\Program Files\\ffmpeg\\ffprobe.exe");
208         } else {
209                 ffprobe_exe = X_("");
210         }
211 #endif
212
213         if (ffmpeg_exe.empty() || ffprobe_exe.empty()) {
214                 return false;
215         }
216         return true;
217 }