custom config directory
This commit is contained in:
parent
8bdbd1074f
commit
f42cfcbdc8
7 changed files with 103 additions and 3 deletions
|
|
@ -3,7 +3,11 @@
|
|||
#include "safeReader.h"
|
||||
#include "../ta-log.h"
|
||||
#include "../audio/sdl.h"
|
||||
#include <cstring>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef HAVE_JACK
|
||||
#include "../audio/jack.h"
|
||||
#endif
|
||||
|
|
@ -1267,6 +1271,10 @@ void DivEngine::reset() {
|
|||
dispatch->reset();
|
||||
}
|
||||
|
||||
String DivEngine::getConfigPath() {
|
||||
return configPath;
|
||||
}
|
||||
|
||||
int DivEngine::getMaxVolumeChan(int ch) {
|
||||
return chan[ch].volMax>>8;
|
||||
}
|
||||
|
|
@ -1580,7 +1588,55 @@ void DivEngine::quitDispatch() {
|
|||
isBusy.unlock();
|
||||
}
|
||||
|
||||
#define CHECK_CONFIG_DIR() \
|
||||
configPath+="/.config"; \
|
||||
if (stat(configPath.c_str(),&st)<0) { \
|
||||
logI("creating user config dir...\n"); \
|
||||
if (mkdir(configPath.c_str(),0755)<0) { \
|
||||
logW("could not make user config dir! (%s)\n",strerror(errno)); \
|
||||
configPath="."; \
|
||||
} \
|
||||
} \
|
||||
if (configPath!=".") { \
|
||||
configPath+="/furnace"; \
|
||||
if (stat(configPath.c_str(),&st)<0) { \
|
||||
logI("creating config dir...\n"); \
|
||||
if (mkdir(configPath.c_str(),0755)<0) { \
|
||||
logW("could not make config dir! (%s)\n",strerror(errno)); \
|
||||
configPath="."; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "winStuff.h"
|
||||
#endif
|
||||
|
||||
bool DivEngine::init(String outName) {
|
||||
// init config
|
||||
#ifdef _WIN32
|
||||
configPath=getWinConfigPath();
|
||||
#else
|
||||
struct stat st;
|
||||
char* home=getenv("HOME");
|
||||
if (home==NULL) {
|
||||
int uid=getuid();
|
||||
struct passwd* entry=getpwuid(uid);
|
||||
if (entry==NULL) {
|
||||
logW("unable to determine config directory! (%s)\n",strerror(errno));
|
||||
configPath=".";
|
||||
} else {
|
||||
configPath=entry->pw_dir;
|
||||
CHECK_CONFIG_DIR();
|
||||
}
|
||||
} else {
|
||||
configPath=home;
|
||||
CHECK_CONFIG_DIR();
|
||||
}
|
||||
#endif
|
||||
logD("config path: %s\n",configPath.c_str());
|
||||
|
||||
// init the rest of engine
|
||||
SNDFILE* outFile=NULL;
|
||||
SF_INFO outInfo;
|
||||
if (outName!="") {
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ class DivEngine {
|
|||
DivAudioEngines audioEngine;
|
||||
bool isMuted[17];
|
||||
std::mutex isBusy;
|
||||
String configPath;
|
||||
|
||||
short vibTable[64];
|
||||
|
||||
|
|
@ -124,6 +125,9 @@ class DivEngine {
|
|||
// reset playback state
|
||||
void reset();
|
||||
|
||||
// get config path
|
||||
String getConfigPath();
|
||||
|
||||
// get sys channel count
|
||||
int getChannelCount(DivSystem sys);
|
||||
|
||||
|
|
|
|||
29
src/engine/winStuff.cpp
Normal file
29
src/engine/winStuff.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include "winStuff.h"
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
#include <shlwapi.h>
|
||||
#include "../ta-log.h"
|
||||
#include "../utfutils.h"
|
||||
|
||||
String getWinConfigPath() {
|
||||
wchar_t path[4096];
|
||||
WString configPath;
|
||||
HRESULT configHR;
|
||||
if ((configHR=SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,path))==S_OK) {
|
||||
configPath=path;
|
||||
configPath+=L"\\furnace";
|
||||
if (!PathIsDirectoryW(configPath.c_str())) {
|
||||
logI("creating config dir...\n");
|
||||
int mkdirRet;
|
||||
if ((mkdirRet=SHCreateDirectory(NULL,configPath.c_str()))!=ERROR_SUCCESS) {
|
||||
logW("could not make config dir! (%.8x)\n",mkdirRet);
|
||||
configPath=L".";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logW("unable to determine config directory! (%.8x)\n",configHR);
|
||||
configPath=L".";
|
||||
}
|
||||
return utf16To8(configPath.c_str());
|
||||
}
|
||||
3
src/engine/winStuff.h
Normal file
3
src/engine/winStuff.h
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#include "../ta-utils.h"
|
||||
|
||||
String getWinConfigPath();
|
||||
Loading…
Add table
Add a link
Reference in a new issue