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

Function folder_sort_thread

src/source.cpp:2053–2224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2051};
2052
2053DWORD WINAPI folder_sort_thread(LPVOID lpParam) {
2054 DLOG_SORT("folder_sort_thread STARTED");
2055 DLOG_MUTEX("Entering G->sort_mutex");
2056 EnterCriticalSection(&G->sort_mutex);
2057 G->sorting = true;
2058
2059 Folder_Sort_Thread_data *data = (Folder_Sort_Thread_data *)lpParam;
2060 if (!data || !data->path || !data->FileName) {
2061 DLOG_ERROR("folder_sort_thread: invalid data!");
2062 G->sorting = false;
2063 LeaveCriticalSection(&G->sort_mutex);
2064 return 0;
2065 }
2066
2067 wchar_t *file_path = data->path;
2068 wchar_t *file_name = data->FileName;
2069
2070 wchar_t folder_path[MAX_PATH];
2071 wcscpy(folder_path, file_path);
2072 wchar_t* last_slash = wcsrchr(folder_path, L'\\');
2073 if (!last_slash) last_slash = wcsrchr(folder_path, L'/');
2074 if (last_slash) *last_slash = L'\0';
2075
2076 Sort_Order detected_sort = Sort_Order_Name_Asc;
2077 bool found_sort_source = false;
2078
2079 // Try FilePilot first
2080 if (G->settings_sort_filepilot) {
2081 if (check_filepilot_sort(folder_path, &detected_sort)) {
2082 found_sort_source = true;
2083 DLOG_SORT("Got sort order from FilePilot");
2084 }
2085 }
2086
2087 // Fall back to Windows Explorer
2088 if (!found_sort_source) {
2089 HRESULT hrCoInit = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
2090
2091 if (SUCCEEDED(hrCoInit) || hrCoInit == S_FALSE) {
2092 IShellWindows *shellWindows = NULL;
2093 if (S_OK == CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL, IID_IShellWindows, (void **)&shellWindows)) {
2094 VARIANT v = {};
2095 V_VT(&v) = VT_I4;
2096 IDispatch *dispatch = NULL;
2097
2098 for (V_I4(&v) = 0; S_OK == shellWindows->Item(v, &dispatch); V_I4(&v)++) {
2099 IWebBrowserApp *webBrowserApp = NULL;
2100 IServiceProvider *serviceProvider = NULL;
2101 IShellBrowser *shellBrowser = NULL;
2102 IShellView *shellView = NULL;
2103 IFolderView2 *folderView2 = NULL;
2104 IPersistFolder2 *persistFolder = NULL;
2105 ITEMIDLIST *folderPIDL = NULL;
2106
2107 wchar_t path_buffer[MAX_PATH + 4] = {0};
2108 bool match = false;
2109
2110 if (S_OK == dispatch->QueryInterface(IID_IWebBrowserApp, (void **)&webBrowserApp) &&

Callers 2

folder_scan_threadFunction · 0.85
scan_folderFunction · 0.85

Calls 1

check_filepilot_sortFunction · 0.85

Tested by

no test coverage detected