diff --git a/Makefile b/Makefile index f7741df..76b08b6 100644 --- a/Makefile +++ b/Makefile @@ -43,9 +43,10 @@ SOURCES := source source/ui source/data source/install source/nx source/nx/ipc DATA := data INCLUDES := include include/ui include/data include/install include/nx include/nx/ipc include/util include/Plutonium/Plutonium/Output-switch/include APP_TITLE := Tinleaf Installer -APP_AUTHOR := Adubbz & Xortroll -APP_VERSION := 1.4.0 +APP_AUTHOR := Adubbz and Xortroll +APP_VERSION := 1.4.1 ROMFS := romfs +APP_ICON := icon.jpg #--------------------------------------------------------------------------------- # options for code generation @@ -132,12 +133,8 @@ endif ifeq ($(strip $(ICON)),) icons := $(wildcard *.jpg) - ifneq (,$(findstring $(TARGET).jpg,$(icons))) - export APP_ICON := $(TOPDIR)/$(TARGET).jpg - else - ifneq (,$(findstring icon.jpg,$(icons))) - export APP_ICON := $(TOPDIR)/icon.jpg - endif + ifneq (,$(findstring icon.jpg,$(icons))) + export APP_ICON := $(TOPDIR)/icon.jpg endif else export APP_ICON := $(TOPDIR)/$(ICON) @@ -159,6 +156,8 @@ ifneq ($(ROMFS),) export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS) endif +$(info $$NROFLAGS is [${NROFLAGS}]) + .PHONY: $(BUILD) clean all #--------------------------------------------------------------------------------- diff --git a/icon.jpg b/icon.jpg index bd3f07b..1c5d4e6 100644 Binary files a/icon.jpg and b/icon.jpg differ diff --git a/include/tx.h b/include/tx.h deleted file mode 100644 index 1649405..0000000 --- a/include/tx.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include - -#ifdef __cplusplus -extern "C" { -#endif - -Result txInitialize(void); - -void txExit(void); - -#ifdef __cplusplus -} -#endif - diff --git a/include/usbfs.h b/include/usbfs.h deleted file mode 100644 index a890df2..0000000 --- a/include/usbfs.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef __USBFS_H__ -#define __USBFS_H__ - -#include - -enum UsbFsServiceCmd { - UsbFs_Cmd_GetMountStatus = 0, - UsbFs_Cmd_OpenFile = 1, - UsbFs_Cmd_CloseFile = 2, - UsbFs_Cmd_ReadFile = 3, - UsbFs_Cmd_IsReady = 4, - UsbFs_Cmd_OpenDir = 5, - UsbFs_Cmd_CloseDir = 6, - UsbFs_Cmd_ReadDir = 7, - UsbFs_Cmd_CreateDir = 8, - UsbFs_Cmd_SeekFile = 9, - UsbFs_Cmd_ReadRaw = 10, - UsbFs_Cmd_WriteFile = 11, - UsbFs_Cmd_SyncFile = 12, - UsbFs_Cmd_DeleteDir = 13, - UsbFs_Cmd_DeleteFile = 14, - UsbFs_Cmd_TruncateFile = 15, - UsbFs_Cmd_StatFile = 16, - UsbFs_Cmd_StatPath = 17, - UsbFs_Cmd_StatFilesystem = 18, -}; - -#ifdef __cplusplus -extern "C" { -#endif - -Result usbFsIsInitialized(void); -Result usbFsInitialize(void); -void usbFsExit(void); -Result usbFsIsReady(void); -Result usbFsGetMountStatus(u64* status); -Result usbFsOpenFile(u64* fileid, const char* filepath, u64 mode); -Result usbFsCloseFile(u64 fileid); -Result usbFsReadFile(u64 fileid, void* buffer, size_t size, size_t* retsize); -Result usbFsWriteFile(u64 fileid, const void* buffer, size_t size, size_t* retsize); -Result usbFsSeekFile(u64 fileid, u64 pos, u64 whence, u64 *retpos); -Result usbFsSyncFile(u64 fileid); -Result usbFsTruncateFile(u64 fileid, u64 size); -Result usbFsDeleteFile(const char* filepath); -Result usbFsStatFile(u64 fileid, u64* size, u64* mode); -Result usbFsStatPath(const char* path, u64* size, u64* mode); -Result usbFsStatFilesystem(u64* totalsize, u64* freesize); -Result usbFsOpenDir(u64* dirid, const char* dirpath); -Result usbFsReadDir(u64 dirid, u64* type, u64* size, char* name, size_t namemax); -Result usbFsCloseDir(u64 dirid); -Result usbFsCreateDir(const char* dirpath); -Result usbFsDeleteDir(const char* dirpath); -Result usbFsReadRaw(u64 sector, u64 sectorcount, void* buffer); -Result sxIsAuth(); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/usbfsdevice.h b/include/usbfsdevice.h deleted file mode 100644 index 54b429b..0000000 --- a/include/usbfsdevice.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef __USBFSDEVICE_H__ -#define __USBFSDEVICE_H__ - -#define USBFS_UNMOUNTED 0 -#define USBFS_MOUNTED 1 -#define USBFS_UNSUPPORTED_FS 2 - -#if defined (__cplusplus) -extern "C" { -#endif - -// Register "usbhdd:" device -void usbFsDeviceRegister(void); - -// Keep calling update periodically to check USB drive ready -// Returns 1 if status changed -int usbFsDeviceUpdate(void); - -// If status changed, check mount status -// Returns 0 == USBFS_UNMOUNTED, 1 == USBFS_MOUNTED, 2 == USBFS_UNSUPPORTED_FS -int usbFsDeviceGetMountStatus(void); - -#if defined (__cplusplus) -} -#endif - -#endif diff --git a/source/nx/tx.c b/source/nx/tx.c deleted file mode 100644 index 656b058..0000000 --- a/source/nx/tx.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "tx.h" - -static Service g_txSrv; -static u64 g_refCnt; - -Result txInitialize(void) { - atomicIncrement64(&g_refCnt); - - if (serviceIsActive(&g_txSrv)) - return 0; - - Result rc = smGetService(&g_txSrv, "tx"); - if (R_FAILED(rc)) - return rc; - - if (R_FAILED(rc)) - txExit(); - - return rc; -} - -void txExit(void) { - if (atomicDecrement64(&g_refCnt) == 0) - { - serviceClose(&g_txSrv); - } -} - diff --git a/source/nx/usbfs.c b/source/nx/usbfs.c deleted file mode 100644 index 554fc2e..0000000 --- a/source/nx/usbfs.c +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright (c) 2018 Team Xecuter -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -#include -#include "usbfs.h" - -static Service g_usbFsSrv; -static u64 g_refCnt; - -Result usbFsIsInitialized() { - if (serviceIsActive(&g_usbFsSrv)) { - return 0; - } - - return 0x666; -} - -Result usbFsInitialize(void) { - Result rc; - atomicIncrement64(&g_refCnt); - - if (serviceIsActive(&g_usbFsSrv)) { - return 0; - } - - rc = smGetService(&g_usbFsSrv, "usbfs"); - if (R_FAILED(rc)) { - return rc; - } - - return rc; -} - -void usbFsExit(void) { - if (atomicDecrement64(&g_refCnt) == 0) { - serviceClose(&g_usbFsSrv); - } -} - - -Result usbFsIsReady() { - return serviceDispatch(&g_usbFsSrv, UsbFs_Cmd_IsReady); -} - - -Result usbFsGetMountStatus(u64* status) { - return serviceDispatchOut(&g_usbFsSrv, UsbFs_Cmd_GetMountStatus, *status); -} - - -Result usbFsOpenFile(u64* fileid, const char* filepath, u64 mode) { - return serviceDispatchInOut(&g_usbFsSrv, UsbFs_Cmd_OpenFile, mode, *fileid, - .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, - .buffers = { { filepath, strlen(filepath) + 1 } }, - ); -} - - -Result usbFsCloseFile(u64 fileid) { - return serviceDispatchIn(&g_usbFsSrv, UsbFs_Cmd_CloseFile, fileid); -} - - -Result usbFsReadFile(u64 fileid, void* buffer, size_t size, size_t* retsize) { - return serviceDispatchInOut(&g_usbFsSrv, UsbFs_Cmd_ReadFile, fileid, *retsize, - .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, - .buffers = { { buffer, size } }, - ); -} - -Result usbFsWriteFile(u64 fileid, const void* buffer, size_t size, size_t* retsize) { - return serviceDispatchInOut(&g_usbFsSrv, UsbFs_Cmd_WriteFile, fileid, *retsize, - .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, - .buffers = { { buffer, size } }, - ); -} - -Result usbFsSeekFile(u64 fileid, u64 pos, u64 whence, u64 *retpos) { - struct { - u64 fileid; - u64 pos; - u64 whence; - } in = {fileid, pos, whence}; - - return serviceDispatchInOut(&g_usbFsSrv, UsbFs_Cmd_SeekFile, in, *retpos); -} - -Result usbFsSyncFile(u64 fileid) { - return serviceDispatchIn(&g_usbFsSrv, UsbFs_Cmd_SyncFile, fileid); -} - - -Result usbFsTruncateFile(u64 fileid, u64 size) { - struct { - u64 fileid; - u64 size; - } in = {fileid, size}; - - return serviceDispatchIn(&g_usbFsSrv, UsbFs_Cmd_TruncateFile, in); -} - -Result usbFsDeleteFile(const char* filepath) { - return serviceDispatch(&g_usbFsSrv, UsbFs_Cmd_DeleteFile, - .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, - .buffers = { { filepath, strlen(filepath) + 1 } }); -} - - -Result usbFsStatFile(u64 fileid, u64* size, u64* mode) { - struct { - u64 size; - u64 mode; - } out; - - Result rc = serviceDispatchInOut(&g_usbFsSrv, UsbFs_Cmd_StatFile, fileid, out); - - if (R_SUCCEEDED(rc)) { - *size = out.size; - *mode = out.mode; - } - - return rc; -} - -Result usbFsStatPath(const char* path, u64* size, u64* mode) { - struct { - u64 size; - u64 mode; - } out; - - Result rc = serviceDispatchOut(&g_usbFsSrv, UsbFs_Cmd_StatPath, out, - .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, - .buffers = { { path, strlen(path) + 1 } }); - - if (R_SUCCEEDED(rc)) { - *size = out.size; - *mode = out.mode; - } - - return rc; -} - - -Result usbFsStatFilesystem(u64* totalsize, u64* freesize) { - struct { - u64 totalsize; - u64 freesize; - } out; - - Result rc = serviceDispatchOut(&g_usbFsSrv, UsbFs_Cmd_StatFilesystem, out); - - if (R_SUCCEEDED(rc)) { - *totalsize = out.totalsize; - *freesize = out.freesize; - } - - return rc; -} - -Result usbFsOpenDir(u64* dirid, const char* dirpath) { - return serviceDispatchOut(&g_usbFsSrv, UsbFs_Cmd_OpenDir, *dirid, - .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, - .buffers = { { dirpath, strlen(dirpath) + 1 } }); -} - -Result usbFsCloseDir(u64 dirid) { - return serviceDispatchIn(&g_usbFsSrv, UsbFs_Cmd_CloseDir, dirid); -} - - -Result usbFsReadDir(u64 dirid, u64* type, u64* size, char* name, size_t namemax) { - struct { - u64 type; - u64 size; - } out; - - int rc = serviceDispatchInOut(&g_usbFsSrv, UsbFs_Cmd_ReadDir, dirid, out, - .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, - .buffers = { { name, namemax } }); - - if(!rc) - { - *type = out.type; - *size = out.size; - } - - return rc; -} - - -Result usbFsCreateDir(const char* dirpath) { - return serviceDispatch(&g_usbFsSrv, UsbFs_Cmd_CreateDir, - .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, - .buffers = { { dirpath, strlen(dirpath) + 1 } }); -} - -Result usbFsDeleteDir(const char* dirpath) { - return serviceDispatch(&g_usbFsSrv, UsbFs_Cmd_DeleteDir, - .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, - .buffers = { { dirpath, strlen(dirpath) + 1 } }); -} - -Result usbFsReadRaw(u64 sector, u64 sectorcount, void* buffer) { - struct { - u64 sector; - u64 sectorcount; - } in = {sector, sectorcount}; - - return serviceDispatchIn(&g_usbFsSrv, UsbFs_Cmd_ReadRaw, in, - .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, - .buffers = { { buffer, 0x200ULL * sectorcount } }); -} diff --git a/source/nx/usbfsdevice.c b/source/nx/usbfsdevice.c deleted file mode 100644 index 59af4e4..0000000 --- a/source/nx/usbfsdevice.c +++ /dev/null @@ -1,400 +0,0 @@ -//#ifdef __SX__ -// Copyright (c) 2018 Team Xecuter -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "usbfs.h" -#include "usbfsdevice.h" - - -static u64 g_mountstatus = USBFS_UNMOUNTED; - -static int usbfs_dev_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode); -static int usbfs_dev_close(struct _reent *r, void *fd); -static ssize_t usbfs_dev_read(struct _reent *r, void *fd, char *ptr, size_t len); -static ssize_t usbfs_dev_write(struct _reent *r, void *fd, const char *ptr, size_t len); -static off_t usbfs_dev_seek(struct _reent *r, void *fd, off_t pos, int dir); -static int usbfs_dev_fstat(struct _reent *r, void *fd, struct stat *st); -static int usbfs_dev_stat(struct _reent *r, const char *path, struct stat *st); -static int usbfs_dev_unlink(struct _reent *r, const char *path); -static int usbfs_dev_chdir(struct _reent *r, const char *path); -static int usbfs_dev_mkdir(struct _reent *r, const char *path, int mode); -static DIR_ITER* usbfs_dev_diropen(struct _reent *r, DIR_ITER *dirState, const char *path); -static int usbfs_dev_dirreset(struct _reent *r, DIR_ITER *dirState); -static int usbfs_dev_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat); -static int usbfs_dev_dirclose(struct _reent *r, DIR_ITER *dirState); -static int usbfs_dev_ftruncate(struct _reent *r, void *fd, off_t len); -static int usbfs_dev_fsync(struct _reent *r, void *fd); -static int usbfs_dev_rmdir(struct _reent *r, const char *path); -static int usbfs_dev_statvfs(struct _reent *r, const char *path, struct statvfs *buf); - -typedef struct { - uint64_t fileid; - int flags; -} usbfs_dev_file; - -typedef struct -{ - uint64_t dirid; -} usbfs_dev_dir; - -static devoptab_t usbfs_dev_devoptab = -{ - .name = "usbhdd", - .structSize = sizeof(usbfs_dev_file), - .open_r = usbfs_dev_open, - .close_r = usbfs_dev_close, - .read_r = usbfs_dev_read, - .write_r = usbfs_dev_write, - .seek_r = usbfs_dev_seek, - .fstat_r = usbfs_dev_fstat, - .stat_r = usbfs_dev_stat, - .unlink_r = usbfs_dev_unlink, - .chdir_r = usbfs_dev_chdir, - .mkdir_r = usbfs_dev_mkdir, - .dirStateSize = sizeof(usbfs_dev_dir), - .diropen_r = usbfs_dev_diropen, - .dirreset_r = usbfs_dev_dirreset, - .dirnext_r = usbfs_dev_dirnext, - .dirclose_r = usbfs_dev_dirclose, - .statvfs_r = usbfs_dev_statvfs, - .ftruncate_r = usbfs_dev_ftruncate, - .fsync_r = usbfs_dev_fsync, - .deviceData = 0, - .rmdir_r = usbfs_dev_rmdir, -}; - -void usbFsDeviceRegister() { - AddDevice(&usbfs_dev_devoptab); -} - -int usbFsDeviceUpdate() { - u64 status; - Result rc = usbFsGetMountStatus(&status); - - if (R_FAILED(rc)) { - return 0; - } - - if (g_mountstatus == status) { - return 0; - } - - g_mountstatus = status; - return 1; -} - -int usbFsDeviceGetMountStatus() { - return g_mountstatus; -} - -int usbfs_dev_open(struct _reent *r, void *fd, const char *path, int flags, int mode) { - usbfs_dev_file* file = (usbfs_dev_file*)fd; - Result rc; - - char* pathAtColon = strchr(path, ':'); - if (pathAtColon) { - path = pathAtColon + 1; - } - - memset(file, 0, sizeof(usbfs_dev_file)); - file->flags = flags; - rc = usbFsOpenFile(&file->fileid, path, flags); - if (R_FAILED(rc)) { - r->_errno = ENOENT; - return -1; - } - - return 0; -} - -int usbfs_dev_close(struct _reent *r, void *fd) { - usbfs_dev_file* file = (usbfs_dev_file*)fd; - Result rc = usbFsCloseFile(file->fileid); - file->fileid = 0xFFFFFFFF; - - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return -1; - } - - return 0; -} - -ssize_t usbfs_dev_read(struct _reent *r, void *fd, char *ptr, size_t len) { - usbfs_dev_file* file = (usbfs_dev_file*)fd; - u64 retsize; - - Result rc = usbFsReadFile(file->fileid, ptr, len, &retsize); - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return -1; - } - - return retsize; -} - - -ssize_t usbfs_dev_write(struct _reent *r, void *fd, const char *ptr, size_t len) { - usbfs_dev_file* file = (usbfs_dev_file*)fd; - u64 retsize; - - Result rc = usbFsWriteFile(file->fileid, ptr, len, &retsize); - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return -1; - } - - if (file->flags & O_SYNC) { - usbFsSyncFile(file->fileid); - } - - return retsize; -} - -off_t usbfs_dev_seek(struct _reent *r, void *fd, off_t pos, int whence) { - usbfs_dev_file* file = (usbfs_dev_file*)fd; - u64 retpos; - Result rc = usbFsSeekFile(file->fileid, pos, whence, &retpos); - - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return -1; - } - - return retpos; -} - -int usbfs_dev_unlink(struct _reent *r, const char *path) { - char* pathAtColon = strchr(path, ':'); - if (pathAtColon) { - path = pathAtColon + 1; - } - - Result rc = usbFsDeleteFile(path); - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return -1; - } - - return 0; -} - -int usbfs_dev_ftruncate(struct _reent *r, void *fd, off_t len) { - usbfs_dev_file* file = (usbfs_dev_file*)fd; - Result rc; - - if (len < 0) { - r->_errno = EINVAL; - return -1; - } - - rc = usbFsTruncateFile(file->fileid, len); - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return -1; - } - - return 0; -} - -int usbfs_dev_fsync(struct _reent *r, void *fd) { - usbfs_dev_file* file = (usbfs_dev_file*)fd; - Result rc; - - rc = usbFsSyncFile(file->fileid); - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return -1; - } - - return 0; -} - -int usbfs_dev_fstat(struct _reent *r, void *fd, struct stat *st) { - usbfs_dev_file* file = (usbfs_dev_file*)fd; - u64 size; - u64 mode; - Result rc; - - rc = usbFsStatFile(file->fileid, &size, &mode); - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return -1; - } - - memset(st, 0, sizeof(struct stat)); - st->st_nlink = 1; - st->st_size = (off_t)size; - st->st_mode = mode; - return 0; -} - -int usbfs_dev_stat(struct _reent *r, const char *path, struct stat *st) { - u64 size; - u64 mode; - Result rc; - - rc = usbFsStatPath(path, &size, &mode); - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return -1; - } - - memset(st, 0, sizeof(struct stat)); - st->st_nlink = 1; - st->st_size = (off_t)size; - st->st_mode = mode; - return 0; -} - -int usbfs_dev_chdir(struct _reent *r, const char *path) { - r->_errno = EINVAL; - return -1; -} - -int usbfs_dev_mkdir(struct _reent *r, const char *path, int mode) { - char* pathAtColon = strchr(path, ':'); - if (pathAtColon) { - path = pathAtColon + 1; - } - - Result rc = usbFsCreateDir(path); - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return -1; - } - - return 0; -} - -DIR_ITER* usbfs_dev_diropen(struct _reent *r, DIR_ITER *dirState, const char *path) { - usbfs_dev_dir *d = (usbfs_dev_dir*)(dirState->dirStruct); - Result rc; - - char* pathAtColon = strchr(path, ':'); - if (pathAtColon) { - path = pathAtColon + 1; - } - - rc = usbFsOpenDir(&d->dirid, path); - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return NULL; - } - - return dirState; -} - -int usbfs_dev_dirreset(struct _reent *r, DIR_ITER *dirState) { - r->_errno = EINVAL; - return -1; -} - -int usbfs_dev_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat) { - usbfs_dev_dir *d = (usbfs_dev_dir*)(dirState->dirStruct); - Result rc; - u64 type, size; - - memset(filename, 0, NAME_MAX); - - - rc = usbFsReadDir(d->dirid, &type, &size, filename, NAME_MAX); - if (rc == 0x68A) { - // there are no more entries; ENOENT signals end-of-directory - r->_errno = ENOENT; - return -1; - } - - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return -1; - } - - filestat->st_ino = 0; - filestat->st_mode = type; - filestat->st_size = size; - - return 0; -} - -int usbfs_dev_dirclose(struct _reent *r, DIR_ITER *dirState) { - usbfs_dev_dir *d = (usbfs_dev_dir*)(dirState->dirStruct); - Result rc; - - rc = usbFsCloseDir(d->dirid); - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return -1; - } - - return 0; -} - - -static int usbfs_dev_rmdir(struct _reent *r, const char *path) { - char* pathAtColon = strchr(path, ':'); - if (pathAtColon) { - path = pathAtColon + 1; - } - - Result rc = usbFsDeleteDir(path); - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return -1; - } - - return 0; -} - -int usbfs_dev_statvfs(struct _reent *r, const char *path, struct statvfs *buf) { - Result rc; - u64 freespace, totalspace; - - rc = usbFsStatFilesystem(&totalspace, &freespace); - if (R_FAILED(rc)) { - r->_errno = EINVAL; - return -1; - } - - buf->f_bsize = 1; - buf->f_frsize = 1; - buf->f_blocks = totalspace; - buf->f_bfree = freespace; - buf->f_bavail = freespace; - buf->f_files = 0; - buf->f_ffree = 0; - buf->f_favail = 0; - buf->f_fsid = 0; - buf->f_flag = ST_NOSUID; - buf->f_namemax = 0; - return 0; -} - -//#endif \ No newline at end of file diff --git a/source/nx/usbhdd.cpp b/source/nx/usbhdd.cpp index 34d5b2c..e03aaed 100644 --- a/source/nx/usbhdd.cpp +++ b/source/nx/usbhdd.cpp @@ -76,43 +76,6 @@ do not use the software. #include #include #include -#include "tx.h" -#include "usbfs.h" -#include "usbfsdevice.h" - -static bool g_isReinx = false; -static bool g_isSx = false; - -bool isServiceRunning(const char *serviceName) -{ - Handle handle; - SmServiceName sn; - memset(&sn, 0, sizeof(sn)); - strcpy(sn.name, serviceName); - bool running = R_FAILED(smRegisterService(&handle, sn, false, 1)); - - svcCloseHandle(handle); - - if(!running) - smUnregisterService(sn); - - return running; -} - -bool isReiNX() -{ - return g_isReinx; -} - -bool isSx() -{ - return g_isSx && !g_isReinx; -} - -bool isAms() -{ - return !g_isSx && !g_isReinx; -} namespace nx::hdd { @@ -171,31 +134,14 @@ namespace nx::hdd u32 count() { - if(isSx()) - { - return usbFsDeviceGetMountStatus() == 1 ? 1 : 0; - } - else - { - return usbHsFsGetMountedDeviceCount(); - } + return usbHsFsGetMountedDeviceCount(); } const char* rootPath(u32 index) { - if(isSx()) + if(index < usbHsFsGetMountedDeviceCount()) { - if(count()) - { - return "usbhdd:/"; - } - } - else - { - if(index < usbHsFsGetMountedDeviceCount()) - { - return g_usbDevices[index].name; - } + return g_usbDevices[index].name; } return nullptr; @@ -203,57 +149,37 @@ namespace nx::hdd bool init() { - g_isReinx = isServiceRunning("rnx"); - g_isSx = isServiceRunning("tx"); - - if(isSx()) + if(g_statusChangeEvent) { - txInitialize(); - usbFsInitialize(); - usbFsDeviceRegister(); + return true; } - else - { - if(g_statusChangeEvent) - { - return true; - } - if(usbHsFsInitialize()) - { - return false; - } + if(usbHsFsInitialize(0)) + { + return false; + } - g_statusChangeEvent = usbHsFsGetStatusChangeUserEvent(); + g_statusChangeEvent = usbHsFsGetStatusChangeUserEvent(); - ueventCreate(&g_exitEvent, true); + ueventCreate(&g_exitEvent, true); - thrd_create(&g_thread, entry, NULL); - } + thrd_create(&g_thread, entry, NULL); return true; } bool exit() { - if(isSx()) + if(!g_statusChangeEvent) { - txExit(); - usbFsExit(); + return false; } - else - { - if(!g_statusChangeEvent) - { - return false; - } - ueventSignal(&g_exitEvent); + ueventSignal(&g_exitEvent); - thrd_join(g_thread, NULL); + thrd_join(g_thread, NULL); - g_statusChangeEvent = NULL; - } + g_statusChangeEvent = NULL; return true; } diff --git a/source/ui/sdInstPage.cpp b/source/ui/sdInstPage.cpp index ae8421e..06b7eba 100644 --- a/source/ui/sdInstPage.cpp +++ b/source/ui/sdInstPage.cpp @@ -41,8 +41,17 @@ namespace inst::ui { void sdInstPage::drawMenuItems(bool clearItems, std::filesystem::path ourPath) { if (clearItems) this->selectedTitles = {}; - if (ourPath == "sdmc:") this->currentDir = std::filesystem::path(ourPath.string() + "/"); - else this->currentDir = ourPath; + this->currentDir = ourPath; + + auto pathStr = this->currentDir.string(); + if(pathStr.length()) + { + if(pathStr[pathStr.length() - 1] == ':') + { + this->currentDir = this->currentDir / ""; + } + } + this->menu->ClearItems(); try { this->ourDirectories = util::getDirsAtPath(this->currentDir); @@ -51,13 +60,13 @@ namespace inst::ui { this->drawMenuItems(false, this->currentDir.parent_path()); return; } - if (this->currentDir != "sdmc:/") { - std::string itm = ".."; - auto ourEntry = pu::ui::elm::MenuItem::New(itm); - ourEntry->SetColor(COLOR("#FFFFFFFF")); - ourEntry->SetIcon("romfs:/images/icons/folder-upload.png"); - this->menu->AddItem(ourEntry); - } + + std::string itm = ".."; + auto ourEntry = pu::ui::elm::MenuItem::New(itm); + ourEntry->SetColor(COLOR("#FFFFFFFF")); + ourEntry->SetIcon("romfs:/images/icons/folder-upload.png"); + this->menu->AddItem(ourEntry); + for (auto& file: this->ourDirectories) { if (file == "..") break; std::string itm = file.filename().string(); @@ -83,10 +92,10 @@ namespace inst::ui { void sdInstPage::followDirectory() { int selectedIndex = this->menu->GetSelectedIndex(); int dirListSize = this->ourDirectories.size(); - if (this->currentDir != "sdmc:/") { - dirListSize++; - selectedIndex--; - } + + dirListSize++; + selectedIndex--; + if (selectedIndex < dirListSize) { if (this->menu->GetItems()[this->menu->GetSelectedIndex()]->GetName() == ".." && this->menu->GetSelectedIndex() == 0) { this->drawMenuItems(true, this->currentDir.parent_path()); @@ -99,7 +108,8 @@ namespace inst::ui { void sdInstPage::selectNsp(int selectedIndex) { int dirListSize = this->ourDirectories.size(); - if (this->currentDir != "sdmc:/") dirListSize++; + dirListSize++; + if (this->menu->GetItems()[selectedIndex]->GetIcon() == "romfs:/images/icons/check-box-outline.png") { for (long unsigned int i = 0; i < this->selectedTitles.size(); i++) { if (this->selectedTitles[i] == this->ourFiles[selectedIndex - dirListSize]) this->selectedTitles.erase(this->selectedTitles.begin() + i); @@ -135,7 +145,7 @@ namespace inst::ui { if (this->selectedTitles.size() == this->ourFiles.size()) this->drawMenuItems(true, currentDir); else { int topDir = 0; - if (this->currentDir != "sdmc:/") topDir++; + topDir++; for (long unsigned int i = this->ourDirectories.size() + topDir; i < this->menu->GetItems().size(); i++) { if (this->menu->GetItems()[i]->GetIcon() == "romfs:/images/icons/check-box-outline.png") continue; else this->selectNsp(i);