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})
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)
target_link_libraries(core ${EPOXY_LIBRARIES})
else()
@ -129,7 +129,7 @@ if (ENABLE_OGLRENDERER)
endif()
else()
if (WIN32)
target_link_libraries(core ole32 comctl32 ws2_32)
target_link_libraries(core ole32 comctl32 ws2_32 shlwapi)
else()
target_link_libraries(core rt)
endif()

View File

@ -557,7 +557,7 @@ void PatchTSC()
void debug_listfiles(const char* path)
{
DIR dir;
fDIR dir;
FILINFO info;
FRESULT res;
@ -677,7 +677,7 @@ void RemoveFile(const char* path)
void RemoveDir(const char* path)
{
DIR dir;
fDIR dir;
FILINFO info;
FRESULT res;
@ -752,7 +752,7 @@ u32 GetTitleVersion(u32 category, u32 titleid)
void ListTitles(u32 category, std::vector<u32>& titlelist)
{
FRESULT res;
DIR titledir;
fDIR titledir;
char path[256];
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);
FRESULT res;
DIR ticketdir;
fDIR ticketdir;
FILINFO info;
char fname[128];

View File

@ -16,10 +16,31 @@
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 "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()
{
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)
{
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));
printf("MKFS RES %d\n", res);
//
BuildSubdirectory(sourcedir, "", 0);
ff_disk_close();
fclose(FF_File);

View File

@ -40,6 +40,7 @@ private:
static UINT FF_ReadStorage(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);
};

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 */
DIR* dp, /* Pointer to directory object */
fDIR* dp, /* Pointer to directory object */
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 */
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 */
)
{
@ -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 */
DIR* dp, /* Pointer to the directory object */
fDIR* dp, /* Pointer to the directory object */
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)
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 */
)
{
@ -2351,7 +2351,7 @@ static FRESULT dir_read (
/*-----------------------------------------------------------------------*/
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;
@ -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 */
DIR* dp /* Target directory with object name to be created */
fDIR* dp /* Target directory with object name to be created */
)
{
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 */
DIR* dp /* Directory object pointing the entry to be removed */
fDIR* dp /* Directory object pointing the entry to be removed */
)
{
FRESULT res;
@ -2584,7 +2584,7 @@ static FRESULT dir_remove ( /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */
/*-----------------------------------------------------------------------*/
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 */
)
{
@ -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 */
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 */
)
{
@ -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 */
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 */
)
{
@ -3657,7 +3657,7 @@ FRESULT f_open (
)
{
FRESULT res;
DIR dj;
fDIR dj;
FATFS *fs;
#if !FF_FS_READONLY
DWORD cl, bcs, clst, tm;
@ -4529,7 +4529,7 @@ FRESULT f_lseek (
/*-----------------------------------------------------------------------*/
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 */
)
{
@ -4595,7 +4595,7 @@ FRESULT f_opendir (
/*-----------------------------------------------------------------------*/
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;
@ -4625,7 +4625,7 @@ FRESULT f_closedir (
/*-----------------------------------------------------------------------*/
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 */
)
{
@ -4661,7 +4661,7 @@ FRESULT f_readdir (
/*-----------------------------------------------------------------------*/
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 */
)
{
@ -4686,7 +4686,7 @@ FRESULT f_findnext (
/*-----------------------------------------------------------------------*/
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 */
const TCHAR* path, /* Pointer to the directory to open */
const TCHAR* pattern /* Pointer to the matching pattern */
@ -4718,7 +4718,7 @@ FRESULT f_stat (
)
{
FRESULT res;
DIR dj;
fDIR dj;
DEF_NAMBUF
@ -4894,7 +4894,7 @@ FRESULT f_unlink (
)
{
FRESULT res;
DIR dj, sdj;
fDIR dj, sdj;
DWORD dclst = 0;
FATFS *fs;
#if FF_FS_EXFAT
@ -4988,7 +4988,7 @@ FRESULT f_mkdir (
)
{
FRESULT res;
DIR dj;
fDIR dj;
FFOBJID sobj;
FATFS *fs;
DWORD dcl, pcl, tm;
@ -5073,7 +5073,7 @@ FRESULT f_rename (
)
{
FRESULT res;
DIR djo, djn;
fDIR djo, djn;
FATFS *fs;
BYTE buf[FF_FS_EXFAT ? SZDIRE * 2 : SZDIRE], *dir;
LBA_t sect;
@ -5121,7 +5121,7 @@ FRESULT f_rename (
#endif
{ /* At FAT/FAT32 volume */
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 */
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;
@ -5184,7 +5184,7 @@ FRESULT f_chmod (
)
{
FRESULT res;
DIR dj;
fDIR dj;
FATFS *fs;
DEF_NAMBUF
@ -5230,7 +5230,7 @@ FRESULT f_utime (
)
{
FRESULT res;
DIR dj;
fDIR dj;
FATFS *fs;
DEF_NAMBUF

View File

@ -238,7 +238,7 @@ typedef struct {
#if FF_USE_FIND
const TCHAR* pat; /* Pointer to the name matching pattern */
#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_truncate (FIL* fp); /* Truncate the 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_closedir (DIR* dp); /* Close an open directory */
FRESULT f_readdir (DIR* 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_findnext (DIR* dp, FILINFO* fno); /* Find next file */
FRESULT f_opendir (fDIR* dp, const TCHAR* path); /* Open a directory */
FRESULT f_closedir (fDIR* dp); /* Close an open directory */
FRESULT f_readdir (fDIR* dp, FILINFO* fno); /* Read a directory item */
FRESULT f_findfirst (fDIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
FRESULT f_findnext (fDIR* dp, FILINFO* fno); /* Find next file */
FRESULT f_mkdir (const TCHAR* path); /* Create a sub 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 */