enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[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 "ui_config.h"
31 #include "video_tool_paths.h"
32 #include "pbd/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         std::string program_files = PBD::get_win_special_folder_path (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.empty() && Glib::file_test(g_build_filename(program_files.c_str(), "harvid", "harvid.exe", NULL), Glib::FILE_TEST_EXISTS))
89         {
90                 harvid_exe = g_build_filename(program_files.c_str(), "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         std::string program_files = PBD::get_win_special_folder_path (CSIDL_PROGRAM_FILES);
110 #endif
111         xjadeo_exe = X_("");
112
113         if (getenv("XJREMOTE")) {
114                 xjadeo_exe = getenv("XJREMOTE");
115 #ifdef __APPLE__
116         } else if (!UIConfiguration::instance().get_xjadeo_binary().empty()
117                         && Glib::file_test (UIConfiguration::instance().get_xjadeo_binary() + "/Contents/MacOS/xjadeo", Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) {
118                 xjadeo_exe = UIConfiguration::instance().get_xjadeo_binary() + "/Contents/MacOS/xjadeo";
119 #endif
120         } else if (!UIConfiguration::instance().get_xjadeo_binary().empty()
121                         && Glib::file_test (UIConfiguration::instance().get_xjadeo_binary(), Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) {
122                 xjadeo_exe = UIConfiguration::instance().get_xjadeo_binary();
123         } else if (find_file (Searchpath(Glib::getenv("PATH")), X_("xjremote"), xjadeo_file_path)) {
124                 xjadeo_exe = xjadeo_file_path;
125         } else if (find_file (Searchpath(Glib::getenv("PATH")), X_("xjadeo"), xjadeo_file_path)) {
126                 xjadeo_exe = xjadeo_file_path;
127         }
128 #ifdef __APPLE__
129         else if (Glib::file_test(X_("/Applications/Xjadeo.app/Contents/MacOS/xjadeo"), Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) {
130                 xjadeo_exe = X_("/Applications/Xjadeo.app/Contents/MacOS/xjadeo");
131         }
132         else if (Glib::file_test(X_("/Applications/Jadeo.app/Contents/MacOS/Jadeo-bin"), Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) {
133                 xjadeo_exe = X_("/Applications/Jadeo.app/Contents/MacOS/Jadeo-bin");
134         }
135 #endif
136 #ifdef PLATFORM_WINDOWS
137         else if ( windows_install_dir("Software\\" PROGRAM_NAME "\\v" PROGRAM_VERSION "\\video", reg))
138         {
139                 xjadeo_exe = std::string(g_build_filename(reg.c_str(), "xjadeo", "xjadeo.exe", NULL));
140         }
141         else if ( windows_install_dir("Software\\RSS\\xjadeo", reg))
142         {
143                 xjadeo_exe = std::string(g_build_filename(reg.c_str(), "xjadeo.exe", NULL));
144         }
145         else if (!program_files.empty() && Glib::file_test(g_build_filename(program_files.c_str(), "xjadeo", "xjadeo.exe", NULL), Glib::FILE_TEST_EXISTS))
146         {
147                 xjadeo_exe = std::string(g_build_filename(program_files.c_str(), "xjadeo", "xjadeo.exe", NULL));
148         }
149         else if (Glib::file_test(X_("C:\\Program Files\\xjadeo\\xjadeo.exe"), Glib::FILE_TEST_EXISTS)) {
150                 xjadeo_exe = X_("C:\\Program Files\\xjadeo\\xjadeo.exe");
151         }
152 #endif
153
154         return (!xjadeo_exe.empty() && Glib::file_test(xjadeo_exe, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE));
155 }
156
157 bool
158 ArdourVideoToolPaths::transcoder_exe (std::string &ffmpeg_exe, std::string &ffprobe_exe)
159 {
160 #ifdef PLATFORM_WINDOWS
161         std::string reg;
162         std::string program_files = PBD::get_win_special_folder_path (CSIDL_PROGRAM_FILES);
163 #endif
164
165         ffmpeg_exe = X_("");
166         ffprobe_exe = X_("");
167
168         std::string ff_file_path;
169         if (find_file (Searchpath(Glib::getenv("PATH")), X_("ffmpeg_harvid"), ff_file_path)) {
170                 ffmpeg_exe = ff_file_path;
171         }
172 #ifdef PLATFORM_WINDOWS
173         else if ( windows_install_dir("Software\\" PROGRAM_NAME "\\v" PROGRAM_VERSION "\\video", reg))
174         {
175                 ffmpeg_exe = g_build_filename(reg.c_str(), X_("harvid"), X_("ffmpeg.exe"), NULL);
176                 ffprobe_exe = g_build_filename(reg.c_str(), X_("harvid"), X_("ffprobe.exe"), NULL);
177         }
178         else if ( windows_install_dir("Software\\RSS\\harvid", reg))
179         {
180                 ffmpeg_exe = g_build_filename(reg.c_str(), X_("ffmpeg.exe"), NULL);
181                 ffprobe_exe = g_build_filename(reg.c_str(), X_("ffprobe.exe"), NULL);
182         }
183
184         if (Glib::file_test(ffmpeg_exe, Glib::FILE_TEST_EXISTS)) {
185                 ;
186         }
187         else if (!program_files.empty() && Glib::file_test(g_build_filename(program_files.c_str(), "harvid", "ffmpeg.exe", NULL), Glib::FILE_TEST_EXISTS)) {
188                 ffmpeg_exe = g_build_filename(program_files.c_str(), "harvid", "ffmpeg.exe", NULL);
189         }
190         else if (Glib::file_test(X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe"), Glib::FILE_TEST_EXISTS)) {
191                 ffmpeg_exe = X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe");
192         } else {
193                 ffmpeg_exe = X_("");
194         }
195 #endif
196
197         if (find_file (Searchpath(Glib::getenv("PATH")), X_("ffprobe_harvid"), ff_file_path)) {
198                 ffprobe_exe = ff_file_path;
199         }
200 #ifdef PLATFORM_WINDOWS
201         if (Glib::file_test(ffprobe_exe, Glib::FILE_TEST_EXISTS)) {
202                 ;
203         }
204         else if (!program_files.empty() && Glib::file_test(g_build_filename(program_files.c_str(), "harvid", "ffprobe.exe", NULL), Glib::FILE_TEST_EXISTS)) {
205                 ffprobe_exe = g_build_filename(program_files.c_str(), "harvid", "ffprobe.exe", NULL);
206         }
207         else if (Glib::file_test(X_("C:\\Program Files\\ffmpeg\\ffprobe.exe"), Glib::FILE_TEST_EXISTS)) {
208                 ffprobe_exe = X_("C:\\Program Files\\ffmpeg\\ffprobe.exe");
209         } else {
210                 ffprobe_exe = X_("");
211         }
212 #endif
213
214         if (ffmpeg_exe.empty() || ffprobe_exe.empty()) {
215                 return false;
216         }
217         return true;
218 }