summaryrefslogtreecommitdiff
path: root/libs/ardour/video_tools_paths.cc
blob: 4c5344331ea3f4415048d3e74429203c2e937059 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
 * Copyright (C) 2018 Robin Gareus <robin@gareus.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/* This extends ardour/filesystem_paths.cc but requires additional
 * includes, in particular 'rc_configuration.h' which in turn
 * pulls in types.h, which include temporal/bbt_time and evoral
 *
 * filesystem_paths.cc is used by various standalone utils,
 * e.g. the VST scanner and pulling in most of libardour's dependencies
 * there is not reasonable.
 */

#include <string>

#include "pbd/file_utils.h"

#include <glibmm/convert.h>
#include <glibmm/miscutils.h>
#include <glibmm/fileutils.h>

#include "ardour/filesystem_paths.h"
#include "ardour/rc_configuration.h"

#include "pbd/i18n.h"

#ifdef PLATFORM_WINDOWS
#include <windows.h>
#include "shlobj.h"
#include "pbd/windows_special_dirs.h"
#endif

using namespace PBD;

namespace ARDOUR {

#ifdef PLATFORM_WINDOWS
static bool
windows_install_dir (const char *regkey, std::string &rv) {
	HKEY key;
	DWORD size = PATH_MAX;
	char tmp[PATH_MAX+1];

	if (   (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ, &key))
	    && (ERROR_SUCCESS == RegQueryValueExA (key, "Install_Dir", 0, NULL, reinterpret_cast<LPBYTE>(tmp), &size))
		 )
	{
		rv = Glib::locale_to_utf8(tmp);
		return true;
	}

	if (   (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ | KEY_WOW64_32KEY, &key))
	    && (ERROR_SUCCESS == RegQueryValueExA (key, "Install_Dir", 0, NULL, reinterpret_cast<LPBYTE>(tmp), &size))
			)
	{
		rv = Glib::locale_to_utf8(tmp);
		return true;
	}

	return false;
}
#endif

bool
ArdourVideoToolPaths::harvid_exe (std::string &harvid_exe)
{

#ifdef PLATFORM_WINDOWS
	std::string reg;
	std::string program_files = PBD::get_win_special_folder_path (CSIDL_PROGRAM_FILES);
#endif

	harvid_exe = "";

	std::string icsd_file_path;
	if (find_file (PBD::Searchpath(Glib::getenv("PATH")), X_("harvid"), icsd_file_path)) {
		harvid_exe = icsd_file_path;
	}
#ifdef PLATFORM_WINDOWS
	else if ( windows_install_dir("Software\\" PROGRAM_NAME "\\v" PROGRAM_VERSION "\\video", reg))
	{
		harvid_exe = g_build_filename(reg.c_str(), "harvid", "harvid.exe", NULL);
	}
	else if ( windows_install_dir("Software\\RSS\\harvid", reg))
	{
		harvid_exe = g_build_filename(reg.c_str(), "harvid.exe", NULL);
	}
	else if (!program_files.empty() && Glib::file_test(g_build_filename(program_files.c_str(), "harvid", "harvid.exe", NULL), Glib::FILE_TEST_EXISTS))
	{
		harvid_exe = g_build_filename(program_files.c_str(), "harvid", "harvid.exe", NULL);
	}
	else if (Glib::file_test(X_("C:\\Program Files\\harvid\\harvid.exe"), Glib::FILE_TEST_EXISTS)) {
		harvid_exe = X_("C:\\Program Files\\harvid\\harvid.exe");
	}
#endif
	else
	{
		return false;
	}
	return true;
}

