21 changes: 21 additions & 0 deletions Externals/FatFs/00readme.txt
@@ -0,0 +1,21 @@
FatFs Module Source Files R0.14b


FILES

00readme.txt This file.
00history.txt Revision history.
ff.c FatFs module.
ffconf.h Configuration file of FatFs module.
ff.h Common include file for FatFs and application module.
diskio.h Common include file for FatFs and disk I/O module.
diskio.c An example of glue function to attach existing disk I/O module to FatFs.
ffunicode.c Optional Unicode utility functions.
ffsystem.c An example of optional O/S related functions.


Low level disk I/O module is not included in this archive because the FatFs
module is only a generic file system layer and it does not depend on any specific
storage device. You need to provide a low level disk I/O module written to
control the storage device that attached to the target system.

12 changes: 12 additions & 0 deletions Externals/FatFs/CMakeLists.txt
@@ -0,0 +1,12 @@
add_library(FatFs STATIC
ff.c
ffunicode.c
diskio.h
ff.h
ffconf.h
)

target_include_directories(FatFs
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
33 changes: 33 additions & 0 deletions Externals/FatFs/FatFs.vcxproj
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\Source\VSProps\Base.Macros.props" />
<Import Project="$(VSPropsDir)Base.Targets.props" />
<PropertyGroup Label="Globals">
<ProjectGuid>{3F17D282-A77D-4931-B844-903AD0809A5E}</ProjectGuid>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VSPropsDir)Configuration.StaticLibrary.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VSPropsDir)Base.props" />
<Import Project="$(VSPropsDir)ClDisableAllWarnings.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemGroup>
<ClCompile Include="ff.c" />
<ClCompile Include="ffunicode.c" />
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="diskio.h" />
<ClInclude Include="ff.h" />
<ClInclude Include="ffconf.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
24 changes: 24 additions & 0 deletions Externals/FatFs/LICENSE.txt
@@ -0,0 +1,24 @@
FatFs License

FatFs has being developped as a personal project of the author, ChaN. It is free from the code anyone else wrote at current release. Following code block shows a copy of the FatFs license document that heading the source files.

/*----------------------------------------------------------------------------/
/ FatFs - Generic FAT Filesystem Module Rx.xx /
/-----------------------------------------------------------------------------/
/
/ Copyright (C) 20xx, ChaN, all right reserved.
/
/ FatFs module is an open source software. Redistribution and use of FatFs in
/ source and binary forms, with or without modification, are permitted provided
/ that the following condition is met:
/
/ 1. Redistributions of source code must retain the above copyright notice,
/ this condition and the following disclaimer.
/
/ This software is provided by the copyright holder and contributors "AS IS"
/ and any warranties related to this software are DISCLAIMED.
/ The copyright owner or contributors be NOT LIABLE for any damages caused
/ by use of this software.
/----------------------------------------------------------------------------*/

Therefore FatFs license is one of the BSD-style licenses, but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, do not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses include GNU GPL. When you redistribute the FatFs source code with changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that not conflict with FatFs license.
229 changes: 229 additions & 0 deletions Externals/FatFs/diskio.c
@@ -0,0 +1,229 @@
/*-----------------------------------------------------------------------*/
/* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */
/*-----------------------------------------------------------------------*/
/* If a working storage control module is available, it should be */
/* attached to the FatFs via a glue function rather than modifying it. */
/* This is an example of glue functions to attach various exsisting */
/* storage control modules to the FatFs module with a defined API. */
/*-----------------------------------------------------------------------*/

#include "ff.h" /* Obtains integer types */
#include "diskio.h" /* Declarations of disk functions */

/* Definitions of physical drive number for each drive */
#define DEV_RAM 0 /* Example: Map Ramdisk to physical drive 0 */
#define DEV_MMC 1 /* Example: Map MMC/SD card to physical drive 1 */
#define DEV_USB 2 /* Example: Map USB MSD to physical drive 2 */


/*-----------------------------------------------------------------------*/
/* Get Drive Status */
/*-----------------------------------------------------------------------*/

DSTATUS disk_status (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
DSTATUS stat;
int result;

switch (pdrv) {
case DEV_RAM :
result = RAM_disk_status();

// translate the reslut code here

return stat;

case DEV_MMC :
result = MMC_disk_status();

// translate the reslut code here

return stat;

case DEV_USB :
result = USB_disk_status();

// translate the reslut code here

return stat;
}
return STA_NOINIT;
}



/*-----------------------------------------------------------------------*/
/* Inidialize a Drive */
/*-----------------------------------------------------------------------*/

DSTATUS disk_initialize (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
DSTATUS stat;
int result;

switch (pdrv) {
case DEV_RAM :
result = RAM_disk_initialize();

// translate the reslut code here

return stat;

case DEV_MMC :
result = MMC_disk_initialize();

// translate the reslut code here

return stat;

case DEV_USB :
result = USB_disk_initialize();

// translate the reslut code here

return stat;
}
return STA_NOINIT;
}



/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
/*-----------------------------------------------------------------------*/

DRESULT disk_read (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
BYTE *buff, /* Data buffer to store read data */
LBA_t sector, /* Start sector in LBA */
UINT count /* Number of sectors to read */
)
{
DRESULT res;
int result;

switch (pdrv) {
case DEV_RAM :
// translate the arguments here

result = RAM_disk_read(buff, sector, count);

// translate the reslut code here

return res;

case DEV_MMC :
// translate the arguments here

result = MMC_disk_read(buff, sector, count);

// translate the reslut code here

return res;

case DEV_USB :
// translate the arguments here

result = USB_disk_read(buff, sector, count);

// translate the reslut code here

return res;
}

return RES_PARERR;
}



/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/

#if FF_FS_READONLY == 0

DRESULT disk_write (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
const BYTE *buff, /* Data to be written */
LBA_t sector, /* Start sector in LBA */
UINT count /* Number of sectors to write */
)
{
DRESULT res;
int result;

switch (pdrv) {
case DEV_RAM :
// translate the arguments here

result = RAM_disk_write(buff, sector, count);

// translate the reslut code here

return res;

case DEV_MMC :
// translate the arguments here

result = MMC_disk_write(buff, sector, count);

// translate the reslut code here

return res;

case DEV_USB :
// translate the arguments here

result = USB_disk_write(buff, sector, count);

// translate the reslut code here

return res;
}

return RES_PARERR;
}

#endif


/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/

DRESULT disk_ioctl (
BYTE pdrv, /* Physical drive nmuber (0..) */
BYTE cmd, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
DRESULT res;
int result;

switch (pdrv) {
case DEV_RAM :

// Process of the command for the RAM drive

return res;

case DEV_MMC :

// Process of the command for the MMC/SD card

return res;

case DEV_USB :

// Process of the command the USB drive

return res;
}

return RES_PARERR;
}

77 changes: 77 additions & 0 deletions Externals/FatFs/diskio.h
@@ -0,0 +1,77 @@
/*-----------------------------------------------------------------------/
/ Low level disk interface modlue include file (C)ChaN, 2019 /
/-----------------------------------------------------------------------*/

#ifndef _DISKIO_DEFINED
#define _DISKIO_DEFINED

#ifdef __cplusplus
extern "C" {
#endif

/* Status of Disk Functions */
typedef BYTE DSTATUS;

/* Results of Disk Functions */
typedef enum {
RES_OK = 0, /* 0: Successful */
RES_ERROR, /* 1: R/W Error */
RES_WRPRT, /* 2: Write Protected */
RES_NOTRDY, /* 3: Not Ready */
RES_PARERR /* 4: Invalid Parameter */
} DRESULT;


/*---------------------------------------*/
/* Prototypes for disk control functions */


DSTATUS disk_initialize (BYTE pdrv);
DSTATUS disk_status (BYTE pdrv);
DRESULT disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count);
DRESULT disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count);
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);


