16
16
*/
17
17
18
18
#include " definitions_cxx.hpp"
19
+ #include " fatfs.hpp"
19
20
#include " hid/button.h"
20
21
#include " model/sample/sample.h"
22
+ #include " util/try.h"
21
23
#include < ranges>
22
24
#undef __GNU_VISIBLE
23
25
#define __GNU_VISIBLE 1 // Makes strcasestr visible. Might already be the reason for the define above
@@ -1191,11 +1193,10 @@ bool SampleBrowser::loadAllSamplesInFolder(bool detectPitch, int32_t* getNumSamp
1191
1193
previouslyViewedFilename = currentFileItem->filename .get ();
1192
1194
}
1193
1195
1194
- FRESULT result = f_opendir (&staticDIR, dirToLoad.get ());
1195
- if (result != FR_OK) {
1196
+ staticDIR = D_TRY_CATCH (FatFS::Directory::open (dirToLoad.get ()), error, {
1196
1197
display->displayError (Error::SD_CARD);
1197
1198
return false ;
1198
- }
1199
+ });
1199
1200
1200
1201
int32_t numSamples = 0 ;
1201
1202
@@ -1240,10 +1241,13 @@ bool SampleBrowser::loadAllSamplesInFolder(bool detectPitch, int32_t* getNumSamp
1240
1241
audioFileManager.loadAnyEnqueuedClusters ();
1241
1242
FilePointer thisFilePointer;
1242
1243
1243
- result = f_readdir_get_filepointer (&staticDIR, &staticFNO, &thisFilePointer); /* Read a directory item */
1244
+ /* Read a directory item */
1245
+ std::tie (staticFNO, thisFilePointer) = D_TRY_CATCH (staticDIR.read_and_get_filepointer (), error, {
1246
+ break ; // break on error
1247
+ });
1244
1248
1245
- if (result != FR_OK || staticFNO.fname [0 ] == 0 ) {
1246
- break ; // Break on error or end of dir
1249
+ if (staticFNO.fname [0 ] == 0 ) {
1250
+ break ; // Break on end of dir
1247
1251
}
1248
1252
if (staticFNO.fname [0 ] == ' .' ) {
1249
1253
continue ; // Ignore dot entry
@@ -1278,7 +1282,7 @@ bool SampleBrowser::loadAllSamplesInFolder(bool detectPitch, int32_t* getNumSamp
1278
1282
1279
1283
if (!maybeNewSample.has_value () || maybeNewSample.value () == nullptr ) {
1280
1284
error = maybeNewSample.error_or (Error::NONE);
1281
- f_closedir (& staticDIR);
1285
+ staticDIR. close ( );
1282
1286
goto removeReasonsFromSamplesAndGetOut;
1283
1287
}
1284
1288
@@ -1301,7 +1305,7 @@ bool SampleBrowser::loadAllSamplesInFolder(bool detectPitch, int32_t* getNumSamp
1301
1305
1302
1306
numSamples++;
1303
1307
}
1304
- f_closedir (& staticDIR);
1308
+ staticDIR. close ( );
1305
1309
1306
1310
if (getPrefixAndDirLength) {
1307
1311
// If just one file, there's no prefix.
@@ -1872,7 +1876,7 @@ bool SampleBrowser::importFolderAsKit() {
1872
1876
range = source->getOrCreateFirstRange ();
1873
1877
if (!range) {
1874
1878
getOut:
1875
- f_closedir (& staticDIR);
1879
+ staticDIR. close ( );
1876
1880
display->displayError (Error::INSUFFICIENT_RAM);
1877
1881
goto doReturnFalse;
1878
1882
}
0 commit comments