Read on start and omit file type

This commit is contained in:
Krzosa Karol
2024-07-12 12:47:29 +02:00
parent 1ec217905d
commit c660118f8b
3 changed files with 127 additions and 76 deletions

View File

@@ -43,64 +43,6 @@ WorkQueue MainWorkQueue;
#include "loading_thread.cpp"
#include "searching_thread.cpp"
struct ReplaceVar {
String replace;
String with;
};
String ReplaceVars(Allocator allocator, Array<ReplaceVar> vars_to_replace, String string) {
Array<char> sb = {allocator};
for (int64_t i = 0; i < string.len; i += 1) {
if (string[i] == '{') {
// extract the variable
i += 1;
String var = {string.data + i, 0};
for (; i < string.len && string[i] != '}'; i += 1)
var.len += 1;
// find the replacement
String found = "<not found>";
For(vars_to_replace) {
if (it.replace == var) {
found = it.with;
break;
}
}
For(found) sb.add(it);
} else sb.add(string[i]);
}
sb.add('\0');
String result = {sb.data, sb.len - 1};
return result;
}
void TestReplaceVars() {
Scratch scratch;
Array<ReplaceVar> vars_to_replace = {scratch};
String exe_folder = GetExePath(scratch);
vars_to_replace.add({"exe_folder", exe_folder});
String data_folder = Format(scratch, "%.*s/data", FmtString(exe_folder));
vars_to_replace.add({"data_folder", data_folder});
{
String r = ReplaceVars(scratch, vars_to_replace, "{exe_folder}");
Assert(r == exe_folder);
}
{
String r = ReplaceVars(scratch, vars_to_replace, "{exe_folder}{data_folder}");
Assert(r == Format(scratch, "%.*s%.*s", FmtString(exe_folder), FmtString(data_folder)));
}
{
String r = ReplaceVars(scratch, vars_to_replace, "..{exe_folder}..{data_folder}..{exe_folder}asd");
Assert(r == Format(scratch, "..%.*s..%.*s..%.*sasd", FmtString(exe_folder), FmtString(data_folder), FmtString(exe_folder)));
}
}
void UISearchResults(Array<String> filenames) {
Scratch scratch;
Array<String> matches = LockSearchResults();
@@ -226,11 +168,10 @@ int main(int, char **) {
XInitLoading();
InitSearch();
LoadConfig();
ThreadStartupInfo infos[16] = {};
InitWorkQueue(&MainWorkQueue, Lengthof(infos), infos);
memcpy(Prompt, "read=D:/zizek", sizeof("read=D:/zizek"));
Array<String> filenames = {};
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) {
@@ -281,6 +222,15 @@ int main(int, char **) {
ImGui_ImplOpenGL3_Init(glsl_version);
io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
{
String read_on_start = ReadOnStart;
if (read_on_start != "-") {
Scratch scratch;
Array<String> strings = Split(scratch, read_on_start, ";");
For(strings) XAddFolder(it, &filenames);
}
}
bool command_menu_open = false;
bool show_loaded_files = false;
bool set_focus_to_input = true;
@@ -407,8 +357,10 @@ int main(int, char **) {
ImGui::InputText(".srt", SRTCommand, sizeof(SRTCommand));
ImGui::InputText(".pdf", PDFCommand, sizeof(PDFCommand));
ImGui::InputText(".txt", TXTCommand, sizeof(TXTCommand));
ImGui::InputText("Folders to read during startup", ReadOnStart, sizeof(ReadOnStart));
if (ImGui::Button("Save config")) {
SaveConfig();
LoadConfig();
}
} else {
if (show_loaded_files) {