summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp52
-rw-r--r--src/main_windows.cpp1
-rw-r--r--src/platform.h1
-rw-r--r--src/search.cpp13
-rw-r--r--src/search.h1
5 files changed, 62 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 424c1b7..e21aead 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -15,7 +15,7 @@ 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 = megabytes(1000);
+int max_file_size = 100; // in MBs
// Popups
bool open_settings_window = false;
@@ -40,6 +40,11 @@ static void _ts_create_popups() {
if (ImGui::BeginPopupModal("Text-Search settings", NULL, ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove)) {
ImGui::SetWindowSize({300, 0});
ImGui::DragInt("Threads", &ts_thread_count, 1.0f, 1, 4);
+ ImGui::SetItemTooltip("Number of threads used to search for text matches");
+
+ ImGui::DragInt("File Size", &max_file_size, 50.0f, 1, 10000, "%dMB");
+ ImGui::SetItemTooltip("Files larger than this will not be searched");
+
ImGui::Combo("Language", &current_locale_index, locales, locales_count);
ImGui::Dummy({0, 70});
@@ -135,7 +140,7 @@ int _tb_query_input_cb(ImGuiInputTextCallbackData* data) {
return 0;
}
-void _ts_ceate_file_match_rows() {
+void _ts_create_file_match_rows() {
int itemcount = current_search_result == 0 ? 0 : current_search_result->files.length;
for (int item = 0; item < itemcount; item++)
{
@@ -156,6 +161,44 @@ void _ts_ceate_file_match_rows() {
}
}
+utf8_int8_t* _ts_file_error_to_message(ts_file_open_error err) {
+ switch (err) {
+ case FILE_ERROR_TOO_MANY_OPEN_FILES_PROCESS: return u8"Too many open files";
+ case FILE_ERROR_TOO_MANY_OPEN_FILES_SYSTEM: return u8"Too many open files";
+ case FILE_ERROR_NO_ACCESS: return u8"No permissions";
+ case FILE_ERROR_NOT_FOUND: return u8"File not found";
+ case FILE_ERROR_CONNECTION_ABORTED: return u8"Connection aborted";
+ case FILE_ERROR_CONNECTION_REFUSED: return u8"Failed to connect";
+ case FILE_ERROR_NETWORK_DOWN: return u8"Drive disconnected";
+ case FILE_ERROR_REMOTE_IO_ERROR: return u8"Remote IO error";
+ case FILE_ERROR_STALE: return u8"Server file moved";
+ case FILE_ERROR_GENERIC: return u8"Failed to open file";
+ case FILE_ERROR_TOO_BIG: return u8"File too big";
+ }
+ return "";
+}
+
+void _ts_create_file_error_rows() {
+ int itemcount = current_search_result == 0 ? 0 : current_search_result->files.length;
+ for (int item = 0; item < itemcount; item++)
+ {
+ ts_found_file *file = *(ts_found_file **)ts_array_at(&current_search_result->files, item);
+ if (file->error == FILE_ERROR_NONE) continue;
+
+ ImGui::TableNextRow();
+ ImGui::TableNextColumn();
+ ImGui::PushStyleColor(ImGuiCol_Text, ImGui::Spectrum::Color(0xFF0000));
+ ImGui::TableHeader("ERROR");
+ ImGui::PopStyleColor();
+
+ ImGui::TableNextColumn();
+ ImGui::TableHeader(file->path);
+
+ ImGui::TableNextColumn();
+ ImGui::TableHeader(_ts_file_error_to_message((ts_file_open_error)file->error));
+ }
+}
+
void _ts_create_text_match_rows() {
int itemcount = current_search_result == 0 ? 0 : current_search_result->matches.length;
ts_found_file* prev_file = nullptr;
@@ -193,6 +236,7 @@ void _ts_create_text_match_rows() {
ImGui::TableNextColumn();
ImGui::Text("line %d", file->line_nr);
}
+ _ts_create_file_error_rows();
}
void ts_create_gui(int window_w, int window_h) {
@@ -276,7 +320,7 @@ void ts_create_gui(int window_w, int window_h) {
{(float)window_w-7.0f, (float)result_area_height}))
{
int nr_w = 50;
- int line_w = 120;
+ int line_w = 180;
int file_w = ImGui::GetWindowWidth() - line_w - nr_w;
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_NoHeaderLabel, nr_w);
ImGui::TableSetupColumn("File", 0, file_w);
@@ -284,7 +328,7 @@ void ts_create_gui(int window_w, int window_h) {
ImGui::TableHeadersRow();
if (current_search_result) {
- if (current_search_result->search_text == nullptr) _ts_ceate_file_match_rows();
+ if (current_search_result->search_text == nullptr) _ts_create_file_match_rows();
else _ts_create_text_match_rows();
}
else {
diff --git a/src/main_windows.cpp b/src/main_windows.cpp
index 45963d1..2a9d3a0 100644
--- a/src/main_windows.cpp
+++ b/src/main_windows.cpp
@@ -328,6 +328,7 @@ void ts_platform_list_files_block(ts_search_result* result, wchar_t* start_dir)
ts_found_file* f = (ts_found_file*)ts_memory_bucket_reserve(&result->memory, sizeof(ts_found_file));
f->path = (utf8_int8_t*)ts_memory_bucket_reserve(&result->memory, MAX_INPUT_LENGTH);
f->match_count = 0;
+ f->error = 0;
WideCharToMultiByte(CP_UTF8,0,complete_file_path,-1,(LPSTR)f->path,MAX_INPUT_LENGTH, NULL, NULL);
ts_mutex_lock(&result->files.mutex);
diff --git a/src/platform.h b/src/platform.h
index 8429058..edaee4c 100644
--- a/src/platform.h
+++ b/src/platform.h
@@ -15,6 +15,7 @@ typedef struct t_ts_file_content
typedef enum t_ts_file_open_error
{
+ FILE_ERROR_NONE,
FILE_ERROR_TOO_MANY_OPEN_FILES_PROCESS = 1,
FILE_ERROR_TOO_MANY_OPEN_FILES_SYSTEM = 2,
FILE_ERROR_NO_ACCESS = 3,
diff --git a/src/search.cpp b/src/search.cpp
index 82ffc64..1e7241c 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -311,7 +311,9 @@ keep_going:;
int read_cursor = new_result->file_list_read_cursor+1;
if (read_cursor >= new_result->files.length) {
ts_mutex_unlock(&new_result->files.mutex);
- continue;
+
+ if (!new_result->done_finding_files) continue;
+ else break;
}
new_result->file_count++;
new_result->file_list_read_cursor++;
@@ -320,7 +322,14 @@ keep_going:;
ts_found_file *f = *(ts_found_file **)ts_array_at(&new_result->files, read_cursor);
ts_file_content content = ts_platform_read_file(f->path, "rb, ccs=UTF-8");
- _ts_search_file(f, content, new_result);
+ if (content.file_error != FILE_ERROR_NONE) {
+ f->error = content.file_error;
+ }
+ if (content.content_length > megabytes(new_result->max_file_size)) {
+ f->error = FILE_ERROR_TOO_BIG;
+ }
+
+ if (f->error == FILE_ERROR_NONE) _ts_search_file(f, content, new_result);
free(content.content);
}
diff --git a/src/search.h b/src/search.h
index 400edbe..5b5f4b7 100644
--- a/src/search.h
+++ b/src/search.h
@@ -14,6 +14,7 @@ typedef struct t_ts_found_file
{
utf8_int8_t *path;
int match_count;
+ int error;
} ts_found_file;
typedef struct t_ts_search_result