consolidate video-tool filepaths - step two:
[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 "video_tool_paths.h"
31 #include "i18n.h"
32
33 using namespace PBD;
34
35 #ifdef PLATFORM_WINDOWS
36
37 static bool
38 windows_install_dir (const char *regkey, std::string &rv) {
39         HKEY key;
40         DWORD size = PATH_MAX;
41         char tmp[PATH_MAX+1];
42
43         if (   (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ, &key))
44             && (ERROR_SUCCESS == RegQueryValueExA (key, "Install_Dir", 0, NULL, reinterpret_cast<LPBYTE>(tmp), &size))
45                  )
46         {
47                 rv = Glib::locale_to_utf8(tmp);
48                 return true;
49         }
50
51         if (   (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ | KEY_WOW64_32KEY, &key))
52             && (ERROR_SUCCESS == RegQueryValueExA (key, "Install_Dir", 0, NULL, reinterpret_cast<LPBYTE>(tmp), &size))
53                         )
54         {
55                 rv = Glib::locale_to_utf8(tmp);
56                 return true;
57         }
58
59         return false;
60 }
61 #endif
62
63 bool
64 ArdourVideoToolPaths::harvid_exe (std::string &harvid_exe)
65 {
66
67 #ifdef PLATFORM_WINDOWS
68         std::string reg;
69         const char *program_files = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
70 #endif
71
72         harvid_exe = "";
73
74         std::string icsd_file_path;
75         if (find_file (PBD::Searchpath(Glib::getenv("PATH")), X_("harvid"), icsd_file_path)) {
76                 harvid_exe = icsd_file_path;
77         }
78 #ifdef PLATFORM_WINDOWS
79         else if ( windows_install_dir("Software\\RSS\\harvid", reg))
80         {
81                 harvid_exe = g_build_filename(reg.c_str(), "harvid.exe", NULL);
82         }
83         else if (program_files && Glib::file_test(g_build_filename(program_files, "harvid", "harvid.exe", NULL), Glib::FILE_TEST_EXISTS))
84         {
85                 harvid_exe = g_build_filename(program_files, "harvid", "harvid.exe", NULL);
86         }
87         else if (Glib::file_test(X_("C:\\Program Files\\harvid\\harvid.exe"), Glib::FILE_TEST_EXISTS)) {
88                 harvid_exe = X_("C:\\Program Files\\harvid\\harvid.exe");
89         }
90 #endif
91         else
92         {
93                 return false;
94         }
95         return true;
96 }
97
98 bool
99 ArdourVideoToolPaths::xjadeo_exe (std::string &xjadeo_exe)
100 {
101         std::string xjadeo_file_path;
102 #ifdef PLATFORM_WINDOWS
103         std::string reg;
104         const char *program_files = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
105 #endif
106         if (getenv("XJREMOTE")) {
107                 xjadeo_exe = getenv("XJREMOTE");
108         } else if (find_file (Searchpath(Glib::getenv("PATH")), X_("xjremote"), xjadeo_file_path)) {
109                 xjadeo_exe = xjadeo_file_path;
110         } else if (find_file (Searchpath(Glib::getenv("PATH")), X_("xjadeo"), xjadeo_file_path)) {
111                 xjadeo_exe = xjadeo_file_path;
112         }
113 #ifdef __APPLE__
114         else if (Glib::file_test(X_("/Applications/Xjadeo.app/Contents/MacOS/xjremote"), Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) {
115                 xjadeo_exe = X_("/Applications/Xjadeo.app/Contents/MacOS/xjremote");
116         }
117         else if (Glib::file_test(X_("/Applications/Jadeo.app/Contents/MacOS/xjremote"), Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) {
118                 xjadeo_exe = X_("/Applications/Jadeo.app/Contents/MacOS/xjremote");
119         }
120 #endif
121 #ifdef PLATFORM_WINDOWS
122         else if ( windows_install_dir("Software\\RSS\\xjadeo", reg))
123         {
124                 xjadeo_exe = std::string(g_build_filename(reg.c_str(), "xjadeo.exe", NULL));
125         }
126         else if (program_files && Glib::file_test(g_build_filename(program_files, "xjadeo", "xjadeo.exe", NULL), Glib::FILE_TEST_EXISTS))
127         {
128                 xjadeo_exe = std::string(g_build_filename(program_files, "xjadeo", "xjadeo.exe", NULL));
129         }
130         else if (Glib::file_test(X_("C:\\Program Files\\xjadeo\\xjadeo.exe"), Glib::FILE_TEST_EXISTS)) {
131                 xjadeo_exe = X_("C:\\Program Files\\xjadeo\\xjadeo.exe");
132         }
133 #endif
134         else  {
135                 xjadeo_exe = X_("");
136                 return false;
137         }
138         return true;
139 }
140
141 bool
142 ArdourVideoToolPaths::transcoder_exe (std::string &ffmpeg_exe, std::string &ffprobe_exe)
143 {
144 #ifdef PLATFORM_WINDOWS
145         std::string reg;
146         const char *program_files = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
147 #endif
148
149         ffmpeg_exe = X_("");
150         ffprobe_exe = X_("");
151
152         std::string ff_file_path;
153         if (find_file (Searchpath(Glib::getenv("PATH")), X_("ffmpeg_harvid"), ff_file_path)) {
154                 ffmpeg_exe = ff_file_path;
155         }
156 #ifdef PLATFORM_WINDOWS
157         else if ( windows_install_dir("Software\\RSS\\harvid", reg))
158         {
159                 ffmpeg_exe = g_build_filename(reg.c_str(), X_("ffmpeg.exe"), NULL);
160                 ffprobe_exe = g_build_filename(reg.c_str(), X_("ffprobe.exe"), NULL);
161         }
162
163         if (Glib::file_test(ffmpeg_exe, Glib::FILE_TEST_EXISTS)) {
164                 ;
165         }
166         else if (program_files && Glib::file_test(g_build_filename(program_files, "harvid", "ffmpeg.exe", NULL), Glib::FILE_TEST_EXISTS)) {
167                 ffmpeg_exe = g_build_filename(program_files, "harvid", "ffmpeg.exe", NULL);
168         }
169         else if (Glib::file_test(X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe"), Glib::FILE_TEST_EXISTS)) {
170                 ffmpeg_exe = X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe");
171         } else {
172                 ffmpeg_exe = X_("");
173         }
174 #endif
175
176         if (find_file (Searchpath(Glib::getenv("PATH")), X_("ffprobe_harvid"), ff_file_path)) {
177                 ffprobe_exe = ff_file_path;
178         }
179 #ifdef PLATFORM_WINDOWS
180         if (Glib::file_test(ffprobe_exe, Glib::FILE_TEST_EXISTS)) {
181                 ;
182         }
183         else if (program_files && Glib::file_test(g_build_filename(program_files, "harvid", "ffprobe.exe", NULL), Glib::FILE_TEST_EXISTS)) {
184                 ffprobe_exe = g_build_filename(program_files, "harvid", "ffprobe.exe", NULL);
185         }
186         else if (Glib::file_test(X_("C:\\Program Files\\ffmpeg\\ffprobe.exe"), Glib::FILE_TEST_EXISTS)) {
187                 ffprobe_exe = X_("C:\\Program Files\\ffmpeg\\ffprobe.exe");
188         } else {
189                 ffprobe_exe = X_("");
190         }
191 #endif
192
193         if (ffmpeg_exe.empty() || ffprobe_exe.empty()) {
194                 return false;
195         }
196         return true;
197 }