Skip to content

Commit

Permalink
Added size and date sort
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOfficialFloW committed Oct 30, 2016
1 parent 899b4a5 commit 825498f
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 82 deletions.
37 changes: 18 additions & 19 deletions UI2.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ static int refreshFileList() {
do {
fileListEmpty(&file_list);

res = fileListGetEntries(&file_list, file_list.path);
res = fileListGetEntries(&file_list, file_list.path, SORT_BY_NAME);

if (res < 0) {
ret = res;
Expand Down Expand Up @@ -537,18 +537,18 @@ enum MenuEntrys {
};

static MenuEntry menu_entries[] = {
{ MARK_ALL, CTX_VISIBILITY_INVISIBLE },
{ -1, CTX_VISIBILITY_UNUSED },
{ MOVE, CTX_VISIBILITY_INVISIBLE },
{ COPY, CTX_VISIBILITY_INVISIBLE },
{ PASTE, CTX_VISIBILITY_INVISIBLE },
{ -1, CTX_VISIBILITY_UNUSED },
{ DELETE, CTX_VISIBILITY_INVISIBLE },
{ RENAME, CTX_VISIBILITY_INVISIBLE },
{ -1, CTX_VISIBILITY_UNUSED },
{ NEW_FOLDER, CTX_VISIBILITY_INVISIBLE },
{ -1, CTX_VISIBILITY_UNUSED },
{ MORE, CTX_VISIBILITY_INVISIBLE }
{ MARK_ALL, 0, CTX_VISIBILITY_INVISIBLE },
{ -1, 0, CTX_VISIBILITY_UNUSED },
{ MOVE, 0, CTX_VISIBILITY_INVISIBLE },
{ COPY, 0, CTX_VISIBILITY_INVISIBLE },
{ PASTE, 0, CTX_VISIBILITY_INVISIBLE },
{ -1, 0, CTX_VISIBILITY_UNUSED },
{ DELETE, 0, CTX_VISIBILITY_INVISIBLE },
{ RENAME, 0, CTX_VISIBILITY_INVISIBLE },
{ -1, 0, CTX_VISIBILITY_UNUSED },
{ NEW_FOLDER, 0, CTX_VISIBILITY_INVISIBLE },
{ -1, 0, CTX_VISIBILITY_UNUSED },
{ MORE, 1, CTX_VISIBILITY_INVISIBLE }
};

#define N_MENU_ENTRIES (sizeof(menu_entries) / sizeof(MenuEntry))
Expand All @@ -562,11 +562,11 @@ enum MenuMoreEntrys {
};

static MenuEntry menu_more_entries[] = {
{ COMPRESS, CTX_VISIBILITY_INVISIBLE },
{ INSTALL_ALL, CTX_VISIBILITY_INVISIBLE },
{ INSTALL_FOLDER, CTX_VISIBILITY_INVISIBLE },
{ EXPORT_MEDIA, CTX_VISIBILITY_INVISIBLE },
{ CALCULATE_SHA1, CTX_VISIBILITY_INVISIBLE },
{ COMPRESS, 0, CTX_VISIBILITY_INVISIBLE },
{ INSTALL_ALL, 0, CTX_VISIBILITY_INVISIBLE },
{ INSTALL_FOLDER, 0, CTX_VISIBILITY_INVISIBLE },
{ EXPORT_MEDIA, 0, CTX_VISIBILITY_INVISIBLE },
{ CALCULATE_SHA1, 0, CTX_VISIBILITY_INVISIBLE },
};

#define N_MENU_MORE_ENTRIES (sizeof(menu_more_entries) / sizeof(MenuEntry))
Expand Down Expand Up @@ -2425,7 +2425,6 @@ void shellUI2() {
context_menu.n_menu_more_entries = N_MENU_MORE_ENTRIES;
context_menu.menu_max_width = ctx_menu_max_width;
context_menu.menu_more_max_width = ctx_menu_more_max_width;
context_menu.more_pos = MENU_ENTRY_MORE;
context_menu.menuEnterCallback = contextMenuEnterCallback;
context_menu.menuMoreEnterCallback = contextMenuMoreEnterCallback;

Expand Down
32 changes: 19 additions & 13 deletions archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int archiveCheckFilesForUnsafeFself() {
return 0; // Safe
}

int fileListGetArchiveEntries(FileList *list, char *path) {
int fileListGetArchiveEntries(FileList *list, char *path, int sort) {
int res;

if (!uf)
Expand All @@ -102,7 +102,7 @@ int fileListGetArchiveEntries(FileList *list, char *path) {
entry->name_length = strlen(entry->name);
entry->is_folder = 1;
entry->type = FILE_TYPE_UNKNOWN;
fileListAddEntry(list, entry, SORT_BY_NAME_AND_FOLDER);
fileListAddEntry(list, entry, sort);

char *archive_path = path + archive_path_start;
int name_length = strlen(archive_path);
Expand Down Expand Up @@ -145,8 +145,9 @@ int fileListGetArchiveEntries(FileList *list, char *path) {

memcpy(&entry->ctime, &archive_entry->ctime, sizeof(SceDateTime));
memcpy(&entry->mtime, &archive_entry->mtime, sizeof(SceDateTime));
memcpy(&entry->atime, &archive_entry->atime, sizeof(SceDateTime));

fileListAddEntry(list, entry, SORT_BY_NAME_AND_FOLDER);
fileListAddEntry(list, entry, sort);
}

if (p)
Expand All @@ -169,7 +170,7 @@ int getArchivePathInfo(char *path, uint64_t *size, uint32_t *folders, uint32_t *
if (archiveFileGetstat(path, &stat) < 0) {
FileList list;
memset(&list, 0, sizeof(FileList));
fileListGetArchiveEntries(&list, path);
fileListGetArchiveEntries(&list, path, SORT_NONE);

FileListEntry *entry = list.head->next; // Ignore ..

Expand Down Expand Up @@ -209,7 +210,7 @@ int extractArchivePath(char *src, char *dst, FileProcessParam *param) {
if (archiveFileGetstat(src, &stat) < 0) {
FileList list;
memset(&list, 0, sizeof(FileList));
fileListGetArchiveEntries(&list, src);
fileListGetArchiveEntries(&list, src, SORT_NONE);

int ret = sceIoMkdir(dst, 0777);
if (ret < 0 && ret != SCE_ERROR_ERRNO_EEXIST) {
Expand Down Expand Up @@ -347,12 +348,12 @@ int archiveFileGetstat(const char *file, SceIoStat *stat) {
for (i = 0; i < archive_list.length; i++) {
if (archive_entry->name_length == name_length && strcasecmp(archive_entry->name, archive_path) == 0) {
if (stat) {
//stat->st_mode =
//stat->st_attr =
// stat->st_mode =
// stat->st_attr =
stat->st_size = archive_entry->size;
memcpy(&stat->st_ctime, &archive_entry->mtime, sizeof(SceDateTime));
memcpy(&stat->st_atime, &archive_entry->mtime, sizeof(SceDateTime));
memcpy(&stat->st_ctime, &archive_entry->ctime, sizeof(SceDateTime));
memcpy(&stat->st_mtime, &archive_entry->mtime, sizeof(SceDateTime));
memcpy(&stat->st_atime, &archive_entry->atime, sizeof(SceDateTime));
}

return 0;
Expand Down Expand Up @@ -470,16 +471,21 @@ int archiveOpen(char *file) {

// Time
SceRtcTick tick;
sceRtcSetDosTime(&entry->mtime, file_info.dosDate);
sceRtcGetTick(&entry->mtime, &tick);
SceDateTime time;
sceRtcSetDosTime(&time, file_info.dosDate);
sceRtcGetTick(&time, &tick);
sceRtcConvertLocalTimeToUtc(&tick, &tick);
sceRtcSetTick(&entry->mtime, &tick);
sceRtcSetTick(&time, &tick);

memcpy(&entry->ctime, &time, sizeof(SceDateTime));
memcpy(&entry->mtime, &time, sizeof(SceDateTime));
memcpy(&entry->atime, &time, sizeof(SceDateTime));

// Get pos
unzGetFilePos64(uf, (unz64_file_pos *)&entry->reserved);

// Add entry
fileListAddEntry(&archive_list, entry, SORT_BY_NAME_AND_FOLDER);
fileListAddEntry(&archive_list, entry, SORT_BY_NAME);

// Next
res = unzGoToNextFile2(uf, &file_info, name, MAX_PATH_LENGTH, NULL, 0, NULL, 0);
Expand Down
2 changes: 1 addition & 1 deletion archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#define ARCHIVE_FD 0x12345678

int fileListGetArchiveEntries(FileList *list, char *path);
int fileListGetArchiveEntries(FileList *list, char *path, int sort);

int getArchivePathInfo(char *path, uint64_t *size, uint32_t *folders, uint32_t *files);
int extractArchivePath(char *src, char *dst, FileProcessParam *param);
Expand Down
4 changes: 2 additions & 2 deletions context_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void drawContextMenu(ContextMenu *ctx) {
pgf_draw_text(SCREEN_WIDTH - ctx_cur_menu_width + CONTEXT_MENU_MARGIN, y, color, FONT_SIZE, language_container[ctx->menu_entries[i].name]);

// Draw arrow for 'More'
if (i == ctx->more_pos) {
if (ctx->menu_entries[i].more) {
char *arrow = NULL;
if (ctx_menu_mode == CONTEXT_MENU_MORE_OPENED || ctx_menu_mode == CONTEXT_MENU_MORE_OPENING) {
arrow = LEFT_ARROW;
Expand All @@ -141,7 +141,7 @@ void drawContextMenu(ContextMenu *ctx) {
if (ctx->menu_more_entries[i].visibility == CTX_VISIBILITY_UNUSED)
continue;

float y = START_Y + ((ctx->more_pos + i) * FONT_Y_SPACE);
float y = START_Y + ((ctx_menu_pos + i) * FONT_Y_SPACE);

uint32_t color = CONTEXT_MENU_TEXT_COLOR;

Expand Down
6 changes: 3 additions & 3 deletions context_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum ContextMenuVisibilities {

typedef struct {
int name;
int more;
int visibility;
} MenuEntry;

Expand All @@ -40,9 +41,8 @@ typedef struct {
int n_menu_more_entries;
float menu_max_width;
float menu_more_max_width;
int more_pos;
int (* menuEnterCallback)(int pos, void* context);
int (* menuMoreEnterCallback)(int pos, void* context);
int (* menuEnterCallback)(int pos, void *context);
int (* menuMoreEnterCallback)(int pos, void *context);
void *context;
} ContextMenu;

Expand Down
83 changes: 67 additions & 16 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,27 +695,78 @@ void fileListAddEntry(FileList *list, FileListEntry *entry, int sort) {
FileListEntry *previous = NULL;

while (p) {
// Sort by type
if (entry->is_folder > p->is_folder)
break;
// Get the minimum length without /
int len = MIN(entry->name_length, p->name_length);
if (entry->name[len - 1] == '/' || p->name[len - 1] == '/')
len--;

// '..' is always at first
if (strcmp(entry->name, "..") == 0)
break;

if (strcmp(p->name, "..") != 0) {
// Get the minimum length without /
int len = MIN(entry->name_length, p->name_length);
if (entry->name[len - 1] == '/' || p->name[len - 1] == '/')
len--;
if (strcmp(p->name, "..") == 0) {
previous = p;
p = p->next;
continue;
}

// Sort by name
// Sort by type
if (sort == SORT_BY_NAME) {
// First folders then files
if (entry->is_folder > p->is_folder)
break;
} else if (sort == SORT_BY_SIZE || sort == SORT_BY_DATE) {
// First files then folders
if (entry->is_folder < p->is_folder)
break;
}

if (sort == SORT_BY_NAME) {
// Sort by name within the same type
if (entry->is_folder == p->is_folder) {
int diff = strncasecmp(entry->name, p->name, len);
if (diff < 0 || (diff == 0 && entry->name_length < p->name_length)) {
break;
}
}
} else if (sort == SORT_BY_SIZE) {
// Sort by name for folders
if (entry->is_folder && p->is_folder) {
int diff = strncasecmp(entry->name, p->name, len);
if (diff < 0 || (diff == 0 && entry->name_length < p->name_length)) {
break;
}
} else if (!entry->is_folder && !p->is_folder) {
// Sort by size for files
if (entry->size > p->size)
break;

// Sort by name for files with the same size
if (entry->size == p->size) {
int diff = strncasecmp(entry->name, p->name, len);
if (diff < 0 || (diff == 0 && entry->name_length < p->name_length)) {
break;
}
}
}
} else if (sort == SORT_BY_DATE) {
if (entry->is_folder == p->is_folder) {
SceRtcTick entry_tick, p_tick;
sceRtcGetTick(&entry->mtime, &entry_tick);
sceRtcGetTick(&p->mtime, &p_tick);

// Sort by date within the same type
if (entry_tick.tick > p_tick.tick)
break;

// Sort by name for files and folders with the same date
if (entry_tick.tick == p_tick.tick) {
int diff = strncasecmp(entry->name, p->name, len);
if (diff < 0 || (diff == 0 && entry->name_length < p->name_length)) {
break;
}
}
}
}

previous = p;
Expand Down Expand Up @@ -856,7 +907,7 @@ int fileListGetMountPointEntries(FileList *list) {
memcpy(&entry->mtime, (SceDateTime *)&stat.st_mtime, sizeof(SceDateTime));
memcpy(&entry->atime, (SceDateTime *)&stat.st_atime, sizeof(SceDateTime));

fileListAddEntry(list, entry, SORT_BY_NAME_AND_FOLDER);
fileListAddEntry(list, entry, SORT_BY_NAME);

list->folders++;
}
Expand All @@ -866,7 +917,7 @@ int fileListGetMountPointEntries(FileList *list) {
return 0;
}

int fileListGetDirectoryEntries(FileList *list, char *path) {
int fileListGetDirectoryEntries(FileList *list, char *path, int sort) {
SceUID dfd = sceIoDopen(path);
if (dfd < 0)
return dfd;
Expand All @@ -876,7 +927,7 @@ int fileListGetDirectoryEntries(FileList *list, char *path) {
entry->name_length = strlen(entry->name);
entry->is_folder = 1;
entry->type = FILE_TYPE_UNKNOWN;
fileListAddEntry(list, entry, SORT_BY_NAME_AND_FOLDER);
fileListAddEntry(list, entry, sort);

int res = 0;

Expand Down Expand Up @@ -907,7 +958,7 @@ int fileListGetDirectoryEntries(FileList *list, char *path) {
memcpy(&entry->mtime, (SceDateTime *)&dir.d_stat.st_mtime, sizeof(SceDateTime));
memcpy(&entry->atime, (SceDateTime *)&dir.d_stat.st_atime, sizeof(SceDateTime));

fileListAddEntry(list, entry, SORT_BY_NAME_AND_FOLDER);
fileListAddEntry(list, entry, sort);
}
} while (res > 0);

Expand All @@ -916,14 +967,14 @@ int fileListGetDirectoryEntries(FileList *list, char *path) {
return 0;
}

int fileListGetEntries(FileList *list, char *path) {
int fileListGetEntries(FileList *list, char *path, int sort) {
if (isInArchive()) {
return fileListGetArchiveEntries(list, path);
return fileListGetArchiveEntries(list, path, sort);
}

if (strcasecmp(path, HOME_PATH) == 0) {
return fileListGetMountPointEntries(list);
}

return fileListGetDirectoryEntries(list, path);
return fileListGetDirectoryEntries(list, path, sort);
}
6 changes: 4 additions & 2 deletions file.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ enum FileTypes {

enum FileSortFlags {
SORT_NONE,
SORT_BY_NAME_AND_FOLDER,
SORT_BY_NAME,
SORT_BY_SIZE,
SORT_BY_DATE,
};

enum FileMoveFlags {
Expand Down Expand Up @@ -113,6 +115,6 @@ int fileListRemoveEntryByName(FileList *list, char *name);

void fileListEmpty(FileList *list);

int fileListGetEntries(FileList *list, char *path);
int fileListGetEntries(FileList *list, char *path, int sort);

#endif
Loading

0 comments on commit 825498f

Please sign in to comment.