From 129d8d9a5922eb3d4df9320418fb98dfbbadc053 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Tue, 5 Mar 2024 20:05:46 +0100 Subject: save previous search query to config and load on startup --- src/config.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/config.cpp (limited to 'src/config.cpp') diff --git a/src/config.cpp b/src/config.cpp new file mode 100644 index 0000000..4813c5c --- /dev/null +++ b/src/config.cpp @@ -0,0 +1,61 @@ +#include "config.h" +#include "../imgui/imgui_internal.h" +#include "search.h" + +#include + +utf8_int8_t path_buffer[MAX_INPUT_LENGTH]; +utf8_int8_t filter_buffer[MAX_INPUT_LENGTH]; +utf8_int8_t query_buffer[MAX_INPUT_LENGTH]; +int ts_thread_count = 4; +int max_file_size = 100; // in MBs + +static void _ts_config_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line) +{ + ImGuiWindowSettings* settings = (ImGuiWindowSettings*)entry; + uint8_t path[MAX_INPUT_LENGTH]; + uint8_t filter[MAX_INPUT_LENGTH]; + uint8_t query[MAX_INPUT_LENGTH]; + + int threads, maxSize; + + if (sscanf(line, "Path=%s", &path) == 1) { strcpy_s(path_buffer, MAX_INPUT_LENGTH, (char*)path); } + else if (sscanf(line, "Filter=%s", &filter) == 1) { strcpy_s(filter_buffer, MAX_INPUT_LENGTH, (char*)filter); } + else if (sscanf(line, "Query=%s", &query) == 1) { strcpy_s(query_buffer, MAX_INPUT_LENGTH, (char*)query); } + else if (sscanf(line, "Threads=%d", &threads) == 1) { ts_thread_count = threads; } + else if (sscanf(line, "MaxSize=%d", &maxSize) == 1) { max_file_size = maxSize; } +} + +static void _ts_config_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf) +{ + // Write to text buffer + buf->reserve(MAX_INPUT_LENGTH*4); // ballpark reserve + buf->appendf("[%s][%s]\n", handler->TypeName, "Search"); + buf->appendf("Path=%s\n", path_buffer); + buf->appendf("Filter=%s\n", filter_buffer); + buf->appendf("Query=%s\n", query_buffer); + buf->appendf("Threads=%d\n", ts_thread_count); + buf->appendf("MaxSize=%d\n", max_file_size); + buf->append("\n"); +} + +static void* _ts_config_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name) { + return (void*)0xFFFFFF; +} + +static void _ts_config_ApplyAll(ImGuiContext* ctx, ImGuiSettingsHandler*) +{ + +} + +void ts_load_config() { + ImGuiSettingsHandler ini_handler; + ini_handler.TypeName = "Query"; + ini_handler.TypeHash = ImHashStr("Query"); + ini_handler.ClearAllFn = nullptr; + ini_handler.ReadOpenFn = _ts_config_ReadOpen; + ini_handler.ReadLineFn = _ts_config_ReadLine; + ini_handler.ApplyAllFn = _ts_config_ApplyAll; + ini_handler.WriteAllFn = _ts_config_WriteAll; + ImGui::AddSettingsHandler(&ini_handler); +} \ No newline at end of file -- cgit v1.2.3-70-g09d2