/* Disk Status Bits (DSTATUS) */

#define STA_NOINIT 0x01 /* Drive not initialized */
#define STA_NODISK 0x02 /* No medium in the drive */
#define STA_PROTECT 0x04 /* Write protected */


/* Command code for disk_ioctrl fucntion */

/* Generic command (Used by FatFs) */
#define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */
#define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */

/* Generic command (Not used by FatFs) */
#define CTRL_POWER 5 /* Get/Set power status */
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
#define CTRL_EJECT 7 /* Eject media */
#define CTRL_FORMAT 8 /* Create physical format on the media */

/* MMC/SDC specific ioctl command */
#define MMC_GET_TYPE 10 /* Get card type */
#define MMC_GET_CSD 11 /* Get CSD */
#define MMC_GET_CID 12 /* Get CID */
#define MMC_GET_OCR 13 /* Get OCR */
#define MMC_GET_SDSTAT 14 /* Get SD status */
#define ISDIO_READ 55 /* Read data form SD iSDIO register */
#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */

/* ATA/CF specific ioctl command */
#define ATA_GET_REV 20 /* Get F/W revision */
#define ATA_GET_MODEL 21 /* Get model name */
#define ATA_GET_SN 22 /* Get serial number */

#ifdef __cplusplus
}
#endif

#endif
6,982 changes: 6,982 additions & 0 deletions Externals/FatFs/ff.c

Large diffs are not rendered by default.

422 changes: 422 additions & 0 deletions Externals/FatFs/ff.h

Large diffs are not rendered by default.

301 changes: 301 additions & 0 deletions Externals/FatFs/ffconf.h
@@ -0,0 +1,301 @@
/*---------------------------------------------------------------------------/
/ FatFs Functional Configurations
/---------------------------------------------------------------------------*/

#define FFCONF_DEF 86631 /* Revision ID */

/*---------------------------------------------------------------------------/
/ Function Configurations
/---------------------------------------------------------------------------*/

#define FF_FS_READONLY 0
/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
/ Read-only configuration removes writing API functions, f_write(), f_sync(),
/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
/ and optional writing functions as well. */


#define FF_FS_MINIMIZE 0
/* This option defines minimization level to remove some basic API functions.
/
/ 0: Basic functions are fully enabled.
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
/ are removed.
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
/ 3: f_lseek() function is removed in addition to 2. */


#define FF_USE_FIND 0
/* This option switches filtered directory read functions, f_findfirst() and
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */


#define FF_USE_MKFS 1
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */


#define FF_USE_FASTSEEK 0
/* This option switches fast seek function. (0:Disable or 1:Enable) */


#define FF_USE_EXPAND 0
/* This option switches f_expand function. (0:Disable or 1:Enable) */


#define FF_USE_CHMOD 1
/* This option switches attribute manipulation functions, f_chmod() and f_utime().
/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */


#define FF_USE_LABEL 0
/* This option switches volume label functions, f_getlabel() and f_setlabel().
/ (0:Disable or 1:Enable) */


#define FF_USE_FORWARD 0
/* This option switches f_forward() function. (0:Disable or 1:Enable) */


#define FF_USE_STRFUNC 0
#define FF_PRINT_LLI 0
#define FF_PRINT_FLOAT 0
#define FF_STRF_ENCODE 0
/* FF_USE_STRFUNC switches string functions, f_gets(), f_putc(), f_puts() and
/ f_printf().
/
/ 0: Disable. FF_PRINT_LLI, FF_PRINT_FLOAT and FF_STRF_ENCODE have no effect.
/ 1: Enable without LF-CRLF conversion.
/ 2: Enable with LF-CRLF conversion.
/
/ FF_PRINT_LLI = 1 makes f_printf() support long long argument and FF_PRINT_FLOAT = 1/2
makes f_printf() support floating point argument. These features want C99 or later.
/ When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character
/ encoding in it. FF_STRF_ENCODE selects assumption of character encoding ON THE FILE
/ to be read/written via those functions.
/
/ 0: ANSI/OEM in current CP
/ 1: Unicode in UTF-16LE
/ 2: Unicode in UTF-16BE
/ 3: Unicode in UTF-8
*/


/*---------------------------------------------------------------------------/
/ Locale and Namespace Configurations
/---------------------------------------------------------------------------*/

#define FF_CODE_PAGE 932
/* This option specifies the OEM code page to be used on the target system.
/ Incorrect code page setting can cause a file open failure.
/
/ 437 - U.S.
/ 720 - Arabic
/ 737 - Greek
/ 771 - KBL
/ 775 - Baltic
/ 850 - Latin 1
/ 852 - Latin 2
/ 855 - Cyrillic
/ 857 - Turkish
/ 860 - Portuguese
/ 861 - Icelandic
/ 862 - Hebrew
/ 863 - Canadian French
/ 864 - Arabic
/ 865 - Nordic
/ 866 - Russian
/ 869 - Greek 2
/ 932 - Japanese (DBCS)
/ 936 - Simplified Chinese (DBCS)
/ 949 - Korean (DBCS)
/ 950 - Traditional Chinese (DBCS)
/ 0 - Include all code pages above and configured by f_setcp()
*/


#define FF_USE_LFN 2
#define FF_MAX_LFN 255
/* The FF_USE_LFN switches the support for LFN (long file name).
/
/ 0: Disable LFN. FF_MAX_LFN has no effect.
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
/ 2: Enable LFN with dynamic working buffer on the STACK.
/ 3: Enable LFN with dynamic working buffer on the HEAP.
/
/ To enable the LFN, ffunicode.c needs to be added to the project. The LFN function
/ requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and
/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.
/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can
/ be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN
/ specification.
/ When use stack for the working buffer, take care on stack overflow. When use heap
/ memory for the working buffer, memory management functions, ff_memalloc() and
/ ff_memfree() exemplified in ffsystem.c, need to be added to the project. */


#define FF_LFN_UNICODE 2
/* This option switches the character encoding on the API when LFN is enabled.
/
/ 0: ANSI/OEM in current CP (TCHAR = char)
/ 1: Unicode in UTF-16 (TCHAR = WCHAR)
/ 2: Unicode in UTF-8 (TCHAR = char)
/ 3: Unicode in UTF-32 (TCHAR = DWORD)
/
/ Also behavior of string I/O functions will be affected by this option.
/ When LFN is not enabled, this option has no effect. */


#define FF_LFN_BUF 255
#define FF_SFN_BUF 12
/* This set of options defines size of file name members in the FILINFO structure
/ which is used to read out directory items. These values should be suffcient for
/ the file names to read. The maximum possible length of the read file name depends
/ on character encoding. When LFN is not enabled, these options have no effect. */


#define FF_FS_RPATH 1
/* This option configures support for relative path.
/
/ 0: Disable relative path and remove related functions.
/ 1: Enable relative path. f_chdir() and f_chdrive() are available.
/ 2: f_getcwd() function is available in addition to 1.
*/


/*---------------------------------------------------------------------------/
/ Drive/Volume Configurations
/---------------------------------------------------------------------------*/

#define FF_VOLUMES 1
/* Number of volumes (logical drives) to be used. (1-10) */


#define FF_STR_VOLUME_ID 0
#define FF_VOLUME_STRS "fat"
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each
/ logical drives. Number of items must not be less than FF_VOLUMES. Valid
/ characters for the volume ID strings are A-Z, a-z and 0-9, however, they are
/ compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is
/ not defined, a user defined volume string table needs to be defined as:
/
/ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",...
*/


