| 181 | } |
| 182 | |
| 183 | void fs_listdir_fileinfo(const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int type, void *user) |
| 184 | { |
| 185 | #if defined(CONF_FAMILY_WINDOWS) |
| 186 | char buffer[IO_MAX_PATH_LENGTH]; |
| 187 | str_format(buffer, sizeof(buffer), "%s/*", dir); |
| 188 | const std::wstring wide_buffer = windows_utf8_to_wide(buffer); |
| 189 | |
| 190 | WIN32_FIND_DATAW finddata; |
| 191 | HANDLE handle = FindFirstFileW(wide_buffer.c_str(), &finddata); |
| 192 | if(handle == INVALID_HANDLE_VALUE) |
| 193 | return; |
| 194 | |
| 195 | do |
| 196 | { |
| 197 | const std::optional<std::string> current_entry = windows_wide_to_utf8(finddata.cFileName); |
| 198 | if(!current_entry.has_value()) |
| 199 | { |
| 200 | log_error("filesystem", "ERROR: file/folder name containing invalid UTF-16 found in folder '%s'", dir); |
| 201 | continue; |
| 202 | } |
| 203 | |
| 204 | CFsFileInfo info; |
| 205 | info.m_pName = current_entry.value().c_str(); |
| 206 | info.m_TimeCreated = filetime_to_unixtime(&finddata.ftCreationTime); |
| 207 | info.m_TimeModified = filetime_to_unixtime(&finddata.ftLastWriteTime); |
| 208 | |
| 209 | if(cb(&info, (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0, type, user)) |
| 210 | break; |
| 211 | } while(FindNextFileW(handle, &finddata)); |
| 212 | |
| 213 | FindClose(handle); |
| 214 | #else |
| 215 | DIR *dir_handle = opendir(dir); |
| 216 | if(dir_handle == nullptr) |
| 217 | return; |
| 218 | |
| 219 | char buffer[IO_MAX_PATH_LENGTH]; |
| 220 | str_format(buffer, sizeof(buffer), "%s/", dir); |
| 221 | size_t length = str_length(buffer); |
| 222 | |
| 223 | while(true) |
| 224 | { |
| 225 | struct dirent *entry = readdir(dir_handle); |
| 226 | if(entry == nullptr) |
| 227 | break; |
| 228 | if(!str_utf8_check(entry->d_name)) |
| 229 | { |
| 230 | log_error("filesystem", "ERROR: file/folder name containing invalid UTF-8 found in folder '%s'", dir); |
| 231 | continue; |
| 232 | } |
| 233 | str_copy(buffer + length, entry->d_name, sizeof(buffer) - length); |
| 234 | time_t created = -1, modified = -1; |
| 235 | fs_file_time(buffer, &created, &modified); |
| 236 | |
| 237 | CFsFileInfo info; |
| 238 | info.m_pName = entry->d_name; |
| 239 | info.m_TimeCreated = created; |
| 240 | info.m_TimeModified = modified; |
no test coverage detected