Allow new Zyn bank creation on Linux (#4905)

Allow new Zyn bank creation on Linux
Closes #4642
This commit is contained in:
Tres Finocchiaro
2019-03-18 12:41:01 -04:00
committed by GitHub
parent e1adfc3952
commit ea5cbe6789
2 changed files with 39 additions and 3 deletions

View File

@@ -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();
@@ -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
@@ -355,6 +362,8 @@ void Bank::rescanforbanks()
void Bank::scanrootdir(string rootdir)
{
expanddirname(rootdir);
DIR *dir = opendir(rootdir.c_str());
if(dir == NULL)
return;
@@ -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 += "/";
}

View File

@@ -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