Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions plugins/zynaddsubfx/zynaddsubfx/src/Misc/Bank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ void Bank::loadfromslot(unsigned int ninstrument, Part *part)
*/
int Bank::loadbank(string bankdirname)
{
normalizedirsuffix(bankdirname);
DIR *dir = opendir(bankdirname.c_str());
clearbank();

Expand Down Expand Up @@ -255,9 +256,15 @@ int Bank::newbank(string newbankdirname)
string bankdir;
bankdir = config.cfg.bankRootDirList[0];

if(((bankdir[bankdir.size() - 1]) != '/')
&& ((bankdir[bankdir.size() - 1]) != '\\'))
bankdir += "/";
expanddirname(bankdir);
normalizedirsuffix(bankdir);

// FIXME: Zyn should automatically handle creation of parent directory
#ifdef WIN32
if(mkdir(bankdir.c_str()) < 0) return -1;
#else
if(mkdir(bankdir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) return -1;
#endif

bankdir += newbankdirname;
#ifdef WIN32
Expand Down Expand Up @@ -355,6 +362,8 @@ void Bank::rescanforbanks()

void Bank::scanrootdir(string rootdir)
{
expanddirname(rootdir);

DIR *dir = opendir(rootdir.c_str());
if(dir == NULL)
return;
Expand Down Expand Up @@ -472,3 +481,23 @@ Bank::ins_t::ins_t()
{
info.PADsynth_used = false;
}

void Bank::expanddirname(std::string &dirname) {
if (dirname.empty())
return;

// if the directory name starts with a ~ and the $HOME variable is
// defined in the environment, replace ~ by the content of $HOME
if (dirname.at(0) == '~') {
char *home_dirname = getenv("HOME");
if (home_dirname != NULL) {
dirname = std::string(home_dirname) + dirname.substr(1);
}
}
}

void Bank::normalizedirsuffix(string &dirname) const {
if(((dirname[dirname.size() - 1]) != '/')
&& ((dirname[dirname.size() - 1]) != '\\'))
dirname += "/";
}
7 changes: 7 additions & 0 deletions plugins/zynaddsubfx/zynaddsubfx/src/Misc/Bank.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ class Bank
std::string dirname;

void scanrootdir(std::string rootdir); //scans a root dir for banks

/** Expends ~ prefix in dirname, if any */
void expanddirname(std::string &dirname);

/** Ensure that the directory name is suffixed by a
* directory separator */
void normalizedirsuffix(std::string &dirname) const;
};

#endif