Merge pull request #99 from soarqin/master

Added folder installation function in 'More...' menu
This commit is contained in:
TheOfficialFloW 2016-09-24 09:21:12 +02:00 committed by GitHub
commit ab377d26c1
5 changed files with 192 additions and 83 deletions

View File

@ -108,6 +108,7 @@ void loadLanguage(int id) {
LANGUAGE_ENTRY(RENAME), LANGUAGE_ENTRY(RENAME),
LANGUAGE_ENTRY(NEW_FOLDER), LANGUAGE_ENTRY(NEW_FOLDER),
LANGUAGE_ENTRY(INSTALL_ALL), LANGUAGE_ENTRY(INSTALL_ALL),
LANGUAGE_ENTRY(INSTALL_FOLDER),
LANGUAGE_ENTRY(CALCULATE_SHA1), LANGUAGE_ENTRY(CALCULATE_SHA1),
LANGUAGE_ENTRY(EXPORT_MEDIA), LANGUAGE_ENTRY(EXPORT_MEDIA),
LANGUAGE_ENTRY(SEARCH), LANGUAGE_ENTRY(SEARCH),
@ -129,6 +130,7 @@ void loadLanguage(int id) {
LANGUAGE_ENTRY(EXPORT_PICTURES_INFO), LANGUAGE_ENTRY(EXPORT_PICTURES_INFO),
LANGUAGE_ENTRY(EXPORT_SONGS_PICTURES_INFO), LANGUAGE_ENTRY(EXPORT_SONGS_PICTURES_INFO),
LANGUAGE_ENTRY(INSTALL_ALL_QUESTION), LANGUAGE_ENTRY(INSTALL_ALL_QUESTION),
LANGUAGE_ENTRY(INSTALL_FOLDER_QUESTION),
LANGUAGE_ENTRY(INSTALL_QUESTION), LANGUAGE_ENTRY(INSTALL_QUESTION),
LANGUAGE_ENTRY(INSTALL_WARNING), LANGUAGE_ENTRY(INSTALL_WARNING),
LANGUAGE_ENTRY(HASH_FILE_QUESTION), LANGUAGE_ENTRY(HASH_FILE_QUESTION),

View File

@ -66,6 +66,7 @@ enum LanguageContainer {
RENAME, RENAME,
NEW_FOLDER, NEW_FOLDER,
INSTALL_ALL, INSTALL_ALL,
INSTALL_FOLDER,
CALCULATE_SHA1, CALCULATE_SHA1,
EXPORT_MEDIA, EXPORT_MEDIA,
SEARCH, SEARCH,
@ -87,6 +88,7 @@ enum LanguageContainer {
EXPORT_PICTURES_INFO, EXPORT_PICTURES_INFO,
EXPORT_SONGS_PICTURES_INFO, EXPORT_SONGS_PICTURES_INFO,
INSTALL_ALL_QUESTION, INSTALL_ALL_QUESTION,
INSTALL_FOLDER_QUESTION,
INSTALL_QUESTION, INSTALL_QUESTION,
INSTALL_WARNING, INSTALL_WARNING,
HASH_FILE_QUESTION, HASH_FILE_QUESTION,

35
main.c
View File

@ -460,12 +460,14 @@ MenuEntry menu_entries[] = {
enum MenuMoreEntrys { enum MenuMoreEntrys {
MENU_MORE_ENTRY_INSTALL_ALL, MENU_MORE_ENTRY_INSTALL_ALL,
MENU_MORE_ENTRY_INSTALL_FOLDER,
MENU_MORE_ENTRY_EXPORT_MEDIA, MENU_MORE_ENTRY_EXPORT_MEDIA,
MENU_MORE_ENTRY_CALCULATE_SHA1, MENU_MORE_ENTRY_CALCULATE_SHA1,
}; };
MenuEntry menu_more_entries[] = { MenuEntry menu_more_entries[] = {
{ INSTALL_ALL, CTX_VISIBILITY_INVISIBLE }, { INSTALL_ALL, CTX_VISIBILITY_INVISIBLE },
{ INSTALL_FOLDER, CTX_VISIBILITY_INVISIBLE },
{ EXPORT_MEDIA, CTX_VISIBILITY_INVISIBLE }, { EXPORT_MEDIA, CTX_VISIBILITY_INVISIBLE },
{ CALCULATE_SHA1, CTX_VISIBILITY_INVISIBLE }, { CALCULATE_SHA1, CTX_VISIBILITY_INVISIBLE },
}; };
@ -572,6 +574,7 @@ void setContextMenuMoreVisibilities() {
// Invisble entries when on '..' // Invisble entries when on '..'
if (strcmp(file_entry->name, DIR_UP) == 0) { if (strcmp(file_entry->name, DIR_UP) == 0) {
menu_more_entries[MENU_MORE_ENTRY_INSTALL_ALL].visibility = CTX_VISIBILITY_INVISIBLE; menu_more_entries[MENU_MORE_ENTRY_INSTALL_ALL].visibility = CTX_VISIBILITY_INVISIBLE;
menu_more_entries[MENU_MORE_ENTRY_INSTALL_FOLDER].visibility = CTX_VISIBILITY_INVISIBLE;
menu_more_entries[MENU_MORE_ENTRY_EXPORT_MEDIA].visibility = CTX_VISIBILITY_INVISIBLE; menu_more_entries[MENU_MORE_ENTRY_EXPORT_MEDIA].visibility = CTX_VISIBILITY_INVISIBLE;
menu_more_entries[MENU_MORE_ENTRY_CALCULATE_SHA1].visibility = CTX_VISIBILITY_INVISIBLE; menu_more_entries[MENU_MORE_ENTRY_CALCULATE_SHA1].visibility = CTX_VISIBILITY_INVISIBLE;
} }
@ -579,12 +582,34 @@ void setContextMenuMoreVisibilities() {
// Invisble operations in archives // Invisble operations in archives
if (isInArchive()) { if (isInArchive()) {
menu_more_entries[MENU_MORE_ENTRY_INSTALL_ALL].visibility = CTX_VISIBILITY_INVISIBLE; menu_more_entries[MENU_MORE_ENTRY_INSTALL_ALL].visibility = CTX_VISIBILITY_INVISIBLE;
menu_more_entries[MENU_MORE_ENTRY_INSTALL_FOLDER].visibility = CTX_VISIBILITY_INVISIBLE;
menu_more_entries[MENU_MORE_ENTRY_EXPORT_MEDIA].visibility = CTX_VISIBILITY_INVISIBLE; menu_more_entries[MENU_MORE_ENTRY_EXPORT_MEDIA].visibility = CTX_VISIBILITY_INVISIBLE;
menu_more_entries[MENU_MORE_ENTRY_CALCULATE_SHA1].visibility = CTX_VISIBILITY_INVISIBLE; menu_more_entries[MENU_MORE_ENTRY_CALCULATE_SHA1].visibility = CTX_VISIBILITY_INVISIBLE;
} }
if (file_entry->is_folder) { if (file_entry->is_folder) {
menu_more_entries[MENU_MORE_ENTRY_CALCULATE_SHA1].visibility = CTX_VISIBILITY_INVISIBLE; menu_more_entries[MENU_MORE_ENTRY_CALCULATE_SHA1].visibility = CTX_VISIBILITY_INVISIBLE;
do {
char check_path[MAX_PATH_LENGTH];
SceIoStat stat;
int statres;
if (strcmp(file_list.path, "ux0:app/") == 0 || strcmp(file_list.path, "ux0:patch/") == 0) {
menu_more_entries[MENU_MORE_ENTRY_INSTALL_FOLDER].visibility = CTX_VISIBILITY_INVISIBLE;
break;
}
snprintf(check_path, MAX_PATH_LENGTH, "%s%s/eboot.bin", file_list.path, file_entry->name);
statres = sceIoGetstat(check_path, &stat);
if (statres < 0 || SCE_S_ISDIR(stat.st_mode)) {
menu_more_entries[MENU_MORE_ENTRY_INSTALL_FOLDER].visibility = CTX_VISIBILITY_INVISIBLE;
break;
}
snprintf(check_path, MAX_PATH_LENGTH, "%s%s/sce_sys/param.sfo", file_list.path, file_entry->name);
statres = sceIoGetstat(check_path, &stat);
if (statres < 0 || SCE_S_ISDIR(stat.st_mode)) {
menu_more_entries[MENU_MORE_ENTRY_INSTALL_FOLDER].visibility = CTX_VISIBILITY_INVISIBLE;
break;
}
} while(0);
} }
if(file_entry->type != FILE_TYPE_VPK) { if(file_entry->type != FILE_TYPE_VPK) {
@ -866,6 +891,15 @@ int contextMenuMoreEnterCallback(int pos, void* context) {
break; break;
} }
case MENU_MORE_ENTRY_INSTALL_FOLDER:
{
FileListEntry *file_entry = fileListGetNthEntry(&file_list, base_pos + rel_pos);
snprintf(cur_file, MAX_PATH_LENGTH, "%s%s", file_list.path, file_entry->name);
initMessageDialog(SCE_MSG_DIALOG_BUTTON_TYPE_YESNO, language_container[INSTALL_FOLDER_QUESTION]);
dialog_step = DIALOG_STEP_INSTALL_QUESTION;
break;
}
case MENU_MORE_ENTRY_EXPORT_MEDIA: case MENU_MORE_ENTRY_EXPORT_MEDIA:
{ {
@ -1210,6 +1244,7 @@ int dialogSteps() {
} }
dialog_step = DIALOG_STEP_NONE; dialog_step = DIALOG_STEP_NONE;
refresh = 1;
} }
break; break;

View File

@ -367,6 +367,8 @@ int install_thread(SceSize args_size, InstallArguments *args) {
int res; int res;
SceUID thid = -1; SceUID thid = -1;
char path[MAX_PATH_LENGTH]; char path[MAX_PATH_LENGTH];
SceIoStat stat;
int isFolder = 0;
// Lock power timers // Lock power timers
powerLock(); powerLock();
@ -379,104 +381,166 @@ int install_thread(SceSize args_size, InstallArguments *args) {
removePath(PACKAGE_PARENT, NULL); removePath(PACKAGE_PARENT, NULL);
sceIoMkdir(PACKAGE_PARENT, 0777); sceIoMkdir(PACKAGE_PARENT, 0777);
// Open archive res = sceIoGetstat(args->file, &stat);
res = archiveOpen(args->file);
if (res < 0) { if (res < 0) {
closeWaitDialog(); closeWaitDialog();
errorDialog(res); errorDialog(res);
goto EXIT; goto EXIT;
} }
// If you cancelled at the time archiveOpen was working, if (SCE_S_ISDIR(stat.st_mode)) {
// it would still open the full permission dialog instead of termiating. // Check for param.sfo
// So terminate now snprintf(path, MAX_PATH_LENGTH, "%s/sce_sys/param.sfo", args->file);
if (cancelHandler()) { if (sceIoGetstat(path, &stat) < 0 || SCE_S_ISDIR(stat.st_mode)) {
closeWaitDialog();
dialog_step = DIALOG_STEP_CANCELLED;
goto EXIT;
}
// Check for param.sfo
snprintf(path, MAX_PATH_LENGTH, "%s/sce_sys/param.sfo", args->file);
if (archiveFileGetstat(path, NULL) < 0) {
closeWaitDialog();
errorDialog(-2);
goto EXIT;
}
// Check permissions
snprintf(path, MAX_PATH_LENGTH, "%s/eboot.bin", args->file);
SceUID fd = archiveFileOpen(path, SCE_O_RDONLY, 0);
if (fd >= 0) {
char buffer[0x88];
archiveFileRead(fd, buffer, sizeof(buffer));
archiveFileClose(fd);
// Team molecule's request: Full permission access warning
uint64_t authid = *(uint64_t *)(buffer + 0x80);
if (authid == 0x2F00000000000001 || authid == 0x2F00000000000003) {
closeWaitDialog(); closeWaitDialog();
errorDialog(-2);
initMessageDialog(SCE_MSG_DIALOG_BUTTON_TYPE_YESNO, language_container[INSTALL_WARNING]); goto EXIT;
dialog_step = DIALOG_STEP_INSTALL_WARNING;
// Wait for response
while (dialog_step == DIALOG_STEP_INSTALL_WARNING) {
sceKernelDelayThread(10 * 1000);
}
// Cancelled
if (dialog_step == DIALOG_STEP_CANCELLED) {
closeWaitDialog();
goto EXIT;
}
// Init again
initMessageDialog(MESSAGE_DIALOG_PROGRESS_BAR, language_container[INSTALLING]);
dialog_step = DIALOG_STEP_INSTALLING;
} }
}
// Src path // Check permissions
char src_path[MAX_PATH_LENGTH]; snprintf(path, MAX_PATH_LENGTH, "%s/eboot.bin", args->file);
strcpy(src_path, args->file); SceUID fd = sceIoOpen(path, SCE_O_RDONLY, 0);
addEndSlash(src_path); if (fd >= 0) {
char buffer[0x88];
sceIoRead(fd, buffer, sizeof(buffer));
sceIoClose(fd);
// Get archive path info // Team molecule's request: Full permission access warning
uint64_t size = 0; uint64_t authid = *(uint64_t *)(buffer + 0x80);
uint32_t folders = 0, files = 0; if (authid == 0x2F00000000000001 || authid == 0x2F00000000000003) {
getArchivePathInfo(src_path, &size, &folders, &files); closeWaitDialog();
// Check memory card free space initMessageDialog(SCE_MSG_DIALOG_BUTTON_TYPE_YESNO, language_container[INSTALL_WARNING]);
if (checkMemoryCardFreeSpace(size)) dialog_step = DIALOG_STEP_INSTALL_WARNING;
goto EXIT;
// Update thread // Wait for response
thid = createStartUpdateThread(size + folders); while (dialog_step == DIALOG_STEP_INSTALL_WARNING) {
sceKernelDelayThread(10 * 1000);
}
// Extract process // Cancelled
uint64_t value = 0; if (dialog_step == DIALOG_STEP_CANCELLED) {
closeWaitDialog();
goto EXIT;
}
FileProcessParam param; // Init again
param.value = &value; initMessageDialog(MESSAGE_DIALOG_PROGRESS_BAR, language_container[INSTALLING]);
param.max = size + folders; dialog_step = DIALOG_STEP_INSTALLING;
param.SetProgress = SetProgress; }
param.cancelHandler = cancelHandler; }
res = extractArchivePath(src_path, PACKAGE_DIR "/", &param); res = sceIoRename(args->file, PACKAGE_DIR);
if (res <= 0) { if (res < 0) {
closeWaitDialog(); closeWaitDialog();
dialog_step = DIALOG_STEP_CANCELLED; dialog_step = DIALOG_STEP_CANCELLED;
errorDialog(res); errorDialog(res);
goto EXIT; goto EXIT;
} }
sceMsgDialogProgressBarSetValue(SCE_MSG_DIALOG_PROGRESSBAR_TARGET_BAR_DEFAULT, 50);
sceKernelDelayThread(COUNTUP_WAIT);
// Close archive isFolder = 1;
res = archiveClose(); } else {
if (res < 0) { // Open archive
closeWaitDialog(); res = archiveOpen(args->file);
errorDialog(res); if (res < 0) {
goto EXIT; closeWaitDialog();
errorDialog(res);
goto EXIT;
}
// If you cancelled at the time archiveOpen was working,
// it would still open the full permission dialog instead of termiating.
// So terminate now
if (cancelHandler()) {
closeWaitDialog();
dialog_step = DIALOG_STEP_CANCELLED;
goto EXIT;
}
// Check for param.sfo
snprintf(path, MAX_PATH_LENGTH, "%s/sce_sys/param.sfo", args->file);
if (archiveFileGetstat(path, NULL) < 0) {
closeWaitDialog();
errorDialog(-2);
goto EXIT;
}
// Check permissions
snprintf(path, MAX_PATH_LENGTH, "%s/eboot.bin", args->file);
SceUID fd = archiveFileOpen(path, SCE_O_RDONLY, 0);
if (fd >= 0) {
char buffer[0x88];
archiveFileRead(fd, buffer, sizeof(buffer));
archiveFileClose(fd);
// Team molecule's request: Full permission access warning
uint64_t authid = *(uint64_t *)(buffer + 0x80);
if (authid == 0x2F00000000000001 || authid == 0x2F00000000000003) {
closeWaitDialog();
initMessageDialog(SCE_MSG_DIALOG_BUTTON_TYPE_YESNO, language_container[INSTALL_WARNING]);
dialog_step = DIALOG_STEP_INSTALL_WARNING;
// Wait for response
while (dialog_step == DIALOG_STEP_INSTALL_WARNING) {
sceKernelDelayThread(10 * 1000);
}
// Cancelled
if (dialog_step == DIALOG_STEP_CANCELLED) {
closeWaitDialog();
goto EXIT;
}
// Init again
initMessageDialog(MESSAGE_DIALOG_PROGRESS_BAR, language_container[INSTALLING]);
dialog_step = DIALOG_STEP_INSTALLING;
}
}
// Src path
char src_path[MAX_PATH_LENGTH];
strcpy(src_path, args->file);
addEndSlash(src_path);
// Get archive path info
uint64_t size = 0;
uint32_t folders = 0, files = 0;
getArchivePathInfo(src_path, &size, &folders, &files);
// Check memory card free space
if (checkMemoryCardFreeSpace(size))
goto EXIT;
// Update thread
thid = createStartUpdateThread(size + folders);
// Extract process
uint64_t value = 0;
FileProcessParam param;
param.value = &value;
param.max = size + folders;
param.SetProgress = SetProgress;
param.cancelHandler = cancelHandler;
res = extractArchivePath(src_path, PACKAGE_DIR "/", &param);
if (res <= 0) {
closeWaitDialog();
dialog_step = DIALOG_STEP_CANCELLED;
errorDialog(res);
goto EXIT;
}
// Close archive
res = archiveClose();
if (res < 0) {
closeWaitDialog();
errorDialog(res);
goto EXIT;
}
} }
// Make head.bin // Make head.bin
@ -484,6 +548,8 @@ int install_thread(SceSize args_size, InstallArguments *args) {
if (res < 0) { if (res < 0) {
closeWaitDialog(); closeWaitDialog();
errorDialog(res); errorDialog(res);
// If failed, move package folder back
if (isFolder) sceIoRename(PACKAGE_DIR, args->file);
goto EXIT; goto EXIT;
} }
@ -492,6 +558,8 @@ int install_thread(SceSize args_size, InstallArguments *args) {
if (res < 0) { if (res < 0) {
closeWaitDialog(); closeWaitDialog();
errorDialog(res); errorDialog(res);
// If failed, move package folder back
if (isFolder) sceIoRename(PACKAGE_DIR, args->file);
goto EXIT; goto EXIT;
} }

View File

@ -46,6 +46,7 @@ DELETE = "Delete"
RENAME = "Rename" RENAME = "Rename"
NEW_FOLDER = "New folder" NEW_FOLDER = "New folder"
INSTALL_ALL = "Install all" INSTALL_ALL = "Install all"
INSTALL_FOLDER = "Install folder"
CALCULATE_SHA1 = "Calculate SHA1" CALCULATE_SHA1 = "Calculate SHA1"
EXPORT_MEDIA = "Export media" EXPORT_MEDIA = "Export media"
SEARCH = "Search" SEARCH = "Search"
@ -67,6 +68,7 @@ EXPORT_SONGS_INFO = "Exported %d song(s)."
EXPORT_PICTURES_INFO = "Exported %d picture(s)." EXPORT_PICTURES_INFO = "Exported %d picture(s)."
EXPORT_SONGS_PICTURES_INFO = "Exported %d song(s) and %d picture(s)." EXPORT_SONGS_PICTURES_INFO = "Exported %d song(s) and %d picture(s)."
INSTALL_ALL_QUESTION = "Do you want to install all packages available in this folder?" INSTALL_ALL_QUESTION = "Do you want to install all packages available in this folder?"
INSTALL_FOLDER_QUESTION = "Do you want to install this folder?\Warning: this action will also delete the folder after installation!"
INSTALL_QUESTION = "Do you want to install this package?" INSTALL_QUESTION = "Do you want to install this package?"
INSTALL_WARNING = "This package requests extended permissions.\It will have access to your personal information.\If you did not obtain it from a trusted source,\please proceed at your own caution.\\Would you like to continue the install?" INSTALL_WARNING = "This package requests extended permissions.\It will have access to your personal information.\If you did not obtain it from a trusted source,\please proceed at your own caution.\\Would you like to continue the install?"
HASH_FILE_QUESTION = "SHA1 hashing may take a long time. Continue?" HASH_FILE_QUESTION = "SHA1 hashing may take a long time. Continue?"
@ -80,4 +82,4 @@ FTP_SERVER = "FTP server is now running at\ftp://%s:%i
SYS_INFO = "System software: %s\Model: 0x%08X\MAC address: %s\IP address: %s\Memory card: %s/%s\Battery level: %d%%" SYS_INFO = "System software: %s\Model: 0x%08X\MAC address: %s\IP address: %s\Memory card: %s/%s\Battery level: %d%%"
UPDATE_QUESTION = "VitaShell %s is now available.\\Do you want to update the application?" UPDATE_QUESTION = "VitaShell %s is now available.\\Do you want to update the application?"
TOOLBOX = "Toolbox" TOOLBOX = "Toolbox"
SYSINFO_TITLE = "System Information" SYSINFO_TITLE = "System Information"