Added persistant config for file source

This commit is contained in:
Ryzerth 2021-04-29 22:04:20 +02:00
parent bed0712be1
commit ce8b4ceb44
5 changed files with 22 additions and 6 deletions

View File

@ -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());
}

View File

@ -10,7 +10,7 @@ class FileSelect {
public:
FileSelect(std::string defaultPath, std::vector<std::string> 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);

View File

@ -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());
}

View File

@ -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);

View File

@ -5,6 +5,7 @@
#include <signal_path/signal_path.h>
#include <wavreader.h>
#include <core.h>
#include <options.h>
#include <gui/widgets/file_select.h>
#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();
}