summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-03-17 15:04:35 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-03-17 15:04:35 +0100
commit95e06b2f6d87b597a52029dbfa9896f4bd8ca74b (patch)
tree250078f1044844a8cfe64592a9181fa0587317ae /src
parent7105b39ca10394723e888161d586461e9e2b1984 (diff)
logging
Diffstat (limited to 'src')
-rw-r--r--src/config.cpp4
-rw-r--r--src/export.cpp11
-rw-r--r--src/fonts.cpp6
-rw-r--r--src/fonts.h28
-rw-r--r--src/image.cpp3
-rw-r--r--src/import.cpp9
-rw-r--r--src/logging.cpp3
-rw-r--r--src/logging.h32
-rw-r--r--src/main.cpp29
-rw-r--r--src/search.cpp7
-rw-r--r--src/windows/main_windows.cpp5
11 files changed, 116 insertions, 21 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 4c5533d..51d45a8 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -1,7 +1,7 @@
#include "config.h"
#include "../imgui/imgui_internal.h"
#include "search.h"
-
+#include "logging.h"
#include <stdio.h>
#include <string.h>
#include <cstring>
@@ -72,4 +72,6 @@ void ts_load_config() {
ini_handler.ApplyAllFn = _ts_config_ApplyAll;
ini_handler.WriteAllFn = _ts_config_WriteAll;
ImGui::AddSettingsHandler(&ini_handler);
+
+ TS_LOG_TRACE("Loaded config");
} \ No newline at end of file
diff --git a/src/export.cpp b/src/export.cpp
index b020b77..22e8956 100644
--- a/src/export.cpp
+++ b/src/export.cpp
@@ -4,6 +4,7 @@
#include "../imfiledialog/ImFileDialog.h"
#include <stdio.h>
#include <inttypes.h>
+#include "logging.h"
export_result last_export_result = EXPORT_NONE;
@@ -249,16 +250,20 @@ struct t_export_thread_args {
static void* _ts_export_thread(void* args) {
struct t_export_thread_args* arg = (struct t_export_thread_args*)args;
+ bool result = false;
if (ts_str_has_extension(arg->path, ".json")) {
- _ts_export_json(arg->result, arg->path);
+ result = _ts_export_json(arg->result, arg->path);
}
if (ts_str_has_extension(arg->path, ".csv")) {
- _ts_export_csv(arg->result, arg->path);
+ result = _ts_export_csv(arg->result, arg->path);
}
if (ts_str_has_extension(arg->path, ".xml")) {
- _ts_export_xml(arg->result, arg->path);
+ result = _ts_export_xml(arg->result, arg->path);
}
+ if (!result) TS_LOG_TRACE("Export failed: cound not open file %s", arg->path)
+ else TS_LOG_TRACE("Export completed: %s", arg->path);
+
arg->result->is_saving = false;
free(arg);
diff --git a/src/fonts.cpp b/src/fonts.cpp
index 34df8f4..2fff05f 100644
--- a/src/fonts.cpp
+++ b/src/fonts.cpp
@@ -5,6 +5,7 @@
#include "../fonts/NotoSerifTC.h"
#include "../fonts/NotoSansSC.h"
#include "../fonts/NotoSansThai.h"
+#include "logging.h"
#include "imgui.h"
#include <stdio.h>
@@ -42,6 +43,8 @@ ts_font_range ts_locale_to_range(wchar_t* buffer) {
if (wcscmp(buffer, L"th-TH") == 0) result = FONT_RANGE_THAI;
if (wcscmp(buffer, L"vi-VN") == 0) result = FONT_RANGE_VIETNAMESE;
+
+ TS_LOG_TRACE("Loaded locale: %ls, alphabet: %s", buffer, FONT_RANGE_STRING[result]);
return result;
}
@@ -126,5 +129,6 @@ void ts_load_fonts(float size, ts_font_range locale) {
size, &config, io.Fonts->GetGlyphRangesVietnamese());
}
- io.Fonts->Build();
+ io.Fonts->Build();
+ TS_LOG_TRACE("Loaded fonts");
} \ No newline at end of file
diff --git a/src/fonts.h b/src/fonts.h
index ef2a23d..82fc324 100644
--- a/src/fonts.h
+++ b/src/fonts.h
@@ -2,17 +2,27 @@
#include <wchar.h>
+#define FOREACH_FONT_RANGE(FONT_RANGE) \
+ FONT_RANGE(FONT_RANGE_ENGLISH) \
+ FONT_RANGE(FONT_RANGE_GREEK) \
+ FONT_RANGE(FONT_RANGE_KOREAN) \
+ FONT_RANGE(FONT_RANGE_JAPANESE) \
+ FONT_RANGE(FONT_RANGE_CHINESE_FULL) \
+ FONT_RANGE(FONT_RANGE_CHINESE_SIMPLE) \
+ FONT_RANGE(FONT_RANGE_CYRILLIC) \
+ FONT_RANGE(FONT_RANGE_THAI) \
+ FONT_RANGE(FONT_RANGE_VIETNAMESE) \
+
+#define GENERATE_ENUM(ENUM) ENUM,
+#define GENERATE_STRING(STRING) #STRING,
+
typedef enum t_ts_font_range {
- FONT_RANGE_ENGLISH,
- FONT_RANGE_GREEK,
- FONT_RANGE_KOREAN,
- FONT_RANGE_JAPANESE,
- FONT_RANGE_CHINESE_FULL,
- FONT_RANGE_CHINESE_SIMPLE,
- FONT_RANGE_CYRILLIC,
- FONT_RANGE_THAI,
- FONT_RANGE_VIETNAMESE,
+ FOREACH_FONT_RANGE(GENERATE_ENUM)
} ts_font_range;
+static const char *FONT_RANGE_STRING[] = {
+ FOREACH_FONT_RANGE(GENERATE_STRING)
+};
+
void ts_load_fonts(float size, ts_font_range locale);
ts_font_range ts_locale_to_range(wchar_t* locale); \ No newline at end of file
diff --git a/src/image.cpp b/src/image.cpp
index 6f87eda..1fa551e 100644
--- a/src/image.cpp
+++ b/src/image.cpp
@@ -1,7 +1,7 @@
#include "image.h"
#include "definitions.h"
#include "../imfiledialog/ImFileDialog.h"
-
+#include "logging.h"
#define STB_IMAGE_IMPLEMENTATION
#include "../stb_image.h"
@@ -88,4 +88,5 @@ void ts_load_images() {
GLuint texID = (GLuint)(intptr_t)tex;
glDeleteTextures(1, &texID);
};
+ TS_LOG_TRACE("Loaded images");
} \ No newline at end of file
diff --git a/src/import.cpp b/src/import.cpp
index 254050d..ed3df4d 100644
--- a/src/import.cpp
+++ b/src/import.cpp
@@ -2,7 +2,7 @@
#include "search.h"
#include "export.h"
#include "../imfiledialog/ImFileDialog.h"
-
+#include "logging.h"
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
@@ -131,6 +131,13 @@ static void* _ts_import_thread(void* args) {
last_import_result = _ts_import_csv(arg->result, arg->path);
}
+ switch(last_import_result) {
+ case IMPORT_NONE: TS_LOG_TRACE("Import success: %s", arg->path); break;
+ case IMPORT_FILE_ERROR: TS_LOG_TRACE("Import error: could not open file %s", arg->path); break;
+ case IMPORT_INVALID_VERSION: TS_LOG_TRACE("Import error: invalid version %s", arg->path); break;
+ case IMPORT_INVALID_DATA: TS_LOG_TRACE("Import error: invalid data %s", arg->path); break;
+ }
+
arg->result->done_finding_files = true;
arg->result->search_completed = true;
diff --git a/src/logging.cpp b/src/logging.cpp
new file mode 100644
index 0000000..e00b373
--- /dev/null
+++ b/src/logging.cpp
@@ -0,0 +1,3 @@
+#include "logging.h"
+
+ts_log logger = {0}; \ No newline at end of file
diff --git a/src/logging.h b/src/logging.h
new file mode 100644
index 0000000..625004d
--- /dev/null
+++ b/src/logging.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include "array.h"
+#include "platform.h"
+#include "../utf8.h"
+
+#define LOG_ENTRY_SIZE 120
+
+typedef struct t_ts_log
+{
+ ts_array entries;
+ uint64_t start_time;
+} ts_log;
+
+extern ts_log logger;
+
+#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
+
+#define TS_LOG_TRACE(__format, ...) { \
+ if (logger.entries.data == NULL) { \
+ logger.start_time = ts_platform_get_time(); \
+ logger.entries = ts_array_create(LOG_ENTRY_SIZE); \
+ ts_array_reserve(&logger.entries, 50); \
+ logger.entries.reserve_jump = 50; \
+ } \
+ utf8_int8_t __tmp[LOG_ENTRY_SIZE]; \
+ utf8_int8_t* __buffer = (utf8_int8_t*)malloc(LOG_ENTRY_SIZE); \
+ memset(__buffer, 0, LOG_ENTRY_SIZE); \
+ snprintf(__tmp, LOG_ENTRY_SIZE, "[%10.3f] %s", ts_platform_get_time(logger.start_time)/1000.0f, __format); \
+ snprintf(__buffer, LOG_ENTRY_SIZE, __tmp, __VA_ARGS__); \
+ ts_array_push(&logger.entries, __buffer); \
+} \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 0828859..a6e8dba 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -11,12 +11,13 @@
#include "config.h"
#include "export.h"
#include "import.h"
-
+#include "logging.h"
#include <stdio.h>
// Popups
bool open_settings_window = false;
bool open_about_window = false;
+bool open_log_window = false;
const char* help_text =
"1. Search directory\n"
@@ -28,8 +29,25 @@ const char* help_text =
"3. Text to search\n"
" - Supports wildcards '*' & '?' in text\n";
-static void _ts_create_popups() {
+static void _ts_create_popups(int window_w, int window_h) {
ImGuiIO& io = ImGui::GetIO();
+
+ if (open_log_window) {
+ ImGui::OpenPopup("Text-Search Log");
+ ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), ImGuiCond_Always, ImVec2(0.5f,0.5f));
+ }
+
+ // Settings window
+ if (ImGui::BeginPopupModal("Text-Search Log", &open_log_window, ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove)) {
+ ImGui::SetWindowSize({window_w*0.8f, window_h*0.8f});
+ for (uint32_t i = 0; i < logger.entries.length; i++) {
+ utf8_int8_t* entry = (utf8_int8_t*)ts_array_at(&logger.entries, i);
+ ImGui::Text("%s", entry);
+ }
+
+ ImGui::EndPopup();
+ }
+
if (open_settings_window) {
ImGui::OpenPopup("Text-Search settings");
ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), ImGuiCond_Always, ImVec2(0.5f,0.5f));
@@ -164,6 +182,9 @@ static int _ts_create_menu(int window_w, int window_h) {
if (ImGui::MenuItem("Settings")) {
open_settings_window = true;
}
+ if (ImGui::MenuItem("Log")) {
+ open_log_window = true;
+ }
if (ImGui::MenuItem("About")) {
open_about_window = true;
}
@@ -177,7 +198,7 @@ static int _ts_create_menu(int window_w, int window_h) {
ImGui::PopStyleVar();
ImGui::PopStyleColor();
- _ts_create_popups();
+ _ts_create_popups(window_w, window_h);
ts_create_import_popup(window_w, window_h);
ts_create_export_popup(window_w, window_h);
@@ -185,6 +206,8 @@ static int _ts_create_menu(int window_w, int window_h) {
}
void ts_init() {
+ TS_LOG_TRACE("Program started");
+
memset(save_path, 0, sizeof(save_path));
memset(path_buffer, 0, sizeof(path_buffer));
memset(filter_buffer, 0, sizeof(filter_buffer));
diff --git a/src/search.cpp b/src/search.cpp
index 35e9a23..3622f28 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -1,6 +1,7 @@
#include "search.h"
#include "platform.h"
#include "config.h"
+#include "logging.h"
#include <stdio.h>
ts_search_result *current_search_result = NULL;
@@ -374,6 +375,8 @@ static void *_ts_list_files_thread(void *args)
ts_platform_list_files_block(info, NULL);
info->done_finding_files = true;
+ TS_LOG_TRACE("Search done listing files: %p", info);
+
// Use this thread to cleanup previous result.
if (info->prev_result) {
while (!info->prev_result->search_completed || info->prev_result->is_saving) {
@@ -388,6 +391,8 @@ static void *_ts_list_files_thread(void *args)
if (info->completed_match_threads == info->max_ts_thread_count) {
info->search_completed = true; // No memory is written after this point.
info->timestamp = ts_platform_get_time(info->timestamp);
+
+ TS_LOG_TRACE("Search completed: %p", info);
}
ts_thread_sleep(10);
}
@@ -407,6 +412,7 @@ void ts_start_search(utf8_int8_t *path, utf8_int8_t *filter, utf8_int8_t *query,
return;
}
+
if (current_search_result)
{
current_search_result->cancel_search = true;
@@ -420,6 +426,7 @@ void ts_start_search(utf8_int8_t *path, utf8_int8_t *filter, utf8_int8_t *query,
new_result->max_ts_thread_count = thread_count;
new_result->max_file_size = max_fs;
new_result->respect_capitalization = case_sensitive;
+ TS_LOG_TRACE("Search started: %p %s -> %s", new_result, path, query);
if (utf8len(query) == 0) {
new_result->search_text = NULL;
diff --git a/src/windows/main_windows.cpp b/src/windows/main_windows.cpp
index becb1c1..c68f326 100644
--- a/src/windows/main_windows.cpp
+++ b/src/windows/main_windows.cpp
@@ -12,6 +12,7 @@
#include "image.h"
#include "config.h"
#include "fonts.h"
+#include "logging.h"
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
@@ -118,10 +119,12 @@ ts_font_range _ts_get_font_range_to_load() {
int main(int, char**)
{
+
if (OleInitialize(NULL) != S_OK) {
return -1;
}
+ QueryPerformanceFrequency(&Frequency);
ts_init();
// Create application window
@@ -161,8 +164,6 @@ int main(int, char**)
ImGui_ImplWin32_InitForOpenGL(hwnd);
ImGui_ImplOpenGL3_Init();
- QueryPerformanceFrequency(&Frequency);
-
ts_load_fonts(18.0f, _ts_get_font_range_to_load());
ts_load_images();
ts_load_config();