#define FF_MULTI_PARTITION 0
/* This option switches support for multiple volumes on the physical drive.
/ By default (0), each logical drive number is bound to the same physical drive
/ number and only an FAT volume found on the physical drive will be mounted.
/ When this function is enabled (1), each logical drive number can be bound to
/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
/ funciton will be available. */


#define FF_MIN_SS 512
#define FF_MAX_SS 512
/* This set of options configures the range of sector size to be supported. (512,
/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
/ harddisk, but a larger value may be required for on-board flash memory and some
/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured
/ for variable sector size mode and disk_ioctl() function needs to implement
/ GET_SECTOR_SIZE command. */


#define FF_LBA64 0
/* This option switches support for 64-bit LBA. (0:Disable or 1:Enable)
/ To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */


#define FF_MIN_GPT 0x10000000
/* Minimum number of sectors to switch GPT as partitioning format in f_mkfs and
/ f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */


#define FF_USE_TRIM 0
/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
/ To enable Trim function, also CTRL_TRIM command should be implemented to the
/ disk_ioctl() function. */



/*---------------------------------------------------------------------------/
/ System Configurations
/---------------------------------------------------------------------------*/

#define FF_FS_TINY 0
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes.
/ Instead of private sector buffer eliminated from the file object, common sector
/ buffer in the filesystem object (FATFS) is used for the file data transfer. */


#define FF_FS_EXFAT 0
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */


#define FF_FS_NORTC 0
#define FF_NORTC_MON 1
#define FF_NORTC_MDAY 1
#define FF_NORTC_YEAR 2020
/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have
/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable
/ the timestamp function. Every object modified by FatFs will have a fixed timestamp
/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time.
/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
/ added to the project to read current time form real-time clock. FF_NORTC_MON,
/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect.
/ These options have no effect in read-only configuration (FF_FS_READONLY = 1). */


#define FF_FS_NOFSINFO 0
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
/ option, and f_getfree() function at first time after volume mount will force
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
/
/ bit0=0: Use free cluster count in the FSINFO if available.
/ bit0=1: Do not trust free cluster count in the FSINFO.
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
*/


#define FF_FS_LOCK 0
/* The option FF_FS_LOCK switches file lock function to control duplicated file open
/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY
/ is 1.
/
/ 0: Disable file lock function. To avoid volume corruption, application program
/ should avoid illegal open, remove and rename to the open objects.
/ >0: Enable file lock function. The value defines how many files/sub-directories
/ can be opened simultaneously under file lock control. Note that the file
/ lock control is independent of re-entrancy. */


/* #include <somertos.h> // O/S definitions */
#define FF_FS_REENTRANT 0
#define FF_FS_TIMEOUT 1000
#define FF_SYNC_t void*
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
/ module itself. Note that regardless of this option, file access to different
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
/ and f_fdisk() function, are always not re-entrant. Only file/directory access
/ to the same volume is under control of this function.
/
/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect.
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
/ function, must be added to the project. Samples are available in
/ option/syscall.c.
/
/ The FF_FS_TIMEOUT defines timeout period in unit of time tick.
/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
/ included somewhere in the scope of ff.h. */



/*--- End of configuration options ---*/
170 changes: 170 additions & 0 deletions Externals/FatFs/ffsystem.c
@@ -0,0 +1,170 @@
/*------------------------------------------------------------------------*/
/* Sample Code of OS Dependent Functions for FatFs */
/* (C)ChaN, 2018 */
/*------------------------------------------------------------------------*/


#include "ff.h"


#if FF_USE_LFN == 3 /* Dynamic memory allocation */

/*------------------------------------------------------------------------*/
/* Allocate a memory block */
/*------------------------------------------------------------------------*/

void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
UINT msize /* Number of bytes to allocate */
)
{
return malloc(msize); /* Allocate a new memory block with POSIX API */
}


/*------------------------------------------------------------------------*/
/* Free a memory block */
/*------------------------------------------------------------------------*/

void ff_memfree (
void* mblock /* Pointer to the memory block to free (nothing to do if null) */
)
{
free(mblock); /* Free the memory block with POSIX API */
}

#endif



#if FF_FS_REENTRANT /* Mutal exclusion */

/*------------------------------------------------------------------------*/
/* Create a Synchronization Object */
/*------------------------------------------------------------------------*/
/* This function is called in f_mount() function to create a new
/ synchronization object for the volume, such as semaphore and mutex.
/ When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
*/

//const osMutexDef_t Mutex[FF_VOLUMES]; /* Table of CMSIS-RTOS mutex */


int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
BYTE vol, /* Corresponding volume (logical drive number) */
FF_SYNC_t* sobj /* Pointer to return the created sync object */
)
{
/* Win32 */
*sobj = CreateMutex(NULL, FALSE, NULL);
return (int)(*sobj != INVALID_HANDLE_VALUE);

/* uITRON */
// T_CSEM csem = {TA_TPRI,1,1};
// *sobj = acre_sem(&csem);
// return (int)(*sobj > 0);

/* uC/OS-II */
// OS_ERR err;
// *sobj = OSMutexCreate(0, &err);
// return (int)(err == OS_NO_ERR);

/* FreeRTOS */
// *sobj = xSemaphoreCreateMutex();
// return (int)(*sobj != NULL);

/* CMSIS-RTOS */
// *sobj = osMutexCreate(&Mutex[vol]);
// return (int)(*sobj != NULL);
}


/*------------------------------------------------------------------------*/
/* Delete a Synchronization Object */
/*------------------------------------------------------------------------*/
/* This function is called in f_mount() function to delete a synchronization
/ object that created with ff_cre_syncobj() function. When a 0 is returned,
/ the f_mount() function fails with FR_INT_ERR.
*/

int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */
FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
)
{
/* Win32 */
return (int)CloseHandle(sobj);

/* uITRON */
// return (int)(del_sem(sobj) == E_OK);

/* uC/OS-II */
// OS_ERR err;
// OSMutexDel(sobj, OS_DEL_ALWAYS, &err);
// return (int)(err == OS_NO_ERR);

/* FreeRTOS */
// vSemaphoreDelete(sobj);
// return 1;

/* CMSIS-RTOS */
// return (int)(osMutexDelete(sobj) == osOK);
}


/*------------------------------------------------------------------------*/
/* Request Grant to Access the Volume */
/*------------------------------------------------------------------------*/
/* This function is called on entering file functions to lock the volume.
/ When a 0 is returned, the file function fails with FR_TIMEOUT.
*/

int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
FF_SYNC_t sobj /* Sync object to wait */
)
{
/* Win32 */
return (int)(WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0);

/* uITRON */
// return (int)(wai_sem(sobj) == E_OK);

/* uC/OS-II */
// OS_ERR err;
// OSMutexPend(sobj, FF_FS_TIMEOUT, &err));
// return (int)(err == OS_NO_ERR);

/* FreeRTOS */
// return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);

/* CMSIS-RTOS */
// return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);
}


/*------------------------------------------------------------------------*/
/* Release Grant to Access the Volume */
/*------------------------------------------------------------------------*/
/* This function is called on leaving file functions to unlock the volume.
*/

void ff_rel_grant (
FF_SYNC_t sobj /* Sync object to be signaled */
)
{
/* Win32 */
ReleaseMutex(sobj);

/* uITRON */
// sig_sem(sobj);

/* uC/OS-II */
// OSMutexPost(sobj);

/* FreeRTOS */
// xSemaphoreGive(sobj);

/* CMSIS-RTOS */
// osMutexRelease(sobj);
}

