MCPcopy Create free account
hub / github.com/Wassimulator/CactusViewer / folder_scan_thread

Function folder_scan_thread

src/source.cpp:2422–2548  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2420static Folder_Scan_Thread_Data folder_scan_data;
2421
2422DWORD WINAPI folder_scan_thread(LPVOID lpParam) {
2423 DLOG_SCAN("folder_scan_thread STARTED");
2424 Folder_Scan_Thread_Data *data = (Folder_Scan_Thread_Data *)lpParam;
2425 wchar_t *full_path = data->full_path;
2426 wchar_t *filename = data->filename;
2427 debug_log_wstr("SCAN", "full_path", full_path);
2428 debug_log_wstr("SCAN", "filename", filename);
2429 G->scanning_folder = true;
2430 DLOG_SCAN("G->scanning_folder = true");
2431
2432 int len = wcslen(full_path);
2433 int newlen = len;
2434 for (int i = len - 1; i > 0; i--) {
2435 if (full_path[i] == '/' || full_path[i] == '\\') {
2436 newlen = i + 1;
2437 break;
2438 }
2439 }
2440
2441 wchar_t *BasePath = (wchar_t *)malloc((newlen + 1) * sizeof(wchar_t));
2442 memcpy(BasePath, full_path, newlen * sizeof(wchar_t));
2443 BasePath[newlen] = L'\0';
2444 debug_log_wstr("SCAN", "BasePath", BasePath);
2445
2446 if (!is_valid_windows_path(BasePath)) {
2447 DLOG_ERROR("Invalid Windows path");
2448 free(BasePath);
2449 G->scanning_folder = false;
2450 if (G->folder_scan_event) SetEvent(G->folder_scan_event);
2451 return 0;
2452 }
2453
2454 cf_dir_t dir;
2455 DLOG_SCAN("Opening directory");
2456 cf_dir_open(&dir, BasePath);
2457 DLOG_SIGNAL("Sending new_folder signal");
2458 send_signal(G->signals.new_folder);
2459 DLOG_MUTEX("Entering G->thumbs_mutex for folder_scan");
2460 EnterCriticalSection(&G->thumbs_mutex);
2461
2462 File_Data current_file_state = {0};
2463 bool had_current_file = G->files.Count > 0;
2464 if (had_current_file) current_file_state = G->files[0];
2465 DLOG_SCAN("Resetting files array, had_current_file=%d", had_current_file);
2466 G->files.reset_count();
2467
2468 int files_found = 0;
2469 while (dir.has_next) {
2470 cf_file_t file_0;
2471 cf_read_file(&dir, &file_0);
2472 if (file_0.is_dir) { cf_dir_next(&dir); continue; }
2473 remove_char(file_0.path, '/');
2474
2475 int type = check_valid_extention(file_0.ext);
2476 if (type == TYPE_UNKNOWN) { cf_dir_next(&dir); continue; }
2477
2478 File_Data new_file = {0};
2479 new_file.type = type;

Callers

nothing calls this directly

Calls 13

debug_log_wstrFunction · 0.85
is_valid_windows_pathFunction · 0.85
cf_dir_openFunction · 0.85
cf_read_fileFunction · 0.85
cf_dir_nextFunction · 0.85
remove_charFunction · 0.85
check_valid_extentionFunction · 0.85
cf_get_file_timeFunction · 0.85
cf_dir_closeFunction · 0.85
folder_sort_threadFunction · 0.85
reset_countMethod · 0.80

Tested by

no test coverage detected