bool
ArdourVideoToolPaths::xjadeo_exe (std::string &xjadeo_exe)
{
	std::string xjadeo_file_path;
#ifdef PLATFORM_WINDOWS
	std::string reg;
	std::string program_files = PBD::get_win_special_folder_path (CSIDL_PROGRAM_FILES);
#endif
	xjadeo_exe = X_("");

	if (getenv("XJREMOTE")) {
		xjadeo_exe = getenv("XJREMOTE");
#ifdef __APPLE__
	} else if (!Config->get_xjadeo_binary().empty()
			&& Glib::file_test (Config->get_xjadeo_binary() + "/Contents/MacOS/xjadeo", Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) {
		xjadeo_exe = Config->get_xjadeo_binary() + "/Contents/MacOS/xjadeo";
#endif
	} else if (!Config->get_xjadeo_binary().empty()
			&& Glib::file_test (Config->get_xjadeo_binary(), Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) {
		xjadeo_exe = Config->get_xjadeo_binary();
	} else if (find_file (Searchpath(Glib::getenv("PATH")), X_("xjremote"), xjadeo_file_path)) {
		xjadeo_exe = xjadeo_file_path;
	} else if (find_file (Searchpath(Glib::getenv("PATH")), X_("xjadeo"), xjadeo_file_path)) {
		xjadeo_exe = xjadeo_file_path;
	}
#ifdef __APPLE__
	else if (Glib::file_test(X_("/Applications/Xjadeo.app/Contents/MacOS/xjadeo"), Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) {
		xjadeo_exe = X_("/Applications/Xjadeo.app/Contents/MacOS/xjadeo");
	}
	else if (Glib::file_test(X_("/Applications/Jadeo.app/Contents/MacOS/Jadeo-bin"), Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) {
		xjadeo_exe = X_("/Applications/Jadeo.app/Contents/MacOS/Jadeo-bin");
	}
#endif
#ifdef PLATFORM_WINDOWS
	else if ( windows_install_dir("Software\\" PROGRAM_NAME "\\v" PROGRAM_VERSION "\\video", reg))
	{
		xjadeo_exe = std::string(g_build_filename(reg.c_str(), "xjadeo", "xjadeo.exe", NULL));
	}
	else if ( windows_install_dir("Software\\RSS\\xjadeo", reg))
	{
		xjadeo_exe = std::string(g_build_filename(reg.c_str(), "xjadeo.exe", NULL));
	}
	else if (!program_files.empty() && Glib::file_test(g_build_filename(program_files.c_str(), "xjadeo", "xjadeo.exe", NULL), Glib::FILE_TEST_EXISTS))
	{
		xjadeo_exe = std::string(g_build_filename(program_files.c_str(), "xjadeo", "xjadeo.exe", NULL));
	}
	else if (Glib::file_test(X_("C:\\Program Files\\xjadeo\\xjadeo.exe"), Glib::FILE_TEST_EXISTS)) {
		xjadeo_exe = X_("C:\\Program Files\\xjadeo\\xjadeo.exe");
	}
#endif

	return (!xjadeo_exe.empty() && Glib::file_test(xjadeo_exe, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE));
}

bool
ArdourVideoToolPaths::transcoder_exe (std::string &ffmpeg_exe, std::string &ffprobe_exe)
{
#ifdef PLATFORM_WINDOWS
	std::string reg;
	std::string program_files = PBD::get_win_special_folder_path (CSIDL_PROGRAM_FILES);
#endif

	ffmpeg_exe = X_("");
	ffprobe_exe = X_("");

	std::string ff_file_path;
	if (find_file (Searchpath(Glib::getenv("PATH")), X_("ffmpeg_harvid"), ff_file_path)) {
		ffmpeg_exe = ff_file_path;
	}
#ifdef PLATFORM_WINDOWS
	else if ( windows_install_dir("Software\\" PROGRAM_NAME "\\v" PROGRAM_VERSION "\\video", reg))
	{
		ffmpeg_exe = g_build_filename(reg.c_str(), X_("harvid"), X_("ffmpeg.exe"), NULL);
		ffprobe_exe = g_build_filename(reg.c_str(), X_("harvid"), X_("ffprobe.exe"), NULL);
	}
	else if ( windows_install_dir("Software\\RSS\\harvid", reg))
	{
		ffmpeg_exe = g_build_filename(reg.c_str(), X_("ffmpeg.exe"), NULL);
		ffprobe_exe = g_build_filename(reg.c_str(), X_("ffprobe.exe"), NULL);
	}

	if (Glib::file_test(ffmpeg_exe, Glib::FILE_TEST_EXISTS)) {
		;
	}
	else if (!program_files.empty() && Glib::file_test(g_build_filename(program_files.c_str(), "harvid", "ffmpeg.exe", NULL), Glib::FILE_TEST_EXISTS)) {
		ffmpeg_exe = g_build_filename(program_files.c_str(), "harvid", "ffmpeg.exe", NULL);
	}
	else if (Glib::file_test(X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe"), Glib::FILE_TEST_EXISTS)) {
		ffmpeg_exe = X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe");
	} else {
		ffmpeg_exe = X_("");
	}
#endif

	if (find_file (Searchpath(Glib::getenv("PATH")), X_("ffprobe_harvid"), ff_file_path)) {
		ffprobe_exe = ff_file_path;
	}
#ifdef PLATFORM_WINDOWS
	if (Glib::file_test(ffprobe_exe, Glib::FILE_TEST_EXISTS)) {
		;
	}
	else if (!program_files.empty() && Glib::file_test(g_build_filename(program_files.c_str(), "harvid", "ffprobe.exe", NULL), Glib::FILE_TEST_EXISTS)) {
		ffprobe_exe = g_build_filename(program_files.c_str(), "harvid", "ffprobe.exe", NULL);
	}
	else if (Glib::file_test(X_("C:\\Program Files\\ffmpeg\\ffprobe.exe"), Glib::FILE_TEST_EXISTS)) {
		ffprobe_exe = X_("C:\\Program Files\\ffmpeg\\ffprobe.exe");
	} else {
		ffprobe_exe = X_("");
	}
#endif

	if (ffmpeg_exe.empty() || ffprobe_exe.empty()) {
		return false;
	}
	return true;
}

} // namespace ARDOUR