Fixes #4715: model notes were read from the settings path, but should be read from SD card path (#4728)

This commit is contained in:
Damjan Adamic
2017-04-01 08:11:16 +02:00
committed by Bertrand Songis
parent b22e45cf18
commit 9c7c8244f4
+34 -4
View File
@@ -101,16 +101,46 @@ void simuFatfsSetPaths(const char * sdPath, const char * settingsPath)
TRACE_SIMPGMSPACE("simuFatfsSetPaths(): simuSettingsDirectory: \"%s\"", simuSettingsDirectory.c_str()); TRACE_SIMPGMSPACE("simuFatfsSetPaths(): simuSettingsDirectory: \"%s\"", simuSettingsDirectory.c_str());
} }
bool startsWith(const char *path, const char * start) bool startsWith(const std::string & str, const std::string & prefix)
{ {
return strncasecmp(path, start, strlen(start)) == 0; return str.length() >= prefix.length() &&
str.compare(0, prefix.length(), prefix) == 0;
}
bool endsWith(const std::string & str, const std::string & suffix)
{
return str.length() >= suffix.length() &&
str.compare(str.length() - suffix.length(), suffix.length(), suffix) == 0;
}
bool redirectToSettingsDirectory(const std::string & path)
{
/*
Decide if we use special simuSettingsDirectory path or normal path
We use special path for:
* radio settings and models list in /RADIO directory
* model (*.bin) files in /MODELS directory
*/
if (!simuSettingsDirectory.empty()) {
#if defined(COLORLCD)
if (path == RADIO_MODELSLIST_PATH || path == RADIO_SETTINGS_PATH) {
return true;
}
#endif
if (startsWith(path, "/MODELS") && endsWith(path, MODELS_EXT)) {
return true;
}
}
return false;
} }
std::string convertToSimuPath(const char * path) std::string convertToSimuPath(const char * path)
{ {
std::string result; std::string result;
if (isPathDelimiter(path[0])) { if (isPathDelimiter(path[0])) {
if (!simuSettingsDirectory.empty() && (startsWith(path, "/MODELS") || startsWith(path, "/RADIO"))) { if (redirectToSettingsDirectory(path)) {
// TRACE("REDIRECT ********************************************");
result = simuSettingsDirectory + std::string(path); result = simuSettingsDirectory + std::string(path);
} }
else { else {
@@ -127,7 +157,7 @@ std::string convertToSimuPath(const char * path)
std::string convertFromSimuPath(const char * path) std::string convertFromSimuPath(const char * path)
{ {
std::string result; std::string result;
if (startsWith(path, simuSdDirectory.c_str())) { if (startsWith(path, simuSdDirectory)) {
result = std::string(path).substr(simuSdDirectory.length(), std::string::npos); result = std::string(path).substr(simuSdDirectory.length(), std::string::npos);
if (result.empty()) { if (result.empty()) {
result = "/"; result = "/";