| 196 | } |
| 197 | |
| 198 | void FileView::Refresh(){ |
| 199 | char* rPath = realpath(currentPath.c_str(), nullptr); |
| 200 | assert(rPath); |
| 201 | |
| 202 | currentPath = rPath; |
| 203 | free(rPath); |
| 204 | |
| 205 | if(currentPath.back() != '/') |
| 206 | currentPath.append("/"); |
| 207 | |
| 208 | pathBox->LoadText(currentPath.c_str()); |
| 209 | |
| 210 | fileList->ClearItems(); |
| 211 | |
| 212 | std::string absPath; |
| 213 | struct dirent** entries; |
| 214 | int entryCount = scandir(currentPath.c_str(), &entries, static_cast<int(*)(const dirent*)>([](const dirent* d) -> int { (void)d; return 1; }), static_cast<int(*)(const dirent**, const dirent**)>([](const dirent** a, const dirent**b) { |
| 215 | if((*a)->d_type == DT_DIR && (*b)->d_type != DT_DIR){ |
| 216 | return -1; |
| 217 | } else if((*b)->d_type == DT_DIR && (*a)->d_type != DT_DIR){ |
| 218 | return 1; |
| 219 | } |
| 220 | return strcmp((*a)->d_name, (*b)->d_name); |
| 221 | })); |
| 222 | |
| 223 | if(entryCount < 0){ |
| 224 | perror("GUI: FileView: open:"); |
| 225 | return; |
| 226 | } |
| 227 | |
| 228 | for(int i = 0; i < entryCount; i++){ |
| 229 | struct dirent& dirent = *entries[i]; |
| 230 | |
| 231 | GridItem item; |
| 232 | item.name = dirent.d_name; |
| 233 | |
| 234 | absPath = currentPath + "/" + dirent.d_name; |
| 235 | |
| 236 | struct stat statResult; |
| 237 | int ret = lstat(absPath.c_str(), &statResult); |
| 238 | if(ret){ |
| 239 | perror("GUI: FileView: File: Stat"); |
| 240 | //assert(!ret); |
| 241 | continue; |
| 242 | } |
| 243 | |
| 244 | if(S_ISDIR(statResult.st_mode)){ |
| 245 | item.icon = &folderIcon; |
| 246 | } else if(char* ext = strchr(dirent.d_name, '.'); ext){ |
| 247 | if(!strcmp(ext, ".txt") || !strcmp(ext, ".cfg") || !strcmp(ext, ".py") || !strcmp(ext, ".asm")){ |
| 248 | item.icon = &textFileIcon; |
| 249 | } else if(!strcmp(ext, ".json")) { |
| 250 | item.icon = &jsonFileIcon; |
| 251 | } else { |
| 252 | item.icon = &fileIcon; |
| 253 | } |
| 254 | } else { |
| 255 | item.icon = &fileIcon; |
no test coverage detected