Skip to content

Commit

Permalink
Inherit file statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOfficialFloW committed Mar 5, 2017
1 parent 8120486 commit cdd77f6
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 59 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,16 @@ Be sure you pull request your customized design or language file there.
- 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).
- Made control smoother.
- Removed battery icon in status bar for PSTV.
- Improved property dialog animation.
- Fixed text editor bugs.
- Fixed bug where USB cable wasn't recognized.
- Fixed bug where VitaShell left to livearea after deleting the updater.
- Improved property dialog animation.
- Removed battery icon in status bar for PSTV.
- File statistics are now inherited when copying.
- I/O operations speed will now be showed in KB/s.
- Made control smoother.

### Changelog 1.51 ###
- Fixed bug where 'Please wait...' was shown instead of a specifc USB message.
Expand Down
52 changes: 18 additions & 34 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,6 @@ int checkFileExist(const char *file) {
return sceIoGetstat(file, &stat) >= 0;
}

int changePathPermissions(const char *path, int perms) {
SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));
int res = sceIoGetstat(path, &stat);
if (res < 0)
return res;

stat.st_mode |= perms;

return sceIoChstat(path, &stat, 1);
}

int getFileSha1(const char *file, uint8_t *pSha1Out, FileProcessParam *param) {
// Set up SHA1 context
SHA1_CTX ctx;
Expand Down Expand Up @@ -335,14 +323,7 @@ int copyFile(const char *src_path, const char *dst_path, FileProcessParam *param
if (strncasecmp(src_path, dst_path, len) == 0 && (dst_path[len] == '/' || dst_path[len-1] == '/')) {
return -2;
}
/*
SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));

int res = sceIoGetstat(src_path, &stat);
if (res < 0)
return res;
*/
SceUID fdsrc = sceIoOpen(src_path, SCE_O_RDONLY, 0);
if (fdsrc < 0)
return fdsrc;
Expand All @@ -364,6 +345,8 @@ int copyFile(const char *src_path, const char *dst_path, FileProcessParam *param
sceIoClose(fddst);
sceIoClose(fdsrc);

sceIoRemove(dst_path);

return read;
}

Expand All @@ -378,6 +361,8 @@ int copyFile(const char *src_path, const char *dst_path, FileProcessParam *param
sceIoClose(fddst);
sceIoClose(fdsrc);

sceIoRemove(dst_path);

return written;
}

Expand All @@ -394,13 +379,21 @@ int copyFile(const char *src_path, const char *dst_path, FileProcessParam *param
sceIoClose(fddst);
sceIoClose(fdsrc);

sceIoRemove(dst_path);

return 0;
}
}
}

free(buf);

// Inherit file stat
SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));
sceIoGetstatByFd(fdsrc, &stat);
sceIoChstatByFd(fddst, &stat, 0x3B);

sceIoClose(fddst);
sceIoClose(fdsrc);

Expand All @@ -418,17 +411,14 @@ int copyPath(const char *src_path, const char *dst_path, FileProcessParam *param
if (strncasecmp(src_path, dst_path, len) == 0 && (dst_path[len] == '/' || dst_path[len-1] == '/')) {
return -2;
}
/*
SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));

int res = sceIoGetstat(src_path, &stat);
if (res < 0)
return res;
*/
SceUID dfd = sceIoDopen(src_path);
if (dfd >= 0) {
int ret = sceIoMkdir(dst_path, 0777);
SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));
sceIoGetstatByFd(dfd, &stat);

