From e41d64724caeca3ca7bc098153c6e6c50e310bc4 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 27 Dec 2011 14:36:14 +0000 Subject: Create Freesound working directory a little more lazily so that a Freesound directory doesn't appear in /home/carl without ever using Freesound. git-svn-id: svn://localhost/ardour2/branches/3.0@11090 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/sfdb_freesound_mootcher.cc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'gtk2_ardour/sfdb_freesound_mootcher.cc') diff --git a/gtk2_ardour/sfdb_freesound_mootcher.cc b/gtk2_ardour/sfdb_freesound_mootcher.cc index 6833bae768..69c13794f6 100644 --- a/gtk2_ardour/sfdb_freesound_mootcher.cc +++ b/gtk2_ardour/sfdb_freesound_mootcher.cc @@ -41,6 +41,7 @@ #include "sfdb_freesound_mootcher.h" #include "pbd/xml++.h" +#include "pbd/filesystem.h" #include #include @@ -64,7 +65,7 @@ Mootcher:: ~Mootcher() } //------------------------------------------------------------------------ -const char* Mootcher::changeWorkingDir(const char *saveLocation) +void Mootcher::changeWorkingDir(const char *saveLocation) { basePath = saveLocation; #ifdef __WIN32__ @@ -78,15 +79,17 @@ const char* Mootcher::changeWorkingDir(const char *saveLocation) // size_t pos2 = basePath.find_last_of("/"); if(basePath.length() != (pos2+1)) basePath += "/"; +} - // create Freesound directory and sound dir - std::string sndLocation = basePath; - mkdir(sndLocation.c_str(), 0777); - sndLocation += "snd"; - mkdir(sndLocation.c_str(), 0777); - - return basePath.c_str(); +void Mootcher::ensureWorkingDir () +{ + PBD::sys::path p = basePath; + p /= "snd"; + if (!PBD::sys::is_directory (p)) { + PBD::sys::create_directories (p); + } } + //------------------------------------------------------------------------ size_t Mootcher::WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) @@ -259,6 +262,7 @@ std::string Mootcher::getSoundResourceFile(std::string ID) // std::cerr << "getSoundResourceFile: saving XML: " << xmlFileName << std::endl; // save the xml file to disk + ensureWorkingDir(); doc.write(xmlFileName.c_str()); //store all the tags in the database @@ -293,7 +297,7 @@ int audioFileWrite(void *buffer, size_t size, size_t nmemb, void *file) //------------------------------------------------------------------------ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, Gtk::ProgressBar *progress_bar) { - + ensureWorkingDir(); std::string audioFileName = basePath + "snd/" + ID + "-" + originalFileName; //check to see if audio file already exists -- cgit v1.2.3