Some SlackBuild scripts for Slackware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.3 KiB

diff --git a/src/Misc/Config.cpp b/src/Misc/Config.cpp
index a8ff54e..4913213 100644
--- a/src/Misc/Config.cpp
+++ b/src/Misc/Config.cpp
@@ -21,6 +21,7 @@
#include "Config.h"
#include "../globals.h"
#include "XMLwrapper.h"
+#include "Util.h"
#define rStdString(name, len, ...) \
{STRINGIFY(name) "::s", rMap(length, len) rProp(parameter) DOC(__VA_ARGS__), NULL, rStringCb(name,len)}
@@ -217,6 +218,7 @@ void Config::init()
char filename[MAX_STRING_SIZE];
getConfigFileName(filename, MAX_STRING_SIZE);
+ migrateOldConfig(filename);
readConfig(filename);
if(cfg.bankRootDirList[0].empty()) {
@@ -384,6 +386,8 @@ void Config::readConfig(const char *filename)
void Config::saveConfig(const char *filename) const
{
+ makedir(filename, 0700);
+
XMLwrapper *xmlcfg = new XMLwrapper();
xmlcfg->beginbranch("CONFIGURATION");
@@ -446,6 +450,25 @@ void Config::saveConfig(const char *filename) const
void Config::getConfigFileName(char *name, int namesize) const
{
+ const char *cfg_dir;
+
name[0] = 0;
- snprintf(name, namesize, "%s%s", getenv("HOME"), "/.zynaddsubfxXML.cfg");
+ if((cfg_dir = getenv("XDG_CONFIG_HOME")))
+ snprintf(name, namesize, "%s/zynaddsubfx/zynaddsubfxXML.cfg", cfg_dir);
+ else
+ snprintf(name, namesize, "%s/.config/zynaddsubfx/zynaddsubfxXML.cfg", getenv("HOME"));
+}
+
+void Config::migrateOldConfig(const char *new_cfg_file)
+{
+ char old_cfg_file[MAX_STRING_SIZE];
+
+ if(!fileexists(new_cfg_file)) {
+ snprintf(old_cfg_file, sizeof(old_cfg_file), "%s/.zynaddsubfxXML.cfg", getenv("HOME"));
+
+ if(fileexists(old_cfg_file)) {
+ makedir(new_cfg_file, 0700);
+ rename(old_cfg_file, new_cfg_file);
+ }
+ }
}
diff --git a/src/Misc/Config.h b/src/Misc/Config.h
index c90b79a..aa08112 100644
--- a/src/Misc/Config.h
+++ b/src/Misc/Config.h
@@ -72,5 +72,6 @@ class Config
void readConfig(const char *filename);
void saveConfig(const char *filename) const;
void getConfigFileName(char *name, int namesize) const;
+ void migrateOldConfig(const char *new_cfg_file);
};
#endif
diff --git a/src/Misc/Util.cpp b/src/Misc/Util.cpp
index d4dab12..cdcbf6d 100644
--- a/src/Misc/Util.cpp
+++ b/src/Misc/Util.cpp
@@ -115,6 +115,30 @@ bool fileexists(const char *filename)
return false;
}
+int makedir(const char *path, int mode)
+{
+ char *p;
+ int ret;
+ struct stat st_buf;
+
+ for(p = (char *)(path + 1), ret = 0; *(p - 1) && ret == 0; ++p) {
+ if(*p == '/' ) {
+ *p = '\0';
+
+ if(stat(path, &st_buf) == -1)
+ ret = mkdir(path, mode);
+ else if(!S_ISDIR(st_buf.st_mode)) {
+ errno = ENOTDIR;
+ ret = -1;
+ }
+
+ *p = '/';
+ }
+ }
+
+ return ret;
+}
+
void set_realtime()
{
#ifdef HAVE_SCHEDULER
diff --git a/src/Misc/Util.h b/src/Misc/Util.h
index 2a27d9e..6341b5e 100644
--- a/src/Misc/Util.h
+++ b/src/Misc/Util.h
@@ -33,6 +33,8 @@ extern bool isPlugin;
bool fileexists(const char *filename);
+int makedir(const char *path, int mode);
+
#define N_DETUNE_TYPES 4 //the number of detune types
extern float getdetune(unsigned char type,
unsigned short int coarsedetune,