This commit is contained in:
Arisotura 2021-09-19 20:22:20 +02:00
parent 529620a49e
commit 2aa1f81301
6 changed files with 114 additions and 36 deletions

View File

@ -121,7 +121,7 @@ if (ENABLE_OGLRENDERER)
target_include_directories(core PRIVATE ${EPOXY_INCLUDE_DIRS}) target_include_directories(core PRIVATE ${EPOXY_INCLUDE_DIRS})
if (WIN32) if (WIN32)
target_link_libraries(core ole32 comctl32 ws2_32 ${EPOXY_LIBRARIES}) target_link_libraries(core ole32 comctl32 ws2_32 shlwapi ${EPOXY_LIBRARIES})
elseif (APPLE) elseif (APPLE)
target_link_libraries(core ${EPOXY_LIBRARIES}) target_link_libraries(core ${EPOXY_LIBRARIES})
else() else()
@ -129,7 +129,7 @@ if (ENABLE_OGLRENDERER)
endif() endif()
else() else()
if (WIN32) if (WIN32)
target_link_libraries(core ole32 comctl32 ws2_32) target_link_libraries(core ole32 comctl32 ws2_32 shlwapi)
else() else()
target_link_libraries(core rt) target_link_libraries(core rt)
endif() endif()

View File

@ -557,7 +557,7 @@ void PatchTSC()
void debug_listfiles(const char* path) void debug_listfiles(const char* path)
{ {
DIR dir; fDIR dir;
FILINFO info; FILINFO info;
FRESULT res; FRESULT res;
@ -677,7 +677,7 @@ void RemoveFile(const char* path)
void RemoveDir(const char* path) void RemoveDir(const char* path)
{ {
DIR dir; fDIR dir;
FILINFO info; FILINFO info;
FRESULT res; FRESULT res;
@ -752,7 +752,7 @@ u32 GetTitleVersion(u32 category, u32 titleid)
void ListTitles(u32 category, std::vector<u32>& titlelist) void ListTitles(u32 category, std::vector<u32>& titlelist)
{ {
FRESULT res; FRESULT res;
DIR titledir; fDIR titledir;
char path[256]; char path[256];
sprintf(path, "0:/title/%08x", category); sprintf(path, "0:/title/%08x", category);
@ -969,7 +969,7 @@ bool ImportTitle(const char* appfile, u8* tmd, bool readonly)
printf("Title ID: %08x/%08x\n", titleid0, titleid1); printf("Title ID: %08x/%08x\n", titleid0, titleid1);
FRESULT res; FRESULT res;
DIR ticketdir; fDIR ticketdir;
FILINFO info; FILINFO info;
char fname[128]; char fname[128];

View File

@ -16,10 +16,31 @@
with melonDS. If not, see http://www.gnu.org/licenses/. with melonDS. If not, see http://www.gnu.org/licenses/.
*/ */
#ifdef __WIN32__
#include <shlwapi.h>
#else
#include <sys/types.h>
#endif // __WIN32__
#include <dirent.h>
#include <errno.h>
#include "FATStorage.h" #include "FATStorage.h"
#include "Platform.h" #include "Platform.h"
static int GetDirEntryType(struct dirent* entry)
{
#ifdef __WIN32__
BOOL res = PathIsDirectoryA(entry->d_name);
return res ? 1:0;
#else
if (entry->d_type == DT_DIR) return 1;
if (entry->d_type == DT_REG) return 0;
return -1;
#endif // __WIN32__
}
FATStorage::FATStorage() FATStorage::FATStorage()
{ {
printf("FATStorage begin\n"); printf("FATStorage begin\n");
@ -86,6 +107,62 @@ UINT FATStorage::FF_WriteStorage(BYTE* buf, LBA_t sector, UINT num)
} }
bool FATStorage::BuildSubdirectory(const char* sourcedir, const char* path, int level)
{
if (level >= 32)
{
printf("FATStorage::BuildSubdirectory: too many subdirectory levels, skipping\n");
return false;
}
char fullpath[1024] = {0};
snprintf(fullpath, 1023, "%s/%s", sourcedir, path);
DIR* dir = opendir(fullpath);
if (!dir) return false;
bool res = true;
for (;;)
{
errno = 0;
struct dirent* entry = readdir(dir);
if (!entry)
{
if (errno != 0) res = false;
break;
}
if (entry->d_name[0] == '.')
{
if (entry->d_name[1] == '\0') continue;
if (entry->d_name[1] == '.' && entry->d_name[2] == '\0') continue;
}
int entrytype = GetDirEntryType(entry);
if (entrytype == -1) continue;
if (entrytype == 1) // directory
{
snprintf(fullpath, 1023, "%s/%s", path, entry->d_name);
printf("DIR: %s/%s\n", sourcedir, fullpath);
if (!BuildSubdirectory(sourcedir, fullpath, level+1))
res = false;
}
else // file
{
snprintf(fullpath, 1023, "%s/%s/%s", sourcedir, path, entry->d_name);
printf("FILE: %s\n", fullpath);
}
}
closedir(dir);
return res;
}
bool FATStorage::Build(const char* sourcedir, u64 size, const char* filename) bool FATStorage::Build(const char* sourcedir, u64 size, const char* filename)
{ {
filesize = size; filesize = size;
@ -110,7 +187,7 @@ bool FATStorage::Build(const char* sourcedir, u64 size, const char* filename)
res = f_mkfs("0:", &fsopt, workbuf, sizeof(workbuf)); res = f_mkfs("0:", &fsopt, workbuf, sizeof(workbuf));
printf("MKFS RES %d\n", res); printf("MKFS RES %d\n", res);
// BuildSubdirectory(sourcedir, "", 0);
ff_disk_close(); ff_disk_close();
fclose(FF_File); fclose(FF_File);

View File

@ -40,6 +40,7 @@ private:
static UINT FF_ReadStorage(BYTE* buf, LBA_t sector, UINT num); static UINT FF_ReadStorage(BYTE* buf, LBA_t sector, UINT num);
static UINT FF_WriteStorage(BYTE* buf, LBA_t sector, UINT num); static UINT FF_WriteStorage(BYTE* buf, LBA_t sector, UINT num);
bool BuildSubdirectory(const char* sourcedir, const char* path, int level);
bool Build(const char* sourcedir, u64 size, const char* filename); bool Build(const char* sourcedir, u64 size, const char* filename);
}; };

View File

@ -1664,7 +1664,7 @@ static FRESULT dir_clear ( /* Returns FR_OK or FR_DISK_ERR */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static FRESULT dir_sdi ( /* FR_OK(0):succeeded, !=0:error */ static FRESULT dir_sdi ( /* FR_OK(0):succeeded, !=0:error */
DIR* dp, /* Pointer to directory object */ fDIR* dp, /* Pointer to directory object */
DWORD ofs /* Offset of directory table */ DWORD ofs /* Offset of directory table */
) )
{ {
@ -1712,7 +1712,7 @@ static FRESULT dir_sdi ( /* FR_OK(0):succeeded, !=0:error */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static FRESULT dir_next ( /* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DENIED:Could not stretch */ static FRESULT dir_next ( /* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DENIED:Could not stretch */
DIR* dp, /* Pointer to the directory object */ fDIR* dp, /* Pointer to the directory object */
int stretch /* 0: Do not stretch table, 1: Stretch table if needed */ int stretch /* 0: Do not stretch table, 1: Stretch table if needed */
) )
{ {
@ -1773,7 +1773,7 @@ static FRESULT dir_next ( /* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DEN
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static FRESULT dir_alloc ( /* FR_OK(0):succeeded, !=0:error */ static FRESULT dir_alloc ( /* FR_OK(0):succeeded, !=0:error */
DIR* dp, /* Pointer to the directory object */ fDIR* dp, /* Pointer to the directory object */
UINT n_ent /* Number of contiguous entries to allocate */ UINT n_ent /* Number of contiguous entries to allocate */
) )
{ {
@ -2273,7 +2273,7 @@ static void create_xdir (
#define DIR_READ_LABEL(dp) dir_read(dp, 1) #define DIR_READ_LABEL(dp) dir_read(dp, 1)
static FRESULT dir_read ( static FRESULT dir_read (
DIR* dp, /* Pointer to the directory object */ fDIR* dp, /* Pointer to the directory object */
int vol /* Filtered by 0:file/directory or 1:volume label */ int vol /* Filtered by 0:file/directory or 1:volume label */
) )
{ {
@ -2351,7 +2351,7 @@ static FRESULT dir_read (
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */
DIR* dp /* Pointer to the directory object with the file name */ fDIR* dp /* Pointer to the directory object with the file name */
) )
{ {
FRESULT res; FRESULT res;
@ -2432,7 +2432,7 @@ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too many SFN collision, FR_DISK_ERR:disk error */ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too many SFN collision, FR_DISK_ERR:disk error */
DIR* dp /* Target directory with object name to be created */ fDIR* dp /* Target directory with object name to be created */
) )
{ {
FRESULT res; FRESULT res;
@ -2538,7 +2538,7 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static FRESULT dir_remove ( /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */ static FRESULT dir_remove ( /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */
DIR* dp /* Directory object pointing the entry to be removed */ fDIR* dp /* Directory object pointing the entry to be removed */
) )
{ {
FRESULT res; FRESULT res;
@ -2584,7 +2584,7 @@ static FRESULT dir_remove ( /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static void get_fileinfo ( static void get_fileinfo (
DIR* dp, /* Pointer to the directory object */ fDIR* dp, /* Pointer to the directory object */
FILINFO* fno /* Pointer to the file information to be filled */ FILINFO* fno /* Pointer to the file information to be filled */
) )
{ {
@ -2799,7 +2799,7 @@ static int pattern_match ( /* 0:mismatched, 1:matched */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create */ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create */
DIR* dp, /* Pointer to the directory object */ fDIR* dp, /* Pointer to the directory object */
const TCHAR** path /* Pointer to pointer to the segment in the path string */ const TCHAR** path /* Pointer to pointer to the segment in the path string */
) )
{ {
@ -3001,7 +3001,7 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */
DIR* dp, /* Directory object to return last directory and found object */ fDIR* dp, /* Directory object to return last directory and found object */
const TCHAR* path /* Full-path string to find a file or directory */ const TCHAR* path /* Full-path string to find a file or directory */
) )
{ {
@ -3657,7 +3657,7 @@ FRESULT f_open (
) )
{ {
FRESULT res; FRESULT res;
DIR dj; fDIR dj;
FATFS *fs; FATFS *fs;
#if !FF_FS_READONLY #if !FF_FS_READONLY
DWORD cl, bcs, clst, tm; DWORD cl, bcs, clst, tm;
@ -4529,7 +4529,7 @@ FRESULT f_lseek (
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
FRESULT f_opendir ( FRESULT f_opendir (
DIR* dp, /* Pointer to directory object to create */ fDIR* dp, /* Pointer to directory object to create */
const TCHAR* path /* Pointer to the directory path */ const TCHAR* path /* Pointer to the directory path */
) )
{ {
@ -4595,7 +4595,7 @@ FRESULT f_opendir (
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
FRESULT f_closedir ( FRESULT f_closedir (
DIR *dp /* Pointer to the directory object to be closed */ fDIR *dp /* Pointer to the directory object to be closed */
) )
{ {
FRESULT res; FRESULT res;
@ -4625,7 +4625,7 @@ FRESULT f_closedir (
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
FRESULT f_readdir ( FRESULT f_readdir (
DIR* dp, /* Pointer to the open directory object */ fDIR* dp, /* Pointer to the open directory object */
FILINFO* fno /* Pointer to file information to return */ FILINFO* fno /* Pointer to file information to return */
) )
{ {
@ -4661,7 +4661,7 @@ FRESULT f_readdir (
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
FRESULT f_findnext ( FRESULT f_findnext (
DIR* dp, /* Pointer to the open directory object */ fDIR* dp, /* Pointer to the open directory object */
FILINFO* fno /* Pointer to the file information structure */ FILINFO* fno /* Pointer to the file information structure */
) )
{ {
@ -4686,7 +4686,7 @@ FRESULT f_findnext (
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
FRESULT f_findfirst ( FRESULT f_findfirst (
DIR* dp, /* Pointer to the blank directory object */ fDIR* dp, /* Pointer to the blank directory object */
FILINFO* fno, /* Pointer to the file information structure */ FILINFO* fno, /* Pointer to the file information structure */
const TCHAR* path, /* Pointer to the directory to open */ const TCHAR* path, /* Pointer to the directory to open */
const TCHAR* pattern /* Pointer to the matching pattern */ const TCHAR* pattern /* Pointer to the matching pattern */
@ -4718,7 +4718,7 @@ FRESULT f_stat (
) )
{ {
FRESULT res; FRESULT res;
DIR dj; fDIR dj;
DEF_NAMBUF DEF_NAMBUF
@ -4894,7 +4894,7 @@ FRESULT f_unlink (
) )
{ {
FRESULT res; FRESULT res;
DIR dj, sdj; fDIR dj, sdj;
DWORD dclst = 0; DWORD dclst = 0;
FATFS *fs; FATFS *fs;
#if FF_FS_EXFAT #if FF_FS_EXFAT
@ -4988,7 +4988,7 @@ FRESULT f_mkdir (
) )
{ {
FRESULT res; FRESULT res;
DIR dj; fDIR dj;
FFOBJID sobj; FFOBJID sobj;
FATFS *fs; FATFS *fs;
DWORD dcl, pcl, tm; DWORD dcl, pcl, tm;
@ -5073,7 +5073,7 @@ FRESULT f_rename (
) )
{ {
FRESULT res; FRESULT res;
DIR djo, djn; fDIR djo, djn;
FATFS *fs; FATFS *fs;
BYTE buf[FF_FS_EXFAT ? SZDIRE * 2 : SZDIRE], *dir; BYTE buf[FF_FS_EXFAT ? SZDIRE * 2 : SZDIRE], *dir;
LBA_t sect; LBA_t sect;
@ -5121,7 +5121,7 @@ FRESULT f_rename (
#endif #endif
{ /* At FAT/FAT32 volume */ { /* At FAT/FAT32 volume */
memcpy(buf, djo.dir, SZDIRE); /* Save directory entry of the object */ memcpy(buf, djo.dir, SZDIRE); /* Save directory entry of the object */
memcpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */ memcpy(&djn, &djo, sizeof (fDIR)); /* Duplicate the directory object */
res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */ res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */
if (res == FR_OK) { /* Is new name already in use by any other object? */ if (res == FR_OK) { /* Is new name already in use by any other object? */
res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST; res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST;
@ -5184,7 +5184,7 @@ FRESULT f_chmod (
) )
{ {
FRESULT res; FRESULT res;
DIR dj; fDIR dj;
FATFS *fs; FATFS *fs;
DEF_NAMBUF DEF_NAMBUF
@ -5230,7 +5230,7 @@ FRESULT f_utime (
) )
{ {
FRESULT res; FRESULT res;
DIR dj; fDIR dj;
FATFS *fs; FATFS *fs;
DEF_NAMBUF DEF_NAMBUF

View File

@ -238,7 +238,7 @@ typedef struct {
#if FF_USE_FIND #if FF_USE_FIND
const TCHAR* pat; /* Pointer to the name matching pattern */ const TCHAR* pat; /* Pointer to the name matching pattern */
#endif #endif
} DIR; } fDIR;
@ -308,11 +308,11 @@ FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data t
FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */ FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */
FRESULT f_truncate (FIL* fp); /* Truncate the file */ FRESULT f_truncate (FIL* fp); /* Truncate the file */
FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */ FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */ FRESULT f_opendir (fDIR* dp, const TCHAR* path); /* Open a directory */
FRESULT f_closedir (DIR* dp); /* Close an open directory */ FRESULT f_closedir (fDIR* dp); /* Close an open directory */
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */ FRESULT f_readdir (fDIR* dp, FILINFO* fno); /* Read a directory item */
FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */ FRESULT f_findfirst (fDIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */ FRESULT f_findnext (fDIR* dp, FILINFO* fno); /* Find next file */
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */ FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */ FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */ FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */