text stringlengths 0 1.47k |
|---|
if (difference) return difference; |
i++; |
} |
return (int)left[i] - (int)right[i]; |
} |
static int session_candidate_better(const bof_session_candidate_t *left, const bof_session_candidate_t *right) { |
int comparison; |
if (left->last_write_time.dwHighDateTime != right->last_write_time.dwHighDateTime) |
return left->last_write_time.dwHighDateTime > right->last_write_time.dwHighDateTime; |
if (left->last_write_time.dwLowDateTime != right->last_write_time.dwLowDateTime) |
return left->last_write_time.dwLowDateTime > right->last_write_time.dwLowDateTime; |
if (left->size_bytes != right->size_bytes) return left->size_bytes > right->size_bytes; |
comparison = ascii_lower((unsigned char)left->tool[0]) - ascii_lower((unsigned char)right->tool[0]); |
if (comparison == 0) { |
int i = 0; |
while (left->tool[i] && right->tool[i]) { |
comparison = ascii_lower((unsigned char)left->tool[i]) - ascii_lower((unsigned char)right->tool[i]); |
if (comparison) break; |
i++; |
} |
if (!comparison) comparison = (unsigned char)left->tool[i] - (unsigned char)right->tool[i]; |
} |
if (comparison != 0) return comparison < 0; |
return wide_path_compare_ci(left->path, right->path) < 0; |
} |
static int session_tool_slot(const char *tool) { |
int length = c_string_len(tool); |
if (ascii_equal_n_ci(tool, length, "codex")) return 0; |
if (ascii_equal_n_ci(tool, length, "claude_code")) return 1; |
if (ascii_equal_n_ci(tool, length, "cursor")) return 2; |
if (ascii_equal_n_ci(tool, length, "antigravity_cli")) return 3; |
if (ascii_equal_n_ci(tool, length, "grok")) return 4; |
return -1; |
} |
static void consider_session_candidate(const char *tool, const wchar_t *path, const WIN32_FIND_DATAW *data) { |
bof_session_candidate_t candidate; |
int tool_slot; |
int base; |
int insert = -1; |
int i; |
if (!tool || !path || !data || !session_file_recognized(tool, path)) return; |
tool_slot = session_tool_slot(tool); |
if (tool_slot < 0) return; |
g_session_artifact_counts[tool_slot]++; |
base = tool_slot * BOF_TOP_SESSIONS_PER_TOOL; |
inline_memset(&candidate, 0, sizeof(candidate)); |
candidate.tool = tool; |
candidate.size_bytes = ((long long)data->nFileSizeHigh << 32) | data->nFileSizeLow; |
candidate.last_write_time = data->ftLastWriteTime; |
copy_wide_path(candidate.path, path, BL_MAX_PATH_LEN); |
for (i = 0; i < BOF_TOP_SESSIONS_PER_TOOL; i++) { |
if (g_top_sessions[base + i].tool && wide_path_compare_ci(g_top_sessions[base + i].path, path) == 0) return; |
if (insert < 0 && (!g_top_sessions[base + i].tool || session_candidate_better(&candidate, &g_top_sessions[base + i]))) insert = i; |
} |
if (insert < 0) return; |
if (!g_top_sessions[base + BOF_TOP_SESSIONS_PER_TOOL - 1].tool) g_top_session_count++; |
for (i = BOF_TOP_SESSIONS_PER_TOOL - 1; i > insert; i--) g_top_sessions[base + i] = g_top_sessions[base + i - 1]; |
g_top_sessions[base + insert] = candidate; |
} |
static void walk_session_files(const char *tool, const wchar_t *directory, int depth) { |
wchar_t search[BL_MAX_PATH_LEN]; |
wchar_t child[BL_MAX_PATH_LEN]; |
WIN32_FIND_DATAW find_data; |
HANDLE find_handle; |
if (g_session_scan_stop) return; |
if (depth > BOF_SESSION_SCAN_MAX_DEPTH) { g_session_scan_partial = 1; return; } |
inline_memset(search, 0, sizeof(search)); |
if (!build_path(directory, L"\\*", search, BL_MAX_PATH_LEN)) { g_session_scan_partial = 1; return; } |
inline_memset(&find_data, 0, sizeof(find_data)); |
find_handle = KERNEL32$FindFirstFileW(search, &find_data); |
if (find_handle == INVALID_HANDLE_VALUE) { |
if (KERNEL32$GetLastError() != ERROR_FILE_NOT_FOUND) g_session_scan_partial = 1; |
return; |
} |
do { |
if (is_dot_directory(find_data.cFileName)) continue; |
if (g_session_entries_scanned >= BOF_SESSION_SCAN_LIMIT) { |
g_session_scan_partial = 1; |
g_session_scan_stop = 1; |
break; |
} |
g_session_entries_scanned++; |
inline_memset(child, 0, sizeof(child)); |
if (!build_path(directory, L"\\", child, BL_MAX_PATH_LEN) || |
!append_wide_in_place(child, find_data.cFileName, BL_MAX_PATH_LEN)) { |
g_session_scan_partial = 1; |
continue; |
} |
if (find_data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) continue; |
if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) walk_session_files(tool, child, depth + 1); |
else consider_session_candidate(tool, child, &find_data); |
} while (!g_session_scan_stop && KERNEL32$FindNextFileW(find_handle, &find_data)); |
if (!g_session_scan_stop && KERNEL32$GetLastError() != ERROR_NO_MORE_FILES) g_session_scan_partial = 1; |
KERNEL32$FindClose(find_handle); |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.