Added support for using fileassoc with netloader, an error will now be thrown if the filename/file-extension used with netloader is not recognized. Various improvements.

This commit is contained in:
yellows8 2019-12-30 11:15:38 -05:00
parent b40d558458
commit 42a4ad9787
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43
4 changed files with 60 additions and 43 deletions

View File

@ -202,18 +202,18 @@ static bool menuEntryLoadExternalNacp(menuEntry_s* me, const char* path) {
} while (lastc);
}*/
bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) {
bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut, bool check_exists) {
int i=0, tmplen;
menu_s *menu_fileassoc = menuFileassocGetCurrent();
menuEntry_s* fileassoc_me = NULL;
char *strptr = NULL;
static char tempbuf[PATH_MAX+1];
char tempbuf[PATH_MAX+1];
//bool isOldAppFolder = false;
if (!fsobjExists(me->path)) return false;
if (check_exists && !fsobjExists(me->path)) return false;
tempbuf[PATH_MAX] = 0;
strcpy(me->name, name);
strncpy(me->name, name, sizeof(me->name)-1);
if (me->type == ENTRY_TYPE_FOLDER)
{
@ -285,9 +285,8 @@ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) {
if (me->type == ENTRY_TYPE_FILE)
{
//strcpy(me->name, name);//This is already done before both if statements
strcpy(me->author, textGetString(StrId_DefaultPublisher));
strcpy(me->version, "1.0.0");
strncpy(me->author, textGetString(StrId_DefaultPublisher), sizeof(me->author)-1);
strncpy(me->version, "1.0.0", sizeof(me->version)-1);
//shortcut_s sc;
@ -554,7 +553,7 @@ void menuEntryFileassocLoad(const char* filepath) {
strptr = getSlash(app_path);
if(strptr[0] == '/') strptr++;
if (menuEntryLoad(me, strptr, 0)) {
if (menuEntryLoad(me, strptr, 0, true)) {
strncpy(app_author, me->author, sizeof(app_author));
app_author[sizeof(app_author)-1] = 0;
strncpy(app_version, me->version, sizeof(app_version));

View File

@ -207,7 +207,7 @@ int menuScan(const char* target) {
strncpy(me->path, tmp_path, sizeof(me->path)-1);
me->path[sizeof(me->path)-1] = 0;
if (menuEntryLoad(me, dp->d_name, shortcut))
if (menuEntryLoad(me, dp->d_name, shortcut, true))
menuAddEntry(me);
else
menuDeleteEntry(me, 0);
@ -253,7 +253,7 @@ int themeMenuScan(const char* target) {
strncpy(me->path, tmp_path, sizeof(me->path)-1);
me->path[sizeof(me->path)-1] = 0;
if (menuEntryLoad(me, dp->d_name, shortcut))
if (menuEntryLoad(me, dp->d_name, shortcut, true))
menuAddEntry(me);
else
menuDeleteEntry(me, 0);
@ -265,7 +265,7 @@ int themeMenuScan(const char* target) {
menuEntry_s* me = menuCreateEntry(ENTRY_TYPE_THEME);
if(me) {
if(menuEntryLoad(me, textGetString(StrId_DefaultThemeName), false))//Create Default theme Menu Entry
if(menuEntryLoad(me, textGetString(StrId_DefaultThemeName), false, false))//Create Default theme Menu Entry
menuAddEntryToFront(me);
else
menuDeleteEntry(me, 0);

View File

@ -86,7 +86,7 @@ extern "C" {
void menuEntryInit(menuEntry_s* me, MenuEntryType type);
void menuEntryFree(menuEntry_s* me, bool skip_icongfx);
bool fileExists(const char* path);
bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut);
bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut, bool check_exists);
void menuEntryParseIcon(menuEntry_s* me);
uint8_t *downscaleImg(const uint8_t *image, int srcWidth, int srcHeight, int destWidth, int destHeight, ImageMode mode);
void menuEntryParseNacp(menuEntry_s* me);

View File

@ -368,7 +368,7 @@ static int decompress(int sock, FILE *fh, size_t filesize) {
int loadnro(menuEntry_s *me, int sock, struct in_addr remote) {
//---------------------------------------------------------------------------------
int len, namelen, filelen;
char filename[PATH_MAX+1];
char filepath[PATH_MAX+1];
len = recvall(sock, &namelen, 4, 0);
if (len != 4) {
@ -376,19 +376,19 @@ int loadnro(menuEntry_s *me, int sock, struct in_addr remote) {
return -1;
}
if (namelen >= sizeof(filename)-1) {
netloader_error("Filename length is too large",errno);
if (namelen >= sizeof(filepath)-1) {
netloader_error("File-path length is too large",errno);
return -1;
}
len = recvall(sock, filename, namelen, 0);
len = recvall(sock, filepath, namelen, 0);
if (len != namelen) {
netloader_error("Error getting filename", errno);
netloader_error("Error getting file-path", errno);
return -1;
}
filename[namelen] = 0;
filepath[namelen] = 0;
len = recvall(sock, &filelen, 4, 0);
@ -403,41 +403,56 @@ int loadnro(menuEntry_s *me, int sock, struct in_addr remote) {
int response = 0;
sanitisePath(filename);
sanitisePath(filepath);
snprintf(me->path, sizeof(me->path)-1, "%s%s%s", menuGetRootPath(), DIRECTORY_SEPARATOR, filename);
me->path[PATH_MAX] = 0;
snprintf(me->path, sizeof(me->path)-1, "%s%s%s", menuGetRootPath(), DIRECTORY_SEPARATOR, filepath);
// make sure it's terminated
me->path[PATH_MAX] = 0;
me->path[sizeof(me->path)-1] = 0;
strncpy(filepath, me->path, sizeof(filepath)-1); // menuEntryLoad() below will overwrite me->path, so copy me->path to filepath and use that instead.
filepath[sizeof(filepath)-1] = 0;
argData_s* ad = &me->args;
ad->dst = (char*)&ad->buf[1];
ad->nxlink_host = remote;
launchAddArg(ad, me->path);
const char* ext = getExtension(me->path);
if (ext && strcasecmp(ext, ".nro")==0)
launchAddArg(ad, me->path);
else {
me->type = ENTRY_TYPE_FILE_OTHER; // Handle fileassoc when extension isn't .nro.
if (!menuEntryLoad(me, "", false, false)) {
response = -3;
errno = EINVAL;
netloader_error("File-extension/filename not recognized",0);
}
menuEntryFree(me, false); // We don't need any of the buffers which may have been allocated.
}
#ifndef _WIN32
int fd = open(me->path,O_CREAT|O_WRONLY, ACCESSPERMS);
if (response == 0) {
int fd = open(filepath,O_CREAT|O_WRONLY, ACCESSPERMS);
if (fd < 0) {
response = -1;
netloader_error("open", errno);
} else {
if (ftruncate(fd,filelen) == -1) {
response = -2;
netloader_error("ftruncate",errno);
if (fd < 0) {
response = -1;
netloader_error("open", errno);
} else {
if (ftruncate(fd,filelen) == -1) {
response = -2;
netloader_error("ftruncate",errno);
}
close(fd);
}
close(fd);
}
#endif
FILE *file = NULL;
if (response == 0) file = fopen(me->path,"wb");
if(NULL == file) {
perror("file");
response = -1;
if (response == 0) {
file = fopen(filepath,"wb");
if(file == NULL) {
perror("file");
response = -1;
}
}
send(sock,(char *)&response,sizeof(response),0);
@ -449,12 +464,14 @@ int loadnro(menuEntry_s *me, int sock, struct in_addr remote) {
netloader_error("Failed to allocate memory",ENOMEM);
response = -1;
}
else
else {
memset(writebuffer, 0, FILE_BUFFER_SIZE);
setvbuf(file,writebuffer,_IOFBF, FILE_BUFFER_SIZE);
}
}
if (response == 0 ) {
//printf("transferring %s\n%d bytes.\n", filename, filelen);
//printf("transferring %s\n%d bytes.\n", filepath, filelen);
if (decompress(sock,file,filelen)==Z_OK) {
int netloaded_cmdlen = 0;
@ -499,13 +516,14 @@ int loadnro(menuEntry_s *me, int sock, struct in_addr remote) {
} else {
response = -1;
}
}
if (file) {
fflush(file);
fclose(file);
free(writebuffer);
if (response == -1) unlink(me->path);
}
if (response == -1) unlink(filepath);
free(writebuffer);
return response;
}