custom config directory

This commit is contained in:
tildearrow 2021-12-19 03:16:24 -05:00
parent 8bdbd1074f
commit f42cfcbdc8
7 changed files with 103 additions and 3 deletions

View File

@ -22,7 +22,7 @@ if (WIN32)
add_subdirectory(extern/zlib) add_subdirectory(extern/zlib)
set(HAVE_SDL2 SDL2-static) set(HAVE_SDL2 SDL2-static)
set(HAVE_Z zlibstatic) set(HAVE_Z zlibstatic)
include_directories(extern/imgui extern/imgui/backends extern/igfd extern/zlib ${CMAKE_CURRENT_BINARY_DIR}/extern/zlib extern/fmt/include) include_directories(extern/imgui extern/imgui/backends extern/igfd extern/zlib ${CMAKE_CURRENT_BINARY_DIR}/extern/zlib extern/fmt/include)
else() else()
if (BUILD_GUI) if (BUILD_GUI)
set(SDL_SHARED ON) set(SDL_SHARED ON)
@ -126,6 +126,7 @@ src/gui/gui.cpp)
if (WIN32) if (WIN32)
list(APPEND ENGINE_SOURCES src/utfutils.cpp) list(APPEND ENGINE_SOURCES src/utfutils.cpp)
list(APPEND ENGINE_SOURCES src/engine/winStuff.cpp)
endif() endif()
if (BUILD_GUI) if (BUILD_GUI)
@ -143,5 +144,5 @@ if (HAVE_JACK)
endif() endif()
if (WIN32) if (WIN32)
target_link_libraries(furnace -static) target_link_libraries(furnace shlwapi -static)
endif() endif()

View File

@ -3,7 +3,11 @@
#include "safeReader.h" #include "safeReader.h"
#include "../ta-log.h" #include "../ta-log.h"
#include "../audio/sdl.h" #include "../audio/sdl.h"
#include <cstring> #ifndef _WIN32
#include <unistd.h>
#include <pwd.h>
#include <sys/stat.h>
#endif
#ifdef HAVE_JACK #ifdef HAVE_JACK
#include "../audio/jack.h" #include "../audio/jack.h"
#endif #endif
@ -1267,6 +1271,10 @@ void DivEngine::reset() {
dispatch->reset(); dispatch->reset();
} }
String DivEngine::getConfigPath() {
return configPath;
}
int DivEngine::getMaxVolumeChan(int ch) { int DivEngine::getMaxVolumeChan(int ch) {
return chan[ch].volMax>>8; return chan[ch].volMax>>8;
} }
@ -1580,7 +1588,55 @@ void DivEngine::quitDispatch() {
isBusy.unlock(); 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) { 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; SNDFILE* outFile=NULL;
SF_INFO outInfo; SF_INFO outInfo;
if (outName!="") { if (outName!="") {

View File

@ -82,6 +82,7 @@ class DivEngine {
DivAudioEngines audioEngine; DivAudioEngines audioEngine;
bool isMuted[17]; bool isMuted[17];
std::mutex isBusy; std::mutex isBusy;
String configPath;
short vibTable[64]; short vibTable[64];
@ -124,6 +125,9 @@ class DivEngine {
// reset playback state // reset playback state
void reset(); void reset();
// get config path
String getConfigPath();
// get sys channel count // get sys channel count
int getChannelCount(DivSystem sys); int getChannelCount(DivSystem sys);

29
src/engine/winStuff.cpp Normal file
View 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
View File

@ -0,0 +1,3 @@
#include "../ta-utils.h"
String getWinConfigPath();

View File

@ -17,8 +17,10 @@
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#define LAYOUT_INI "\\layout.ini"
#else #else
#include <unistd.h> #include <unistd.h>
#define LAYOUT_INI "/layout.ini"
#endif #endif
const int _ZERO=0; const int _ZERO=0;
@ -1961,7 +1963,10 @@ bool FurnaceGUI::init() {
sty.ScaleAllSizes(dpiScale); sty.ScaleAllSizes(dpiScale);
strncpy(finalConfigPath,(e->getConfigPath()+String(LAYOUT_INI)).c_str(),4095);
ImGui::GetIO().ConfigFlags|=ImGuiConfigFlags_DockingEnable; ImGui::GetIO().ConfigFlags|=ImGuiConfigFlags_DockingEnable;
ImGui::GetIO().IniFilename=finalConfigPath;
if ((mainFont=ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(defFont_main_compressed_data,defFont_main_compressed_size,18*dpiScale))==NULL) { if ((mainFont=ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(defFont_main_compressed_data,defFont_main_compressed_size,18*dpiScale))==NULL) {
logE("could not load UI font!\n"); logE("could not load UI font!\n");

View File

@ -86,6 +86,8 @@ class FurnaceGUI {
ImVec4 uiColors[GUI_COLOR_MAX]; ImVec4 uiColors[GUI_COLOR_MAX];
ImVec4 volColors[128]; ImVec4 volColors[128];
char finalConfigPath[4096];
int curIns, curWave, curSample, curOctave, oldRow, editStep; int curIns, curWave, curSample, curOctave, oldRow, editStep;
bool editControlsOpen, ordersOpen, insListOpen, songInfoOpen, patternOpen, insEditOpen; bool editControlsOpen, ordersOpen, insListOpen, songInfoOpen, patternOpen, insEditOpen;
bool waveListOpen, waveEditOpen, sampleListOpen, sampleEditOpen, aboutOpen; bool waveListOpen, waveEditOpen, sampleListOpen, sampleEditOpen, aboutOpen;