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)
set(HAVE_SDL2 SDL2-static)
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()
if (BUILD_GUI)
set(SDL_SHARED ON)
@ -126,6 +126,7 @@ src/gui/gui.cpp)
if (WIN32)
list(APPEND ENGINE_SOURCES src/utfutils.cpp)
list(APPEND ENGINE_SOURCES src/engine/winStuff.cpp)
endif()
if (BUILD_GUI)
@ -143,5 +144,5 @@ if (HAVE_JACK)
endif()
if (WIN32)
target_link_libraries(furnace -static)
target_link_libraries(furnace shlwapi -static)
endif()

View file

@ -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!="") {

View file

@ -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
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
#include <windows.h>
#define LAYOUT_INI "\\layout.ini"
#else
#include <unistd.h>
#define LAYOUT_INI "/layout.ini"
#endif
const int _ZERO=0;
@ -1961,7 +1963,10 @@ bool FurnaceGUI::init() {
sty.ScaleAllSizes(dpiScale);
strncpy(finalConfigPath,(e->getConfigPath()+String(LAYOUT_INI)).c_str(),4095);
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) {
logE("could not load UI font!\n");

View file

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