summaryrefslogtreecommitdiff
path: root/src/config.cpp
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-03-05 20:05:46 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-03-05 20:05:46 +0100
commit129d8d9a5922eb3d4df9320418fb98dfbbadc053 (patch)
tree47422dcb5536ebc0c0ba62907aab9c2daa9c10f8 /src/config.cpp
parentf3401ce1532938fec63d22095ca8b14affcfdce3 (diff)
save previous search query to config and load on startup
Diffstat (limited to 'src/config.cpp')
-rw-r--r--src/config.cpp61
1 files changed, 61 insertions, 0 deletions
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 <stdio.h>
+
+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