int ret = sceIoMkdir(dst_path, stat.st_mode & 0xFFF);
if (ret < 0 && ret != SCE_ERROR_ERRNO_EEXIST) {
sceIoDclose(dfd);
return ret;
Expand Down Expand Up @@ -501,10 +491,7 @@ int movePath(const char *src_path, const char *dst_path, int flags, FileProcessP

int res = sceIoRename(src_path, dst_path);

if (res >= 0) {
// Give group RW permissions
changePathPermissions(dst_path, SCE_S_IROTH | SCE_S_IWOTH);
} else if (res == SCE_ERROR_ERRNO_EEXIST && flags & (MOVE_INTEGRATE | MOVE_REPLACE)) {
if (res == SCE_ERROR_ERRNO_EEXIST && flags & (MOVE_INTEGRATE | MOVE_REPLACE)) {
// Src stat
SceIoStat src_stat;
memset(&src_stat, 0, sizeof(SceIoStat));
Expand Down Expand Up @@ -535,9 +522,6 @@ int movePath(const char *src_path, const char *dst_path, int flags, FileProcessP
if (res < 0)
return res;

// Give group RW permissions
changePathPermissions(dst_path, SCE_S_IROTH | SCE_S_IWOTH);

return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion init.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void initVitaShell() {
initPowerTickThread();

// Delete VitaShell updater if available
if (checkAppExist("VSUPDATER") >= 0) {
if (checkAppExist("VSUPDATER")) {
deleteApp("VSUPDATER");
}

Expand Down
1 change: 0 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
TODO:
- Theme manager
- PFS bypass
- Inherit file stat when copying
*/

int _newlib_heap_size_user = 128 * 1024 * 1024;
Expand Down
4 changes: 2 additions & 2 deletions package_installer.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int checkAppExist(const char *titleid) {

scePromoterUtilityExit();

return res;
return res >= 0;
}

static void fpkg_hmac(const uint8_t *data, unsigned int len, uint8_t hmac[16]) {
Expand Down Expand Up @@ -108,7 +108,7 @@ int makeHeadBin() {
SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));

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

// Read param.sfo
Expand Down
48 changes: 31 additions & 17 deletions refresh.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "io_process.h"
#include "refresh.h"
#include "package_installer.h"
#include "sfo.h"
#include "file.h"
#include "message_dialog.h"
#include "language.h"
Expand All @@ -44,40 +45,53 @@ int sceRegMgrGetKeyBin(const char *category, const char *name, void *buf, int si
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 refreshApp(const char *name) {
char app_path[MAX_PATH_LENGTH], param_path[MAX_PATH_LENGTH], license_path[MAX_PATH_LENGTH];
int res;

// Path
snprintf(app_path, MAX_PATH_LENGTH, "ux0:app/%s", name);
snprintf(param_path, MAX_PATH_LENGTH, "ux0:app/%s/sce_sys/param.sfo", name);

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

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

// Free sfo buffer
free(sfo_buffer);

// Check if app exists
if (checkAppExist(titleid) >= 0) {
if (checkAppExist(titleid)) {
char rif_name[48];

uint64_t aid;
sceRegMgrGetKeyBin("/CONFIG/NP", "account_id", &aid, sizeof(uint64_t));

char rif_name[48];
char path[MAX_PATH_LENGTH];

// Check if bounded rif file exits
_sceNpDrmGetRifName(rif_name, 0, aid);
snprintf(path, MAX_PATH_LENGTH, "ux0:license/app/%s/%s", titleid, rif_name);

if (checkFileExist(path))
snprintf(license_path, MAX_PATH_LENGTH, "ux0:license/app/%s/%s", titleid, rif_name);
if (checkFileExist(license_path))
return 0;

// Check if fixed rif file exits
_sceNpDrmGetFixedRifName(rif_name, 0, 0);
snprintf(path, MAX_PATH_LENGTH, "ux0:license/app/%s/%s", titleid, rif_name);

if (checkFileExist(path))
snprintf(license_path, MAX_PATH_LENGTH, "ux0:license/app/%s/%s", titleid, rif_name);
if (checkFileExist(license_path))
return 0;
}

// Clean
removePath("ux0:temp/game", NULL);
sceIoMkdir("ux0:temp", 0006);

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

// Rename app
res = sceIoRename(path, "ux0:temp/game");
res = sceIoRename(app_path, "ux0:temp/game");
if (res < 0)
return res;

Expand All @@ -90,7 +104,7 @@ int refreshApp(const char *titleid) {

// Rename back if it failed
if (res < 0) {
sceIoRename("ux0:temp/game", path);
sceIoRename("ux0:temp/game", app_path);
return res;
}

Expand Down

0 comments on commit cdd77f6

Please sign in to comment.