Create Freesound working directory a little more lazily so
authorCarl Hetherington <carl@carlh.net>
Tue, 27 Dec 2011 14:36:14 +0000 (14:36 +0000)
committerCarl Hetherington <carl@carlh.net>
Tue, 27 Dec 2011 14:36:14 +0000 (14:36 +0000)
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
gtk2_ardour/sfdb_freesound_mootcher.h

index 6833bae7684c44320878837fae3958b9bd0b770d..69c13794f6270e20c94289fae5fe32f4c85fb15e 100644 (file)
@@ -41,6 +41,7 @@
 #include "sfdb_freesound_mootcher.h"\r
 \r
 #include "pbd/xml++.h"\r
+#include "pbd/filesystem.h"\r
 \r
 #include <sys/stat.h>\r
 #include <sys/types.h>\r
@@ -64,7 +65,7 @@ Mootcher:: ~Mootcher()
 }\r
 \r
 //------------------------------------------------------------------------\r
-const char* Mootcher::changeWorkingDir(const char *saveLocation)\r
+void Mootcher::changeWorkingDir(const char *saveLocation)\r
 {\r
        basePath = saveLocation;\r
 #ifdef __WIN32__\r
@@ -78,15 +79,17 @@ const char* Mootcher::changeWorkingDir(const char *saveLocation)
        //\r
        size_t pos2 = basePath.find_last_of("/");\r
        if(basePath.length() != (pos2+1)) basePath += "/";\r
+}\r
 \r
-       // create Freesound directory and sound dir\r
-       std::string sndLocation = basePath;\r
-       mkdir(sndLocation.c_str(), 0777);\r
-       sndLocation += "snd";\r
-       mkdir(sndLocation.c_str(), 0777);\r
-\r
-       return basePath.c_str();\r
+void Mootcher::ensureWorkingDir ()\r
+{\r
+       PBD::sys::path p = basePath;\r
+       p /= "snd";\r
+       if (!PBD::sys::is_directory (p)) {\r
+               PBD::sys::create_directories (p);\r
+       }\r
 }\r
+       \r
 \r
 //------------------------------------------------------------------------\r
 size_t Mootcher::WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)\r
@@ -259,6 +262,7 @@ std::string Mootcher::getSoundResourceFile(std::string ID)
                // std::cerr << "getSoundResourceFile: saving XML: " << xmlFileName << std::endl;\r
 \r
                // save the xml file to disk\r
+               ensureWorkingDir();\r
                doc.write(xmlFileName.c_str());\r
 \r
                //store all the tags in the database\r
@@ -293,7 +297,7 @@ int audioFileWrite(void *buffer, size_t size, size_t nmemb, void *file)
 //------------------------------------------------------------------------\r
 std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, Gtk::ProgressBar *progress_bar)\r
 {\r
-\r
+       ensureWorkingDir();\r
        std::string audioFileName = basePath + "snd/" + ID + "-" + originalFileName;\r
 \r
        //check to see if audio file already exists\r
index b76150e1061a7950768ec07ecfd92f05442a4378..9f5c38c0fd6619c86114b79cc83e45f569dd3bc4 100644 (file)
@@ -55,7 +55,8 @@ public:
 \r
 private:\r
 \r
-       const char*     changeWorkingDir(const char *saveLocation);\r
+       void            changeWorkingDir(const char *saveLocation);\r
+       void            ensureWorkingDir();\r
 \r
        std::string     doRequest(std::string uri, std::string params);\r
        void            setcUrlOptions();\r