From 4c090853d60faa5aa271476ebaee3373fa870854 Mon Sep 17 00:00:00 2001 From: Andrin Bertschi Date: Sat, 16 Jun 2018 21:54:19 +0200 Subject: [PATCH] create new files (#432) * introduce new file creation, remove new folder from main menu * aesthetics --- language.c | 2 + language.h | 2 + main.c | 37 ++++++- main.h | 2 + main_context.c | 215 ++++++++++++++++++++++++++++----------- main_context.h | 1 + resources/english_us.txt | 2 + 7 files changed, 196 insertions(+), 65 deletions(-) diff --git a/language.c b/language.c index 109c3f72..646ee638 100644 --- a/language.c +++ b/language.c @@ -119,6 +119,8 @@ void loadLanguage(int id) { LANGUAGE_ENTRY(PASTE), LANGUAGE_ENTRY(DELETE), LANGUAGE_ENTRY(RENAME), + LANGUAGE_ENTRY(NEW), + LANGUAGE_ENTRY(NEW_FILE), LANGUAGE_ENTRY(NEW_FOLDER), LANGUAGE_ENTRY(PROPERTIES), LANGUAGE_ENTRY(SEND), diff --git a/language.h b/language.h index b7368e9e..0090a688 100644 --- a/language.h +++ b/language.h @@ -78,6 +78,8 @@ enum LanguageContainer { PASTE, DELETE, RENAME, + NEW, + NEW_FILE, NEW_FOLDER, PROPERTIES, SEND, diff --git a/main.c b/main.c index 49024d47..b4f99621 100644 --- a/main.c +++ b/main.c @@ -893,7 +893,7 @@ static int dialogSteps() { break; } - + case DIALOG_STEP_NEW_FOLDER: { if (ime_result == IME_DIALOG_RESULT_FINISHED) { @@ -922,7 +922,38 @@ static int dialogSteps() { break; } - + + case DIALOG_STEP_NEW_FILE: + { + if (ime_result == IME_DIALOG_RESULT_FINISHED) { + char *name = (char *)getImeDialogInputTextUTF8(); + if (name[0] == '\0') { + setDialogStep(DIALOG_STEP_NONE); + } else { + char path[MAX_PATH_LENGTH]; + snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", file_list.path, name); + + SceUID fd = sceIoOpen(path, SCE_O_WRONLY | SCE_O_CREAT, 0777); + if (fd < 0) { + errorDialog(fd); + } else { + sceIoClose(fd); + + // Focus + strcpy(focus_name, name); + addEndSlash(focus_name); + + refresh = REFRESH_MODE_SETFOCUS; + setDialogStep(DIALOG_STEP_NONE); + refreshFileList(); + } + } + } else if (ime_result == IME_DIALOG_RESULT_CANCELED) { + setDialogStep(DIALOG_STEP_NONE); + } + break; + } + case DIALOG_STEP_COMPRESS_NAME: { if (ime_result == IME_DIALOG_RESULT_FINISHED) { @@ -941,7 +972,7 @@ static int dialogSteps() { break; } - + case DIALOG_STEP_COMPRESS_LEVEL: { if (ime_result == IME_DIALOG_RESULT_FINISHED) { diff --git a/main.h b/main.h index 14d9927d..75d7a0bf 100644 --- a/main.h +++ b/main.h @@ -176,6 +176,8 @@ enum DialogSteps { DIALOG_STEP_USB, DIALOG_STEP_RENAME, + + DIALOG_STEP_NEW_FILE, DIALOG_STEP_NEW_FOLDER, DIALOG_STEP_COPYING, diff --git a/main_context.c b/main_context.c index e8cb2a03..fb21b5dd 100644 --- a/main_context.c +++ b/main_context.c @@ -61,7 +61,7 @@ enum MenuMainEntrys { MENU_MAIN_ENTRY_PASTE, MENU_MAIN_ENTRY_DELETE, MENU_MAIN_ENTRY_RENAME, - MENU_MAIN_ENTRY_NEW_FOLDER, + MENU_MAIN_ENTRY_NEW, MENU_MAIN_ENTRY_PROPERTIES, MENU_MAIN_ENTRY_SORT_BY, MENU_MAIN_ENTRY_MORE, @@ -77,7 +77,7 @@ MenuEntry menu_main_entries[] = { { PASTE, 5, 0, CTX_INVISIBLE }, { DELETE, 7, 0, CTX_INVISIBLE }, { RENAME, 8, 0, CTX_INVISIBLE }, - { NEW_FOLDER, 10, 0, CTX_INVISIBLE }, + { NEW, 10, CTX_FLAG_MORE, CTX_VISIBLE }, { PROPERTIES, 11, 0, CTX_INVISIBLE }, { SORT_BY, 13, CTX_FLAG_MORE, CTX_VISIBLE }, { MORE, 14, CTX_FLAG_MORE, CTX_INVISIBLE }, @@ -119,10 +119,24 @@ MenuEntry menu_more_entries[] = { #define N_MENU_MORE_ENTRIES (sizeof(menu_more_entries) / sizeof(MenuEntry)) +enum MenuNewEntrys { + MENU_NEW_FILE, + MENU_NEW_FOLDER +}; + +MenuEntry menu_new_entries[] = { + {NEW_FILE, 10, 0, CTX_INVISIBLE}, + {NEW_FOLDER, 11, 0, CTX_INVISIBLE} + +}; + +#define N_MENU_NEW_ENTRIES (sizeof(menu_new_entries) / sizeof(MenuEntry)) + static int contextMenuHomeEnterCallback(int sel, void *context); static int contextMenuMainEnterCallback(int sel, void *context); static int contextMenuSortEnterCallback(int sel, void *context); static int contextMenuMoreEnterCallback(int sel, void *context); +static int contextMenuNewEnterCallback(int sel, void *context); ContextMenu context_menu_home = { .parent = NULL, @@ -160,6 +174,15 @@ ContextMenu context_menu_more = { .sel = -1, }; +ContextMenu context_menu_new = { + .parent = &context_menu_main, + .entries = menu_new_entries, + .n_entries = N_MENU_NEW_ENTRIES, + .max_width = 0.0f, + .callback = contextMenuNewEnterCallback, + .sel = -1, +}; + /* SceAppMgr mount IDs: 0x64: ux0:picture @@ -195,9 +218,9 @@ int pfsMount(const char *path) { char klicensee[0x10]; char license_buf[0x200]; ShellMountIdArgs args; - + memset(klicensee, 0, sizeof(klicensee)); - + /* snprintf(work_path, MAX_PATH_LENGTH - 1, "%ssce_sys/package/work.bin", path); if (ReadFile(work_path, license_buf, sizeof(license_buf)) == sizeof(license_buf)) { @@ -212,7 +235,7 @@ int pfsMount(const char *path) { args.mount_point = pfs_mount_point; read_only = 0; - + int i; for (i = 0; i < sizeof(known_pfs_ids) / sizeof(int); i++) { args.id = known_pfs_ids[i]; @@ -278,6 +301,14 @@ void initContextMenuWidth() { context_menu_more.max_width += 2.0f * CONTEXT_MENU_MARGIN; context_menu_more.max_width = MAX(context_menu_more.max_width, CONTEXT_MENU_MIN_WIDTH); + + // New + for (i = 0; i < N_MENU_NEW_ENTRIES; i++) { + context_menu_new.max_width = MAX(context_menu_new.max_width, + pgf_text_width(language_container[menu_new_entries[i].name])); + } + context_menu_new.max_width += 2.0f * CONTEXT_MENU_MARGIN; + context_menu_new.max_width = MAX(context_menu_new.max_width, CONTEXT_MENU_MIN_WIDTH); } void setContextMenuHomeVisibilities() { @@ -333,7 +364,7 @@ void setContextMenuMainVisibilities() { // menu_main_entries[MENU_MAIN_ENTRY_SEND].flags = CTX_FLAG_BARRIER; // menu_main_entries[MENU_MAIN_ENTRY_RECEIVE].flags = 0; - + // Invisble entries when on '..' if (strcmp(file_entry->name, DIR_UP) == 0) { menu_main_entries[MENU_MAIN_ENTRY_OPEN_DECRYPTED].visibility = CTX_INVISIBLE; @@ -379,7 +410,7 @@ void setContextMenuMainVisibilities() { menu_main_entries[MENU_MAIN_ENTRY_PASTE].visibility = CTX_INVISIBLE; menu_main_entries[MENU_MAIN_ENTRY_DELETE].visibility = CTX_INVISIBLE; menu_main_entries[MENU_MAIN_ENTRY_RENAME].visibility = CTX_INVISIBLE; - menu_main_entries[MENU_MAIN_ENTRY_NEW_FOLDER].visibility = CTX_INVISIBLE; + menu_main_entries[MENU_MAIN_ENTRY_NEW].visibility = CTX_INVISIBLE; menu_main_entries[MENU_MAIN_ENTRY_SEND].visibility = CTX_INVISIBLE; menu_main_entries[MENU_MAIN_ENTRY_RECEIVE].visibility = CTX_INVISIBLE; } @@ -402,7 +433,7 @@ void setContextMenuMainVisibilities() { } else { char path[MAX_PATH_LENGTH]; snprintf(path, MAX_PATH_LENGTH - 1, "%s%ssce_pfs", file_list.path, file_entry->name); - + if (!checkFolderExist(path)) menu_main_entries[MENU_MAIN_ENTRY_OPEN_DECRYPTED].visibility = CTX_INVISIBLE; } @@ -435,7 +466,7 @@ void setContextMenuSortVisibilities() { menu_sort_entries[MENU_SORT_ENTRY_BY_SIZE].visibility = CTX_INVISIBLE; else if (sort_mode == SORT_BY_DATE) menu_sort_entries[MENU_SORT_ENTRY_BY_DATE].visibility = CTX_INVISIBLE; - + // Go to first entry for (i = 0; i < N_MENU_SORT_ENTRIES; i++) { if (menu_sort_entries[i].visibility == CTX_VISIBLE) { @@ -490,13 +521,13 @@ void setContextMenuMoreVisibilities() { menu_more_entries[MENU_MORE_ENTRY_INSTALL_FOLDER].visibility = CTX_INVISIBLE; break; } - + snprintf(check_path, MAX_PATH_LENGTH - 1, "%s%s/eboot.bin", file_list.path, file_entry->name); if (!checkFileExist(check_path)) { menu_more_entries[MENU_MORE_ENTRY_INSTALL_FOLDER].visibility = CTX_INVISIBLE; break; } - + snprintf(check_path, MAX_PATH_LENGTH - 1, "%s%s/sce_sys/param.sfo", file_list.path, file_entry->name); if (!checkFileExist(check_path)) { menu_more_entries[MENU_MORE_ENTRY_INSTALL_FOLDER].visibility = CTX_INVISIBLE; @@ -531,6 +562,27 @@ void setContextMenuMoreVisibilities() { context_menu_more.sel = -1; } +void setContextMenuNewVisibilities() { + int i; + + // All visible + for (i = 0; i < N_MENU_NEW_ENTRIES; i++) { + if (menu_new_entries[i].visibility == CTX_INVISIBLE) + menu_new_entries[i].visibility = CTX_VISIBLE; + } + + // Go to first entry + for (i = 0; i < N_MENU_NEW_ENTRIES; i++) { + if (menu_new_entries[i].visibility == CTX_VISIBLE) { + context_menu_new.sel = i; + break; + } + } + + if (i == N_MENU_NEW_ENTRIES) + context_menu_new.sel = -1; +} + static int contextMenuHomeEnterCallback(int sel, void *context) { switch (sel) { case MENU_HOME_ENTRY_REFRESH_LIVEAREA: @@ -574,10 +626,10 @@ static int contextMenuHomeEnterCallback(int sel, void *context) { setDialogStep(DIALOG_STEP_USB_ATTACH_WAIT); } } - + break; } - + case MENU_HOME_ENTRY_MOUNT_IMC0: { if (is_safe_mode) { @@ -590,10 +642,10 @@ static int contextMenuHomeEnterCallback(int sel, void *context) { infoDialog(language_container[IMC0_MOUNTED]); refreshFileList(); } - + break; } - + case MENU_HOME_ENTRY_MOUNT_USB_UX0: { if (mountUsbUx0() >= 0) { @@ -602,7 +654,7 @@ static int contextMenuHomeEnterCallback(int sel, void *context) { } break; } - + case MENU_HOME_ENTRY_UMOUNT_USB_UX0: { if (umountUsbUx0() >= 0) { @@ -637,14 +689,14 @@ static int contextMenuMainEnterCallback(int sel, void *context) { strncasecmp(file_list.path, "grw0:patch", 10) == 0) { snprintf(path, MAX_PATH_LENGTH - 1, "ux0:app/%s", file_entry->name); res = pfsMount(path); - + if (res < 0) { snprintf(path, MAX_PATH_LENGTH - 1, "gro0:app/%s", file_entry->name); res = pfsMount(path); } } } - + if (res < 0) errorDialog(res); @@ -668,7 +720,7 @@ static int contextMenuMainEnterCallback(int sel, void *context) { break; } - + case MENU_MAIN_ENTRY_MARK_UNMARK_ALL: { FileListEntry *file_entry = fileListGetNthEntry(&file_list, base_pos + rel_pos); @@ -698,7 +750,7 @@ static int contextMenuMainEnterCallback(int sel, void *context) { break; } - + case MENU_MAIN_ENTRY_MOVE: case MENU_MAIN_ENTRY_COPY: { @@ -717,7 +769,7 @@ static int contextMenuMainEnterCallback(int sel, void *context) { } else { copy_mode = isInArchive() ? COPY_MODE_EXTRACT : COPY_MODE_NORMAL; } - + strcpy(archive_copy_path, archive_path); // Empty copy list at first @@ -741,7 +793,7 @@ static int contextMenuMainEnterCallback(int sel, void *context) { strcpy(copy_list.path, file_list.path); copy_list.is_in_archive = isInArchive(); - + char *message; // On marked entry @@ -766,11 +818,11 @@ static int contextMenuMainEnterCallback(int sel, void *context) { case COPY_MODE_NORMAL: copy_text = COPYING; break; - + case COPY_MODE_MOVE: copy_text = MOVING; break; - + case COPY_MODE_EXTRACT: copy_text = EXTRACTING; break; @@ -800,7 +852,7 @@ static int contextMenuMainEnterCallback(int sel, void *context) { break; } - + case MENU_MAIN_ENTRY_RENAME: { FileListEntry *file_entry = fileListGetNthEntry(&file_list, base_pos + rel_pos); @@ -813,10 +865,10 @@ static int contextMenuMainEnterCallback(int sel, void *context) { setDialogStep(DIALOG_STEP_RENAME); } - + break; } - + case MENU_MAIN_ENTRY_PROPERTIES: { FileListEntry *file_entry = fileListGetNthEntry(&file_list, base_pos + rel_pos); @@ -827,52 +879,35 @@ static int contextMenuMainEnterCallback(int sel, void *context) { break; } - - case MENU_MAIN_ENTRY_NEW_FOLDER: - { - // Find a new folder name - char path[MAX_PATH_LENGTH]; - - int count = 1; - while (1) { - if (count == 1) { - snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", file_list.path, language_container[NEW_FOLDER]); - } else { - snprintf(path, MAX_PATH_LENGTH - 1, "%s%s (%d)", file_list.path, language_container[NEW_FOLDER], count); - } - - if (!checkFolderExist(path)) - break; - count++; - } - - initImeDialog(language_container[NEW_FOLDER], path + strlen(file_list.path), MAX_NAME_LENGTH, SCE_IME_TYPE_BASIC_LATIN, 0, 0); - setDialogStep(DIALOG_STEP_NEW_FOLDER); - break; + case MENU_MAIN_ENTRY_NEW: + { + setContextMenu(&context_menu_new); + setContextMenuNewVisibilities(); + return CONTEXT_MENU_MORE_OPENING; } - + case MENU_MAIN_ENTRY_MORE: { setContextMenu(&context_menu_more); setContextMenuMoreVisibilities(); return CONTEXT_MENU_MORE_OPENING; } - + case MENU_MAIN_ENTRY_SORT_BY: { setContextMenu(&context_menu_sort); setContextMenuSortVisibilities(); return CONTEXT_MENU_MORE_OPENING; } - + case MENU_MAIN_ENTRY_SEND: { initNetCheckDialog(SCE_NETCHECK_DIALOG_MODE_PSP_ADHOC_JOIN, 60 * 1000 * 1000); setDialogStep(DIALOG_STEP_ADHOC_SEND_NETCHECK); break; } - + case MENU_MAIN_ENTRY_RECEIVE: { initNetCheckDialog(SCE_NETCHECK_DIALOG_MODE_PSP_ADHOC_CONN, 0); @@ -889,11 +924,11 @@ static int contextMenuSortEnterCallback(int sel, void *context) { case MENU_SORT_ENTRY_BY_NAME: sort_mode = SORT_BY_NAME; break; - + case MENU_SORT_ENTRY_BY_SIZE: sort_mode = SORT_BY_SIZE; break; - + case MENU_SORT_ENTRY_BY_DATE: sort_mode = SORT_BY_DATE; break; @@ -947,10 +982,10 @@ static int contextMenuMoreEnterCallback(int sel, void *context) { initImeDialog(language_container[ARCHIVE_NAME], path, MAX_NAME_LENGTH, SCE_IME_TYPE_BASIC_LATIN, 0, 0); setDialogStep(DIALOG_STEP_COMPRESS_NAME); } - + break; } - + case MENU_MORE_ENTRY_INSTALL_ALL: { // Empty install list @@ -976,7 +1011,7 @@ static int contextMenuMoreEnterCallback(int sel, void *context) { initMessageDialog(SCE_MSG_DIALOG_BUTTON_TYPE_YESNO, language_container[INSTALL_ALL_QUESTION]); setDialogStep(DIALOG_STEP_INSTALL_QUESTION); - + break; } @@ -988,10 +1023,10 @@ static int contextMenuMoreEnterCallback(int sel, void *context) { initMessageDialog(SCE_MSG_DIALOG_BUTTON_TYPE_YESNO, language_container[INSTALL_FOLDER_QUESTION]); setDialogStep(DIALOG_STEP_INSTALL_QUESTION); } - + break; } - + case MENU_MORE_ENTRY_EXPORT_MEDIA: { FileListEntry *file_entry = fileListGetNthEntry(&file_list, base_pos + rel_pos); @@ -1008,10 +1043,10 @@ static int contextMenuMoreEnterCallback(int sel, void *context) { initMessageDialog(SCE_MSG_DIALOG_BUTTON_TYPE_YESNO, message); setDialogStep(DIALOG_STEP_EXPORT_QUESTION); } - + break; } - + case MENU_MORE_ENTRY_CALCULATE_SHA1: { // Ensure user wants to actually take the hash @@ -1023,3 +1058,59 @@ static int contextMenuMoreEnterCallback(int sel, void *context) { return CONTEXT_MENU_CLOSING; } + +static int contextMenuNewEnterCallback(int sel, void *context) { + switch (sel) { + case MENU_NEW_FILE: { + char path[MAX_PATH_LENGTH]; + int count = 1; + while (1) { + if (count == 1) { + snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", file_list.path, + language_container[NEW_FILE]); + } else { + snprintf(path, MAX_PATH_LENGTH - 1, "%s%s (%d)", file_list.path, + language_container[NEW_FILE], count); + } + if (!checkFileExist(path)) + break; + + count++; + } + initImeDialog(language_container[NEW_FILE], path + strlen(file_list.path), + MAX_NAME_LENGTH, SCE_IME_TYPE_BASIC_LATIN, 0, 0); + setDialogStep(DIALOG_STEP_NEW_FILE); + break; + }; + case MENU_NEW_FOLDER: { + // Find a new folder name + char path[MAX_PATH_LENGTH]; + + int count = 1; + while (1) { + if (count == 1) { + snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", file_list.path, + language_container[NEW_FOLDER]); + } else { + snprintf(path, MAX_PATH_LENGTH - 1, "%s%s (%d)", file_list.path, + language_container[NEW_FOLDER], count); + } + + if (!checkFolderExist(path)) + break; + + count++; + } + + initImeDialog(language_container[NEW_FOLDER], path + strlen(file_list.path), + MAX_NAME_LENGTH, SCE_IME_TYPE_BASIC_LATIN, 0, 0); + setDialogStep(DIALOG_STEP_NEW_FOLDER); + break; + } + } + // Refresh list + refreshFileList(); + + return CONTEXT_MENU_CLOSING; +} + diff --git a/main_context.h b/main_context.h index 492fb404..0fac954b 100644 --- a/main_context.h +++ b/main_context.h @@ -36,5 +36,6 @@ void setContextMenuHomeVisibilities(); void setContextMenuMainVisibilities(); void setContextMenuSortVisibilities(); void setContextMenuMoreVisibilities(); +void setContextMenuNewVisibilities(); #endif \ No newline at end of file diff --git a/resources/english_us.txt b/resources/english_us.txt index 15b272b0..696f5b35 100644 --- a/resources/english_us.txt +++ b/resources/english_us.txt @@ -60,6 +60,8 @@ PASTE = "Paste" DELETE = "Delete" RENAME = "Rename" NEW_FOLDER = "New folder" +NEW = "New" +NEW_FILE = "New file" PROPERTIES = "Properties" SEND = "Send" RECEIVE = "Receive"