13
0

Change return type and name of get_win_special_folder

Rename it get_win_special_folder_path to indicate what it is returning

Move documentation for the function into the header and use doxygen style
comments.

Fixes a couple of memory leaks in ArdourVideoToolPaths class although it looks
as if there are more.
This commit is contained in:
Tim Mayberry 2015-08-18 14:44:53 +10:00
parent 36e4c11a2a
commit a2fbce0e7f
4 changed files with 40 additions and 43 deletions

View File

@ -66,7 +66,7 @@ ArdourVideoToolPaths::harvid_exe (std::string &harvid_exe)
#ifdef PLATFORM_WINDOWS
std::string reg;
const char *program_files = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
std::string program_files = PBD::get_win_special_folder_path (CSIDL_PROGRAM_FILES);
#endif
harvid_exe = "";
@ -84,9 +84,9 @@ ArdourVideoToolPaths::harvid_exe (std::string &harvid_exe)
{
harvid_exe = g_build_filename(reg.c_str(), "harvid.exe", NULL);
}
else if (program_files && Glib::file_test(g_build_filename(program_files, "harvid", "harvid.exe", NULL), Glib::FILE_TEST_EXISTS))
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, "harvid", "harvid.exe", NULL);
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");
@ -105,7 +105,7 @@ ArdourVideoToolPaths::xjadeo_exe (std::string &xjadeo_exe)
std::string xjadeo_file_path;
#ifdef PLATFORM_WINDOWS
std::string reg;
const char *program_files = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
std::string program_files = PBD::get_win_special_folder_path (CSIDL_PROGRAM_FILES);
#endif
if (getenv("XJREMOTE")) {
xjadeo_exe = getenv("XJREMOTE");
@ -131,9 +131,9 @@ ArdourVideoToolPaths::xjadeo_exe (std::string &xjadeo_exe)
{
xjadeo_exe = std::string(g_build_filename(reg.c_str(), "xjadeo.exe", NULL));
}
else if (program_files && Glib::file_test(g_build_filename(program_files, "xjadeo", "xjadeo.exe", NULL), Glib::FILE_TEST_EXISTS))
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, "xjadeo", "xjadeo.exe", NULL));
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");
@ -151,7 +151,7 @@ ArdourVideoToolPaths::transcoder_exe (std::string &ffmpeg_exe, std::string &ffpr
{
#ifdef PLATFORM_WINDOWS
std::string reg;
const char *program_files = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
std::string program_files = PBD::get_win_special_folder_path (CSIDL_PROGRAM_FILES);
#endif
ffmpeg_exe = X_("");
@ -176,8 +176,8 @@ ArdourVideoToolPaths::transcoder_exe (std::string &ffmpeg_exe, std::string &ffpr
if (Glib::file_test(ffmpeg_exe, Glib::FILE_TEST_EXISTS)) {
;
}
else if (program_files && Glib::file_test(g_build_filename(program_files, "harvid", "ffmpeg.exe", NULL), Glib::FILE_TEST_EXISTS)) {
ffmpeg_exe = g_build_filename(program_files, "harvid", "ffmpeg.exe", NULL);
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");
@ -193,8 +193,8 @@ ArdourVideoToolPaths::transcoder_exe (std::string &ffmpeg_exe, std::string &ffpr
if (Glib::file_test(ffprobe_exe, Glib::FILE_TEST_EXISTS)) {
;
}
else if (program_files && Glib::file_test(g_build_filename(program_files, "harvid", "ffprobe.exe", NULL), Glib::FILE_TEST_EXISTS)) {
ffprobe_exe = g_build_filename(program_files, "harvid", "ffprobe.exe", NULL);
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");

View File

@ -196,11 +196,11 @@ vst_search_path ()
if (p == 0) {
char *pVSTx86 = 0;
char *pProgFilesX86 = PBD::get_win_special_folder (CSIDL_PROGRAM_FILESX86);
std::string pProgFilesX86 = PBD::get_win_special_folder_path (CSIDL_PROGRAM_FILESX86);
if (pProgFilesX86) {
if (!pProgFilesX86.empty()) {
// Look for a VST folder under C:\Program Files (x86)
if ((pVSTx86 = g_build_filename (pProgFilesX86, "Steinberg", "VSTPlugins", NULL)))
if ((pVSTx86 = g_build_filename (pProgFilesX86.c_str(), "Steinberg", "VSTPlugins", NULL)))
{
if (Glib::file_test (pVSTx86, Glib::FILE_TEST_EXISTS))
if (Glib::file_test (pVSTx86, Glib::FILE_TEST_IS_DIR))
@ -208,25 +208,21 @@ vst_search_path ()
g_free (pVSTx86);
}
g_free (pProgFilesX86);
}
if (p == 0) {
// Look for a VST folder under C:\Program Files
char *pVST = 0;
char *pProgFiles = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
std::string pProgFiles = PBD::get_win_special_folder_path (CSIDL_PROGRAM_FILES);
if (pProgFiles) {
if ((pVST = g_build_filename (pProgFiles, "Steinberg", "VSTPlugins", NULL))) {
if (!pProgFiles.empty()) {
if ((pVST = g_build_filename (pProgFiles.c_str(), "Steinberg", "VSTPlugins", NULL))) {
if (Glib::file_test (pVST, Glib::FILE_TEST_EXISTS))
if (Glib::file_test (pVST, Glib::FILE_TEST_IS_DIR))
p = g_build_filename (pVST, NULL);
g_free (pVST);
}
g_free (pProgFiles);
}
}
}

View File

@ -20,10 +20,22 @@
#ifndef __libpbd_windows_special_dirs_h__
#define __libpbd_windows_special_dirs_h__
#include <string>
#include "pbd/libpbd_visibility.h"
namespace PBD {
LIBPBD_API char * get_win_special_folder (int csidl);
/**
* Gets the full path that corresponds of one of the Windows special folders,
* such as "My Documents" and the like.
*
* @param csidl corresponds to CSIDL values, such as CSIDL_SYSTEM etc.
* @return A string containing the name of the special folder or an empty
* string on failure.
*/
LIBPBD_API std::string get_win_special_folder_path (int csidl);
}
#endif /* __libpbd_windows_special_dirs_h__ */

View File

@ -23,38 +23,27 @@
#include "pbd/windows_special_dirs.h"
//***************************************************************
//
// get_win_special_folder()
//
// Gets the full path name that corresponds of one of the Windows
// special folders, such as "My Documents" and the like. The input
// parameter must be one of the corresponding CSIDL values, such
// as CSIDL_SYSTEM etc.
//
// Returns:
//
// On Success: A pointer to a newly allocated string containing
// the name of the special folder (must later be freed).
// On Failure: NULL
//
char *
PBD::get_win_special_folder (int csidl)
std::string
PBD::get_win_special_folder_path (int csidl)
{
wchar_t path[PATH_MAX+1];
HRESULT hr;
LPITEMIDLIST pidl = 0;
char *retval = 0;
char *utf8_folder_path = 0;
if (S_OK == (hr = SHGetSpecialFolderLocation (0, csidl, &pidl))) {
if (SHGetPathFromIDListW (pidl, path)) {
retval = g_utf16_to_utf8 ((const gunichar2*)path, -1, 0, 0, 0);
utf8_folder_path = g_utf16_to_utf8 ((const gunichar2*)path, -1, 0, 0, 0);
}
CoTaskMemFree (pidl);
}
return retval;
if (utf8_folder_path != NULL) {
std::string folder_path(utf8_folder_path);
g_free (utf8_folder_path);
return folder_path;
}
return std::string();
}