Skip to content

Commit

Permalink
- Use unsorted view for autoload entry.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Dec 10, 2024
1 parent 4f96f21 commit e1d2a59
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions cube/swiss/include/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ file_handle** getSortedDirEntries();
file_handle* getCurrentDirEntries();
int getSortedDirEntryCount();
int getCurrentDirEntryCount();
int getSortedDirEntryIndex(file_handle* file);
u64 getCurrentDirSize();
size_t concat_path(char *pathName, const char *dirName, const char *baseName);
size_t concatf_path(char *pathName, const char *dirName, const char *baseName, ...);
Expand Down
16 changes: 13 additions & 3 deletions cube/swiss/source/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ int sortFiles(file_handle* dir, int numFiles, file_handle*** sortedDir)
if(*sortedDir) {
for(int j = 0; j < numFiles; j++) {
switch(dir[j].fileType) {
case IS_SPECIAL:
break;
case IS_FILE:
if(!checkExtension(dir[j].name, devices[DEVICE_CUR]->extraExtensions))
continue;
default:
case IS_DIR:
if(!swissSettings.showHiddenFiles && ((dir[j].fileAttrib & ATTRIB_HIDDEN) || *getRelativeName(dir[j].name) == '.'))
continue;
default:
break;
}
(*sortedDir)[i++] = &dir[j];
}
Expand All @@ -58,6 +58,7 @@ int sortFiles(file_handle* dir, int numFiles, file_handle*** sortedDir)
void freeFiles() {
free(sortedDirEntries);
sortedDirEntries = NULL;
sortedDirEntryCount = 0;
if(curDirEntries) {
for(int i = 0; i < curDirEntryCount; i++) {
if(curDirEntries[i].meta) {
Expand Down Expand Up @@ -120,6 +121,15 @@ int getCurrentDirEntryCount() {
return curDirEntryCount;
}

int getSortedDirEntryIndex(file_handle* file) {
for(int i = 0; i < sortedDirEntryCount; i++) {
if(file == sortedDirEntries[i]) {
return i;
}
}
return 0;
}

u64 getCurrentDirSize() {
u64 curDirSize = 0LL;
for(int i = 0; i < curDirEntryCount; i++) {
Expand Down
22 changes: 11 additions & 11 deletions cube/swiss/source/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,20 +296,20 @@ int find_existing_entry(char *entry, bool load) {
needsRefresh = 0;

// Finally, read the actual file
file_handle **dirEntries = getSortedDirEntries();
int dirEntryCount = getSortedDirEntryCount();
file_handle *dirEntries = getCurrentDirEntries();
int dirEntryCount = getCurrentDirEntryCount();
for(int i = 0; i < dirEntryCount; i++) {
if(!strcmp(entry, dirEntries[i]->name)
|| !fnmatch(entry, dirEntries[i]->name, FNM_PATHNAME)) {
curSelection = i;
if(dirEntries[i]->fileType == IS_FILE && load) {
populate_meta(dirEntries[i]);
memcpy(&curFile, dirEntries[i], sizeof(file_handle));
if(!strcmp(entry, dirEntries[i].name)
|| !fnmatch(entry, dirEntries[i].name, FNM_PATHNAME)) {
curSelection = getSortedDirEntryIndex(&dirEntries[i]);
if(dirEntries[i].fileType == IS_FILE && load) {
populate_meta(&dirEntries[i]);
memcpy(&curFile, &dirEntries[i], sizeof(file_handle));
load_file();
memcpy(dirEntries[i], &curFile, sizeof(file_handle));
memcpy(&dirEntries[i], &curFile, sizeof(file_handle));
}
else if(dirEntries[i]->fileType == IS_DIR) {
memcpy(&curDir, dirEntries[i], sizeof(file_handle));
else if(dirEntries[i].fileType == IS_DIR) {
memcpy(&curDir, &dirEntries[i], sizeof(file_handle));
needsRefresh = 1;
}
return 0;
Expand Down

0 comments on commit e1d2a59

Please sign in to comment.