@@ -66,9 +66,7 @@ void loadSettings()
66
66
int resetCount = settings.resetCount ;
67
67
SystemState stateFromLFS = settings.lastState ;
68
68
69
- bool readFromSD = false ;
70
- if (loadSystemSettingsFromFileSD (settingsFileName) == true )
71
- readFromSD = true ;
69
+ loadSystemSettingsFromFileSD (settingsFileName);
72
70
73
71
settings.resetCount = resetCount;
74
72
@@ -77,11 +75,9 @@ void loadSettings()
77
75
78
76
// Change empty profile name to 'Profile1' etc
79
77
if (strlen (settings.profileName ) == 0 )
78
+ {
80
79
snprintf (settings.profileName , sizeof (settings.profileName ), " Profile%d" , profileNumber + 1 );
81
80
82
- // Only re-record settings if SD was accessed
83
- if (readFromSD == true )
84
- {
85
81
// Record these settings to LittleFS and SD file to be sure they are the same
86
82
recordSystemSettings ();
87
83
}
@@ -593,6 +589,9 @@ void recordSystemSettingsToFile(File *settingsFile)
593
589
// Don't update settings when searching.
594
590
bool loadSystemSettingsFromFileSD (char *fileName, const char *findMe, char *found, int len)
595
591
{
592
+ if ((findMe != nullptr ) && (found != nullptr ))
593
+ *found = 0 ; // If searching, set found to NULL
594
+
596
595
bool gotSemaphore = false ;
597
596
bool status = false ;
598
597
bool wasSdCardOnline;
@@ -719,6 +718,9 @@ bool loadSystemSettingsFromFileLFS(char *fileName, const char *findMe, char *fou
719
718
{
720
719
// log_d("reading setting fileName: %s", fileName);
721
720
721
+ if ((findMe != nullptr ) && (found != nullptr ))
722
+ *found = 0 ; // If searching, set found to NULL
723
+
722
724
File settingsFile = LittleFS.open (fileName, FILE_READ);
723
725
if (!settingsFile)
724
726
{
@@ -768,10 +770,19 @@ bool loadSystemSettingsFromFileLFS(char *fileName, const char *findMe, char *fou
768
770
else
769
771
{
770
772
// Check if line contains findMe. If it does, return the remainder of the line in found.
773
+ // Don't copy the \r or \n
771
774
const char *ptr = strstr (line, findMe);
772
775
if (ptr != nullptr )
773
776
{
774
- strncpy (found, ptr + strlen (findMe), len);
777
+ ptr += strlen (findMe);
778
+ for (size_t i = strlen (findMe); i < strlen (line); i++)
779
+ {
780
+ if ((line[i] == ' \r ' ) || (line[i] == ' \n ' ))
781
+ {
782
+ line[i] = 0 ;
783
+ }
784
+ }
785
+ strncpy (found, ptr, len);
775
786
break ;
776
787
}
777
788
}
@@ -1450,21 +1461,21 @@ void setProfileName(uint8_t ProfileNumber)
1450
1461
// Looks at LittleFS first, then SD
1451
1462
bool getProfileName (char *fileName, char *profileName, uint8_t profileNameLength)
1452
1463
{
1453
- char profileNameLFS[50 ] = " " ;
1464
+ char profileNameLFS[50 ];
1454
1465
loadSystemSettingsFromFileLFS (fileName, " profileName=" , profileNameLFS, sizeof (profileNameLFS));
1455
- char profileNameSD[50 ] = " " ;
1466
+ char profileNameSD[50 ];
1456
1467
loadSystemSettingsFromFileSD (fileName, " profileName=" , profileNameSD, sizeof (profileNameSD));
1457
1468
1458
1469
// Zero terminate the profile name
1459
1470
*profileName = 0 ;
1460
1471
1461
1472
// If we have a profile in both LFS and SD, SD wins
1462
- if (profileNameLFS != " " )
1473
+ if (strlen ( profileNameLFS) > 0 )
1463
1474
strncpy (profileName, profileNameLFS, profileNameLength); // snprintf handles null terminator
1464
- if (profileNameSD != " " )
1475
+ if (strlen ( profileNameSD) > 0 )
1465
1476
strncpy (profileName, profileNameSD, profileNameLength); // snprintf handles null terminator
1466
1477
1467
- return ((profileNameLFS != " " ) || (profileNameSD != " " ));
1478
+ return ((strlen ( profileNameLFS) > 0 ) || (strlen ( profileNameSD) > 0 ));
1468
1479
}
1469
1480
1470
1481
// Loads a given profile name.
0 commit comments