diff --git a/core/src/gui/widgets/file_select.cpp b/core/src/gui/widgets/file_select.cpp index 86261ef3..c9bcd49d 100644 --- a/core/src/gui/widgets/file_select.cpp +++ b/core/src/gui/widgets/file_select.cpp @@ -45,10 +45,11 @@ bool FileSelect::render(std::string id) { return _pathChanged; } -void FileSelect::setPath(std::string path) { +void FileSelect::setPath(std::string path, bool markChanged) { this->path = path; std::string expandedPath = expandString(path); pathValid = std::filesystem::is_regular_file(expandedPath); + if (markChanged) { pathChanged = true; } strcpy(strPath, path.c_str()); } diff --git a/core/src/gui/widgets/file_select.h b/core/src/gui/widgets/file_select.h index a36463ef..e5d578c1 100644 --- a/core/src/gui/widgets/file_select.h +++ b/core/src/gui/widgets/file_select.h @@ -10,7 +10,7 @@ class FileSelect { public: FileSelect(std::string defaultPath, std::vector filter = {"All Files", "*"}); bool render(std::string id); - void setPath(std::string path); + void setPath(std::string path, bool markChanged = false); bool pathIsValid(); std::string expandString(std::string input); diff --git a/core/src/gui/widgets/folder_select.cpp b/core/src/gui/widgets/folder_select.cpp index 20705f32..a2fb5169 100644 --- a/core/src/gui/widgets/folder_select.cpp +++ b/core/src/gui/widgets/folder_select.cpp @@ -44,10 +44,11 @@ bool FolderSelect::render(std::string id) { return _pathChanged; } -void FolderSelect::setPath(std::string path) { +void FolderSelect::setPath(std::string path, bool markChanged) { this->path = path; std::string expandedPath = expandString(path); pathValid = std::filesystem::is_directory(expandedPath); + if (markChanged) { pathChanged = true; } strcpy(strPath, path.c_str()); } diff --git a/core/src/gui/widgets/folder_select.h b/core/src/gui/widgets/folder_select.h index 1061b2a8..0f7ce60e 100644 --- a/core/src/gui/widgets/folder_select.h +++ b/core/src/gui/widgets/folder_select.h @@ -9,7 +9,7 @@ class FolderSelect { public: FolderSelect(std::string defaultPath); bool render(std::string id); - void setPath(std::string path); + void setPath(std::string path, bool markChanged = false); bool pathIsValid(); std::string expandString(std::string input); diff --git a/file_source/src/main.cpp b/file_source/src/main.cpp index 3cd07fc8..9610054f 100644 --- a/file_source/src/main.cpp +++ b/file_source/src/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #define CONCAT(a, b) ((std::string(a) + b).c_str()) @@ -17,12 +18,17 @@ SDRPP_MOD_INFO { /* Max instances */ 1 }; +ConfigManager config; class FileSourceModule : public ModuleManager::Instance { public: FileSourceModule(std::string name) : fileSelect("", {"Wav IQ Files (*.wav)", "*.wav", "All Files", "*"}) { this->name = name; + config.aquire(); + fileSelect.setPath(config.conf["path"], true); + config.release(); + handler.ctx = this; handler.selectHandler = menuSelected; handler.deselectHandler = menuDeselected; @@ -105,6 +111,9 @@ private: core::setInputSampleRate(_this->sampleRate); } catch (std::exception e) {} + config.aquire(); + config.conf["path"] = _this->fileSelect.path; + config.release(true); } } @@ -157,7 +166,11 @@ private: }; MOD_EXPORT void _INIT_() { - // Do your one time init here + json def = json({}); + def["path"] = ""; + config.setPath(options::opts.root + "/file_source_config.json"); + config.load(def); + config.enableAutoSave(); } MOD_EXPORT void* _CREATE_INSTANCE_(std::string name) { @@ -169,5 +182,6 @@ MOD_EXPORT void _DELETE_INSTANCE_(void* instance) { } MOD_EXPORT void _END_() { - // Do your one shutdown here + config.disableAutoSave(); + config.save(); } \ No newline at end of file