Skip to content

Commit

Permalink
Improved some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOfficialFloW committed Mar 5, 2017
1 parent 04f932e commit 8120486
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 247 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ target_link_libraries(VitaShell
SceMusicExport_stub
SceNet_stub
SceNetCtl_stub
SceNpDrm_stub
SceReg_stub
SceShellSvc_stub
SceSsl_stub
SceSysmodule_stub
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ Be sure you pull request your customized design or language file there.
* Everybody who contributed on vitasdk

### Changelog 1.60 ###
- Added ability to mount uma0: and ability to use uma0: as ux0:.
- Added ability to mount game card as usb device.
- Added possibility to refresh the livearea.
- Added I/O operations speed in KB/s.
- Added scrolling text for long filenames.
- Added 'Sort by' option to context menu (R trigger combo removed).
Expand Down
7 changes: 2 additions & 5 deletions audioplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,20 @@ void shortenString(char *out, const char *in, int width) {
}

vita2d_texture *getAlternativeCoverImage(const char *file) {
SceIoStat stat;
char path[MAX_PATH_LENGTH];

char *p = strrchr(file, '/');
if (p) {
*p = '\0';

snprintf(path, MAX_PATH_LENGTH, "%s/cover.jpg", file);
memset(&stat, 0, sizeof(SceIoStat));
if (sceIoGetstat(path, &stat) >= 0) {
if (checkFileExist(path)) {
*p = '/';
return vita2d_load_JPEG_file(path);
}

snprintf(path, MAX_PATH_LENGTH, "%s/folder.jpg", file);
memset(&stat, 0, sizeof(SceIoStat));
if (sceIoGetstat(path, &stat) >= 0) {
if (checkFileExist(path)) {
*p = '/';
return vita2d_load_JPEG_file(path);
}
Expand Down
7 changes: 7 additions & 0 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ int getFileSize(const char *file) {
return fileSize;
}

int checkFileExist(const char *file) {
SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));

return sceIoGetstat(file, &stat) >= 0;
}

int changePathPermissions(const char *path, int perms) {
SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));
Expand Down
1 change: 1 addition & 0 deletions file.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ typedef struct {
int allocateReadFile(const char *file, void **buffer);
int ReadFile(const char *file, void *buf, int size);
int WriteFile(const char *file, const void *buf, int size);
int checkFileExist(const char *file);

int getFileSize(const char *file);
int getFileSha1(const char *file, uint8_t *pSha1Out, FileProcessParam *param);
Expand Down
4 changes: 1 addition & 3 deletions init.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,7 @@ void initVitaShell() {
initPowerTickThread();

// Delete VitaShell updater if available
SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));
if (sceIoGetstat("ux0:app/VSUPDATER", &stat) >= 0) {
if (checkAppExist("VSUPDATER") >= 0) {
deleteApp("VSUPDATER");
}

Expand Down
4 changes: 1 addition & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1325,9 +1325,7 @@ static int shellMain() {
ReadFile(VITASHELL_LASTDIR, lastdir, sizeof(lastdir));

// Calculate dir positions if the dir is valid
SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));
if (sceIoGetstat(lastdir, &stat) >= 0) {
if (checkFileExist(lastdir)) {
int i;
for (i = 0; i < strlen(lastdir)+1; i++) {
if (lastdir[i] == ':' || lastdir[i] == '/') {
Expand Down
8 changes: 2 additions & 6 deletions main_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ void setContextMenuHomeVisibilities() {
menu_home_entries[MENU_HOME_ENTRY_MOUNT_USB_UX0].visibility = CTX_INVISIBLE;
menu_home_entries[MENU_HOME_ENTRY_UMOUNT_USB_UX0].visibility = CTX_INVISIBLE;
} else {
SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));
if (sceIoGetstat("uma0:", &stat) >= 0) {
if (checkFileExist("uma0:")) {
menu_home_entries[MENU_HOME_ENTRY_MOUNT_UMA0].visibility = CTX_INVISIBLE;
} else {
menu_home_entries[MENU_HOME_ENTRY_MOUNT_USB_UX0].visibility = CTX_INVISIBLE;
Expand Down Expand Up @@ -631,9 +629,7 @@ static int contextMenuMainEnterCallback(int sel, void *context) {
snprintf(path, MAX_PATH_LENGTH, "%s%s (%d)", file_list.path, language_container[NEW_FOLDER], count);
}

SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));
if (sceIoGetstat(path, &stat) < 0)
if (!checkFileExist(path))
break;

count++;
Expand Down
132 changes: 30 additions & 102 deletions package_installer.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,129 +27,51 @@
#include "sfo.h"
#include "sha1.h"

#include "resources/base_head_bin.h"
INCLUDE_EXTERN_RESOURCE(head_bin);

int promoteUpdate(const char *path, const char *titleid, const char *category, void *sfo_buffer, int sfo_size) {
int promoteApp(const char *path) {
int res;

// Update installation
if (strcmp(category, "gp") == 0) {
// Change category to 'gd'
setSfoString(sfo_buffer, "CATEGORY", "gd");
WriteFile(PACKAGE_DIR "/sce_sys/param.sfo", sfo_buffer, sfo_size);

// App path
char app_path[MAX_PATH_LENGTH];
snprintf(app_path, MAX_PATH_LENGTH, "ux0:app/%s", titleid);

/*
Without the following trick, the livearea won't be updated and the game will even crash
*/

// Integrate patch to app
res = movePath(path, app_path, MOVE_INTEGRATE | MOVE_REPLACE, NULL);
if (res < 0)
return res;

// Move app to promotion directory
res = movePath(app_path, path, 0, NULL);
if (res < 0)
return res;
}

return 0;
}

int promotePkg(const char *path) {
int res, ret;

res = scePromoterUtilityInit();
if (res < 0)
goto ERROR_EXIT;

res = scePromoterUtilityPromotePkg(path, 0);
if (res < 0)
goto ERROR_EXIT;

int state = 0;
do {
res = scePromoterUtilityGetState(&state);
if (res < 0)
goto ERROR_EXIT;

sceKernelDelayThread(100 * 1000);
} while (state);

res = scePromoterUtilityGetResult(&ret);

ERROR_EXIT:
scePromoterUtilityExit();

if (res < 0)
return res;

// Using the promoteUpdate trick, we get 0x80870005 as result, but it installed correctly though, so return ok
return ret == 0x80870005 ? 0 : ret;
}
res = scePromoterUtilityPromotePkgWithRif(path, 1);

int promoteApp(const char *path) {
int res;

// Read param.sfo
void *sfo_buffer = NULL;
int sfo_size = allocateReadFile(PACKAGE_DIR "/sce_sys/param.sfo", &sfo_buffer);
if (sfo_size < 0)
return sfo_size;

// Get titleid
char titleid[12];
getSfoString(sfo_buffer, "TITLE_ID", titleid, sizeof(titleid));

// Get category
char category[4];
getSfoString(sfo_buffer, "CATEGORY", category, sizeof(category));

// Promote update
promoteUpdate(path, titleid, category, sfo_buffer, sfo_size);

// Free sfo buffer
free(sfo_buffer);
scePromoterUtilityExit();

// Promote pkg
return promotePkg(path);
return res;
}

int deleteApp(const char *titleid) {
int res, ret;
int res;

sceAppMgrDestroyOtherApp();

res = scePromoterUtilityInit();
if (res < 0)
goto ERROR_EXIT;
return res;

res = scePromoterUtilityDeletePkg(titleid);
if (res < 0)
goto ERROR_EXIT;

int state = 0;
do {
res = scePromoterUtilityGetState(&state);
if (res < 0)
goto ERROR_EXIT;

sceKernelDelayThread(100 * 1000);
} while (state);
scePromoterUtilityExit();

res = scePromoterUtilityGetResult(&ret);
return res;
}

ERROR_EXIT:
scePromoterUtilityExit();
int checkAppExist(const char *titleid) {
int res;
int ret;

res = scePromoterUtilityInit();
if (res < 0)
return res;

return ret;
res = scePromoterUtilityCheckExist(titleid, &ret);

scePromoterUtilityExit();

return res;
}

static void fpkg_hmac(const uint8_t *data, unsigned int len, uint8_t hmac[16]) {
Expand Down Expand Up @@ -183,6 +105,12 @@ int makeHeadBin() {
uint32_t len;
uint32_t out;

SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));

if (checkFileExist(HEAD_BIN) >= 0)
return 0;

// Read param.sfo
void *sfo_buffer = NULL;
int res = allocateReadFile(PACKAGE_DIR "/sce_sys/param.sfo", &sfo_buffer);
Expand All @@ -207,12 +135,12 @@ int makeHeadBin() {
free(sfo_buffer);

// Allocate head.bin buffer
uint8_t *head_bin = malloc(sizeof(base_head_bin));
memcpy(head_bin, base_head_bin, sizeof(base_head_bin));
uint8_t *head_bin = malloc((int)&_binary_resources_head_bin_size);
memcpy(head_bin, (void *)&_binary_resources_head_bin_start, (int)&_binary_resources_head_bin_size);

// Write full title id
char full_title_id[48];
snprintf(full_title_id, sizeof(full_title_id), "EP9000-%s_00-XXXXXXXXXXXXXXXX", titleid);
snprintf(full_title_id, sizeof(full_title_id), "EP9000-%s_00-0000000000000000", titleid);
strncpy((char *)&head_bin[0x30], strlen(contentid) > 0 ? contentid : full_title_id, 48);

// hmac of pkg header
Expand All @@ -224,7 +152,7 @@ int makeHeadBin() {
off = ntohl(*(uint32_t *)&head_bin[0x8]);
len = ntohl(*(uint32_t *)&head_bin[0x10]);
out = ntohl(*(uint32_t *)&head_bin[0xD4]);
fpkg_hmac(&head_bin[off], len - 64, hmac);
fpkg_hmac(&head_bin[off], len-64, hmac);
memcpy(&head_bin[out], hmac, 16);

// hmac of everything
Expand All @@ -236,7 +164,7 @@ int makeHeadBin() {
sceIoMkdir(PACKAGE_DIR "/sce_sys/package", 0777);

// Write head.bin
WriteFile(HEAD_BIN, head_bin, sizeof(base_head_bin));
WriteFile(HEAD_BIN, head_bin, (int)&_binary_resources_head_bin_size);

free(head_bin);

Expand Down
2 changes: 1 addition & 1 deletion package_installer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ typedef struct {
char *file;
} InstallArguments;

int promotePkg(const char *path);
int promoteApp(const char *path);
int deleteApp(const char *titleid);
int checkAppExist(const char *titleid);

int makeHeadBin();

Expand Down
49 changes: 32 additions & 17 deletions refresh.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,33 @@ int isCustomHomebrew() {
return 1;
}

int sceRegMgrGetKeyBin(const char *category, const char *name, void *buf, int size);
int _sceNpDrmGetRifName(char *rif_name, int flags, uint64_t aid);
int _sceNpDrmGetFixedRifName(char *rif_name, int flags, uint64_t aid);

int refreshApp(const char *titleid) {
int res;
int ret;

res = scePromoterUtilityInit();
if (res < 0)
goto ERROR_EXIT;
// Check if app exists
if (checkAppExist(titleid) >= 0) {
uint64_t aid;
sceRegMgrGetKeyBin("/CONFIG/NP", "account_id", &aid, sizeof(uint64_t));

res = scePromoterUtilityCheckExist(titleid, &ret);
if (res >= 0)
goto ERROR_EXIT;
char rif_name[48];
char path[MAX_PATH_LENGTH];

_sceNpDrmGetRifName(rif_name, 0, aid);
snprintf(path, MAX_PATH_LENGTH, "ux0:license/app/%s/%s", titleid, rif_name);

if (checkFileExist(path))
return 0;

_sceNpDrmGetFixedRifName(rif_name, 0, 0);
snprintf(path, MAX_PATH_LENGTH, "ux0:license/app/%s/%s", titleid, rif_name);

if (checkFileExist(path))
return 0;
}

// Clean
removePath("ux0:temp/game", NULL);
Expand All @@ -63,24 +79,23 @@ int refreshApp(const char *titleid) {
// Rename app
res = sceIoRename(path, "ux0:temp/game");
if (res < 0)
goto ERROR_EXIT;
return res;

// Remove work.bin for custom homebrews
if (isCustomHomebrew())
sceIoRemove("ux0:temp/game/sce_sys/package/work.bin");

res = scePromoterUtilityPromotePkgWithRif("ux0:temp/game", 1);
// Promote app
res = promoteApp("ux0:temp/game");

// Rename back if it failed, or set to 1 if succeeded
if (res < 0)
// Rename back if it failed
if (res < 0) {
sceIoRename("ux0:temp/game", path);
else
res = 1;

ERROR_EXIT:
scePromoterUtilityExit();
return res;
}

return res;
// Return success
return 1;
}

int refresh_thread(SceSize args, void *argp) {
Expand Down
Loading

0 comments on commit 8120486

Please sign in to comment.