#endif

15,593 changes: 15,593 additions & 0 deletions Externals/FatFs/ffunicode.c

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Externals/licenses.md
Expand Up @@ -14,6 +14,8 @@ Dolphin includes or links code of the following third-party software projects:
[MIT](https://github.com/discordapp/discord-rpc/blob/master/LICENSE)
- [ENet](http://enet.bespin.org/):
[MIT](http://enet.bespin.org/License.html)
- [FatFs](http://elm-chan.org/fsw/ff/00index_e.html):
[BSD-1-Clause](http://elm-chan.org/fsw/ff/doc/appnote.html#license)
- [GCEmu](http://sourceforge.net/projects/gcemu-project/):
GPLv2+
- [gettext](https://www.gnu.org/software/gettext/):
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Common/CMakeLists.txt
Expand Up @@ -44,6 +44,8 @@ add_library(common
EnumFormatter.h
EnumMap.h
Event.h
FatFsUtil.cpp
FatFsUtil.h
FileSearch.cpp
FileSearch.h
FileUtil.cpp
Expand Down Expand Up @@ -144,6 +146,7 @@ PUBLIC

PRIVATE
${CURL_LIBRARIES}
FatFs
${ICONV_LIBRARIES}
png
${VTUNE_LIBRARIES}
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Common/CommonPaths.h
Expand Up @@ -73,6 +73,7 @@
#define RESOURCEPACK_DIR "ResourcePacks"
#define DYNAMICINPUT_DIR "DynamicInputTextures"
#define GRAPHICSMOD_DIR "GraphicMods"
#define WIISDSYNC_DIR "WiiSDSync"

// This one is only used to remove it if it was present
#define SHADERCACHE_LEGACY_DIR "ShaderCache"
Expand Down Expand Up @@ -128,7 +129,7 @@

#define WII_STATE "state.dat"

#define WII_SDCARD "sd.raw"
#define WII_SD_CARD_IMAGE "WiiSD.raw"
#define WII_BTDINF_BACKUP "btdinf.bak"

#define WII_SETTING "setting.txt"
Expand Down
743 changes: 743 additions & 0 deletions Source/Core/Common/FatFsUtil.cpp

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions Source/Core/Common/FatFsUtil.h
@@ -0,0 +1,12 @@
// Copyright 2022 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "Common/CommonTypes.h"

namespace Common
{
bool SyncSDFolderToSDImage(bool deterministic);
bool SyncSDImageToSDFolder();
} // namespace Common
3 changes: 2 additions & 1 deletion Source/Core/Common/FileUtil.cpp
Expand Up @@ -978,6 +978,7 @@ static void RebuildUserDirectories(unsigned int dir_index)
s_user_paths[D_RESOURCEPACK_IDX] = s_user_paths[D_USER_IDX] + RESOURCEPACK_DIR DIR_SEP;
s_user_paths[D_DYNAMICINPUT_IDX] = s_user_paths[D_LOAD_IDX] + DYNAMICINPUT_DIR DIR_SEP;
s_user_paths[D_GRAPHICSMOD_IDX] = s_user_paths[D_LOAD_IDX] + GRAPHICSMOD_DIR DIR_SEP;
s_user_paths[D_WIISDCARDSYNCFOLDER_IDX] = s_user_paths[D_LOAD_IDX] + WIISDSYNC_DIR DIR_SEP;
s_user_paths[F_DOLPHINCONFIG_IDX] = s_user_paths[D_CONFIG_IDX] + DOLPHIN_CONFIG;
s_user_paths[F_GCPADCONFIG_IDX] = s_user_paths[D_CONFIG_IDX] + GCPAD_CONFIG;
s_user_paths[F_WIIPADCONFIG_IDX] = s_user_paths[D_CONFIG_IDX] + WIIPAD_CONFIG;
Expand All @@ -994,7 +995,7 @@ static void RebuildUserDirectories(unsigned int dir_index)
s_user_paths[F_ARAMDUMP_IDX] = s_user_paths[D_DUMP_IDX] + ARAM_DUMP;
s_user_paths[F_FAKEVMEMDUMP_IDX] = s_user_paths[D_DUMP_IDX] + FAKEVMEM_DUMP;
s_user_paths[F_GCSRAM_IDX] = s_user_paths[D_GCUSER_IDX] + GC_SRAM;
s_user_paths[F_WIISDCARD_IDX] = s_user_paths[D_WIIROOT_IDX] + WII_SDCARD;
s_user_paths[F_WIISDCARDIMAGE_IDX] = s_user_paths[D_LOAD_IDX] + WII_SD_CARD_IMAGE;

s_user_paths[D_MEMORYWATCHER_IDX] = s_user_paths[D_USER_IDX] + MEMORYWATCHER_DIR DIR_SEP;
s_user_paths[F_MEMORYWATCHERLOCATIONS_IDX] =
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Common/FileUtil.h
Expand Up @@ -63,6 +63,7 @@ enum
D_GRAPHICSMOD_IDX,
D_GBAUSER_IDX,
D_GBASAVES_IDX,
D_WIISDCARDSYNCFOLDER_IDX,
FIRST_FILE_USER_PATH_IDX,
F_DOLPHINCONFIG_IDX = FIRST_FILE_USER_PATH_IDX,
F_GCPADCONFIG_IDX,
Expand All @@ -79,7 +80,7 @@ enum
F_GCSRAM_IDX,
F_MEMORYWATCHERLOCATIONS_IDX,
F_MEMORYWATCHERSOCKET_IDX,
F_WIISDCARD_IDX,
F_WIISDCARDIMAGE_IDX,
F_DUALSHOCKUDPCLIENTCONFIG_IDX,
F_FREELOOKCONFIG_IDX,
F_GBABIOS_IDX,
Expand Down
6 changes: 5 additions & 1 deletion Source/Core/Core/Config/MainSettings.cpp
Expand Up @@ -159,6 +159,8 @@ const Info<bool>& GetInfoForSimulateKonga(int channel)
}

const Info<bool> MAIN_WII_SD_CARD{{System::Main, "Core", "WiiSDCard"}, true};
const Info<bool> MAIN_WII_SD_CARD_ENABLE_FOLDER_SYNC{
{System::Main, "Core", "WiiSDCardEnableFolderSync"}, false};
const Info<bool> MAIN_WII_KEYBOARD{{System::Main, "Core", "WiiKeyboard"}, false};
const Info<bool> MAIN_WIIMOTE_CONTINUOUS_SCANNING{
{System::Main, "Core", "WiimoteContinuousScanning"}, false};
Expand Down Expand Up @@ -268,7 +270,9 @@ const Info<std::string> MAIN_DUMP_PATH{{System::Main, "General", "DumpPath"}, ""
const Info<std::string> MAIN_LOAD_PATH{{System::Main, "General", "LoadPath"}, ""};
const Info<std::string> MAIN_RESOURCEPACK_PATH{{System::Main, "General", "ResourcePackPath"}, ""};
const Info<std::string> MAIN_FS_PATH{{System::Main, "General", "NANDRootPath"}, ""};
const Info<std::string> MAIN_SD_PATH{{System::Main, "General", "WiiSDCardPath"}, ""};
const Info<std::string> MAIN_WII_SD_CARD_IMAGE_PATH{{System::Main, "General", "WiiSDCardPath"}, ""};
const Info<std::string> MAIN_WII_SD_CARD_SYNC_FOLDER_PATH{
{System::Main, "General", "WiiSDCardSyncFolder"}, ""};
const Info<std::string> MAIN_WFS_PATH{{System::Main, "General", "WFSPath"}, ""};
const Info<bool> MAIN_SHOW_LAG{{System::Main, "General", "ShowLag"}, false};
const Info<bool> MAIN_SHOW_FRAME_COUNT{{System::Main, "General", "ShowFrameCount"}, false};
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/Core/Config/MainSettings.h
Expand Up @@ -92,6 +92,7 @@ const Info<SerialInterface::SIDevices>& GetInfoForSIDevice(int channel);
const Info<bool>& GetInfoForAdapterRumble(int channel);
const Info<bool>& GetInfoForSimulateKonga(int channel);
extern const Info<bool> MAIN_WII_SD_CARD;
extern const Info<bool> MAIN_WII_SD_CARD_ENABLE_FOLDER_SYNC;
extern const Info<bool> MAIN_WII_KEYBOARD;
extern const Info<bool> MAIN_WIIMOTE_CONTINUOUS_SCANNING;
extern const Info<bool> MAIN_WIIMOTE_ENABLE_SPEAKER;
Expand Down Expand Up @@ -178,7 +179,8 @@ extern const Info<std::string> MAIN_DUMP_PATH;
extern const Info<std::string> MAIN_LOAD_PATH;
extern const Info<std::string> MAIN_RESOURCEPACK_PATH;
extern const Info<std::string> MAIN_FS_PATH;
extern const Info<std::string> MAIN_SD_PATH;
extern const Info<std::string> MAIN_WII_SD_CARD_IMAGE_PATH;
extern const Info<std::string> MAIN_WII_SD_CARD_SYNC_FOLDER_PATH;
extern const Info<std::string> MAIN_WFS_PATH;
extern const Info<bool> MAIN_SHOW_LAG;
extern const Info<bool> MAIN_SHOW_FRAME_COUNT;
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp
Expand Up @@ -110,6 +110,7 @@ bool IsSettingSaveable(const Config::Location& config_location)
&Config::MAIN_FASTMEM.GetLocation(),
&Config::MAIN_TIMING_VARIANCE.GetLocation(),
&Config::MAIN_WII_SD_CARD.GetLocation(),
&Config::MAIN_WII_SD_CARD_ENABLE_FOLDER_SYNC.GetLocation(),
&Config::MAIN_WII_KEYBOARD.GetLocation(),
&Config::MAIN_WIIMOTE_CONTINUOUS_SCANNING.GetLocation(),
&Config::MAIN_WIIMOTE_ENABLE_SPEAKER.GetLocation(),
Expand Down
11 changes: 11 additions & 0 deletions Source/Core/Core/Core.cpp
Expand Up @@ -25,6 +25,7 @@
#include "Common/CommonTypes.h"
#include "Common/Event.h"
#include "Common/FPURoundMode.h"
#include "Common/FatFsUtil.h"
#include "Common/FileUtil.h"
#include "Common/Flag.h"
#include "Common/Logging/Log.h"
Expand Down Expand Up @@ -495,6 +496,16 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
const bool delete_savestate =
boot_session_data.GetDeleteSavestate() == DeleteSavestateAfterBoot::Yes;

bool sync_sd_folder = core_parameter.bWii && Config::Get(Config::MAIN_WII_SD_CARD) &&
Config::Get(Config::MAIN_WII_SD_CARD_ENABLE_FOLDER_SYNC);
if (sync_sd_folder)
sync_sd_folder = Common::SyncSDFolderToSDImage(Core::WantsDeterminism());

Common::ScopeGuard sd_folder_sync_guard{[sync_sd_folder] {
if (sync_sd_folder && Config::Get(Config::MAIN_ALLOW_SD_WRITES))
Common::SyncSDImageToSDFolder();
}};

// Load and Init Wiimotes - only if we are booting in Wii mode
bool init_wiimotes = false;
if (core_parameter.bWii && !Config::Get(Config::MAIN_BLUETOOTH_PASSTHROUGH_ENABLED))
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp
Expand Up @@ -89,7 +89,7 @@ void SDIOSlot0Device::EventNotify()

void SDIOSlot0Device::OpenInternal()
{
const std::string filename = File::GetUserPath(F_WIISDCARD_IDX);
const std::string filename = File::GetUserPath(F_WIISDCARDIMAGE_IDX);
m_card.Open(filename, "r+b");
if (!m_card)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/NetPlayClient.cpp
Expand Up @@ -2479,7 +2479,7 @@ void NetPlayClient::ComputeMD5(const SyncIdentifier& sync_identifier)

std::string file;
if (sync_identifier == GetSDCardIdentifier())
file = File::GetUserPath(F_WIISDCARD_IDX);
file = File::GetUserPath(F_WIISDCARDIMAGE_IDX);
else if (auto game = m_dialog->FindGameFile(sync_identifier))
file = game->GetFilePath();

Expand Down
2 changes: 2 additions & 0 deletions Source/Core/DolphinLib.props
Expand Up @@ -45,6 +45,7 @@
<ClInclude Include="Common\EnumFormatter.h" />
<ClInclude Include="Common\EnumMap.h" />
<ClInclude Include="Common\Event.h" />
<ClInclude Include="Common\FatFsUtil.h" />
<ClInclude Include="Common\FileSearch.h" />
<ClInclude Include="Common\FileUtil.h" />
<ClInclude Include="Common\FixedSizeQueue.h" />
Expand Down Expand Up @@ -725,6 +726,7 @@
<ClCompile Include="Common\Debug\Watches.cpp" />
<ClCompile Include="Common\DynamicLibrary.cpp" />
<ClCompile Include="Common\ENetUtil.cpp" />
<ClCompile Include="Common\FatFsUtil.cpp" />
<ClCompile Include="Common\FileSearch.cpp" />
<ClCompile Include="Common\FileUtil.cpp" />
<ClCompile Include="Common\FloatUtils.cpp" />
Expand Down
32 changes: 3 additions & 29 deletions Source/Core/DolphinQt/Settings/PathPane.cpp
Expand Up @@ -99,19 +99,6 @@ void PathPane::BrowseResourcePack()
}
}

void PathPane::BrowseSDCard()
{
QString file = QDir::toNativeSeparators(DolphinFileDialog::getOpenFileName(
this, tr("Select a SD Card Image"), QString::fromStdString(Config::Get(Config::MAIN_SD_PATH)),
tr("SD Card Image (*.raw);;"
"All Files (*)")));
if (!file.isEmpty())
{
m_sdcard_edit->setText(file);
OnSDCardPathChanged();
}
}

void PathPane::BrowseWFS()
{
const QString dir = QDir::toNativeSeparators(DolphinFileDialog::getExistingDirectory(
Expand All @@ -123,11 +110,6 @@ void PathPane::BrowseWFS()
}
}

void PathPane::OnSDCardPathChanged()
{
Config::SetBase(Config::MAIN_SD_PATH, m_sdcard_edit->text().toStdString());
}

void PathPane::OnNANDPathChanged()
{
Config::SetBase(Config::MAIN_FS_PATH, m_nand_edit->text().toStdString());
Expand Down Expand Up @@ -241,22 +223,14 @@ QGridLayout* PathPane::MakePathsLayout()
layout->addWidget(m_resource_pack_edit, 4, 1);
layout->addWidget(resource_pack_open, 4, 2);

m_sdcard_edit = new QLineEdit(QString::fromStdString(File::GetUserPath(F_WIISDCARD_IDX)));
connect(m_sdcard_edit, &QLineEdit::editingFinished, this, &PathPane::OnSDCardPathChanged);
QPushButton* sdcard_open = new NonDefaultQPushButton(QStringLiteral("..."));
connect(sdcard_open, &QPushButton::clicked, this, &PathPane::BrowseSDCard);
layout->addWidget(new QLabel(tr("SD Card Path:")), 5, 0);
layout->addWidget(m_sdcard_edit, 5, 1);
layout->addWidget(sdcard_open, 5, 2);

m_wfs_edit = new QLineEdit(QString::fromStdString(File::GetUserPath(D_WFSROOT_IDX)));
connect(m_load_edit, &QLineEdit::editingFinished,
[=] { Config::SetBase(Config::MAIN_WFS_PATH, m_wfs_edit->text().toStdString()); });
QPushButton* wfs_open = new NonDefaultQPushButton(QStringLiteral("..."));
connect(wfs_open, &QPushButton::clicked, this, &PathPane::BrowseWFS);
layout->addWidget(new QLabel(tr("WFS Path:")), 6, 0);
layout->addWidget(m_wfs_edit, 6, 1);
layout->addWidget(wfs_open, 6, 2);
layout->addWidget(new QLabel(tr("WFS Path:")), 5, 0);
layout->addWidget(m_wfs_edit, 5, 1);
layout->addWidget(wfs_open, 5, 2);

return layout;
}
Expand Down
3 changes: 0 additions & 3 deletions Source/Core/DolphinQt/Settings/PathPane.h
Expand Up @@ -24,13 +24,11 @@ class PathPane final : public QWidget
void BrowseDump();
void BrowseLoad();
void BrowseResourcePack();
void BrowseSDCard();
void BrowseWFS();
QGroupBox* MakeGameFolderBox();
QGridLayout* MakePathsLayout();
void RemovePath();

void OnSDCardPathChanged();
void OnNANDPathChanged();

QListWidget* m_path_list;
Expand All @@ -39,7 +37,6 @@ class PathPane final : public QWidget
QLineEdit* m_dump_edit;
QLineEdit* m_load_edit;
QLineEdit* m_resource_pack_edit;
QLineEdit* m_sdcard_edit;
QLineEdit* m_wfs_edit;

QPushButton* m_remove_path;
Expand Down
165 changes: 147 additions & 18 deletions Source/Core/DolphinQt/Settings/WiiPane.cpp
Expand Up @@ -5,25 +5,32 @@

#include <QCheckBox>
#include <QComboBox>
#include <QDir>
#include <QGridLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QPushButton>
#include <QSlider>
#include <QSpacerItem>
#include <QStringList>

#include "Common/Config/Config.h"
#include "Common/FatFsUtil.h"
#include "Common/FileUtil.h"
#include "Common/StringUtil.h"

#include "Core/Config/MainSettings.h"
#include "Core/Config/SYSCONFSettings.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"

#include "DolphinQt/QtUtils/DolphinFileDialog.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/QtUtils/NonDefaultQPushButton.h"
#include "DolphinQt/QtUtils/SignalBlocking.h"
#include "DolphinQt/Settings.h"
#include "DolphinQt/Settings/USBDeviceAddToWhitelistDialog.h"

Expand Down Expand Up @@ -56,6 +63,7 @@ void WiiPane::CreateLayout()
{
m_main_layout = new QVBoxLayout;
CreateMisc();
CreateSDCard();
CreateWhitelistedUSBPassthroughDevices();
CreateWiiRemoteSettings();
m_main_layout->addStretch(1);
Expand All @@ -73,14 +81,17 @@ void WiiPane::ConnectLayout()
&WiiPane::OnSaveConfig);
connect(m_screensaver_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
connect(m_pal60_mode_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
connect(m_sd_card_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
connect(m_allow_sd_writes_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
connect(m_connect_keyboard_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
connect(&Settings::Instance(), &Settings::SDCardInsertionChanged, m_sd_card_checkbox,
&QCheckBox::setChecked);
connect(&Settings::Instance(), &Settings::USBKeyboardConnectionChanged,
m_connect_keyboard_checkbox, &QCheckBox::setChecked);

// SD Card Settings
connect(m_sd_card_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
connect(m_allow_sd_writes_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
connect(m_sync_sd_folder_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);

// Whitelisted USB Passthrough Devices
connect(m_whitelist_usb_list, &QListWidget::itemClicked, this, &WiiPane::ValidateSelectionState);
connect(m_whitelist_usb_add_button, &QPushButton::clicked, this,
Expand Down Expand Up @@ -108,8 +119,6 @@ void WiiPane::CreateMisc()
m_main_layout->addWidget(misc_settings_group);
m_pal60_mode_checkbox = new QCheckBox(tr("Use PAL60 Mode (EuRGB60)"));
m_screensaver_checkbox = new QCheckBox(tr("Enable Screen Saver"));
m_sd_card_checkbox = new QCheckBox(tr("Insert SD Card"));
m_allow_sd_writes_checkbox = new QCheckBox(tr("Allow Writes to SD Card"));
m_connect_keyboard_checkbox = new QCheckBox(tr("Connect USB Keyboard"));

m_aspect_ratio_choice_label = new QLabel(tr("Aspect Ratio:"));
Expand Down Expand Up @@ -141,20 +150,103 @@ void WiiPane::CreateMisc()
"(576i) for PAL games.\nMay not work for all games."));
m_screensaver_checkbox->setToolTip(tr("Dims the screen after five minutes of inactivity."));
m_system_language_choice->setToolTip(tr("Sets the Wii system language."));
m_sd_card_checkbox->setToolTip(tr("Supports SD and SDHC. Default size is 128 MB."));
m_connect_keyboard_checkbox->setToolTip(tr("May cause slow down in Wii Menu and some games."));

misc_settings_group_layout->addWidget(m_pal60_mode_checkbox, 0, 0, 1, 1);
misc_settings_group_layout->addWidget(m_sd_card_checkbox, 0, 1, 1, 1);
misc_settings_group_layout->addWidget(m_connect_keyboard_checkbox, 0, 1, 1, 1);
misc_settings_group_layout->addWidget(m_screensaver_checkbox, 1, 0, 1, 1);
misc_settings_group_layout->addWidget(m_allow_sd_writes_checkbox, 1, 1, 1, 1);
misc_settings_group_layout->addWidget(m_connect_keyboard_checkbox, 2, 1, 1, 1);
misc_settings_group_layout->addWidget(m_aspect_ratio_choice_label, 3, 0, 1, 1);
misc_settings_group_layout->addWidget(m_aspect_ratio_choice, 3, 1, 1, 1);
misc_settings_group_layout->addWidget(m_system_language_choice_label, 4, 0, 1, 1);
misc_settings_group_layout->addWidget(m_system_language_choice, 4, 1, 1, 1);
misc_settings_group_layout->addWidget(m_sound_mode_choice_label, 5, 0, 1, 1);
misc_settings_group_layout->addWidget(m_sound_mode_choice, 5, 1, 1, 1);
misc_settings_group_layout->addWidget(m_aspect_ratio_choice_label, 2, 0, 1, 1);
misc_settings_group_layout->addWidget(m_aspect_ratio_choice, 2, 1, 1, 1);
misc_settings_group_layout->addWidget(m_system_language_choice_label, 3, 0, 1, 1);
misc_settings_group_layout->addWidget(m_system_language_choice, 3, 1, 1, 1);
misc_settings_group_layout->addWidget(m_sound_mode_choice_label, 4, 0, 1, 1);
misc_settings_group_layout->addWidget(m_sound_mode_choice, 4, 1, 1, 1);
}

void WiiPane::CreateSDCard()
{
auto* sd_settings_group = new QGroupBox(tr("SD Card Settings"));
auto* sd_settings_group_layout = new QGridLayout();
sd_settings_group->setLayout(sd_settings_group_layout);
m_main_layout->addWidget(sd_settings_group);

int row = 0;
m_sd_card_checkbox = new QCheckBox(tr("Insert SD Card"));
m_sd_card_checkbox->setToolTip(tr("Supports SD and SDHC. Default size is 128 MB."));
m_allow_sd_writes_checkbox = new QCheckBox(tr("Allow Writes to SD Card"));
sd_settings_group_layout->addWidget(m_sd_card_checkbox, row, 0, 1, 1);
sd_settings_group_layout->addWidget(m_allow_sd_writes_checkbox, row, 1, 1, 1);
++row;

{
QHBoxLayout* hlayout = new QHBoxLayout;
m_sd_raw_edit = new QLineEdit(QString::fromStdString(File::GetUserPath(F_WIISDCARDIMAGE_IDX)));
connect(m_sd_raw_edit, &QLineEdit::editingFinished,
[this] { SetSDRaw(m_sd_raw_edit->text()); });
QPushButton* sdcard_open = new NonDefaultQPushButton(QStringLiteral("..."));
connect(sdcard_open, &QPushButton::clicked, this, &WiiPane::BrowseSDRaw);
hlayout->addWidget(new QLabel(tr("SD Card Path:")));
hlayout->addWidget(m_sd_raw_edit);
hlayout->addWidget(sdcard_open);

sd_settings_group_layout->addLayout(hlayout, row, 0, 1, 2);
++row;
}

m_sync_sd_folder_checkbox =
new QCheckBox(tr("Automatically sync with Folder on emulation start and end"));
sd_settings_group_layout->addWidget(m_sync_sd_folder_checkbox, row, 0, 1, 2);
++row;

{
QHBoxLayout* hlayout = new QHBoxLayout;
m_sd_sync_folder_edit =
new QLineEdit(QString::fromStdString(File::GetUserPath(D_WIISDCARDSYNCFOLDER_IDX)));
connect(m_sd_sync_folder_edit, &QLineEdit::editingFinished,
[this] { SetSDSyncFolder(m_sd_sync_folder_edit->text()); });
QPushButton* sdcard_open = new NonDefaultQPushButton(QStringLiteral("..."));
connect(sdcard_open, &QPushButton::clicked, this, &WiiPane::BrowseSDSyncFolder);
hlayout->addWidget(new QLabel(tr("SD Sync Folder:")));
hlayout->addWidget(m_sd_sync_folder_edit);
hlayout->addWidget(sdcard_open);

sd_settings_group_layout->addLayout(hlayout, row, 0, 1, 2);
++row;
}

QPushButton* pack_now = new NonDefaultQPushButton(tr("Convert Folder to File now"));
QPushButton* unpack_now = new NonDefaultQPushButton(tr("Convert File to Folder now"));
connect(pack_now, &QPushButton::clicked, [this] {
auto result = ModalMessageBox::warning(
this, tr("Convert Folder to File now"),
tr("You are about to convert the content of the folder at %1 into the file at %2. All "
"current content of the file will be deleted. Are you sure you want to continue?")
.arg(QString::fromStdString(File::GetUserPath(D_WIISDCARDSYNCFOLDER_IDX)))
.arg(QString::fromStdString(File::GetUserPath(F_WIISDCARDIMAGE_IDX))),
QMessageBox::Yes | QMessageBox::No);
if (result == QMessageBox::Yes)
{
if (!Common::SyncSDFolderToSDImage(false))
ModalMessageBox::warning(this, tr("Convert Folder to File now"), tr("Conversion failed."));
}
});
connect(unpack_now, &QPushButton::clicked, [this] {
auto result = ModalMessageBox::warning(
this, tr("Convert File to Folder now"),
tr("You are about to convert the content of the file at %2 into the folder at %1. All "
"current content of the folder will be deleted. Are you sure you want to continue?")
.arg(QString::fromStdString(File::GetUserPath(D_WIISDCARDSYNCFOLDER_IDX)))
.arg(QString::fromStdString(File::GetUserPath(F_WIISDCARDIMAGE_IDX))),
QMessageBox::Yes | QMessageBox::No);
if (result == QMessageBox::Yes)
{
if (!Common::SyncSDImageToSDFolder())
ModalMessageBox::warning(this, tr("Convert File to Folder now"), tr("Conversion failed."));
}
});
sd_settings_group_layout->addWidget(pack_now, row, 0, 1, 1);
sd_settings_group_layout->addWidget(unpack_now, row, 1, 1, 1);
++row;
}

void WiiPane::CreateWhitelistedUSBPassthroughDevices()
Expand Down Expand Up @@ -232,13 +324,15 @@ void WiiPane::LoadConfig()
{
m_screensaver_checkbox->setChecked(Config::Get(Config::SYSCONF_SCREENSAVER));
m_pal60_mode_checkbox->setChecked(Config::Get(Config::SYSCONF_PAL60));
m_sd_card_checkbox->setChecked(Settings::Instance().IsSDCardInserted());
m_allow_sd_writes_checkbox->setChecked(Config::Get(Config::MAIN_ALLOW_SD_WRITES));
m_connect_keyboard_checkbox->setChecked(Settings::Instance().IsUSBKeyboardConnected());
m_aspect_ratio_choice->setCurrentIndex(Config::Get(Config::SYSCONF_WIDESCREEN));
m_system_language_choice->setCurrentIndex(Config::Get(Config::SYSCONF_LANGUAGE));
m_sound_mode_choice->setCurrentIndex(Config::Get(Config::SYSCONF_SOUND_MODE));

m_sd_card_checkbox->setChecked(Settings::Instance().IsSDCardInserted());
m_allow_sd_writes_checkbox->setChecked(Config::Get(Config::MAIN_ALLOW_SD_WRITES));
m_sync_sd_folder_checkbox->setChecked(Config::Get(Config::MAIN_WII_SD_CARD_ENABLE_FOLDER_SYNC));

PopulateUSBPassthroughListWidget();

m_wiimote_ir_sensor_position->setCurrentIndex(
Expand All @@ -254,8 +348,6 @@ void WiiPane::OnSaveConfig()

Config::SetBase(Config::SYSCONF_SCREENSAVER, m_screensaver_checkbox->isChecked());
Config::SetBase(Config::SYSCONF_PAL60, m_pal60_mode_checkbox->isChecked());
Settings::Instance().SetSDCardInserted(m_sd_card_checkbox->isChecked());
Config::SetBase(Config::MAIN_ALLOW_SD_WRITES, m_allow_sd_writes_checkbox->isChecked());
Settings::Instance().SetUSBKeyboardConnected(m_connect_keyboard_checkbox->isChecked());

Config::SetBase<u32>(Config::SYSCONF_SENSOR_BAR_POSITION,
Expand All @@ -266,6 +358,11 @@ void WiiPane::OnSaveConfig()
Config::SetBase<bool>(Config::SYSCONF_WIDESCREEN, m_aspect_ratio_choice->currentIndex());
Config::SetBase<u32>(Config::SYSCONF_SOUND_MODE, m_sound_mode_choice->currentIndex());
Config::SetBase(Config::SYSCONF_WIIMOTE_MOTOR, m_wiimote_motor->isChecked());

Settings::Instance().SetSDCardInserted(m_sd_card_checkbox->isChecked());
Config::SetBase(Config::MAIN_ALLOW_SD_WRITES, m_allow_sd_writes_checkbox->isChecked());
Config::SetBase(Config::MAIN_WII_SD_CARD_ENABLE_FOLDER_SYNC,
m_sync_sd_folder_checkbox->isChecked());
}

void WiiPane::ValidateSelectionState()
Expand Down Expand Up @@ -307,3 +404,35 @@ void WiiPane::PopulateUSBPassthroughListWidget()
}
ValidateSelectionState();
}

void WiiPane::BrowseSDRaw()
{
QString file = QDir::toNativeSeparators(DolphinFileDialog::getOpenFileName(
this, tr("Select a SD Card Image"),
QString::fromStdString(Config::Get(Config::MAIN_WII_SD_CARD_IMAGE_PATH)),
tr("SD Card Image (*.raw);;"
"All Files (*)")));
if (!file.isEmpty())
SetSDRaw(file);
}

void WiiPane::SetSDRaw(const QString& path)
{
Config::SetBase(Config::MAIN_WII_SD_CARD_IMAGE_PATH, path.toStdString());
SignalBlocking(m_sd_raw_edit)->setText(path);
}

void WiiPane::BrowseSDSyncFolder()
{
QString file = QDir::toNativeSeparators(DolphinFileDialog::getExistingDirectory(
this, tr("Select a Folder to sync with the SD Card Image"),
QString::fromStdString(Config::Get(Config::MAIN_WII_SD_CARD_SYNC_FOLDER_PATH))));
if (!file.isEmpty())
SetSDSyncFolder(file);
}

void WiiPane::SetSDSyncFolder(const QString& path)
{
Config::SetBase(Config::MAIN_WII_SD_CARD_SYNC_FOLDER_PATH, path.toStdString());
SignalBlocking(m_sd_sync_folder_edit)->setText(path);
}
25 changes: 19 additions & 6 deletions Source/Core/DolphinQt/Settings/WiiPane.h
Expand Up @@ -5,13 +5,15 @@

#include <QWidget>

class QCheckBox;
class QComboBox;
class QLabel;
class QSlider;
class QVBoxLayout;
class QLineEdit;
class QListWidget;
class QPushButton;
class QComboBox;
class QCheckBox;
class QSlider;
class QString;
class QVBoxLayout;

class WiiPane : public QWidget
{
Expand All @@ -24,6 +26,7 @@ class WiiPane : public QWidget
void CreateLayout();
void ConnectLayout();
void CreateMisc();
void CreateSDCard();
void CreateWhitelistedUSBPassthroughDevices();
void CreateWiiRemoteSettings();

Expand All @@ -36,14 +39,17 @@ class WiiPane : public QWidget
void OnUSBWhitelistAddButton();
void OnUSBWhitelistRemoveButton();

void BrowseSDRaw();
void SetSDRaw(const QString& path);
void BrowseSDSyncFolder();
void SetSDSyncFolder(const QString& path);

// Widgets
QVBoxLayout* m_main_layout;

// Misc Settings
QCheckBox* m_screensaver_checkbox;
QCheckBox* m_pal60_mode_checkbox;
QCheckBox* m_sd_card_checkbox;
QCheckBox* m_allow_sd_writes_checkbox;
QCheckBox* m_connect_keyboard_checkbox;
QComboBox* m_system_language_choice;
QLabel* m_system_language_choice_label;
Expand All @@ -52,6 +58,13 @@ class WiiPane : public QWidget
QComboBox* m_sound_mode_choice;
QLabel* m_sound_mode_choice_label;

// SD Card Settings
QCheckBox* m_sd_card_checkbox;
QCheckBox* m_allow_sd_writes_checkbox;
QCheckBox* m_sync_sd_folder_checkbox;
QLineEdit* m_sd_raw_edit;
QLineEdit* m_sd_sync_folder_edit;

// Whitelisted USB Passthrough Devices
QListWidget* m_whitelist_usb_list;
QPushButton* m_whitelist_usb_add_button;
Expand Down
5 changes: 4 additions & 1 deletion Source/Core/UICommon/UICommon.cpp
Expand Up @@ -91,7 +91,10 @@ static void InitCustomPaths()
CreateDumpPath(Config::Get(Config::MAIN_DUMP_PATH));
CreateResourcePackPath(Config::Get(Config::MAIN_RESOURCEPACK_PATH));
CreateWFSPath(Config::Get(Config::MAIN_WFS_PATH));
File::SetUserPath(F_WIISDCARD_IDX, Config::Get(Config::MAIN_SD_PATH));
File::SetUserPath(F_WIISDCARDIMAGE_IDX, Config::Get(Config::MAIN_WII_SD_CARD_IMAGE_PATH));
File::SetUserPath(D_WIISDCARDSYNCFOLDER_IDX,
Config::Get(Config::MAIN_WII_SD_CARD_SYNC_FOLDER_PATH));
File::CreateFullPath(File::GetUserPath(D_WIISDCARDSYNCFOLDER_IDX));
#ifdef HAS_LIBMGBA
File::SetUserPath(F_GBABIOS_IDX, Config::Get(Config::MAIN_GBA_BIOS_PATH));
File::SetUserPath(D_GBASAVES_IDX, Config::Get(Config::MAIN_GBA_SAVES_PATH));
Expand Down
1 change: 1 addition & 0 deletions Source/VSProps/Base.props
Expand Up @@ -35,6 +35,7 @@
<AdditionalIncludeDirectories>$(ExternalsDir)ed25519;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ExternalsDir)enet\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ExternalsDir)FFmpeg-bin\$(Platform)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ExternalsDir)FatFs;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ExternalsDir)fmt\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ExternalsDir)GL;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ExternalsDir)glslang;$(ExternalsDir)glslang\StandAlone;$(ExternalsDir)glslang\glslang\Public;$(ExternalsDir)glslang\SPIRV;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
Expand Down
11 changes: 11 additions & 0 deletions Source/dolphin-emu.sln
Expand Up @@ -83,6 +83,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spirv_cross", "..\Externals
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2", "..\Externals\SDL\SDL2.vcxproj", "{8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FatFs", "..\Externals\FatFs\FatFs.vcxproj", "{3F17D282-A77D-4931-B844-903AD0809A5E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Expand Down Expand Up @@ -399,6 +401,14 @@ Global
{8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}.Release|ARM64.Build.0 = Release|ARM64
{8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}.Release|x64.ActiveCfg = Release|x64
{8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}.Release|x64.Build.0 = Release|x64
{3F17D282-A77D-4931-B844-903AD0809A5E}.Debug|ARM64.ActiveCfg = Debug|ARM64
{3F17D282-A77D-4931-B844-903AD0809A5E}.Debug|ARM64.Build.0 = Debug|ARM64
{3F17D282-A77D-4931-B844-903AD0809A5E}.Debug|x64.ActiveCfg = Debug|x64
{3F17D282-A77D-4931-B844-903AD0809A5E}.Debug|x64.Build.0 = Debug|x64
{3F17D282-A77D-4931-B844-903AD0809A5E}.Release|ARM64.ActiveCfg = Release|ARM64
{3F17D282-A77D-4931-B844-903AD0809A5E}.Release|ARM64.Build.0 = Release|ARM64
{3F17D282-A77D-4931-B844-903AD0809A5E}.Release|x64.ActiveCfg = Release|x64
{3F17D282-A77D-4931-B844-903AD0809A5E}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -433,6 +443,7 @@ Global
{4BC5A148-0AB3-440F-A980-A29B4B999190} = {87ADDFF9-5768-4DA2-A33B-2477593D6677}
{3D780617-EC8C-4721-B9FD-DFC9BB658C7C} = {87ADDFF9-5768-4DA2-A33B-2477593D6677}
{8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA} = {87ADDFF9-5768-4DA2-A33B-2477593D6677}
{3F17D282-A77D-4931-B844-903AD0809A5E} = {87ADDFF9-5768-4DA2-A33B-2477593D6677}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {64B0A343-3B94-4522-9C24-6937FE5EFB22}
Expand Down